Changeset 7914 for branches/ia32/level-0


Ignore:
Timestamp:
Dec 15, 2007, 8:59:44 AM (12 years ago)
Author:
rme
Message:

Remove functions that won't be called; corrections after some minor
testing; a first cut at %NORMALIZE-BIGNUM-2.

File:
1 edited

Legend:

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

    r7907 r7914  
    66;;; The easiest thing to do is to store the 32 raw bits in two fixnums
    77;;; and return multiple values.
     8;;; XXX -- figure out how we're going to handle multiple-values...
    89(defx8632lapfunction %bignum-ref ((bignum arg_y) (i arg_z))
     10  (movl (% esp) (% temp0))
     11  (movzwl (@ (+ 2 x8632::misc-data-offset) (% bignum) (% i)) (% imm0))
     12  (box-fixnum imm0 temp1)
     13  (push (% temp1))                      ;high
    914  (movzwl (@ x8632::misc-data-offset (% bignum) (% i)) (% imm0))
    10   (box-fixnum imm0 temp1)               ;low
    11   (movzwl (@ (+ 2 x8632::misc-data-offset) (% bignum) (% i)) (% imm0))
    12   (box-fixnum imm0 temp0)               ;high
    13   (push (% temp0))
    14   (push (% temp1))
     15  (box-fixnum imm0 temp1)
     16  (push (% temp1))                      ;low
    1517  (set-nargs 2)
    1618  (jmp-subprim .SPvalues))
    17 
    18 ;;; Set the 0th element of DEST (a bignum or some other 32-bit ivector)
    19 ;;; to the Ith element of the bignum SRC.
    20 (defx8632lapfunction %ref-digit ((bignum 4) #|(ra 0)|# (i arg_y) (dest arg_z))
    21   (movl (@ bignum (% esp)) (% temp0))
    22   (movl (@ x8632::misc-data-offset (% temp0) (% i)) (% imm0))
    23   (svset dest 0 imm0)
    24   (single-value-return 3))
    2519
    2620;;; BIGNUM[I] := DIGIT[0]
     
    3125  (single-value-return 3))
    3226
    33 ;;; Return 0 if the 0th digit in X is 0.
    34 (defx8632lapfunction %digit-zerop ((x arg_z))
    35   (svref x 0 imm0)
    36   (movl ($ x8632::nil-value) (% arg_z))
    37   (testl (% imm0) (% imm0))
    38   (cmovzl (% imm0) (% arg_z))
    39   (single-value-return))
    40 
    41 ;;; store the sign of bignum (0 or -1) in the one-word bignum "digit".
    42 (defx8632lapfunction %bignum-sign-digit ((bignum arg_y) (digit arg_z))
    43   (vector-length bignum imm0)
    44   (movl (@ (- 4 x8632::misc-data-offset) (% bignum) (% imm0)) (% imm0))
    45   (shr ($ 31) (% imm0))                        ;propagate sign bit
    46   (svset digit 0 imm0)
    47   (single-value-return))
    48 
    4927;;; Return the sign of bignum (0 or -1) as a fixnum
    5028(defx8632lapfunction %bignum-sign ((bignum arg_z))
    5129  (vector-length bignum imm0)
    52   (movl (@ (- 4 x8632::misc-data-offset) (% bignum) (% imm0)) (% imm0))
    53   (shr ($ 31) (% imm0))                        ;propagate sign bit
     30  (movl (@ (- x8632::misc-data-offset 4) (% bignum) (% imm0)) (% imm0))
     31  (sarl ($ 31) (% imm0))                ;propagate sign bit
    5432  (box-fixnum imm0 arg_z)
    5533  (single-value-return))
     
    5836;;; return fixnum count.
    5937(defx8632lapfunction %bignum-sign-bits ((bignum arg_z))
    60   (vector-size bignum imm0 imm0)
    61   (movl (@ (- x8632::misc-data-offset 4) (% bignum) (% imm0) 4) (% imm0))
     38  (vector-length bignum imm0)
     39  (movl (@ (- x8632::misc-data-offset 4) (% bignum) (% imm0)) (% imm0))
    6240  (mark-as-imm temp0)
    6341  (movl (% imm0) (% temp0))
     
    7856  (movl (@ x8632::misc-data-offset (% bignum) (% idx)) (% imm0))
    7957  (movl ($ x8632::nil-value) (% temp0))
     58  (leal (@ x8632::t-offset (% temp0)) (% arg_z))
    8059  (testl (% imm0) (% imm0))
    81   (cmovsl (% temp0) (% arg_z))
     60  (cmovll (% temp0) (% arg_z))
    8261  (single-value-return))
    8362
     
    8665  (movl (@ x8632::misc-data-offset (% bignum)) (% imm0))
    8766  (movl ($ x8632::nil-value) (% temp0))
    88   (btl ($ 0) (% imm0))                  ;copy bit 0 to carry flag
    89   (cmovncl (% temp0) (% arg_z))
     67  (leal (@ x8632::t-offset (% temp0)) (% arg_z))
     68  (testb ($ 1) (% imm0.b))
     69  (cmovzl (% temp0) (% arg_z))
    9070  (single-value-return))
    9171
    9272(defx8632lapfunction bignum-plusp ((bignum arg_z))
    9373  (vector-length bignum imm0)
    94   (movl (@ (- 4 x8632::misc-data-offset) (% bignum)) (% imm0))
    95   (movl ($ x8632::nil-value) (% temp0))
    96   (cmpl ($ 1) (% imm0))
    97   (cmovbl (% temp0) (% arg_z))
    98   (single-value-return))
    99 
    100 (defx8632lapfunction %fixnum-to-bignum-set ((bignum arg_y) (fixnum arg_z))
    101   (unbox-fixnum fixnum imm0)
    102   (movl (% imm0) (@ x8632::misc-data-offset (% bignum)))
     74  (movl (@ (- x8632::misc-data-offset 4) (% bignum) (% imm0)) (% imm0))
     75  (movl ($ x8632::nil-value) (% temp0))
     76  (lea (@ x8632::t-offset (% temp0)) (% arg_z))
     77  (testl (% imm0) (% imm0))
     78  (cmovlel (% temp0) (% arg_z))
    10379  (single-value-return))
    10480
    10581(defx8632lapfunction bignum-minusp ((bignum arg_z))
    10682  (vector-length bignum imm0)
    107   (movl (@ (- 4 x8632::misc-data-offset) (% bignum) (% imm0)) (% imm0))
    108   (movl ($ x8632::nil-value) (% temp0))
     83  (movl (@ (- x8632::misc-data-offset 4) (% bignum) (% imm0)) (% imm0))
     84  (movl ($ x8632::nil-value) (% temp0))
     85  (lea (@ x8632::t-offset (% temp0)) (% arg_z))
    10986  (testl (% imm0) (% imm0))
    110   (cmovnsl (% temp0) (% arg_z))
    111   (single-value-return))
    112 
    113 ;;; Add the digits A[I] and B[J], and the incoming carry C (a fixnum).
    114 ;;; Store the result in R[K], and return the outgoing carry.
    115 ;;; If I is NIL, A is a fixnum.  If J is NIL, B is a fixnum.
     87  (cmovgl (% temp0) (% arg_z))
     88  (single-value-return))
     89
     90;;; Add the digits A[I] and B[J], and the incoming carry C (a fixnum,
     91;;; either 0 or 1).  Store the result in R[K], and return the outgoing
     92;;; carry.  If I is NIL, A is a fixnum.  If J is NIL, B is a fixnum.
    11693(defx8632lapfunction %add-with-carry ((r 20) (k 16) (c 12) (a 8) (i 4) #|(ra 0)|# (b arg_y) (j arg_z))
    11794  (mark-as-imm temp0)
     
    130107  ;; unboxed a or a[i] now in temp0
    131108  ;; unboxed b or b[j] now in imm0
    132   (movl ($ x8632::fixnumone) (% arg_z)) ;for outgoing carry
     109  (movl ($ '1) (% arg_z))               ;for outgoing carry
    133110  (movl (@ c (% esp)) (% arg_y))
    134111  (testl (% arg_y) (% arg_y))           ;clears carry flag
     
    142119  (movl (@ k (% esp)) (% temp1))
    143120  (movl (% imm0) (@ x8632::misc-data-offset (% temp0) (% temp1)))
    144   (cmovnc (% arg_y) (% arg_z))          ;outgoing carry
     121  (cmovnc (% arg_y) (% arg_z))          ;zero outgoing carry if no carry
    145122  (mark-as-node temp0)
    146123  (single-value-return 7))
     
    164141  ;; unboxed a or a[i] now in temp0
    165142  ;; unboxed b or b[j] now in imm0
    166   (movl ($ x8632::fixnumone) (% arg_z)) ;for outgoing carry
     143  (movl ($ '1) (% arg_z))               ;for outgoing carry
    167144  (movl (@ borrow (% esp)) (% arg_y))
    168145  (testl (% arg_y) (% arg_y))           ;clears carry flag
     
    176153  (movl (@ k (% esp)) (% temp1))
    177154  (movl (% imm0) (@ x8632::misc-data-offset (% temp0) (% temp1)))
    178   (cmovnc (% arg_y) (% arg_z))          ;outgoing carry
     155  (cmovnc (% arg_y) (% arg_z))          ;zero outgoing carry if no carry
    179156  (mark-as-node temp0)
    180157  (single-value-return 7))
     158
     159;;; To normalize a bignum is to drop "trailing" digits which are
     160;;; redundant sign information.  When return-fixum-p is t, make
     161;;; the resultant bignum into a fixnum if it fits.
     162(defx8632lapfunction %normalize-bignum-2 ((return-fixnum-p arg_y) (bignum arg_z))
     163  (push (% return-fixnum-p))
     164  (mark-as-imm temp0)
     165  (mark-as-imm temp1)
     166  ;; %zero-trailing-sign-digits
     167  (let ((len arg_y)
     168        (sign temp0)
     169        (next temp1))
     170    (vector-length bignum len)
     171    (cmpl ($ '1) (% len))
     172    (jle @maybe-fixnumize)
     173    ;; next-to-last digit
     174    (movl (@ (- x8632::misc-data-offset 8) (% bignum) (% len)) (% next))
     175    ;; last digit
     176    (movl (@ (- x8632::misc-data-offset 4) (% bignum) (% len)) (% sign))
     177    (jmp @test)
     178    @loop
     179    (subl ($ '1) (% len))
     180    (movl ($ 0) (@ x8632::misc-data-offset (% bignum) (% len)))
     181    (cmpl ($ '1) (% len))               ;any more digits?
     182    (je @maybe-fixnumize)
     183    (movl (% next) (% sign))
     184    ;; (bignum-ref bignum (- len 2)), i.e., next-to-last digit
     185    (movl (@ (- x8632::misc-data-offset 8) (% bignum) (% imm0)) (% next))
     186    @test
     187    (movl (% next) (% imm0))
     188    (sarl ($ 31) (% imm0))              ;propagate sign bit
     189    (xorl (% sign) (% imm0))
     190    (testl (% imm0) (% imm0))           ;whole digit only sign?
     191    (jz @loop)
     192    @maybe-fixnumize
     193    (pop (% return-fixnum-p))
     194    (cmpl ($ x8632::nil-value) (% return-fixnum-p))
     195    (je @done)
     196    (vector-length bignum len)
     197    (cmpl ($ '1) (% len))
     198    (jg @done)
     199    ;; Bignum has one digit.  If it fits in a fixnum, return a fixnum.
     200    (movl (@ x8632::misc-data-offset (% bignum)) (% imm0))
     201    (box-fixnum imm0 arg_y)
     202    (cmpl ($ #x3fffffff) (% imm0))
     203    (cmovbel (% arg_y) (% arg_z))
     204    @done
     205    (mark-as-node temp0)
     206    (mark-as-node temp1)
     207    (single-value-return)))
Note: See TracChangeset for help on using the changeset viewer.