Gerhard Niklasch on Fri, 3 Jul 1998 16:24:52 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Now if we are utterly pedantic...


...and take the utterly remote possiblity of a 1's complement machine
into account, then the following should go over Louis Granboulan's
recent `signed minus' patch  (we discussed this in email off the list):

bash$ diff -u src/kernel/none/mp.c~ src/kernel/none/mp.c
--- src/kernel/none/mp.c~       Thu Jul  2 11:19:41 1998
+++ src/kernel/none/mp.c        Fri Jul  3 16:08:29 1998
@@ -876,7 +876,7 @@
 #ifdef LONG_IS_64BIT
   if (! (z&0xffffffff)) { s = 32; z >>=32; } else s = 0;
 #endif  
-  z = z | -(long)z;
+  z = z | (~z + 1);
   z = (z<<4) + z;
   z = (z<<6) + z;
   z = z ^ (z<<16); /* or  z = z - (z<<16);  or  z = z &~ (z<<16);  */

(the reason being that here we really want the bit pattern of ~z+1,
regardless of whether it happens to be minus z for the machine integer
addition).

(However, I wouldn't vouch for all the remainder of the PARI code not
to rely anywhere on 2's complement arithmetic...:^)

Then again, many modern processors have a single machine instruction
for counting the _leading_ zeros in a word  (bfffo() in the PARI kernel),
and there is a cute little trick to use this for doing what the above
vals() code does  (counting the _trailing_ zeros).  Friday trivia quiz:
	(1) what is this trick?
	(2) why is that other function called bfffo? ;)

Merry guessing and have a nice weekend everywhere,
Gerhard "while (--bugs_in_factorizing) fix_them() && do_test;"