Re: compiler generated output



Hello Gerd,

Gerd Isenberg <spamtrap@xxxxxxxxxx> schrieb:


> So the code snipped from AMD Optimization Guide is recommended
>
> Remainder of Signed Division by 2n or -(2n)
> ; In: EAX = dividend
> ; Out: EAX = remainder
> cdq ; Sign extend into EDX.
> and edx, (2^n - 1) ; Mask correction (abs(divisor) - 1)
> add eax, edx ; Apply pre-correction.
> and eax, (2^n - 1) ; Mask out remainder (abs(divisor) - 1)
> sub eax, edx ; Apply pre-correction if necessary.

Well, very interesting. I had to think about that code in order to
understand that it really works. ;)

Regards,
Spiro.

--
Spiro R. Trikaliotis http://cbm4win.sf.net/
http://www.trikaliotis.net/ http://www.viceteam.org/

.



Relevant Pages

  • Re: Amusing C, amusing compiler
    ... mov eax, DWORD PTR _x$ ... sub eax, DWORD PTR _x$ ... mov edx, DWORD PTR _x$ ... It is we that give the understanding to the machines, ...
    (comp.lang.c)
  • Re: Superoptimizer
    ... > SUB EAX, EDX ... > ADC EAX, EDX ...
    (borland.public.delphi.language.basm)
  • Re: Superoptimizer
    ... > mov ecx, 1 ... > sub eax, edx ... > cmovg eax, ecx ...
    (borland.public.delphi.language.basm)