<?xml version="1.0" encoding="windows-1252"?>
<node id="947373" title="Re: emulate 32-bit on perl 64" created="2012-01-11 10:58:33" updated="2012-01-11 10:58:33">
<type id="11">
note</type>
<author id="647953">
sundialsvc4</author>
<data>
<field name="doctext">
&lt;p&gt;
Probably the key improvement here &lt;em&gt;is&lt;/em&gt; the use of hexadecimal notation: &amp;nbsp; &lt;tt&gt;0xffffffff&lt;/tt&gt; instead of the corresponding, &amp;ldquo;magic&amp;rdquo; decimal. &amp;nbsp; As long as you are very careful to use &lt;u&gt;unsigned&lt;/u&gt; arithmetic and specify bitmasks that are no larger than the integer-size you know that you are using, code like this ought to be transportable. &amp;nbsp; (It might not be &lt;em&gt;readable,&lt;/em&gt; heh, but it ought to be &lt;tt&gt;int&lt;/tt&gt;-length agnostic.)
&lt;/p&gt;&lt;p&gt;
I would almost edit my comment to say, &lt;em&gt;don&amp;rsquo;t use&lt;/em&gt; &amp;ldquo;arithmetic&amp;rdquo; at all when you are bit-twiddling, as in code like this:
&lt;code&gt;$num = $num - 4294967296 if $num &gt; 4294967295;
$num = $num + 4294967296 if $num &lt; -2147483648;&lt;/code&gt; &amp;nbsp; That&amp;rsquo;s &lt;em&gt;nasty...&lt;/em&gt; &amp;nbsp; And I recognize at least one of those numbers, &lt;tt&gt;-2147483648&lt;/tt&gt;, as an old, familiar 32-bit friend. &amp;nbsp; I also detect the presence of signed arithmetic, dependent upon the &lt;em&gt;thirty-first&lt;/em&gt; bit being the sign-bit. &amp;nbsp; I suggest that this code should be rewritten to use bit-masking operators ... and to do so, perhaps, in a &lt;em&gt;very specific&lt;/em&gt; way, as follows:
&lt;/p&gt;&lt;p&gt;
If you want to mash-off, say, all but the rightmost 31 bits of an integer quantity, you should take: &amp;nbsp; &lt;tt&gt; qty := qty &lt;b&gt;and&lt;/b&gt; ( &lt;b&gt;not&lt;/b&gt; 0x7fffffff );&lt;/tt&gt;. &amp;nbsp; (I am not using Perl notation here, for clarity.) &amp;nbsp; The subexpression, &lt;tt&gt;(&lt;b&gt;not&lt;/b&gt; 0x7fffffff)&lt;/tt&gt;, will evaluate to an &lt;tt&gt;int&lt;/tt&gt; in which all bits are &lt;tt&gt;1&lt;/tt&gt; except for the rightmost 31 bits, and it will do so correctly no matter what the &lt;tt&gt;sizeof(int)&lt;/tt&gt; may be.
&lt;/p&gt;&lt;p&gt;
So, I suggest that you need to go through code like this (fortunately, it is a &lt;em&gt;small&lt;/em&gt; piece of code), work out what it is doing and then rewrite it. &amp;nbsp; Construct a very thorough set of [mod://Test::More] cases that you can run on both a 32-bit and a 64-bit system to &lt;em&gt;prove&lt;/em&gt; that your rewrite is thoroughly correct.
&lt;/p&gt;
</field>
<field name="root_node">
947353</field>
<field name="parent_node">
947353</field>
</data>
</node>
