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

# 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); }
and the results are very interesting

during the first modification of C mix4exp shows (it is best to look at the following using download version without wrap)

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
The Dump calls are Dump($_[C]);

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


In reply to Re^2: Pure perl Jenkins 32 bit Hash by huck
in thread Pure perl Jenkins 32 bit Hash by huck

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.