#1 2019-04-21 07:06:15

pony5551
Member
Registered: 2018-01-24
Posts: 9

Instruction error in strspnsse42!

SynCommons.pas

descript:

strspnsse42('gggggg', '0123456789abcdefghi') return 0, should be 6


reson:

function strspnsse42(s,accept: pointer): integer;
asm // eax=s, edx=accept
        push    edi
        push    esi
        push    ebx
        mov     edi, eax
        mov     esi, edx
        mov     ebx,  esi
        xor     ecx, ecx
@1:     {$ifdef HASAESNI}
        movdqu  xmm2, dqword [edi]
        movdqu  xmm1, dqword [esi]
        pcmpistrm xmm1, xmm2, $00 //  find in set, return bit mask in xmm0
        movd    eax, xmm0
        {$else}
        db $F3,$0F,$6F,$17
        db $F3,$0F,$6F,$0E
        db $66,$0F,$3A,$62,$CA,$00
        db $66,$0F,$7E,$C0
        {$endif}
        jns     @5
@2:     cmp     ax, -1
        jne     @3
        add     edi, 16 // first 16 chars matched, continue with next 16 chars
        add     ecx, 16
        jmp     @1
@3:     not     eax
        bsf     eax, eax
        add     eax, ecx
        pop     ebx
        pop     esi
        pop     edi
        ret


//*****************************************************************************************************************
@4:     and     eax, edx // accumulate matches  <-------------------------------------- should be or eax, edx
//*****************************************************************************************************************

@5:     add     esi, 16  // the set is more than 16 bytes
        {$ifdef HASAESNI}
        movdqu  xmm1, [esi]
        pcmpistrm xmm1, xmm2, $00
        movd    edx, xmm0
        {$else}
        db $F3,$0F,$6F,$0E
        db $66,$0F,$3A,$62,$CA,$00
        db $66,$0F,$7E,$C2
        {$endif}
        jns     @4
        mov     esi, ebx   // restore set pointer

//*****************************************************************************************************************
        and     eax, edx   // accumulate matches  <------------------------------------- should be or eax, edx
//*****************************************************************************************************************


        jmp     @2
end;


function strspnsse42(s,accept: pointer): integer;
{$ifdef FPC}nostackframe; assembler; asm {$else}
asm // rcx=s, rdx=accept (Linux: rdi,rsi)
        .noframe
{$endif FPC}
{$ifdef win64}
        push    rdi
        push    rsi
        mov     rdi, rcx
        mov     rsi, rdx
{$endif}mov     r8,  rsi
        xor     ecx, ecx
@1:     movdqu  xmm2, [rdi]
        movdqu  xmm1, [rsi]
        {$ifdef HASAESNI}
        pcmpistrm xmm1, xmm2, $00 //  find in set, return bit mask in xmm0
        {$else}
        db $66,$0F,$3A,$62,$CA,$00
        {$endif}
        movd    eax, xmm0
        jns     @5
@2:     cmp     ax, -1
        jne     @3
        add     rdi, 16 // first 16 chars matched, continue with next 16 chars
        add     rcx, 16
        jmp     @1
@3:     not     eax
        bsf     eax, eax
        add     rax, rcx
{$ifdef win64}
        pop     rsi
        pop     rdi
{$endif}ret


//*****************************************************************************************************************
@4:     and     eax, edx // accumulate matches <-------------------------------------- should be or eax, edx
//*****************************************************************************************************************


@5:     add     rsi, 16  // the set is more than 16 bytes
        movdqu  xmm1, [rsi]
        {$ifdef HASAESNI}
        pcmpistrm xmm1, xmm2, $00
        {$else}
        db $66,$0F,$3A,$62,$CA,$00
        {$endif}
        movd    edx, xmm0
        jns     @4
        mov     rsi, r8    // restore set pointer


//*****************************************************************************************************************
        and     eax, edx   // accumulate matches <-------------------------------------- should be or eax, edx
//*****************************************************************************************************************


        jmp     @2
end;

Last edited by pony5551 (2019-04-21 07:07:21)

Offline

#2 2019-04-24 15:42:12

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Instruction error in strspnsse42!

1. Please DO NOT post huge source content in the forum.
See the forum rules - https://synopse.info/forum/misc.php?action=rules

The preferred option is to make a pull request on https://github.com/synopse/mORMot

2. Check https://synopse.info/fossil/info/bea3ace0d2

Offline

Board footer

Powered by FluxBB