Index: /branches/ia32/level-0/X86/X8632/x8632-bignum.lisp
===================================================================
--- /branches/ia32/level-0/X86/X8632/x8632-bignum.lisp	(revision 7915)
+++ /branches/ia32/level-0/X86/X8632/x8632-bignum.lisp	(revision 7916)
@@ -158,5 +158,5 @@
 
 ;;; To normalize a bignum is to drop "trailing" digits which are
-;;; redundant sign information.  When return-fixnum-p is t, make
+;;; redundant sign information.  When return-fixnum-p is non-nil, make
 ;;; the resultant bignum into a fixnum if it fits.
 (defx8632lapfunction %normalize-bignum-2 ((return-fixnum-p arg_y) (bignum arg_z))
@@ -164,5 +164,4 @@
   (mark-as-imm temp0)
   (mark-as-imm temp1)
-  ;; %zero-trailing-sign-digits
   (let ((len arg_y)
 	(sign temp0)
@@ -170,5 +169,7 @@
     (vector-length bignum len)
     (cmpl ($ '1) (% len))
-    (jle @maybe-fixnumize)
+    (jle @maybe-return-fixnum)
+    ;; Zero trailing sign digits.
+    (push (% len))
     ;; next-to-last digit
     (movl (@ (- x8632::misc-data-offset 8) (% bignum) (% len)) (% next))
@@ -180,5 +181,5 @@
     (movl ($ 0) (@ x8632::misc-data-offset (% bignum) (% len)))
     (cmpl ($ '1) (% len))		;any more digits?
-    (je @maybe-fixnumize)
+    (je @adjust-length)
     (movl (% next) (% sign))
     ;; (bignum-ref bignum (- len 2)), i.e., next-to-last digit
@@ -190,17 +191,32 @@
     (testl (% imm0) (% imm0))		;whole digit only sign?
     (jz @loop)
-    @maybe-fixnumize
+    ;; New length now in len.
+    @adjust-length
+    (pop (% imm0))			;original length
+    (cmpl (% len) (% imm0))
+    ;; If the new length is the same as the original length, we know
+    ;; that the bignum is at least two digits long, and will never fit
+    ;; in a fixnum.  Therefore, there's no need to do either of the
+    ;; tests at @maybe-return-fixnum.
+    (je @done)
+    (movl (% len) (% imm0))
+    (shll ($ (- x8632::num-subtag-bits x8632::fixnumshift)) (% imm0))
+    (movb ($ x8632::subtag-bignum) (% imm0.b))
+    (movl (% imm0) (@ x8632::misc-header-offset (% bignum)))
+    @maybe-return-fixnum
+    ;; could use SETcc here to avoid one branch
     (pop (% return-fixnum-p))
-    (cmpl ($ x8632::nil-value) (% return-fixnum-p))
+    (cmpl ($ x8632::nil-value) (@ 0 (% esp))) ;return-fixnum-p
     (je @done)
-    (vector-length bignum len)
-    (cmpl ($ '1) (% len))
-    (jg @done)
+    (cmpl ($ x8632::one-digit-bignum-header) (% bignum))
+    (jne @done)
     ;; Bignum has one digit.  If it fits in a fixnum, return a fixnum.
     (movl (@ x8632::misc-data-offset (% bignum)) (% imm0))
     (box-fixnum imm0 arg_y)
-    (cmpl ($ #x3fffffff) (% imm0))
-    (cmovbel (% arg_y) (% arg_z))
+    (unbox-fixnum arg_y temp0)
+    (cmpl (% temp0) (% imm0))
+    (cmovel (% arg_y) (% arg_z))
     @done
+    (pop (% imm0))			;discard saved return-fixnum-p
     (mark-as-node temp0)
     (mark-as-node temp1)
