"be consistent" PerlMonks

### Re^2: emulate 32-bit on perl 64

by loofort (Initiate)
 on Jan 11, 2012 at 15:17 UTC ( #947360=note: print w/replies, xml ) Need Help??

in reply to Re: emulate 32-bit on perl 64
in thread emulate 32-bit on perl 64

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;

}

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;
}

Replies are listed 'Best First'.
Re^3: emulate 32-bit on perl 64
by Corion (Pope) on Jan 11, 2012 at 15:24 UTC

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.

Re^3: emulate 32-bit on perl 64
by BrowserUk (Pope) on Jan 11, 2012 at 15:54 UTC

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;

}

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?

Re^3: emulate 32-bit on perl 64
by BrowserUk (Pope) on Jan 11, 2012 at 16:06 UTC

```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?

Create A New User
Node Status?
node history
Node Type: note [id://947360]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-03-23 04:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
When I think of a mole I think of:

Results (287 votes). Check out past polls.

Notices?