Re: compiler generated output
- From: "Gerd Isenberg" <spamtrap@xxxxxxxxxx>
- Date: Tue, 25 Oct 2005 17:57:13 +0000 (UTC)
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
.
- Follow-Ups:
- Re: compiler generated output
- From: Spiro Trikaliotis
- Re: compiler generated output
- References:
- Re: compiler generated output
- From: Skarmander
- Re: compiler generated output
- From: Spiro Trikaliotis
- Re: compiler generated output
- From: Gerd Isenberg
- Re: compiler generated output
- Prev by Date: Re: Self-modifying code on SMP operating systems
- Next by Date: Re: improve strlen
- Previous by thread: Re: compiler generated output
- Next by thread: Re: compiler generated output
- Index(es):
Relevant Pages
|