in reply to Re: Perl XS portable uint32_t
in thread Perl XS portable uint32_t
Hi Rob,
Unfortunately most hashing behaviour depends on the idiosyncrcies of overflow wrap and truncation implicit in an (32 bit) int. Consider this case (using a 4 bit "int" on a 4 and 8 bit machine)
So after two identical operations the results on 4 vs 8 bit architecture now differ. Essentially by having the spare high order bits we do not lose those bits to the big bit bucket in the sky, so when we right shift they reappear. As a result any algorithm that uses much bitshifting will not work as desired if the int being used is not exacty the design width.1111 << 1 = 1110 (4 bit) 1111 << 1 = 00011110 (8 bit) Now consider what happens if we then go on to perform a rightshift 1110 >> 2 = 0011 (4 bit) 00011110 >> 2 = 00000111 (8 bit) ^ Oops
Unfortunately you can't use sizeof in a preprocessor directive to do the setup one way on a 32 bit machine and another way on a 64 bit one.
Cheers
tachyon
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Perl XS portable uint32_t
by syphilis (Archbishop) on Jun 06, 2008 at 14:15 UTC | |
by tachyon-II (Chaplain) on Jun 06, 2008 at 15:30 UTC | |
by syphilis (Archbishop) on Jun 06, 2008 at 22:30 UTC |