assembly - Delphi inline assembler and class properties -
i trying rewrite tlist.indexof method in assembler (xe3). here code
function tfastlist.indexofasm(item: pointer): integer; {var p: ppointer; begin p := pointer(flist); result := 0 fcount - 1 begin if p^ = item exit; inc(p); end; result := -1;} var fcnt, rslt: integer; fdata: pointer; begin fcnt := count; fdata := list; asm push edi mov ecx, fcnt mov edi, fdata mov eax, item repne scasd mov eax, fcnt sub eax, ecx dec eax mov rslt, eax pop edi end; result := rslt; end;
naturally use properties count or list directly. understand why compiler refuses give access private fields fcount , flist, how access corresponding properties? count, self.count, , [eax].count give inline assembler error.
jic: don't handle not found situation here intent
you can't access object property via delphi assembler!
delphi compiler , delphi compiled code belive fast.
your code has mistake because doesn't test 0 count velue should cause memory access violation!
do not use repne scasd
because slow.
however can hack code manualy make test... :)
function tfastlist.indexofasm(item: pointer): integer; //eax = self //edx = item {var p: ppointer; begin p := pointer(flist); result := 0 fcount - 1 begin if p^ = item exit; inc(p); end; result := -1;} const fitems = 4; //data offset of fitems fcount = 8; //data offset of fcount asm mov ecx, [eax].fitems //ecx = @fitems mov eax, [eax].fcount //eax = fcount dec eax //test 0 count! js @exit //if count 0 exit -1 @loop: //repeat cmp item, [ecx + eax * 4] jz @exit dec eax jns @loop //until eax < 0 (actually -1) @exit: end;
Comments
Post a Comment