From: Arthur Gleckler Date: Wed, 29 Jun 1988 08:05:42 +0000 (+0000) Subject: Portable multiply function Mul() was broken because of lack of unsignedness X-Git-Tag: 20090517-FFI~12688 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=f7f051881e3bbb5f3162a36dc3537375f75baa68;p=mit-scheme.git Portable multiply function Mul() was broken because of lack of unsignedness and a fencepost error. --- diff --git a/v7/src/microcode/mul.c b/v7/src/microcode/mul.c index f48d76c37..3b73de2c2 100644 --- a/v7/src/microcode/mul.c +++ b/v7/src/microcode/mul.c @@ -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)) { diff --git a/v7/src/microcode/version.h b/v7/src/microcode/version.h index 669729a71..9787e71a2 100644 --- a/v7/src/microcode/version.h +++ b/v7/src/microcode/version.h @@ -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 diff --git a/v8/src/microcode/mul.c b/v8/src/microcode/mul.c index 339c23864..056329ef2 100644 --- a/v8/src/microcode/mul.c +++ b/v8/src/microcode/mul.c @@ -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)) { diff --git a/v8/src/microcode/version.h b/v8/src/microcode/version.h index 138eedb65..1c0ebe7c3 100644 --- a/v8/src/microcode/version.h +++ b/v8/src/microcode/version.h @@ -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