Re: compiler generated output



Oups - nonsense - sorry.
My "optimal" signed modulo assembly for 32-bit DWORDS is wrong because
it calcs -8,-16... mod 8 was -8 instead 0.

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.

with this possible C-Code to emulate it - if compiler is not able to
generate it with %.

int deltaMod8 (int a, int b)
{
int delta = a - b;
int signx = (delta >> 31) & 7; // arithmetic shift - like cdq
delta += signx;
delta &= 7;
delta -= signx;
return delta;
}

- Gerd

.



Relevant Pages