7 (define-vop (fixnum-unop)
8 (:args (x :scs (any-reg)))
9 (:results (res :scs (any-reg)))
10 (:note "inline fixnum arithmetic")
11 (:arg-types tagged-num)
12 (:result-types tagged-num)
15 (define-vop (signed-unop)
16 (:args (x :scs (signed-reg)))
17 (:results (res :scs (signed-reg)))
18 (:note "inline (signed-byte 32) arithmetic")
19 (:arg-types signed-num)
20 (:result-types signed-num)
23 (define-vop (fast-negate/fixnum fixnum-unop)
26 (inst subu res zero-tn x)))
28 (define-vop (fast-negate/signed signed-unop)
31 (inst subu res zero-tn x)))
33 (define-vop (fast-lognot/fixnum fixnum-unop)
34 (:temporary (:scs (any-reg) :type fixnum :to (:result 0))
38 (inst li temp (fixnumize -1))
39 (inst xor res x temp)))
41 (define-vop (fast-lognot/signed signed-unop)
44 (inst nor res x zero-tn)))
48 ;;;; Binary fixnum operations.
50 ;;; Assume that any constant operand is the second arg...
52 (define-vop (fast-fixnum-binop)
53 (:args (x :target r :scs (any-reg))
54 (y :target r :scs (any-reg)))
55 (:arg-types tagged-num tagged-num)
56 (:results (r :scs (any-reg)))
57 (:result-types tagged-num)
58 (:note "inline fixnum arithmetic")
63 (define-vop (fast-unsigned-binop)
64 (:args (x :target r :scs (unsigned-reg))
65 (y :target r :scs (unsigned-reg)))
66 (:arg-types unsigned-num unsigned-num)
67 (:results (r :scs (unsigned-reg)))
68 (:result-types unsigned-num)
69 (:note "inline (unsigned-byte 32) arithmetic")
74 (define-vop (fast-signed-binop)
75 (:args (x :target r :scs (signed-reg))
76 (y :target r :scs (signed-reg)))
77 (:arg-types signed-num signed-num)
78 (:results (r :scs (signed-reg)))
79 (:result-types signed-num)
80 (:note "inline (signed-byte 32) arithmetic")
85 (define-vop (fast-fixnum-c-binop fast-fixnum-binop)
86 (:args (x :target r :scs (any-reg)))
88 (:arg-types tagged-num (:constant integer)))
90 (define-vop (fast-signed-c-binop fast-signed-binop)
91 (:args (x :target r :scs (signed-reg)))
93 (:arg-types tagged-num (:constant integer)))
95 (define-vop (fast-unsigned-c-binop fast-unsigned-binop)
96 (:args (x :target r :scs (unsigned-reg)))
98 (:arg-types tagged-num (:constant integer)))
100 (defmacro define-binop (translate cost untagged-cost op
101 tagged-type untagged-type)
103 (define-vop (,(symbolicate "FAST-" translate "/FIXNUM=>FIXNUM")
105 (:args (x :target r :scs (any-reg))
106 (y :target r :scs (any-reg)))
107 (:translate ,translate)
108 (:generator ,(1+ cost)
110 (define-vop (,(symbolicate "FAST-" translate "/SIGNED=>SIGNED")
112 (:args (x :target r :scs (signed-reg))
113 (y :target r :scs (signed-reg)))
114 (:translate ,translate)
115 (:generator ,(1+ untagged-cost)
117 (define-vop (,(symbolicate "FAST-" translate "/UNSIGNED=>UNSIGNED")
119 (:args (x :target r :scs (unsigned-reg))
120 (y :target r :scs (unsigned-reg)))
121 (:translate ,translate)
122 (:generator ,(1+ untagged-cost)
125 `((define-vop (,(symbolicate "FAST-" translate "-C/FIXNUM=>FIXNUM")
127 (:arg-types tagged-num (:constant ,tagged-type))
128 (:translate ,translate)
130 (inst ,op r x (fixnumize y))))))
131 ,@(when untagged-type
132 `((define-vop (,(symbolicate "FAST-" translate "-C/SIGNED=>SIGNED")
134 (:arg-types signed-num (:constant ,untagged-type))
135 (:translate ,translate)
136 (:generator ,untagged-cost
138 (define-vop (,(symbolicate "FAST-" translate
139 "-C/UNSIGNED=>UNSIGNED")
140 fast-unsigned-c-binop)
141 (:arg-types unsigned-num (:constant ,untagged-type))
142 (:translate ,translate)
143 (:generator ,untagged-cost
144 (inst ,op r x y)))))))
146 (define-binop + 1 5 addu (signed-byte 14) (signed-byte 16))
147 (define-binop - 1 5 subu
148 (integer #.(- (1- (ash 1 14))) #.(ash 1 14))
149 (integer #.(- (1- (ash 1 16))) #.(ash 1 16)))
150 (define-binop logior 1 3 or (unsigned-byte 14) (unsigned-byte 16))
151 (define-binop lognor 1 3 nor nil nil)
152 (define-binop logand 1 3 and (unsigned-byte 14) (unsigned-byte 16))
153 (define-binop logxor 1 3 xor (unsigned-byte 14) (unsigned-byte 16))
155 ;;; Special case fixnum + and - that trap on overflow. Useful when we don't
156 ;;; know that the result is going to be a fixnum.
159 (define-vop (fast-+/fixnum fast-+/fixnum=>fixnum)
160 (:results (r :scs (any-reg descriptor-reg)))
161 (:result-types (:or signed-num unsigned-num))
166 (define-vop (fast-+-c/fixnum fast-+-c/fixnum=>fixnum)
167 (:results (r :scs (any-reg descriptor-reg)))
168 (:result-types (:or signed-num unsigned-num))
171 (inst add r x (fixnumize y))))
173 (define-vop (fast--/fixnum fast--/fixnum=>fixnum)
174 (:results (r :scs (any-reg descriptor-reg)))
175 (:result-types (:or signed-num unsigned-num))
180 (define-vop (fast---c/fixnum fast---c/fixnum=>fixnum)
181 (:results (r :scs (any-reg descriptor-reg)))
182 (:result-types (:or signed-num unsigned-num))
185 (inst sub r x (fixnumize y))))
186 ) ; bogus trap-to-c-land +/-
190 (define-vop (fast-ash/unsigned=>unsigned)
192 (:args (number :scs (unsigned-reg) :to :save)
193 (amount :scs (signed-reg)))
194 (:arg-types unsigned-num signed-num)
195 (:results (result :scs (unsigned-reg)))
196 (:result-types unsigned-num)
199 (:temporary (:sc non-descriptor-reg) ndesc)
200 (:temporary (:sc non-descriptor-reg :to :eval) temp)
202 (inst bgez amount positive)
203 (inst subu ndesc zero-tn amount)
204 (inst slt temp ndesc 31)
205 (inst bne temp zero-tn done)
206 (inst srl result number ndesc)
208 (inst srl result number 31)
211 ;; The result-type assures us that this shift will not overflow.
212 (inst sll result number amount)
216 (define-vop (fast-ash/signed=>signed)
218 (:args (number :scs (signed-reg) :to :save)
219 (amount :scs (signed-reg)))
220 (:arg-types signed-num signed-num)
221 (:results (result :scs (signed-reg)))
222 (:result-types signed-num)
225 (:temporary (:sc non-descriptor-reg) ndesc)
226 (:temporary (:sc non-descriptor-reg :to :eval) temp)
228 (inst bgez amount positive)
229 (inst subu ndesc zero-tn amount)
230 (inst slt temp ndesc 31)
231 (inst bne temp zero-tn done)
232 (inst sra result number ndesc)
234 (inst sra result number 31)
237 ;; The result-type assures us that this shift will not overflow.
238 (inst sll result number amount)
243 (define-vop (fast-ash-c/unsigned=>unsigned)
247 (:args (number :scs (unsigned-reg)))
249 (:arg-types unsigned-num (:constant integer))
250 (:results (result :scs (unsigned-reg)))
251 (:result-types unsigned-num)
254 ;; It is a right shift.
255 (inst srl result number (min (- count) 31)))
257 ;; It is a left shift.
258 (inst sll result number (min count 31)))
260 ;; Count=0? Shouldn't happen, but it's easy:
261 (move result number)))))
263 (define-vop (fast-ash-c/signed=>signed)
267 (:args (number :scs (signed-reg)))
269 (:arg-types signed-num (:constant integer))
270 (:results (result :scs (signed-reg)))
271 (:result-types signed-num)
274 ;; It is a right shift.
275 (inst sra result number (min (- count) 31)))
277 ;; It is a left shift.
278 (inst sll result number (min count 31)))
280 ;; Count=0? Shouldn't happen, but it's easy:
281 (move result number)))))
283 (define-vop (signed-byte-32-len)
284 (:translate integer-length)
285 (:note "inline (signed-byte 32) integer-length")
287 (:args (arg :scs (signed-reg) :target shift))
288 (:arg-types signed-num)
289 (:results (res :scs (any-reg)))
290 (:result-types positive-fixnum)
291 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) shift)
293 (let ((loop (gen-label))
296 (inst bgez shift test)
299 (inst nor shift shift)
302 (inst add res (fixnumize 1))
305 (inst bne shift loop)
306 (inst srl shift 1))))
308 (define-vop (unsigned-byte-32-count)
309 (:translate logcount)
310 (:note "inline (unsigned-byte 32) logcount")
312 (:args (arg :scs (unsigned-reg) :target num))
313 (:arg-types unsigned-num)
314 (:results (res :scs (unsigned-reg)))
315 (:result-types positive-fixnum)
316 (:temporary (:scs (non-descriptor-reg) :from (:argument 0) :to (:result 0)
318 (:temporary (:scs (non-descriptor-reg)) mask temp)
320 (inst li mask #x55555555)
321 (inst srl temp arg 1)
322 (inst and num arg mask)
325 (inst li mask #x33333333)
326 (inst srl temp num 2)
330 (inst li mask #x0f0f0f0f)
331 (inst srl temp num 4)
335 (inst li mask #x00ff00ff)
336 (inst srl temp num 8)
340 (inst li mask #x0000ffff)
341 (inst srl temp num 16)
344 (inst addu res num temp)))
347 ;;; Multiply and Divide.
349 (define-vop (fast-*/fixnum=>fixnum fast-fixnum-binop)
350 (:temporary (:scs (non-descriptor-reg)) temp)
357 (define-vop (fast-*/signed=>signed fast-signed-binop)
363 (define-vop (fast-*/unsigned=>unsigned fast-unsigned-binop)
371 (define-vop (fast-truncate/fixnum fast-fixnum-binop)
372 (:translate truncate)
373 (:results (q :scs (any-reg))
375 (:result-types tagged-num tagged-num)
376 (:temporary (:scs (non-descriptor-reg) :to :eval) temp)
378 (:save-p :compute-only)
380 (let ((zero (generate-error-code vop division-by-zero-error x y)))
381 (inst beq y zero-tn zero))
388 (define-vop (fast-truncate/unsigned fast-unsigned-binop)
389 (:translate truncate)
390 (:results (q :scs (unsigned-reg))
391 (r :scs (unsigned-reg)))
392 (:result-types unsigned-num unsigned-num)
394 (:save-p :compute-only)
396 (let ((zero (generate-error-code vop division-by-zero-error x y)))
397 (inst beq y zero-tn zero))
403 (define-vop (fast-truncate/signed fast-signed-binop)
404 (:translate truncate)
405 (:results (q :scs (signed-reg))
406 (r :scs (signed-reg)))
407 (:result-types signed-num signed-num)
409 (:save-p :compute-only)
411 (let ((zero (generate-error-code vop division-by-zero-error x y)))
412 (inst beq y zero-tn zero))
420 ;;;; Binary conditional VOPs:
422 (define-vop (fast-conditional)
427 (:temporary (:scs (non-descriptor-reg)) temp)
428 (:policy :fast-safe))
430 (define-vop (fast-conditional/fixnum fast-conditional)
431 (:args (x :scs (any-reg))
433 (:arg-types tagged-num tagged-num)
434 (:note "inline fixnum comparison"))
436 (define-vop (fast-conditional-c/fixnum fast-conditional/fixnum)
437 (:args (x :scs (any-reg)))
438 (:arg-types tagged-num (:constant (signed-byte-with-a-bite-out 14 4)))
439 (:info target not-p y))
441 (define-vop (fast-conditional/signed fast-conditional)
442 (:args (x :scs (signed-reg))
443 (y :scs (signed-reg)))
444 (:arg-types signed-num signed-num)
445 (:note "inline (signed-byte 32) comparison"))
447 (define-vop (fast-conditional-c/signed fast-conditional/signed)
448 (:args (x :scs (signed-reg)))
449 (:arg-types signed-num (:constant (signed-byte-with-a-bite-out 16 1)))
450 (:info target not-p y))
452 (define-vop (fast-conditional/unsigned fast-conditional)
453 (:args (x :scs (unsigned-reg))
454 (y :scs (unsigned-reg)))
455 (:arg-types unsigned-num unsigned-num)
456 (:note "inline (unsigned-byte 32) comparison"))
458 (define-vop (fast-conditional-c/unsigned fast-conditional/unsigned)
459 (:args (x :scs (unsigned-reg)))
460 (:arg-types unsigned-num (:constant (and (signed-byte-with-a-bite-out 16 1)
462 (:info target not-p y))
465 (defmacro define-conditional-vop (translate &rest generator)
467 ,@(mapcar #'(lambda (suffix cost signed)
468 (unless (and (member suffix '(/fixnum -c/fixnum))
470 `(define-vop (,(intern (format nil "~:@(FAST-IF-~A~A~)"
473 (format nil "~:@(FAST-CONDITIONAL~A~)"
475 (:translate ,translate)
477 (let* ((signed ,signed)
478 (-c/fixnum ,(eq suffix '-c/fixnum))
479 (y (if -c/fixnum (fixnumize y) y)))
480 (declare (ignorable signed -c/fixnum y))
482 '(/fixnum -c/fixnum /signed -c/signed /unsigned -c/unsigned)
484 '(t t t t nil nil))))
486 (define-conditional-vop <
487 (cond ((and signed (eql y 0))
490 (inst bltz x target)))
494 (inst sltu temp x y))
496 (inst beq temp zero-tn target)
497 (inst bne temp zero-tn target))))
500 (define-conditional-vop >
501 (cond ((and signed (eql y 0))
504 (inst bgtz x target)))
506 (let ((y (+ y (if -c/fixnum (fixnumize 1) 1))))
509 (inst sltu temp x y))
511 (inst bne temp zero-tn target)
512 (inst beq temp zero-tn target))))
516 (inst sltu temp y x))
518 (inst beq temp zero-tn target)
519 (inst bne temp zero-tn target))))
522 ;;; EQL/FIXNUM is funny because the first arg can be of any type, not just a
525 (define-conditional-vop eql
526 (declare (ignore signed))
531 (inst bne x y target)
532 (inst beq x y target))
535 ;;; These versions specify a fixnum restriction on their first arg. We have
536 ;;; also generic-eql/fixnum VOPs which are the same, but have no restriction on
537 ;;; the first arg and a higher cost. The reason for doing this is to prevent
538 ;;; fixnum specific operations from being used on word integers, spuriously
539 ;;; consing the argument.
541 (define-vop (fast-eql/fixnum fast-conditional)
542 (:args (x :scs (any-reg))
544 (:arg-types tagged-num tagged-num)
545 (:note "inline fixnum comparison")
550 (inst bne x y target)
551 (inst beq x y target))
554 (define-vop (generic-eql/fixnum fast-eql/fixnum)
555 (:args (x :scs (any-reg descriptor-reg))
557 (:arg-types * tagged-num)
560 (define-vop (fast-eql-c/fixnum fast-conditional/fixnum)
561 (:args (x :scs (any-reg)))
562 (:arg-types tagged-num (:constant (signed-byte 14)))
563 (:info target not-p y)
566 (let ((y (cond ((eql y 0) zero-tn)
568 (inst li temp (fixnumize y))
571 (inst bne x y target)
572 (inst beq x y target))
575 (define-vop (generic-eql-c/fixnum fast-eql-c/fixnum)
576 (:args (x :scs (any-reg descriptor-reg)))
577 (:arg-types * (:constant (signed-byte 14)))
581 ;;;; 32-bit logical operations
583 (define-vop (merge-bits)
584 (:translate merge-bits)
585 (:args (shift :scs (signed-reg unsigned-reg))
586 (prev :scs (unsigned-reg))
587 (next :scs (unsigned-reg)))
588 (:arg-types tagged-num unsigned-num unsigned-num)
589 (:temporary (:scs (unsigned-reg) :to (:result 0)) temp)
590 (:temporary (:scs (unsigned-reg) :to (:result 0) :target result) res)
591 (:results (result :scs (unsigned-reg)))
592 (:result-types unsigned-num)
595 (let ((done (gen-label)))
596 (inst beq shift done)
597 (inst srl res next shift)
598 (inst subu temp zero-tn shift)
599 (inst sll temp prev temp)
600 (inst or res res temp)
605 (define-vop (32bit-logical)
606 (:args (x :scs (unsigned-reg))
607 (y :scs (unsigned-reg)))
608 (:arg-types unsigned-num unsigned-num)
609 (:results (r :scs (unsigned-reg)))
610 (:result-types unsigned-num)
611 (:policy :fast-safe))
613 (define-vop (32bit-logical-not 32bit-logical)
614 (:translate 32bit-logical-not)
615 (:args (x :scs (unsigned-reg)))
616 (:arg-types unsigned-num)
618 (inst nor r x zero-tn)))
620 (define-vop (32bit-logical-and 32bit-logical)
621 (:translate 32bit-logical-and)
625 (deftransform 32bit-logical-nand ((x y) (* *))
626 '(32bit-logical-not (32bit-logical-and x y)))
628 (define-vop (32bit-logical-or 32bit-logical)
629 (:translate 32bit-logical-or)
633 (define-vop (32bit-logical-nor 32bit-logical)
634 (:translate 32bit-logical-nor)
638 (define-vop (32bit-logical-xor 32bit-logical)
639 (:translate 32bit-logical-xor)
643 (deftransform 32bit-logical-eqv ((x y) (* *))
644 '(32bit-logical-not (32bit-logical-xor x y)))
646 (deftransform 32bit-logical-andc1 ((x y) (* *))
647 '(32bit-logical-and (32bit-logical-not x) y))
649 (deftransform 32bit-logical-andc2 ((x y) (* *))
650 '(32bit-logical-and x (32bit-logical-not y)))
652 (deftransform 32bit-logical-orc1 ((x y) (* *))
653 '(32bit-logical-or (32bit-logical-not x) y))
655 (deftransform 32bit-logical-orc2 ((x y) (* *))
656 '(32bit-logical-or x (32bit-logical-not y)))
659 (define-vop (shift-towards-someplace)
661 (:args (num :scs (unsigned-reg))
662 (amount :scs (signed-reg)))
663 (:arg-types unsigned-num tagged-num)
664 (:results (r :scs (unsigned-reg)))
665 (:result-types unsigned-num))
667 (define-vop (shift-towards-start shift-towards-someplace)
668 (:translate shift-towards-start)
669 (:note "SHIFT-TOWARDS-START")
671 (ecase *backend-byte-order*
673 (inst sll r num amount))
675 (inst srl r num amount)))))
677 (define-vop (shift-towards-end shift-towards-someplace)
678 (:translate shift-towards-end)
679 (:note "SHIFT-TOWARDS-END")
681 (ecase *backend-byte-order*
683 (inst srl r num amount))
685 (inst sll r num amount)))))
691 (define-vop (bignum-length get-header-data)
692 (:translate sb!bignum::%bignum-length)
693 (:policy :fast-safe))
695 (define-vop (bignum-set-length set-header-data)
696 (:translate sb!bignum::%bignum-set-length)
697 (:policy :fast-safe))
699 (define-full-reffer bignum-ref * bignum-digits-offset other-pointer-lowtag
700 (unsigned-reg) unsigned-num sb!bignum::%bignum-ref)
702 (define-full-setter bignum-set * bignum-digits-offset other-pointer-lowtag
703 (unsigned-reg) unsigned-num sb!bignum::%bignum-set)
705 (define-vop (digit-0-or-plus)
706 (:translate sb!bignum::%digit-0-or-plusp)
708 (:args (digit :scs (unsigned-reg)))
709 (:arg-types unsigned-num)
714 (inst bltz digit target)
715 (inst bgez digit target))
718 (define-vop (add-w/carry)
719 (:translate sb!bignum::%add-with-carry)
721 (:args (a :scs (unsigned-reg))
722 (b :scs (unsigned-reg))
724 (:arg-types unsigned-num unsigned-num positive-fixnum)
725 (:temporary (:scs (unsigned-reg) :to (:result 0) :target result) res)
726 (:results (result :scs (unsigned-reg))
727 (carry :scs (unsigned-reg) :from :eval))
728 (:result-types unsigned-num positive-fixnum)
729 (:temporary (:scs (non-descriptor-reg)) temp)
731 (let ((carry-in (gen-label))
733 (inst bne c carry-in)
737 (inst sltu carry res b)
739 (emit-label carry-in)
741 (inst nor temp a zero-tn)
742 (inst sltu carry b temp)
748 (define-vop (sub-w/borrow)
749 (:translate sb!bignum::%subtract-with-borrow)
751 (:args (a :scs (unsigned-reg))
752 (b :scs (unsigned-reg))
754 (:arg-types unsigned-num unsigned-num positive-fixnum)
755 (:temporary (:scs (unsigned-reg) :to (:result 0) :target result) res)
756 (:results (result :scs (unsigned-reg))
757 (borrow :scs (unsigned-reg) :from :eval))
758 (:result-types unsigned-num positive-fixnum)
760 (let ((no-borrow-in (gen-label))
763 (inst bne c no-borrow-in)
768 (inst sltu borrow b a)
770 (emit-label no-borrow-in)
771 (inst sltu borrow a b)
777 (define-vop (bignum-mult-and-add-3-arg)
778 (:translate sb!bignum::%multiply-and-add)
780 (:args (x :scs (unsigned-reg))
781 (y :scs (unsigned-reg))
782 (carry-in :scs (unsigned-reg) :to :save))
783 (:arg-types unsigned-num unsigned-num unsigned-num)
784 (:temporary (:scs (unsigned-reg) :from (:argument 1)) temp)
785 (:results (hi :scs (unsigned-reg))
786 (lo :scs (unsigned-reg)))
787 (:result-types unsigned-num unsigned-num)
791 (inst addu lo temp carry-in)
792 (inst sltu temp lo carry-in)
794 (inst addu hi temp)))
796 (define-vop (bignum-mult-and-add-4-arg)
797 (:translate sb!bignum::%multiply-and-add)
799 (:args (x :scs (unsigned-reg))
800 (y :scs (unsigned-reg))
801 (prev :scs (unsigned-reg))
802 (carry-in :scs (unsigned-reg) :to :save))
803 (:arg-types unsigned-num unsigned-num unsigned-num unsigned-num)
804 (:temporary (:scs (unsigned-reg) :from (:argument 2)) temp)
805 (:results (hi :scs (unsigned-reg))
806 (lo :scs (unsigned-reg)))
807 (:result-types unsigned-num unsigned-num)
810 (inst addu lo prev carry-in)
811 (inst sltu temp lo carry-in)
816 (inst sltu temp lo temp)
817 (inst addu hi temp)))
819 (define-vop (bignum-mult)
820 (:translate sb!bignum::%multiply)
822 (:args (x :scs (unsigned-reg))
823 (y :scs (unsigned-reg)))
824 (:arg-types unsigned-num unsigned-num)
825 (:results (hi :scs (unsigned-reg))
826 (lo :scs (unsigned-reg)))
827 (:result-types unsigned-num unsigned-num)
833 (define-vop (bignum-lognot)
834 (:translate sb!bignum::%lognot)
836 (:args (x :scs (unsigned-reg)))
837 (:arg-types unsigned-num)
838 (:results (r :scs (unsigned-reg)))
839 (:result-types unsigned-num)
841 (inst nor r x zero-tn)))
843 (define-vop (fixnum-to-digit)
844 (:translate sb!bignum::%fixnum-to-digit)
846 (:args (fixnum :scs (any-reg)))
847 (:arg-types tagged-num)
848 (:results (digit :scs (unsigned-reg)))
849 (:result-types unsigned-num)
851 (inst sra digit fixnum 2)))
853 (define-vop (bignum-floor)
854 (:translate sb!bignum::%floor)
856 (:args (num-high :scs (unsigned-reg) :target rem)
857 (num-low :scs (unsigned-reg) :target rem-low)
858 (denom :scs (unsigned-reg) :to (:eval 1)))
859 (:arg-types unsigned-num unsigned-num unsigned-num)
860 (:temporary (:scs (unsigned-reg) :from (:argument 1)) rem-low)
861 (:temporary (:scs (unsigned-reg) :from (:eval 0)) temp)
862 (:results (quo :scs (unsigned-reg) :from (:eval 0))
863 (rem :scs (unsigned-reg) :from (:argument 0)))
864 (:result-types unsigned-num unsigned-num)
865 (:generator 325 ; number of inst assuming targeting works.
867 (move rem-low num-low)
868 (flet ((maybe-subtract (&optional (guess temp))
869 (inst subu temp guess 1)
870 (inst and temp denom)
871 (inst subu rem temp)))
872 (inst sltu quo rem denom)
876 (inst srl temp rem-low 31)
879 (inst sltu temp rem denom)
883 (inst nor quo zero-tn)))
885 (define-vop (signify-digit)
886 (:translate sb!bignum::%fixnum-digit-with-correct-sign)
888 (:args (digit :scs (unsigned-reg) :target res))
889 (:arg-types unsigned-num)
890 (:results (res :scs (any-reg signed-reg)))
891 (:result-types signed-num)
895 (inst sll res digit 2))
900 (define-vop (digit-ashr)
901 (:translate sb!bignum::%ashr)
903 (:args (digit :scs (unsigned-reg))
904 (count :scs (unsigned-reg)))
905 (:arg-types unsigned-num positive-fixnum)
906 (:results (result :scs (unsigned-reg)))
907 (:result-types unsigned-num)
909 (inst sra result digit count)))
911 (define-vop (digit-lshr digit-ashr)
912 (:translate sb!bignum::%digit-logical-shift-right)
914 (inst srl result digit count)))
916 (define-vop (digit-ashl digit-ashr)
917 (:translate sb!bignum::%ashl)
919 (inst sll result digit count)))
922 ;;;; Static functions.
924 (define-static-fun two-arg-gcd (x y) :translate gcd)
925 (define-static-fun two-arg-lcm (x y) :translate lcm)
927 (define-static-fun two-arg-+ (x y) :translate +)
928 (define-static-fun two-arg-- (x y) :translate -)
929 (define-static-fun two-arg-* (x y) :translate *)
930 (define-static-fun two-arg-/ (x y) :translate /)
932 (define-static-fun two-arg-< (x y) :translate <)
933 (define-static-fun two-arg-<= (x y) :translate <=)
934 (define-static-fun two-arg-> (x y) :translate >)
935 (define-static-fun two-arg->= (x y) :translate >=)
936 (define-static-fun two-arg-= (x y) :translate =)
937 (define-static-fun two-arg-/= (x y) :translate /=)
939 (define-static-fun %negate (x) :translate %negate)
941 (define-static-fun two-arg-and (x y) :translate logand)
942 (define-static-fun two-arg-ior (x y) :translate logior)
943 (define-static-fun two-arg-xor (x y) :translate logxor)