in reply to Re: Pure perl Jenkins 32 bit Hash
in thread Pure perl Jenkins 32 bit Hash
Doing low-level unsigned arithmetic can be awkward in perl.
yupo
ok so i developed an overly debugged version of mix and the revised mix4 and ran it on the 32 bit box
# this is inside a 'use integer;' block sub mix4 ($$$) { # per http://www.perlmonks.org/?node_id=1203705 this is a revised 32bi +t under 'use integer'; $_[A] -= $_[B]; $_[A] -= $_[C]; { no integer; $_[A] ^= ($_[C]>>13) +; } $_[B] -= $_[C]; $_[B] -= $_[A]; { no integer; $_[B] ^= ($_[A]<< 8) +; } $_[C] -= $_[A]; $_[C] -= $_[B]; { no integer; $_[C] ^= ($_[B]>>13) +; } $_[A] -= $_[B]; $_[A] -= $_[C]; { no integer; $_[A] ^= ($_[C]>>12) +; } $_[B] -= $_[C]; $_[B] -= $_[A]; { no integer; $_[B] ^= ($_[A]<<16) +; } $_[C] -= $_[A]; $_[C] -= $_[B]; { no integer; $_[C] ^= ($_[B]>> 5) +; } $_[A] -= $_[B]; $_[A] -= $_[C]; { no integer; $_[A] ^= ($_[C]>> 3) +; } $_[B] -= $_[C]; $_[B] -= $_[A]; { no integer; $_[B] ^= ($_[A]<<10) +; } $_[C] -= $_[A]; $_[C] -= $_[B]; { no integer; $_[C] ^= ($_[B]>>15) +; } }
This is mix
and the results are very interesting# there is no 'use integer;' here; sub mix ($$$) { $_[A] -= $_[B]; $_[A] -= $_[C]; $_[A] ^= ($_[C]>>13); $_[B] -= $_[C]; $_[B] -= $_[A]; $_[B] ^= ($_[A]<< 8); $_[C] -= $_[A]; $_[C] -= $_[B]; $_[C] ^= ($_[B]>>13); $_[A] -= $_[B]; $_[A] -= $_[C]; $_[A] ^= ($_[C]>>12); $_[B] -= $_[C]; $_[B] -= $_[A]; $_[B] ^= ($_[A]<<16); $_[C] -= $_[A]; $_[C] -= $_[B]; $_[C] ^= ($_[B]>> 5); $_[A] -= $_[B]; $_[A] -= $_[C]; $_[A] ^= ($_[C]>> 3); $_[B] -= $_[C]; $_[B] -= $_[A]; $_[B] ^= ($_[A]<<10); $_[C] -= $_[A]; $_[C] -= $_[B]; $_[C] ^= ($_[B]>>15); }
during the first modification of C mix4exp shows (it is best to look at the following using download version without wrap)
The Dump calls are Dump($_[C]);a1-x c>13 : A : 59743 0000e95f b1-x a< 8 : B : - -162 +9499560 9edfcf58 c1-a : C : - + - -59741 ffff16a3 SV = IV(0xc5f738) at 0xc5f73c REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = -59741 c1-b : C : - + - 1629439819 611f474b SV = IV(0xc5f738) at 0xc5f73c REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = 1629439819 c1-x b>13 : orig 1 : 01100 +001000111110100011101001011 611f474b : orig 2 : 10011 +110110111111100111101011000 9edfcf58 : >>13 : 00000 +000000001001111011011111110 0004f6fe : res : 01100 +001000110111011000110110101 611bb1b5 c1-x b>13 : C : - + - 1629204917 611bb1b5 while mixexp shows a1-x c>13 : A : 59743 0000e95f b1-x a< 8 : B : - -162 +9499560 9edfcf58 c1-a : C : - + - -59741 ffff16a3 SV = IV(0xc5f418) at 0xc5f41c REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = -59741 c1-b : C : - + - -2147483648 80000000 SV = PVNV(0xc7355c) at 0xc5f41c REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) IV = -59741 NV = -2665527477 PV = 0 c1-x b>13 : orig 1 : 10000 +000000000000000000000000000 80000000 : orig 2 : 10011 +110110111111100111101011000 9edfcf58 : >>13 : 00000 +000000001001111011011111110 0004f6fe : res : 10000 +000000001001111011011111110 8004f6fe c1-x b>13 : C : - + - -2147158274 8004f6fe
Notice that in mix4exp the Dump shows C stays IV, and shows the proper result of mod(32) arithmetic with A and B .
But notice how in mixexp the Dump shows that after -=A C has stayed IV, with the proper result, but that after -=B C overflowed the IV creating a NV and when it comes to the shift portion it is an overflow indicator (0x80000000) that gets shifted. Of course everything goes to L in a handbasket after that.
Doing low-level unsigned arithmetic can be awkward in perl.
yupo
|
|---|