1 ;;;; the VM definition arithmetic VOPs for the Alpha
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.
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 64) arithmetic")
28 (:arg-types signed-num)
29 (:result-types signed-num)
32 (define-vop (fast-negate/fixnum fixnum-unop)
35 (inst subq zero-tn x res)))
37 (define-vop (fast-negate/signed signed-unop)
40 (inst subq zero-tn x res)))
42 (define-vop (fast-lognot/fixnum fixnum-unop)
45 (inst eqv x zero-tn res)))
47 (define-vop (fast-lognot/signed signed-unop)
52 ;;;; binary fixnum operations
54 ;;; Assume that any constant operand is the second arg...
56 (define-vop (fast-fixnum-binop)
57 (:args (x :target r :scs (any-reg))
58 (y :target r :scs (any-reg)))
59 (:arg-types tagged-num tagged-num)
60 (:results (r :scs (any-reg)))
61 (:result-types tagged-num)
62 (:note "inline fixnum arithmetic")
67 (define-vop (fast-unsigned-binop)
68 (:args (x :target r :scs (unsigned-reg))
69 (y :target r :scs (unsigned-reg)))
70 (:arg-types unsigned-num unsigned-num)
71 (:results (r :scs (unsigned-reg)))
72 (:result-types unsigned-num)
73 (:note "inline (unsigned-byte 64) arithmetic")
78 (define-vop (fast-signed-binop)
79 (:args (x :target r :scs (signed-reg))
80 (y :target r :scs (signed-reg)))
81 (:arg-types signed-num signed-num)
82 (:results (r :scs (signed-reg)))
83 (:result-types signed-num)
84 (:note "inline (signed-byte 64) arithmetic")
89 (define-vop (fast-fixnum-c-binop fast-fixnum-binop)
90 (:args (x :target r :scs (any-reg)))
92 (:arg-types tagged-num (:constant integer)))
94 (define-vop (fast-signed-c-binop fast-signed-binop)
95 (:args (x :target r :scs (signed-reg)))
97 (:arg-types tagged-num (:constant integer)))
99 (define-vop (fast-unsigned-c-binop fast-unsigned-binop)
100 (:args (x :target r :scs (unsigned-reg)))
102 (:arg-types tagged-num (:constant integer)))
104 (defmacro define-binop (translate cost untagged-cost op
105 tagged-type untagged-type
106 &optional arg-swap restore-fixnum-mask)
108 (define-vop (,(symbolicate "FAST-" translate "/FIXNUM=>FIXNUM")
110 ,@(when restore-fixnum-mask
111 `((:temporary (:sc non-descriptor-reg) temp)))
112 (:args (x ,@(unless restore-fixnum-mask `(:target r)) :scs (any-reg))
113 (y ,@(unless restore-fixnum-mask `(:target r)) :scs (any-reg)))
114 (:translate ,translate)
115 (:generator ,(1+ cost)
117 `(inst ,op y x ,(if restore-fixnum-mask 'temp 'r))
118 `(inst ,op x y ,(if restore-fixnum-mask 'temp 'r)))
119 ,@(when restore-fixnum-mask
120 `((inst bic temp #.(ash lowtag-mask -1) r)))))
121 (define-vop (,(symbolicate "FAST-" translate "/SIGNED=>SIGNED")
123 (:args (x :target r :scs (signed-reg))
124 (y :target r :scs (signed-reg)))
125 (:translate ,translate)
126 (:generator ,(1+ untagged-cost)
130 (define-vop (,(symbolicate "FAST-" translate "/UNSIGNED=>UNSIGNED")
132 (:args (x :target r :scs (unsigned-reg))
133 (y :target r :scs (unsigned-reg)))
134 (:translate ,translate)
135 (:generator ,(1+ untagged-cost)
139 ,@(when (and tagged-type (not arg-swap))
140 `((define-vop (,(symbolicate "FAST-" translate "-C/FIXNUM=>FIXNUM")
142 (:arg-types tagged-num (:constant ,tagged-type))
143 ,@(when restore-fixnum-mask
144 `((:temporary (:sc non-descriptor-reg) temp)))
145 (:translate ,translate)
147 (inst ,op x (fixnumize y) ,(if restore-fixnum-mask 'temp 'r))
148 ,@(when restore-fixnum-mask
149 `((inst bic temp #.(ash lowtag-mask -1) r)))))))
150 ,@(when (and untagged-type (not arg-swap))
151 `((define-vop (,(symbolicate "FAST-" translate "-C/SIGNED=>SIGNED")
153 (:arg-types signed-num (:constant ,untagged-type))
154 (:translate ,translate)
155 (:generator ,untagged-cost
157 (define-vop (,(symbolicate "FAST-" translate
158 "-C/UNSIGNED=>UNSIGNED")
159 fast-unsigned-c-binop)
160 (:arg-types unsigned-num (:constant ,untagged-type))
161 (:translate ,translate)
162 (:generator ,untagged-cost
163 (inst ,op x y r)))))))
165 (define-binop + 1 5 addq (unsigned-byte 6) (unsigned-byte 8))
166 (define-binop - 1 5 subq (unsigned-byte 6) (unsigned-byte 8))
167 (define-binop logand 1 3 and (unsigned-byte 6) (unsigned-byte 8))
168 (define-binop logandc1 1 3 bic (unsigned-byte 6) (unsigned-byte 8) t)
169 (define-binop logandc2 1 3 bic (unsigned-byte 6) (unsigned-byte 8))
170 (define-binop logior 1 3 bis (unsigned-byte 6) (unsigned-byte 8))
171 (define-binop logorc1 1 3 ornot (unsigned-byte 6) (unsigned-byte 8) t t)
172 (define-binop logorc2 1 3 ornot (unsigned-byte 6) (unsigned-byte 8) nil t)
173 (define-binop logxor 1 3 xor (unsigned-byte 6) (unsigned-byte 8))
174 (define-binop logeqv 1 3 eqv (unsigned-byte 6) (unsigned-byte 8) nil t)
176 ;;; special cases for LOGAND where we can use a mask operation
177 (define-vop (fast-logand-c-mask/unsigned=>unsigned fast-unsigned-c-binop)
179 (:arg-types unsigned-num
180 (:constant (or (integer #xffffffff #xffffffff)
181 (integer #xffffffff00000000 #xffffffff00000000))))
184 (#xffffffff (inst mskll x 4 r))
185 (#xffffffff00000000 (inst mskll x 0 r)))))
189 (define-vop (fast-ash/unsigned=>unsigned)
191 (:args (number :scs (unsigned-reg) :to :save)
192 (amount :scs (signed-reg)))
193 (:arg-types unsigned-num signed-num)
194 (:results (result :scs (unsigned-reg)))
195 (:result-types unsigned-num)
198 (:temporary (:sc non-descriptor-reg) ndesc)
199 (:temporary (:sc non-descriptor-reg) temp)
201 (inst bge amount positive)
202 (inst subq zero-tn amount ndesc)
203 (inst cmplt ndesc 64 temp)
204 (inst srl number ndesc result)
205 ;; FIXME: this looks like a candidate for a conditional move --
208 (move zero-tn result)
209 (inst br zero-tn done)
212 (inst sll number amount result)
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) temp)
228 (inst bge amount positive)
229 (inst subq zero-tn amount ndesc)
230 (inst cmplt ndesc 63 temp)
231 (inst sra number ndesc result)
233 (inst sra number 63 result)
234 (inst br zero-tn done)
237 (inst sll number amount result)
241 (define-vop (fast-ash-c/signed=>signed)
245 (:args (number :scs (signed-reg)))
247 (:arg-types signed-num (:constant integer))
248 (:results (result :scs (signed-reg)))
249 (:result-types signed-num)
252 ((< count 0) (inst sra number (min 63 (- count)) result))
253 ((> count 0) (inst sll number (min 63 count) result))
254 (t (bug "identity ASH not transformed away")))))
256 (define-vop (fast-ash-c/unsigned=>unsigned)
260 (:args (number :scs (unsigned-reg)))
262 (:arg-types unsigned-num (:constant integer))
263 (:results (result :scs (unsigned-reg)))
264 (:result-types unsigned-num)
267 ((< count -63) (move zero-tn result))
268 ((< count 0) (inst sra number (- count) result))
269 ((> count 0) (inst sll number (min 63 count) result))
270 (t (bug "identity ASH not transformed away")))))
272 (define-vop (signed-byte-64-len)
273 (:translate integer-length)
274 (:note "inline (signed-byte 64) integer-length")
276 (:args (arg :scs (signed-reg) :to (:argument 1)))
277 (:arg-types signed-num)
278 (:results (res :scs (any-reg)))
279 (:result-types positive-fixnum)
280 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) shift)
283 (inst cmovge arg arg shift)
284 (inst subq zero-tn (fixnumize 1) res)
285 (inst sll shift 1 shift)
287 (inst addq res (fixnumize 1) res)
288 (inst srl shift 1 shift)
289 (inst bne shift loop)))
291 (define-vop (unsigned-byte-64-count)
292 (:translate logcount)
293 (:note "inline (unsigned-byte 64) logcount")
295 (:args (arg :scs (unsigned-reg) :target num))
296 (:arg-types unsigned-num)
297 (:results (res :scs (unsigned-reg)))
298 (:result-types positive-fixnum)
299 (:temporary (:scs (non-descriptor-reg) :from (:argument 0) :to (:result 0)
301 (:temporary (:scs (non-descriptor-reg)) mask temp)
303 ;; FIXME: now this looks expensive, what with these 64bit loads.
304 ;; Maybe a loop and count would be faster? -- CSR, 2003-09-10
305 (inst li #x5555555555555555 mask)
306 (inst srl arg 1 temp)
307 (inst and arg mask num)
308 (inst and temp mask temp)
309 (inst addq num temp num)
310 (inst li #x3333333333333333 mask)
311 (inst srl num 2 temp)
312 (inst and num mask num)
313 (inst and temp mask temp)
314 (inst addq num temp num)
315 (inst li #x0f0f0f0f0f0f0f0f mask)
316 (inst srl num 4 temp)
317 (inst and num mask num)
318 (inst and temp mask temp)
319 (inst addq num temp num)
320 (inst li #x00ff00ff00ff00ff mask)
321 (inst srl num 8 temp)
322 (inst and num mask num)
323 (inst and temp mask temp)
324 (inst addq num temp num)
325 (inst li #x0000ffff0000ffff mask)
326 (inst srl num 16 temp)
327 (inst and num mask num)
328 (inst and temp mask temp)
329 (inst addq num temp num)
330 (inst li #x00000000ffffffff mask)
331 (inst srl num 32 temp)
332 (inst and num mask num)
333 (inst and temp mask temp)
334 (inst addq num temp res)))
338 (define-vop (fast-*/fixnum=>fixnum fast-fixnum-binop)
339 (:temporary (:scs (non-descriptor-reg)) temp)
343 (inst mulq x temp r)))
345 (define-vop (fast-*/signed=>signed fast-signed-binop)
350 (define-vop (fast-*/unsigned=>unsigned fast-unsigned-binop)
355 ;;;; Modular functions:
356 (define-modular-fun lognot-mod64 (x) lognot 64)
357 (define-vop (lognot-mod64/unsigned=>unsigned)
358 (:translate lognot-mod64)
359 (:args (x :scs (unsigned-reg)))
360 (:arg-types unsigned-num)
361 (:results (res :scs (unsigned-reg)))
362 (:result-types unsigned-num)
368 ((define-modular-backend (fun &optional constantp)
369 (let ((mfun-name (symbolicate fun '-mod64))
370 (modvop (symbolicate 'fast- fun '-mod64/unsigned=>unsigned))
371 (modcvop (symbolicate 'fast- fun 'mod64-c/unsigned=>unsigned))
372 (vop (symbolicate 'fast- fun '/unsigned=>unsigned))
373 (cvop (symbolicate 'fast- fun '-c/unsigned=>unsigned)))
375 (define-modular-fun ,mfun-name (x y) ,fun 64)
376 (define-vop (,modvop ,vop)
377 (:translate ,mfun-name))
379 `((define-vop (,modcvop ,cvop)
380 (:translate ,mfun-name))))))))
381 (define-modular-backend + t)
382 (define-modular-backend logxor t)
383 (define-modular-backend logeqv t)
384 (define-modular-backend logandc1)
385 (define-modular-backend logandc2 t)
386 (define-modular-backend logorc1)
387 (define-modular-backend logorc2 t))
389 (define-source-transform lognand (x y)
390 `(lognot (logand ,x ,y)))
391 (define-source-transform lognor (x y)
392 `(lognot (logior ,x ,y)))
394 ;;;; binary conditional VOPs
396 (define-vop (fast-conditional)
401 (:temporary (:scs (non-descriptor-reg)) temp)
402 (:policy :fast-safe))
404 (define-vop (fast-conditional/fixnum fast-conditional)
405 (:args (x :scs (any-reg))
407 (:arg-types tagged-num tagged-num)
408 (:note "inline fixnum comparison"))
410 (define-vop (fast-conditional-c/fixnum fast-conditional/fixnum)
411 (:args (x :scs (any-reg)))
412 (:arg-types tagged-num (:constant (unsigned-byte-with-a-bite-out 6 4)))
413 (:info target not-p y))
415 (define-vop (fast-conditional/signed fast-conditional)
416 (:args (x :scs (signed-reg))
417 (y :scs (signed-reg)))
418 (:arg-types signed-num signed-num)
419 (:note "inline (signed-byte 64) comparison"))
421 (define-vop (fast-conditional-c/signed fast-conditional/signed)
422 (:args (x :scs (signed-reg)))
423 (:arg-types signed-num (:constant (unsigned-byte-with-a-bite-out 8 1)))
424 (:info target not-p y))
426 (define-vop (fast-conditional/unsigned fast-conditional)
427 (:args (x :scs (unsigned-reg))
428 (y :scs (unsigned-reg)))
429 (:arg-types unsigned-num unsigned-num)
430 (:note "inline (unsigned-byte 64) comparison"))
432 (define-vop (fast-conditional-c/unsigned fast-conditional/unsigned)
433 (:args (x :scs (unsigned-reg)))
434 (:arg-types unsigned-num (:constant (unsigned-byte-with-a-bite-out 8 1)))
435 (:info target not-p y))
438 (defmacro define-conditional-vop (translate &rest generator)
440 ,@(mapcar (lambda (suffix cost signed)
441 (unless (and (member suffix '(/fixnum -c/fixnum))
443 `(define-vop (,(intern (format nil "~:@(FAST-IF-~A~A~)"
446 (format nil "~:@(FAST-CONDITIONAL~A~)"
448 (:translate ,translate)
450 (let* ((signed ,signed)
451 (-c/fixnum ,(eq suffix '-c/fixnum))
452 (y (if -c/fixnum (fixnumize y) y)))
454 '(/fixnum -c/fixnum /signed -c/signed /unsigned -c/unsigned)
456 '(t t t t nil nil))))
458 (define-conditional-vop <
459 (cond ((and signed (eql y 0))
462 (inst blt x target)))
465 (inst cmplt x y temp)
466 (inst cmpult x y temp))
468 (inst beq temp target)
469 (inst bne temp target)))))
471 (define-conditional-vop >
472 (cond ((and signed (eql y 0))
475 (inst bgt x target)))
477 (let ((y (+ y (if -c/fixnum (fixnumize 1) 1))))
479 (inst cmplt x y temp)
480 (inst cmpult x y temp))
482 (inst bne temp target)
483 (inst beq temp target))))
486 (inst cmplt y x temp)
487 (inst cmpult y x temp))
489 (inst beq temp target)
490 (inst bne temp target)))))
492 ;;; EQL/FIXNUM is funny because the first arg can be of any type, not
493 ;;; just a known fixnum.
495 (define-conditional-vop eql
496 (declare (ignore signed))
500 (inst cmpeq x y temp)
502 (inst beq temp target)
503 (inst bne temp target)))
505 ;;; These versions specify a fixnum restriction on their first arg. We
506 ;;; have also generic-eql/fixnum VOPs which are the same, but have no
507 ;;; restriction on the first arg and a higher cost. The reason for
508 ;;; doing this is to prevent fixnum specific operations from being
509 ;;; used on word integers, spuriously consing the argument.
510 (define-vop (fast-eql/fixnum fast-conditional)
511 (:args (x :scs (any-reg))
513 (:arg-types tagged-num tagged-num)
514 (:note "inline fixnum comparison")
517 (cond ((equal y zero-tn)
520 (inst beq x target)))
522 (inst cmpeq x y temp)
524 (inst beq temp target)
525 (inst bne temp target))))))
528 (define-vop (generic-eql/fixnum fast-eql/fixnum)
529 (:args (x :scs (any-reg descriptor-reg))
531 (:arg-types * tagged-num)
534 (define-vop (fast-eql-c/fixnum fast-conditional/fixnum)
535 (:args (x :scs (any-reg)))
536 (:arg-types tagged-num (:constant (signed-byte 6)))
537 (:temporary (:scs (non-descriptor-reg)) temp)
538 (:info target not-p y)
541 (let ((y (cond ((eql y 0) zero-tn)
543 (inst li (fixnumize y) temp)
545 (inst cmpeq x y temp)
547 (inst beq temp target)
548 (inst bne temp target)))))
550 (define-vop (generic-eql-c/fixnum fast-eql-c/fixnum)
551 (:args (x :scs (any-reg descriptor-reg)))
552 (:arg-types * (:constant (signed-byte 6)))
556 ;;;; 32-bit logical operations
558 (define-vop (merge-bits)
559 (:translate merge-bits)
560 (:args (shift :scs (signed-reg unsigned-reg))
561 (prev :scs (unsigned-reg))
562 (next :scs (unsigned-reg)))
563 (:arg-types tagged-num unsigned-num unsigned-num)
564 (:temporary (:scs (unsigned-reg) :to (:result 0)) temp)
565 (:temporary (:scs (unsigned-reg) :to (:result 0) :target result) res)
566 (:results (result :scs (unsigned-reg)))
567 (:result-types unsigned-num)
570 (let ((done (gen-label)))
571 (inst srl next shift res)
572 (inst beq shift done)
573 (inst subq zero-tn shift temp)
574 (inst sll prev temp temp)
575 (inst bis res temp res)
579 (define-source-transform 32bit-logical-not (x)
580 `(logand (lognot (the (unsigned-byte 32) ,x)) #.(1- (ash 1 32))))
582 (deftransform 32bit-logical-and ((x y))
585 (define-source-transform 32bit-logical-nand (x y)
586 `(32bit-logical-not (32bit-logical-and ,x ,y)))
588 (deftransform 32bit-logical-or ((x y))
591 (define-source-transform 32bit-logical-nor (x y)
592 `(logand (lognor (the (unsigned-byte 32) ,x) (the (unsigned-byte 32) ,y))
595 (deftransform 32bit-logical-xor ((x y))
598 (define-source-transform 32bit-logical-eqv (x y)
599 `(logand (logeqv (the (unsigned-byte 32) ,x) (the (unsigned-byte 32) ,y))
602 (define-source-transform 32bit-logical-orc1 (x y)
603 `(logand (logorc1 (the (unsigned-byte 32) ,x) (the (unsigned-byte 32) ,y))
606 (define-source-transform 32bit-logical-orc2 (x y)
607 `(logand (logorc2 (the (unsigned-byte 32) ,x) (the (unsigned-byte 32) ,y))
610 (define-source-transform 32bit-logical-andc1 (x y)
611 `(logandc1 (the (unsigned-byte 32) ,x) (the (unsigned-byte 32) ,y)))
613 (define-source-transform 32bit-logical-andc2 (x y)
614 `(logandc2 (the (unsigned-byte 32) ,x) (the (unsigned-byte 32) ,y)))
616 (define-vop (shift-towards-someplace)
618 (:args (num :scs (unsigned-reg))
619 (amount :scs (signed-reg)))
620 (:arg-types unsigned-num tagged-num)
621 (:results (r :scs (unsigned-reg)))
622 (:result-types unsigned-num))
624 (define-vop (shift-towards-start shift-towards-someplace)
625 (:translate shift-towards-start)
626 (:note "SHIFT-TOWARDS-START")
627 (:temporary (:sc non-descriptor-reg) temp)
629 (inst and amount #x1f temp)
630 (inst srl num temp r)))
632 (define-vop (shift-towards-end shift-towards-someplace)
633 (:translate shift-towards-end)
634 (:note "SHIFT-TOWARDS-END")
635 (:temporary (:sc non-descriptor-reg) temp)
637 (inst and amount #x1f temp)
638 (inst sll num temp r)))
642 (define-vop (bignum-length get-header-data)
643 (:translate sb!bignum::%bignum-length)
644 (:policy :fast-safe))
646 (define-vop (bignum-set-length set-header-data)
647 (:translate sb!bignum::%bignum-set-length)
648 (:policy :fast-safe))
650 (define-full-reffer bignum-ref * bignum-digits-offset other-pointer-lowtag
651 (unsigned-reg) unsigned-num sb!bignum::%bignum-ref)
653 (define-full-setter bignum-set * bignum-digits-offset other-pointer-lowtag
654 (unsigned-reg) unsigned-num sb!bignum::%bignum-set #!+gengc nil)
656 (define-vop (digit-0-or-plus)
657 (:translate sb!bignum::%digit-0-or-plusp)
659 (:args (digit :scs (unsigned-reg)))
660 (:arg-types unsigned-num)
661 (:temporary (:sc non-descriptor-reg) temp)
665 (inst sll digit 32 temp)
667 (inst blt temp target)
668 (inst bge temp target))))
670 (define-vop (add-w/carry)
671 (:translate sb!bignum::%add-with-carry)
673 (:args (a :scs (unsigned-reg))
674 (b :scs (unsigned-reg))
675 (c :scs (unsigned-reg)))
676 (:arg-types unsigned-num unsigned-num positive-fixnum)
677 (:results (result :scs (unsigned-reg) :from :load)
678 (carry :scs (unsigned-reg) :from :eval))
679 (:result-types unsigned-num positive-fixnum)
681 (inst addq a b result)
682 (inst addq result c result)
683 (inst sra result 32 carry)
684 (inst mskll result 4 result)))
686 (define-vop (sub-w/borrow)
687 (:translate sb!bignum::%subtract-with-borrow)
689 (:args (a :scs (unsigned-reg))
690 (b :scs (unsigned-reg))
691 (c :scs (unsigned-reg)))
692 (:arg-types unsigned-num unsigned-num positive-fixnum)
693 (:results (result :scs (unsigned-reg) :from :load)
694 (borrow :scs (unsigned-reg) :from :eval))
695 (:result-types unsigned-num positive-fixnum)
697 (inst xor c 1 result)
698 (inst subq a result result)
699 (inst subq result b result)
700 (inst srl result 63 borrow)
701 (inst xor borrow 1 borrow)
702 (inst mskll result 4 result)))
704 (define-vop (bignum-mult-and-add-3-arg)
705 (:translate sb!bignum::%multiply-and-add)
707 (:args (x :scs (unsigned-reg))
708 (y :scs (unsigned-reg))
709 (carry-in :scs (unsigned-reg) :to :save))
710 (:arg-types unsigned-num unsigned-num unsigned-num)
711 (:results (hi :scs (unsigned-reg))
712 (lo :scs (unsigned-reg)))
713 (:result-types unsigned-num unsigned-num)
716 (inst addq lo carry-in lo)
718 (inst mskll lo 4 lo)))
721 (define-vop (bignum-mult-and-add-4-arg)
722 (:translate sb!bignum::%multiply-and-add)
724 (:args (x :scs (unsigned-reg))
725 (y :scs (unsigned-reg))
726 (prev :scs (unsigned-reg))
727 (carry-in :scs (unsigned-reg) :to :save))
728 (:arg-types unsigned-num unsigned-num unsigned-num unsigned-num)
729 (:results (hi :scs (unsigned-reg))
730 (lo :scs (unsigned-reg)))
731 (:result-types unsigned-num unsigned-num)
734 (inst addq lo prev lo)
735 (inst addq lo carry-in lo)
737 (inst mskll lo 4 lo)))
739 (define-vop (bignum-mult)
740 (:translate sb!bignum::%multiply)
742 (:args (x :scs (unsigned-reg))
743 (y :scs (unsigned-reg)))
744 (:arg-types unsigned-num unsigned-num)
745 (:results (hi :scs (unsigned-reg))
746 (lo :scs (unsigned-reg)))
747 (:result-types unsigned-num unsigned-num)
751 (inst mskll lo 4 lo)))
753 (define-vop (bignum-lognot)
754 (:translate sb!bignum::%lognot)
756 (:args (x :scs (unsigned-reg)))
757 (:arg-types unsigned-num)
758 (:results (r :scs (unsigned-reg)))
759 (:result-types unsigned-num)
764 (define-vop (fixnum-to-digit)
765 (:translate sb!bignum::%fixnum-to-digit)
767 (:args (fixnum :scs (any-reg)))
768 (:arg-types tagged-num)
769 (:results (digit :scs (unsigned-reg)))
770 (:result-types unsigned-num)
772 (inst sra fixnum 2 digit)))
774 (define-vop (bignum-floor)
775 (:translate sb!bignum::%floor)
777 (:args (num-high :scs (unsigned-reg))
778 (num-low :scs (unsigned-reg))
779 (denom-arg :scs (unsigned-reg) :target denom))
780 (:arg-types unsigned-num unsigned-num unsigned-num)
781 (:temporary (:scs (unsigned-reg) :from (:argument 2)) denom)
782 (:temporary (:scs (unsigned-reg) :from (:eval 0)) temp)
783 (:results (quo :scs (unsigned-reg) :from (:eval 0))
784 (rem :scs (unsigned-reg) :from (:argument 0)))
785 (:result-types unsigned-num unsigned-num)
786 (:generator 325 ; number of inst assuming targeting works.
787 (inst sll num-high 32 rem)
788 (inst bis rem num-low rem)
789 (inst sll denom-arg 32 denom)
790 (inst cmpule denom rem quo)
791 (inst beq quo shift1)
792 (inst subq rem denom rem)
795 (let ((shift2 (gen-label)))
796 (inst srl denom 1 denom)
797 (inst cmpule denom rem temp)
799 (inst beq temp shift2)
800 (inst subq rem denom rem)
802 (emit-label shift2)))))
804 (define-vop (signify-digit)
805 (:translate sb!bignum::%fixnum-digit-with-correct-sign)
807 (:args (digit :scs (unsigned-reg) :target res))
808 (:arg-types unsigned-num)
809 (:results (res :scs (any-reg signed-reg)))
810 (:result-types signed-num)
814 (inst sll digit 34 res)
815 (inst sra res 32 res))
817 (inst sll digit 32 res)
818 (inst sra res 32 res)))))
821 (define-vop (digit-ashr)
822 (:translate sb!bignum::%ashr)
824 (:args (digit :scs (unsigned-reg))
825 (count :scs (unsigned-reg)))
826 (:arg-types unsigned-num positive-fixnum)
827 (:results (result :scs (unsigned-reg) :from (:argument 0)))
828 (:result-types unsigned-num)
830 (inst sll digit 32 result)
831 (inst sra result count result)
832 (inst srl result 32 result)))
834 (define-vop (digit-lshr digit-ashr)
835 (:translate sb!bignum::%digit-logical-shift-right)
837 (inst srl digit count result)))
839 (define-vop (digit-ashl digit-ashr)
840 (:translate sb!bignum::%ashl)
842 (inst sll digit count result)))
844 ;;;; static functions
846 (define-static-fun two-arg-gcd (x y) :translate gcd)
847 (define-static-fun two-arg-lcm (x y) :translate lcm)
849 (define-static-fun two-arg-+ (x y) :translate +)
850 (define-static-fun two-arg-- (x y) :translate -)
851 (define-static-fun two-arg-* (x y) :translate *)
852 (define-static-fun two-arg-/ (x y) :translate /)
854 (define-static-fun two-arg-< (x y) :translate <)
855 (define-static-fun two-arg-<= (x y) :translate <=)
856 (define-static-fun two-arg-> (x y) :translate >)
857 (define-static-fun two-arg->= (x y) :translate >=)
858 (define-static-fun two-arg-= (x y) :translate =)
859 (define-static-fun two-arg-/= (x y) :translate /=)
861 (define-static-fun %negate (x) :translate %negate)
863 (define-static-fun two-arg-and (x y) :translate logand)
864 (define-static-fun two-arg-ior (x y) :translate logior)
865 (define-static-fun two-arg-xor (x y) :translate logxor)
866 (define-static-fun two-arg-eqv (x y) :translate logeqv)