Re: compiler generated output



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

.



Relevant Pages

  • Re: Creationist Math
    ... >>Zoe says that dividing by zero is the same as not dividing, ... Does that mean I am going to Hell, ...
    (talk.origins)
  • Re: Interesting math
    ... infinite number for that reason. ... divisor approaches zero the result grows larger and larger. ... dividend is constant. ...
    (alt.usage.english)
  • Re: Interesting math
    ... infinite number for that reason. ... divisor approaches zero the result grows larger and larger. ... dividend is constant. ...
    (alt.usage.english)
  • Re: #Num! Error
    ... Use IIfto test for zero in the divisor: ... When there is a number in the divisor, ... > but when the divisor is zero (the dividend is always zero at that point as ... The control source for this control is: ...
    (microsoft.public.access.reports)
  • Re: Admired designs / designs to study
    ... instructions to try to pack together a whole word ... resort to using one of the string or bit move ... Get the next character from the ... if the number isn't zero yet. ...
    (comp.arch)