Portable multiply function Mul() was broken because of lack of unsignedness
authorArthur Gleckler <edu/mit/csail/zurich/arthur>
Wed, 29 Jun 1988 08:05:42 +0000 (08:05 +0000)
committerArthur Gleckler <edu/mit/csail/zurich/arthur>
Wed, 29 Jun 1988 08:05:42 +0000 (08:05 +0000)
and a fencepost error.

v7/src/microcode/mul.c
v7/src/microcode/version.h
v8/src/microcode/mul.c
v8/src/microcode/version.h

index f48d76c377e937e8aab8ba74a2f91a5402d9ee51..3b73de2c29dc5ac15abad52af31ca323b829d36b 100644 (file)
@@ -30,7 +30,7 @@ Technology nor of any adaptation thereof in any advertising,
 promotional, or sales literature without prior written consent from
 MIT in each case. */
 
-/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/mul.c,v 9.22 1987/04/16 02:26:41 jinx Rel $
+/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/mul.c,v 9.23 1988/06/29 08:01:51 arthur Exp $
  *
  * This file contains the portable fixnum multiplication procedure.
  * Returns NIL if the result does not fit in a fixnum.
@@ -49,7 +49,7 @@ Mul(Arg1, Arg2)
      long Arg1, Arg2;
 {
   long A, B, C;
-  fast long Hi_A, Hi_B, Lo_A, Lo_B, Lo_C, Middle_C;
+  fast unsigned long Hi_A, Hi_B, Lo_A, Lo_B, Lo_C, Middle_C;
   Boolean Sign;
 
   Sign_Extend(Arg1, A);
@@ -59,16 +59,16 @@ Mul(Arg1, Arg2)
   B = ABS(B);
   Hi_A = ((A >> HALF_WORD_SIZE) & HALF_WORD_MASK);
   Hi_B = ((B >> HALF_WORD_SIZE) & HALF_WORD_MASK);
+  if ((Hi_A > 0) && (Hi_B > 0))
+    return NIL;
   Lo_A = (A & HALF_WORD_MASK);
   Lo_B = (B & HALF_WORD_MASK);
   Lo_C = (Lo_A * Lo_B);
-  if (Lo_C > FIXNUM_SIGN_BIT)
+  if (Lo_C >= FIXNUM_SIGN_BIT)
     return NIL;
   Middle_C = (Lo_A * Hi_B) + (Hi_A * Lo_B);
   if (Middle_C >= MAX_MIDDLE)
     return NIL;
-  if ((Hi_A > 0) && (Hi_B > 0))
-    return NIL;
   C = Lo_C + (Middle_C << HALF_WORD_SIZE);
   if (Fixnum_Fits(C))
   {
index 669729a718ba32cebb437ea7cb003e199a01a453..9787e71a2743d175bfdd31b7f390a94dbae68656 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 10.42 1988/06/10 07:58:04 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/microcode/Attic/version.h,v 10.43 1988/06/29 08:05:42 arthur Exp $
 
 Copyright (c) 1988 Massachusetts Institute of Technology
 
@@ -46,7 +46,7 @@ MIT in each case. */
 #define VERSION                10
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION     42
+#define SUBVERSION     43
 #endif
 
 #ifndef UCODE_TABLES_FILENAME
index 339c23864344fc6de692eea811c95a0940ea0906..056329ef26717e1abcdfcc117f4d610a1259a8b4 100644 (file)
@@ -30,7 +30,7 @@ Technology nor of any adaptation thereof in any advertising,
 promotional, or sales literature without prior written consent from
 MIT in each case. */
 
-/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/mul.c,v 9.22 1987/04/16 02:26:41 jinx Rel $
+/* $Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/mul.c,v 9.23 1988/06/29 08:01:51 arthur Exp $
  *
  * This file contains the portable fixnum multiplication procedure.
  * Returns NIL if the result does not fit in a fixnum.
@@ -49,7 +49,7 @@ Mul(Arg1, Arg2)
      long Arg1, Arg2;
 {
   long A, B, C;
-  fast long Hi_A, Hi_B, Lo_A, Lo_B, Lo_C, Middle_C;
+  fast unsigned long Hi_A, Hi_B, Lo_A, Lo_B, Lo_C, Middle_C;
   Boolean Sign;
 
   Sign_Extend(Arg1, A);
@@ -59,16 +59,16 @@ Mul(Arg1, Arg2)
   B = ABS(B);
   Hi_A = ((A >> HALF_WORD_SIZE) & HALF_WORD_MASK);
   Hi_B = ((B >> HALF_WORD_SIZE) & HALF_WORD_MASK);
+  if ((Hi_A > 0) && (Hi_B > 0))
+    return NIL;
   Lo_A = (A & HALF_WORD_MASK);
   Lo_B = (B & HALF_WORD_MASK);
   Lo_C = (Lo_A * Lo_B);
-  if (Lo_C > FIXNUM_SIGN_BIT)
+  if (Lo_C >= FIXNUM_SIGN_BIT)
     return NIL;
   Middle_C = (Lo_A * Hi_B) + (Hi_A * Lo_B);
   if (Middle_C >= MAX_MIDDLE)
     return NIL;
-  if ((Hi_A > 0) && (Hi_B > 0))
-    return NIL;
   C = Lo_C + (Middle_C << HALF_WORD_SIZE);
   if (Fixnum_Fits(C))
   {
index 138eedb65861058732af844059629c3d464cb74b..1c0ebe7c306a01e03b2a2d2c631f68a4026ae2fa 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-C-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 10.42 1988/06/10 07:58:04 cph Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v8/src/microcode/version.h,v 10.43 1988/06/29 08:05:42 arthur Exp $
 
 Copyright (c) 1988 Massachusetts Institute of Technology
 
@@ -46,7 +46,7 @@ MIT in each case. */
 #define VERSION                10
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION     42
+#define SUBVERSION     43
 #endif
 
 #ifndef UCODE_TABLES_FILENAME