![]() |
![]() |
#1 | ||
Dec 2005
9210 Posts |
![]()
I was browsing gmp's powm_ui.c file in its generic C library. After dechipering it enough to understand part of what it is doing, I noticed the following lines:
Quote:
Quote:
|
||
![]() |
![]() |
![]() |
#2 |
Tribal Bullet
Oct 2004
32·5·79 Posts |
![]()
My guess is the code is as written because the C standard does not specify what happens to shifts when the shift amount exceeds the bits in a word. For a 32-bit machine, if x is 1 then c is 31 and (x << c) << 1 will be zero, as expected. However, the result of x << (c+1) depends on the processor. x86 machines only look at the bottom 5 bits of the shift amount, so x << 32 becomes x. 32-bit powerPC looks at the bottom 6 bits, so x << 32 is zero.
Variable shifts are a challenge to portable code that many C programmers are not aware of. |
![]() |
![]() |
![]() |
#3 |
Dec 2005
22×23 Posts |
![]()
Wow, you are right. I had no idea that the shifts were different on different platforms.
I guess this makes my question why GMP does not use preprocessor definitions to give x86 machines the slow workaround code and other machines the fast code. |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Good air-cooler good enough for overclocked i7-5820K | RienS | Hardware | 17 | 2014-11-18 22:58 |
Norwegians seems to love primes for some reason | kaffikanne | Lounge | 8 | 2010-05-27 20:51 |
The crime of reason | jasonp | Soap Box | 1 | 2009-12-20 15:09 |
My fatalistic(sp?) reason for believing in God. | jasong | Soap Box | 22 | 2006-05-04 19:26 |
Another reason for high attrition... | guest | PrimeNet | 27 | 2004-03-17 13:50 |