Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: emulate 32-bit on perl 64

by Corion (Pope)
on Jan 11, 2012 at 14:48 UTC ( #947355=note: print w/ replies, xml ) Need Help??


in reply to emulate 32-bit on perl 64

My recommendation is to use 32-bit bitwise operations instead of using unrestricted bitwise operations, or to operate on 64 bits worth of data instead of 32 bits at a time.

As you don't show any code, it is hard to give any more concrete advice. Please post a Short, Self Contained, Correct (Compilable), Example so we can see what the cause for your problem might be and suggest appropriate remedies or workarounds.


Comment on Re: emulate 32-bit on perl 64
Re^2: emulate 32-bit on perl 64
by loofort (Initiate) on Jan 11, 2012 at 15:17 UTC
    I'm not sure that example brings any clearence. I'm not the author and I use it as black box. here is little part::
    for ($h = 16; $h < 80; $h++) { $i[$h] = a2 ($i[$h - 3] ^ $i[$h - 8] ^ $i[$h - 14] ^ $i[$h - 16], +1); } sub a2 { my ($b, $a) = @_; my $c = $b >> 32 - $a; my $e = (1 << 32 - $a) - 1; my $d = $b & $e; return tos($d << $a | $c); } sub tos { my ($num) = @_; $num = $num - 4294967296 if $num > 4294967295; $num = $num + 4294967296 if $num < -2147483648; if ($num >= 0) { $num = $num - 2 ** 32 if ($num >> 31); } return $num; }

      There is no magic to sprinkle over an algorithm that relies on 32-bit integers to make it behave with other integer sizes. The hardcoded numbers here are magic for 32-bit numbers:

      $num = $num - 4294967296 if $num > 4294967295; $num = $num + 4294967296 if $num < -2147483648;

      You will have to understand the algorithm involved to be able to make the required changes. Alternatively, you can run the program under a Perl compiled with 32-bit integers.

      Try this -- 'scuse the formatting, but there's no good way to format it. It produces the same results on 32-bit and 64-bit Perls for one randomly generated set of input data:

      for( my $h = 16; $h < 80; $h++ ) { $i[$h] = a2( ( ( ( ( ( $i[$h - 3] ^ $i[$h - 8] ) & 0xffffffff ) ^ $i[$h - 14] ) & 0xffffffff ) ^ $i[$h - 16] ) & 0xffffffff , 1 ); } print "@i"; sub a2 { my ($b, $a) = @_; my $c = $b >> 32 - $a; my $e = (1 << 32 - $a) - 1; my $d = $b & $e; return tos($d << $a | $c); } sub tos { my ($num) = @_; $num = $num - 4294967296 if $num > 4294967295; $num = $num + 4294967296 if $num < -2147483648; if ($num >= 0) { $num = $num - 2 ** 32 if ($num >> 31); } return $num; }

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

      This is slightly more readable:

      sub fix32{ $_[0] & 0xffffffff } for( my $h = 16; $h < 80; $h++ ) { $i[$h] = a2( fix32( fix32( fix32( $i[$h - 3] ^ $i[$h - 8] ) ^ $i[$h - 14] ) + ^ $i[$h - 16] ) , 1 ); }

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://947355]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (16)
As of 2014-07-31 13:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (248 votes), past polls