1 ;;;; the VM definition arithmetic VOPs for MIPS
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 ;;;; Unary operations.
16 (define-vop (fixnum-unop)
17 (:args (x :scs (any-reg)))
18 (:results (res :scs (any-reg)))
19 (:note "inline fixnum arithmetic")
20 (:arg-types tagged-num)
21 (:result-types tagged-num)
24 (define-vop (signed-unop)
25 (:args (x :scs (signed-reg)))
26 (:results (res :scs (signed-reg)))
27 (:note "inline (signed-byte 32) arithmetic")
28 (:arg-types signed-num)
29 (:result-types signed-num)
32 (define-vop (fast-negate/fixnum fixnum-unop)
35 (inst subu res zero-tn x)))
37 (define-vop (fast-negate/signed signed-unop)
40 (inst subu res zero-tn x)))
42 (define-vop (fast-lognot/fixnum fixnum-unop)
43 (:temporary (:scs (any-reg) :type fixnum :to (:result 0))
47 (inst li temp (fixnumize -1))
48 (inst xor res x temp)))
50 (define-vop (fast-lognot/signed signed-unop)
53 (inst nor res x zero-tn)))
57 ;;;; Binary fixnum operations.
59 ;;; Assume that any constant operand is the second arg...
61 (define-vop (fast-fixnum-binop)
62 (:args (x :target r :scs (any-reg))
63 (y :target r :scs (any-reg)))
64 (:arg-types tagged-num tagged-num)
65 (:results (r :scs (any-reg)))
66 (:result-types tagged-num)
67 (:note "inline fixnum arithmetic")
72 (define-vop (fast-unsigned-binop)
73 (:args (x :target r :scs (unsigned-reg))
74 (y :target r :scs (unsigned-reg)))
75 (:arg-types unsigned-num unsigned-num)
76 (:results (r :scs (unsigned-reg)))
77 (:result-types unsigned-num)
78 (:note "inline (unsigned-byte 32) arithmetic")
83 (define-vop (fast-signed-binop)
84 (:args (x :target r :scs (signed-reg))
85 (y :target r :scs (signed-reg)))
86 (:arg-types signed-num signed-num)
87 (:results (r :scs (signed-reg)))
88 (:result-types signed-num)
89 (:note "inline (signed-byte 32) arithmetic")
94 (define-vop (fast-fixnum-c-binop fast-fixnum-binop)
95 (:args (x :target r :scs (any-reg)))
97 (:arg-types tagged-num (:constant integer)))
99 (define-vop (fast-signed-c-binop fast-signed-binop)
100 (:args (x :target r :scs (signed-reg)))
102 (:arg-types tagged-num (:constant integer)))
104 (define-vop (fast-unsigned-c-binop fast-unsigned-binop)
105 (:args (x :target r :scs (unsigned-reg)))
107 (:arg-types tagged-num (:constant integer)))
109 (defmacro define-binop (translate cost untagged-cost op
110 tagged-type untagged-type)
112 (define-vop (,(symbolicate "FAST-" translate "/FIXNUM=>FIXNUM")
114 (:args (x :target r :scs (any-reg))
115 (y :target r :scs (any-reg)))
116 (:translate ,translate)
117 (:generator ,(1+ cost)
119 (define-vop (,(symbolicate "FAST-" translate "/SIGNED=>SIGNED")
121 (:args (x :target r :scs (signed-reg))
122 (y :target r :scs (signed-reg)))
123 (:translate ,translate)
124 (:generator ,(1+ untagged-cost)
126 (define-vop (,(symbolicate "FAST-" translate "/UNSIGNED=>UNSIGNED")
128 (:args (x :target r :scs (unsigned-reg))
129 (y :target r :scs (unsigned-reg)))
130 (:translate ,translate)
131 (:generator ,(1+ untagged-cost)
134 `((define-vop (,(symbolicate "FAST-" translate "-C/FIXNUM=>FIXNUM")
136 (:arg-types tagged-num (:constant ,tagged-type))
137 (:translate ,translate)
139 (inst ,op r x (fixnumize y))))))
140 ,@(when untagged-type
141 `((define-vop (,(symbolicate "FAST-" translate "-C/SIGNED=>SIGNED")
143 (:arg-types signed-num (:constant ,untagged-type))
144 (:translate ,translate)
145 (:generator ,untagged-cost
147 (define-vop (,(symbolicate "FAST-" translate
148 "-C/UNSIGNED=>UNSIGNED")
149 fast-unsigned-c-binop)
150 (:arg-types unsigned-num (:constant ,untagged-type))
151 (:translate ,translate)
152 (:generator ,untagged-cost
153 (inst ,op r x y)))))))
155 (define-binop + 1 5 addu (signed-byte 14) (signed-byte 16))
156 (define-binop - 1 5 subu
157 (integer #.(- (1- (ash 1 14))) #.(ash 1 14))
158 (integer #.(- (1- (ash 1 16))) #.(ash 1 16)))
159 (define-binop logior 1 3 or (unsigned-byte 14) (unsigned-byte 16))
160 (define-binop lognor 1 3 nor nil nil)
161 (define-binop logand 1 3 and (unsigned-byte 14) (unsigned-byte 16))
162 (define-binop logxor 1 3 xor (unsigned-byte 14) (unsigned-byte 16))
164 ;;; Special case fixnum + and - that trap on overflow. Useful when we don't
165 ;;; know that the result is going to be a fixnum.
168 (define-vop (fast-+/fixnum fast-+/fixnum=>fixnum)
169 (:results (r :scs (any-reg descriptor-reg)))
170 (:result-types (:or signed-num unsigned-num))
175 (define-vop (fast-+-c/fixnum fast-+-c/fixnum=>fixnum)
176 (:results (r :scs (any-reg descriptor-reg)))
177 (:result-types (:or signed-num unsigned-num))
180 (inst add r x (fixnumize y))))
182 (define-vop (fast--/fixnum fast--/fixnum=>fixnum)
183 (:results (r :scs (any-reg descriptor-reg)))
184 (:result-types (:or signed-num unsigned-num))
189 (define-vop (fast---c/fixnum fast---c/fixnum=>fixnum)
190 (:results (r :scs (any-reg descriptor-reg)))
191 (:result-types (:or signed-num unsigned-num))
194 (inst sub r x (fixnumize y))))
195 ) ; bogus trap-to-c-land +/-
199 (define-vop (fast-ash/unsigned=>unsigned)
201 (:args (number :scs (unsigned-reg) :to :save)
202 (amount :scs (signed-reg) :to :save))
203 (:arg-types unsigned-num signed-num)
204 (:results (result :scs (unsigned-reg)))
205 (:result-types unsigned-num)
208 (:temporary (:sc non-descriptor-reg) ndesc)
209 (:temporary (:sc non-descriptor-reg :to :eval) temp)
211 (inst bgez amount positive)
212 (inst subu ndesc zero-tn amount)
213 (inst slt temp ndesc 32)
214 (inst bne temp zero-tn done)
215 (inst srl result number ndesc)
217 (inst move result zero-tn)
220 ;; The result-type assures us that this shift will not overflow.
221 (inst sll result number amount)
225 (define-vop (fast-ash/signed=>signed)
227 (:args (number :scs (signed-reg) :to :save)
228 (amount :scs (signed-reg)))
229 (:arg-types signed-num signed-num)
230 (:results (result :scs (signed-reg)))
231 (:result-types signed-num)
234 (:temporary (:sc non-descriptor-reg) ndesc)
235 (:temporary (:sc non-descriptor-reg :to :eval) temp)
237 (inst bgez amount positive)
238 (inst subu ndesc zero-tn amount)
239 (inst slt temp ndesc 31)
240 (inst bne temp zero-tn done)
241 (inst sra result number ndesc)
243 (inst sra result number 31)
246 ;; The result-type assures us that this shift will not overflow.
247 (inst sll result number amount)
252 (define-vop (fast-ash-c/unsigned=>unsigned)
256 (:args (number :scs (unsigned-reg)))
258 (:arg-types unsigned-num (:constant integer))
259 (:results (result :scs (unsigned-reg)))
260 (:result-types unsigned-num)
263 ((< count -31) (move result zero-tn))
264 ((< count 0) (inst srl result number (min (- count) 31)))
265 ((> count 0) (inst sll result number (min count 31)))
266 (t (bug "identity ASH not transformed away")))))
268 (define-vop (fast-ash-c/signed=>signed)
272 (:args (number :scs (signed-reg)))
274 (:arg-types signed-num (:constant integer))
275 (:results (result :scs (signed-reg)))
276 (:result-types signed-num)
279 ((< count 0) (inst sra result number (min (- count) 31)))
280 ((> count 0) (inst sll result number (min count 31)))
281 (t (bug "identity ASH not transformed away")))))
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)