Changeset 7914 for branches/ia32/level0/X86/X8632/x8632bignum.lisp
 Timestamp:
 Dec 15, 2007, 8:59:44 AM (13 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/ia32/level0/X86/X8632/x8632bignum.lisp
r7907 r7914 6 6 ;;; The easiest thing to do is to store the 32 raw bits in two fixnums 7 7 ;;; and return multiple values. 8 ;;; XXX  figure out how we're going to handle multiplevalues... 8 9 (defx8632lapfunction %bignumref ((bignum arg_y) (i arg_z)) 10 (movl (% esp) (% temp0)) 11 (movzwl (@ (+ 2 x8632::miscdataoffset) (% bignum) (% i)) (% imm0)) 12 (boxfixnum imm0 temp1) 13 (push (% temp1)) ;high 9 14 (movzwl (@ x8632::miscdataoffset (% bignum) (% i)) (% imm0)) 10 (boxfixnum imm0 temp1) ;low 11 (movzwl (@ (+ 2 x8632::miscdataoffset) (% bignum) (% i)) (% imm0)) 12 (boxfixnum imm0 temp0) ;high 13 (push (% temp0)) 14 (push (% temp1)) 15 (boxfixnum imm0 temp1) 16 (push (% temp1)) ;low 15 17 (setnargs 2) 16 18 (jmpsubprim .SPvalues)) 17 18 ;;; Set the 0th element of DEST (a bignum or some other 32bit ivector)19 ;;; to the Ith element of the bignum SRC.20 (defx8632lapfunction %refdigit ((bignum 4) #(ra 0)# (i arg_y) (dest arg_z))21 (movl (@ bignum (% esp)) (% temp0))22 (movl (@ x8632::miscdataoffset (% temp0) (% i)) (% imm0))23 (svset dest 0 imm0)24 (singlevaluereturn 3))25 19 26 20 ;;; BIGNUM[I] := DIGIT[0] … … 31 25 (singlevaluereturn 3)) 32 26 33 ;;; Return 0 if the 0th digit in X is 0.34 (defx8632lapfunction %digitzerop ((x arg_z))35 (svref x 0 imm0)36 (movl ($ x8632::nilvalue) (% arg_z))37 (testl (% imm0) (% imm0))38 (cmovzl (% imm0) (% arg_z))39 (singlevaluereturn))40 41 ;;; store the sign of bignum (0 or 1) in the oneword bignum "digit".42 (defx8632lapfunction %bignumsigndigit ((bignum arg_y) (digit arg_z))43 (vectorlength bignum imm0)44 (movl (@ ( 4 x8632::miscdataoffset) (% bignum) (% imm0)) (% imm0))45 (shr ($ 31) (% imm0)) ;propagate sign bit46 (svset digit 0 imm0)47 (singlevaluereturn))48 49 27 ;;; Return the sign of bignum (0 or 1) as a fixnum 50 28 (defx8632lapfunction %bignumsign ((bignum arg_z)) 51 29 (vectorlength bignum imm0) 52 (movl (@ ( 4 x8632::miscdataoffset) (% bignum) (% imm0)) (% imm0))53 (s hr ($ 31) (% imm0));propagate sign bit30 (movl (@ ( x8632::miscdataoffset 4) (% bignum) (% imm0)) (% imm0)) 31 (sarl ($ 31) (% imm0)) ;propagate sign bit 54 32 (boxfixnum imm0 arg_z) 55 33 (singlevaluereturn)) … … 58 36 ;;; return fixnum count. 59 37 (defx8632lapfunction %bignumsignbits ((bignum arg_z)) 60 (vector size bignum imm0imm0)61 (movl (@ ( x8632::miscdataoffset 4) (% bignum) (% imm0) 4) (% imm0))38 (vectorlength bignum imm0) 39 (movl (@ ( x8632::miscdataoffset 4) (% bignum) (% imm0)) (% imm0)) 62 40 (markasimm temp0) 63 41 (movl (% imm0) (% temp0)) … … 78 56 (movl (@ x8632::miscdataoffset (% bignum) (% idx)) (% imm0)) 79 57 (movl ($ x8632::nilvalue) (% temp0)) 58 (leal (@ x8632::toffset (% temp0)) (% arg_z)) 80 59 (testl (% imm0) (% imm0)) 81 (cmov sl (% temp0) (% arg_z))60 (cmovll (% temp0) (% arg_z)) 82 61 (singlevaluereturn)) 83 62 … … 86 65 (movl (@ x8632::miscdataoffset (% bignum)) (% imm0)) 87 66 (movl ($ x8632::nilvalue) (% temp0)) 88 (btl ($ 0) (% imm0)) ;copy bit 0 to carry flag 89 (cmovncl (% temp0) (% arg_z)) 67 (leal (@ x8632::toffset (% temp0)) (% arg_z)) 68 (testb ($ 1) (% imm0.b)) 69 (cmovzl (% temp0) (% arg_z)) 90 70 (singlevaluereturn)) 91 71 92 72 (defx8632lapfunction bignumplusp ((bignum arg_z)) 93 73 (vectorlength bignum imm0) 94 (movl (@ ( 4 x8632::miscdataoffset) (% bignum)) (% imm0)) 95 (movl ($ x8632::nilvalue) (% temp0)) 96 (cmpl ($ 1) (% imm0)) 97 (cmovbl (% temp0) (% arg_z)) 98 (singlevaluereturn)) 99 100 (defx8632lapfunction %fixnumtobignumset ((bignum arg_y) (fixnum arg_z)) 101 (unboxfixnum fixnum imm0) 102 (movl (% imm0) (@ x8632::miscdataoffset (% bignum))) 74 (movl (@ ( x8632::miscdataoffset 4) (% bignum) (% imm0)) (% imm0)) 75 (movl ($ x8632::nilvalue) (% temp0)) 76 (lea (@ x8632::toffset (% temp0)) (% arg_z)) 77 (testl (% imm0) (% imm0)) 78 (cmovlel (% temp0) (% arg_z)) 103 79 (singlevaluereturn)) 104 80 105 81 (defx8632lapfunction bignumminusp ((bignum arg_z)) 106 82 (vectorlength bignum imm0) 107 (movl (@ ( 4 x8632::miscdataoffset) (% bignum) (% imm0)) (% imm0)) 108 (movl ($ x8632::nilvalue) (% temp0)) 83 (movl (@ ( x8632::miscdataoffset 4) (% bignum) (% imm0)) (% imm0)) 84 (movl ($ x8632::nilvalue) (% temp0)) 85 (lea (@ x8632::toffset (% temp0)) (% arg_z)) 109 86 (testl (% imm0) (% imm0)) 110 (cmov nsl (% temp0) (% arg_z))111 (singlevaluereturn)) 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 (singlevaluereturn)) 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. 116 93 (defx8632lapfunction %addwithcarry ((r 20) (k 16) (c 12) (a 8) (i 4) #(ra 0)# (b arg_y) (j arg_z)) 117 94 (markasimm temp0) … … 130 107 ;; unboxed a or a[i] now in temp0 131 108 ;; unboxed b or b[j] now in imm0 132 (movl ($ x8632::fixnumone) (% arg_z));for outgoing carry109 (movl ($ '1) (% arg_z)) ;for outgoing carry 133 110 (movl (@ c (% esp)) (% arg_y)) 134 111 (testl (% arg_y) (% arg_y)) ;clears carry flag … … 142 119 (movl (@ k (% esp)) (% temp1)) 143 120 (movl (% imm0) (@ x8632::miscdataoffset (% temp0) (% temp1))) 144 (cmovnc (% arg_y) (% arg_z)) ; outgoingcarry121 (cmovnc (% arg_y) (% arg_z)) ;zero outgoing carry if no carry 145 122 (markasnode temp0) 146 123 (singlevaluereturn 7)) … … 164 141 ;; unboxed a or a[i] now in temp0 165 142 ;; unboxed b or b[j] now in imm0 166 (movl ($ x8632::fixnumone) (% arg_z));for outgoing carry143 (movl ($ '1) (% arg_z)) ;for outgoing carry 167 144 (movl (@ borrow (% esp)) (% arg_y)) 168 145 (testl (% arg_y) (% arg_y)) ;clears carry flag … … 176 153 (movl (@ k (% esp)) (% temp1)) 177 154 (movl (% imm0) (@ x8632::miscdataoffset (% temp0) (% temp1))) 178 (cmovnc (% arg_y) (% arg_z)) ; outgoingcarry155 (cmovnc (% arg_y) (% arg_z)) ;zero outgoing carry if no carry 179 156 (markasnode temp0) 180 157 (singlevaluereturn 7)) 158 159 ;;; To normalize a bignum is to drop "trailing" digits which are 160 ;;; redundant sign information. When returnfixump is t, make 161 ;;; the resultant bignum into a fixnum if it fits. 162 (defx8632lapfunction %normalizebignum2 ((returnfixnump arg_y) (bignum arg_z)) 163 (push (% returnfixnump)) 164 (markasimm temp0) 165 (markasimm temp1) 166 ;; %zerotrailingsigndigits 167 (let ((len arg_y) 168 (sign temp0) 169 (next temp1)) 170 (vectorlength bignum len) 171 (cmpl ($ '1) (% len)) 172 (jle @maybefixnumize) 173 ;; nexttolast digit 174 (movl (@ ( x8632::miscdataoffset 8) (% bignum) (% len)) (% next)) 175 ;; last digit 176 (movl (@ ( x8632::miscdataoffset 4) (% bignum) (% len)) (% sign)) 177 (jmp @test) 178 @loop 179 (subl ($ '1) (% len)) 180 (movl ($ 0) (@ x8632::miscdataoffset (% bignum) (% len))) 181 (cmpl ($ '1) (% len)) ;any more digits? 182 (je @maybefixnumize) 183 (movl (% next) (% sign)) 184 ;; (bignumref bignum ( len 2)), i.e., nexttolast digit 185 (movl (@ ( x8632::miscdataoffset 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 @maybefixnumize 193 (pop (% returnfixnump)) 194 (cmpl ($ x8632::nilvalue) (% returnfixnump)) 195 (je @done) 196 (vectorlength 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::miscdataoffset (% bignum)) (% imm0)) 201 (boxfixnum imm0 arg_y) 202 (cmpl ($ #x3fffffff) (% imm0)) 203 (cmovbel (% arg_y) (% arg_z)) 204 @done 205 (markasnode temp0) 206 (markasnode temp1) 207 (singlevaluereturn)))
Note: See TracChangeset
for help on using the changeset viewer.