BeRo1985 / flre

FLRE - Fast Light Regular Expressions - A fast light regular expression library
GNU Lesser General Public License v2.1
94 stars 23 forks source link

PtrPosCharPairSearch not working with valgrind #79

Open benibela opened 3 years ago

benibela commented 3 years ago

Consider:

var s: string;
begin
 s := 'ABRACA';
 s += 'DABRA';
 writeln(PtrPosCharPair('A', 'B', pchar(s), 11, 2));

Prints 5 as it should.

Calling the same program with valgrind, it prints -1 (PtrPosCharPairSearch returns 0)

fpc 3.2.2 on linux64, valgrind-3.16.1

When I tried to initialized the string with s := 'ABRACADABRA', it worked the first time even with valgrind, but now it stopped working.

It also seems to work with every other string. Like 'xABRACADABRA'. Or

 for i := 1 to 10 do begin
   s := '';
   s += 'ABRACA';
   for j := 1 to i do s += 'A';
   s += 'DABRA';
   writeln(PtrPosCharPair('A', 'B', pchar(s), 11 + i, 2  ));
 end;
benibela commented 3 years ago
movdqa xmm2,[rdi]
movdqa xmm3,[rdi]
movdqa xmm4,[rdi+16]
movdqa xmm5,[rdi+16]

That assumes rdi is aligned, does it not?

But it is not aligned since the offset is 2...

edit: Ok, the and rdi,-32 makes it aligned. But then it is reading from the string header