Re: compiler generated output
- From: "Gerd Isenberg" <spamtrap@xxxxxxxxxx>
- Date: Wed, 26 Oct 2005 23:21:55 +0000 (UTC)
Hi Spiro,
yes, some clever way of parallel execution of two branches.
If the dividend is positive or zero, edx becomes zero after cdq.
Then only "and eax, (2^n - 1, here 7)" does the positive mod 8.
All other three instructions, and 0,7 add0,sub0 are nops in this case.
If dividend is negative, edx becomes -1 or 0xffffffff after cdq, or 7
after "and edx,7".
We need -8,-16...% 8 == 0.
-8 is 11...11000B, like +8 all multiplies of -8 have the three least
significant bits 0..2 cleared, but of course -8*{1,2,3...} has at least
the sign bit set.
Doing the +7,&7,-7 sequence here results in the desired zero - no add
overflow to bit 3 or later borrow after "and" occurs (making the
remainder negative). Negative dividends with bit 0..2 != zero become
the negative remainders:
eax +7 &7 -7 => %8
-1 6 6 -1
-2 5 5 -2
-3 4 4 -3
-4 3 3 -4
-5 2 2 -5
-6 1 1 -6
-7 0 0 -7
-8 -1 7 0
-9 -2 6 -1
cycle closed ....
If we like to implement a hash-fuction with this signed power of two
modulo, we have to consider that we get a value range with odd elements
;-)
Cheers,
Gerd
.
- 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
- From: Gerd Isenberg
- Re: compiler generated output
- From: Spiro Trikaliotis
- Re: compiler generated output
- Prev by Date: Re: Combining two MMX registers into one SSE register?
- Next by Date: Re: Combining two MMX registers into one SSE register?
- Previous by thread: Re: compiler generated output
- Next by thread: Re: compiler generated output
- Index(es):
Relevant Pages
|