Changeset 7916 for branches/ia32/level-0


Ignore:
Timestamp:
Dec 17, 2007, 3:14:37 AM (12 years ago)
Author:
rme
Message:

More work on %normalize-bignum-2.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ia32/level-0/X86/X8632/x8632-bignum.lisp

    r7915 r7916  
    158158
    159159;;; To normalize a bignum is to drop "trailing" digits which are
    160 ;;; redundant sign information.  When return-fixnum-p is t, make
     160;;; redundant sign information.  When return-fixnum-p is non-nil, make
    161161;;; the resultant bignum into a fixnum if it fits.
    162162(defx8632lapfunction %normalize-bignum-2 ((return-fixnum-p arg_y) (bignum arg_z))
     
    164164  (mark-as-imm temp0)
    165165  (mark-as-imm temp1)
    166   ;; %zero-trailing-sign-digits
    167166  (let ((len arg_y)
    168167        (sign temp0)
     
    170169    (vector-length bignum len)
    171170    (cmpl ($ '1) (% len))
    172     (jle @maybe-fixnumize)
     171    (jle @maybe-return-fixnum)
     172    ;; Zero trailing sign digits.
     173    (push (% len))
    173174    ;; next-to-last digit
    174175    (movl (@ (- x8632::misc-data-offset 8) (% bignum) (% len)) (% next))
     
    180181    (movl ($ 0) (@ x8632::misc-data-offset (% bignum) (% len)))
    181182    (cmpl ($ '1) (% len))               ;any more digits?
    182     (je @maybe-fixnumize)
     183    (je @adjust-length)
    183184    (movl (% next) (% sign))
    184185    ;; (bignum-ref bignum (- len 2)), i.e., next-to-last digit
     
    190191    (testl (% imm0) (% imm0))           ;whole digit only sign?
    191192    (jz @loop)
    192     @maybe-fixnumize
     193    ;; New length now in len.
     194    @adjust-length
     195    (pop (% imm0))                      ;original length
     196    (cmpl (% len) (% imm0))
     197    ;; If the new length is the same as the original length, we know
     198    ;; that the bignum is at least two digits long, and will never fit
     199    ;; in a fixnum.  Therefore, there's no need to do either of the
     200    ;; tests at @maybe-return-fixnum.
     201    (je @done)
     202    (movl (% len) (% imm0))
     203    (shll ($ (- x8632::num-subtag-bits x8632::fixnumshift)) (% imm0))
     204    (movb ($ x8632::subtag-bignum) (% imm0.b))
     205    (movl (% imm0) (@ x8632::misc-header-offset (% bignum)))
     206    @maybe-return-fixnum
     207    ;; could use SETcc here to avoid one branch
    193208    (pop (% return-fixnum-p))
    194     (cmpl ($ x8632::nil-value) (% return-fixnum-p))
     209    (cmpl ($ x8632::nil-value) (@ 0 (% esp))) ;return-fixnum-p
    195210    (je @done)
    196     (vector-length bignum len)
    197     (cmpl ($ '1) (% len))
    198     (jg @done)
     211    (cmpl ($ x8632::one-digit-bignum-header) (% bignum))
     212    (jne @done)
    199213    ;; Bignum has one digit.  If it fits in a fixnum, return a fixnum.
    200214    (movl (@ x8632::misc-data-offset (% bignum)) (% imm0))
    201215    (box-fixnum imm0 arg_y)
    202     (cmpl ($ #x3fffffff) (% imm0))
    203     (cmovbel (% arg_y) (% arg_z))
     216    (unbox-fixnum arg_y temp0)
     217    (cmpl (% temp0) (% imm0))
     218    (cmovel (% arg_y) (% arg_z))
    204219    @done
     220    (pop (% imm0))                      ;discard saved return-fixnum-p
    205221    (mark-as-node temp0)
    206222    (mark-as-node temp1)
Note: See TracChangeset for help on using the changeset viewer.