compiler/sparc/arith: Fix SCs for FAST-EQL{,-C}/FIXNUM.
[sbcl.git] / src / compiler / sparc / arith.lisp
1 ;;;; the VM definition arithmetic VOPs for the SPARC
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
11
12 (in-package "SB!VM")
13 \f
14 ;;;; unary operations.
15
16 (define-vop (fast-safe-arith-op)
17   (:policy :fast-safe)
18   (:effects)
19   (:affected))
20
21 (define-vop (fixnum-unop fast-safe-arith-op)
22   (:args (x :scs (any-reg)))
23   (:results (res :scs (any-reg)))
24   (:note "inline fixnum arithmetic")
25   (:arg-types tagged-num)
26   (:result-types tagged-num))
27
28 (define-vop (signed-unop fast-safe-arith-op)
29   (:args (x :scs (signed-reg)))
30   (:results (res :scs (signed-reg)))
31   (:note "inline (signed-byte 32) arithmetic")
32   (:arg-types signed-num)
33   (:result-types signed-num))
34
35 (define-vop (fast-negate/fixnum fixnum-unop)
36   (:translate %negate)
37   (:generator 1
38     (inst neg res x)))
39
40 (define-vop (fast-negate/signed signed-unop)
41   (:translate %negate)
42   (:generator 2
43     (inst neg res x)))
44
45 (define-vop (fast-lognot/fixnum fixnum-unop)
46   (:translate lognot)
47   (:generator 1
48     (inst xor res x (fixnumize -1))))
49
50 (define-vop (fast-lognot/signed signed-unop)
51   (:translate lognot)
52   (:generator 2
53     (inst not res x)))
54 \f
55 ;;;; Binary fixnum operations.
56
57 ;;; Assume that any constant operand is the second arg...
58
59 (define-vop (fast-fixnum-binop fast-safe-arith-op)
60   (:args (x :target r :scs (any-reg zero))
61          (y :target r :scs (any-reg zero)))
62   (:arg-types tagged-num tagged-num)
63   (:results (r :scs (any-reg)))
64   (:result-types tagged-num)
65   (:note "inline fixnum arithmetic"))
66
67 (define-vop (fast-unsigned-binop fast-safe-arith-op)
68   (:args (x :target r :scs (unsigned-reg zero))
69          (y :target r :scs (unsigned-reg zero)))
70   (:arg-types unsigned-num unsigned-num)
71   (:results (r :scs (unsigned-reg)))
72   (:result-types unsigned-num)
73   (:note "inline (unsigned-byte 32) arithmetic"))
74
75 (define-vop (fast-signed-binop fast-safe-arith-op)
76   (:args (x :target r :scs (signed-reg zero))
77          (y :target r :scs (signed-reg zero)))
78   (:arg-types signed-num signed-num)
79   (:results (r :scs (signed-reg)))
80   (:result-types signed-num)
81   (:note "inline (signed-byte 32) arithmetic"))
82
83
84 (define-vop (fast-fixnum-binop-c fast-safe-arith-op)
85   (:args (x :target r :scs (any-reg zero)))
86   (:info y)
87   (:arg-types tagged-num
88               (:constant (and (signed-byte 11) (not (integer 0 0)))))
89   (:results (r :scs (any-reg)))
90   (:result-types tagged-num)
91   (:note "inline fixnum arithmetic"))
92
93 (define-vop (fast-unsigned-binop-c fast-safe-arith-op)
94   (:args (x :target r :scs (unsigned-reg zero)))
95   (:info y)
96   (:arg-types unsigned-num
97               (:constant (and (signed-byte 13) (not (integer 0 0)))))
98   (:results (r :scs (unsigned-reg)))
99   (:result-types unsigned-num)
100   (:note "inline (unsigned-byte 32) arithmetic"))
101
102 (define-vop (fast-signed-binop-c fast-safe-arith-op)
103   (:args (x :target r :scs (signed-reg zero)))
104   (:info y)
105   (:arg-types signed-num
106               (:constant (and (signed-byte 13) (not (integer 0 0)))))
107   (:results (r :scs (signed-reg)))
108   (:result-types signed-num)
109   (:note "inline (signed-byte 32) arithmetic"))
110
111
112 (eval-when (:compile-toplevel :load-toplevel :execute)
113
114 (defmacro define-binop (translate untagged-penalty op
115                         &optional arg-swap restore-fixnum-mask)
116   `(progn
117      (define-vop (,(symbolicate 'fast translate '/fixnum=>fixnum)
118                   fast-fixnum-binop)
119        ,@(when restore-fixnum-mask
120            `((:temporary (:sc non-descriptor-reg) temp)))
121        (:translate ,translate)
122        (:generator 2
123          ,(if arg-swap
124               `(inst ,op ,(if restore-fixnum-mask 'temp 'r) y x)
125               `(inst ,op ,(if restore-fixnum-mask 'temp 'r) x y))
126          ,@(when restore-fixnum-mask
127              `((inst andn r temp fixnum-tag-mask)))))
128      ,@(unless arg-swap
129          `((define-vop (,(symbolicate 'fast- translate '-c/fixnum=>fixnum)
130                         fast-fixnum-binop-c)
131              ,@(when restore-fixnum-mask
132                  `((:temporary (:sc non-descriptor-reg) temp)))
133              (:translate ,translate)
134              (:generator 1
135                (inst ,op ,(if restore-fixnum-mask 'temp 'r) x (fixnumize y))
136                ,@(when restore-fixnum-mask
137                    `((inst andn r temp fixnum-tag-mask)))))))
138      (define-vop (,(symbolicate 'fast- translate '/signed=>signed)
139                   fast-signed-binop)
140        (:translate ,translate)
141        (:generator ,(1+ untagged-penalty)
142          ,(if arg-swap
143               `(inst ,op r y x)
144               `(inst ,op r x y))))
145      ,@(unless arg-swap
146          `((define-vop (,(symbolicate 'fast- translate '-c/signed=>signed)
147                         fast-signed-binop-c)
148              (:translate ,translate)
149              (:generator ,untagged-penalty
150                (inst ,op r x y)))))
151      (define-vop (,(symbolicate 'fast- translate '/unsigned=>unsigned)
152                   fast-unsigned-binop)
153        (:translate ,translate)
154        (:generator ,(1+ untagged-penalty)
155          ,(if arg-swap
156               `(inst ,op r y x)
157               `(inst ,op r x y))))
158      ,@(unless arg-swap
159          `((define-vop (,(symbolicate 'fast- translate '-c/unsigned=>unsigned)
160                         fast-unsigned-binop-c)
161              (:translate ,translate)
162              (:generator ,untagged-penalty
163                (inst ,op r x y)))))))
164
165 ); eval-when
166
167 (define-binop + 4 add)
168 (define-binop - 4 sub)
169 (define-binop logand 2 and)
170 (define-binop logandc1 2 andn t)
171 (define-binop logandc2 2 andn)
172 (define-binop logior 2 or)
173 (define-binop logorc1 2 orn t t)
174 (define-binop logorc2 2 orn nil t)
175 (define-binop logxor 2 xor)
176 (define-binop logeqv 2 xnor nil t)
177
178 (define-vop (fast-logand/signed-unsigned=>unsigned fast-logand/unsigned=>unsigned)
179   (:args (x :scs (signed-reg) :target r)
180          (y :scs (unsigned-reg) :target r))
181   (:arg-types signed-num unsigned-num)
182   (:translate logand))
183
184 ;;; Special case fixnum + and - that trap on overflow.  Useful when we
185 ;;; don't know that the output type is a fixnum.
186
187 ;;; I (Raymond Toy) took these out. They don't seem to be used
188 ;;; anywhere at all.
189 #+nil
190 (progn
191 (define-vop (+/fixnum fast-+/fixnum=>fixnum)
192   (:policy :safe)
193   (:results (r :scs (any-reg descriptor-reg)))
194   (:result-types tagged-num)
195   (:note "safe inline fixnum arithmetic")
196   (:generator 4
197     (inst taddcctv r x y)))
198
199 (define-vop (+-c/fixnum fast-+-c/fixnum=>fixnum)
200   (:policy :safe)
201   (:results (r :scs (any-reg descriptor-reg)))
202   (:result-types tagged-num)
203   (:note "safe inline fixnum arithmetic")
204   (:generator 3
205     (inst taddcctv r x (fixnumize y))))
206
207 (define-vop (-/fixnum fast--/fixnum=>fixnum)
208   (:policy :safe)
209   (:results (r :scs (any-reg descriptor-reg)))
210   (:result-types tagged-num)
211   (:note "safe inline fixnum arithmetic")
212   (:generator 4
213     (inst tsubcctv r x y)))
214
215 (define-vop (--c/fixnum fast---c/fixnum=>fixnum)
216   (:policy :safe)
217   (:results (r :scs (any-reg descriptor-reg)))
218   (:result-types tagged-num)
219   (:note "safe inline fixnum arithmetic")
220   (:generator 3
221     (inst tsubcctv r x (fixnumize y))))
222
223 )
224
225 ;;; Truncate
226
227 ;; This doesn't work for some reason.
228 #+nil
229 (define-vop (fast-v8-truncate/fixnum=>fixnum fast-safe-arith-op)
230   (:translate truncate)
231   (:args (x :scs (any-reg))
232          (y :scs (any-reg)))
233   (:arg-types tagged-num tagged-num)
234   (:results (quo :scs (any-reg))
235             (rem :scs (any-reg)))
236   (:result-types tagged-num tagged-num)
237   (:note "inline fixnum arithmetic")
238   (:temporary (:scs (any-reg) :target quo) q)
239   (:temporary (:scs (any-reg)) r)
240   (:temporary (:scs (signed-reg)) y-int)
241   (:vop-var vop)
242   (:save-p :compute-only)
243   (:guard (or (member :sparc-v8 *backend-subfeatures*)
244               (and (member :sparc-v9 *backend-subfeatures*)
245                    (not (member :sparc-64 *backend-subfeatures*)))))
246   (:generator 12
247     (let ((zero (generate-error-code vop division-by-zero-error x y)))
248       (inst cmp y zero-tn)
249       (inst b :eq zero)
250       ;; Extend the sign of X into the Y register
251         (inst sra r x 31)
252       (inst wry r)
253       ;; Remove tag bits so Q and R will be tagged correctly.
254       (inst sra y-int y n-fixnum-tag-bits)
255       (inst nop)
256       (inst nop)
257
258       (inst sdiv q x y-int)             ; Q is tagged.
259       ;; We have the quotient so we need to compute the remainder
260       (inst smul r q y-int)             ; R is tagged
261       (inst sub rem x r)
262       (unless (location= quo q)
263         (move quo q)))))
264
265 (define-vop (fast-v8-truncate/signed=>signed fast-safe-arith-op)
266   (:translate truncate)
267   (:args (x :scs (signed-reg))
268          (y :scs (signed-reg)))
269   (:arg-types signed-num signed-num)
270   (:results (quo :scs (signed-reg))
271             (rem :scs (signed-reg)))
272   (:result-types signed-num signed-num)
273   (:note "inline (signed-byte 32) arithmetic")
274   (:temporary (:scs (signed-reg) :target quo) q)
275   (:temporary (:scs (signed-reg)) r)
276   (:vop-var vop)
277   (:save-p :compute-only)
278   (:guard (or (member :sparc-v8 *backend-subfeatures*)
279               (and (member :sparc-v9 *backend-subfeatures*)
280                    (not (member :sparc-64 *backend-subfeatures*)))))
281   (:generator 12
282     (let ((zero (generate-error-code vop division-by-zero-error x y)))
283       (inst cmp y zero-tn)
284       (if (member :sparc-v9 *backend-subfeatures*)
285           (inst b :eq zero :pn)
286           (inst b :eq zero))
287       ;; Extend the sign of X into the Y register
288       (inst sra r x 31)
289       (inst wry r)
290       (inst nop)
291       (inst nop)
292       (inst nop)
293
294       (inst sdiv q x y)
295       ;; We have the quotient so we need to compue the remainder
296       (inst smul r q y)         ; rem
297       (inst sub rem x r)
298       (unless (location= quo q)
299         (move quo q)))))
300
301 (define-vop (fast-v8-truncate/unsigned=>unsigned fast-safe-arith-op)
302   (:translate truncate)
303   (:args (x :scs (unsigned-reg))
304          (y :scs (unsigned-reg)))
305   (:arg-types unsigned-num unsigned-num)
306   (:results (quo :scs (unsigned-reg))
307             (rem :scs (unsigned-reg)))
308   (:result-types unsigned-num unsigned-num)
309   (:note "inline (unsigned-byte 32) arithmetic")
310   (:temporary (:scs (unsigned-reg) :target quo) q)
311   (:temporary (:scs (unsigned-reg)) r)
312   (:vop-var vop)
313   (:save-p :compute-only)
314   (:guard (or (member :sparc-v8 *backend-subfeatures*)
315               (and (member :sparc-v9 *backend-subfeatures*)
316                    (not (member :sparc-64 *backend-subfeatures*)))))
317   (:generator 8
318     (let ((zero (generate-error-code vop division-by-zero-error x y)))
319       (inst cmp y zero-tn)
320       (if (member :sparc-v9 *backend-subfeatures*)
321           (inst b :eq zero :pn)
322           (inst b :eq zero))
323       (inst wry zero-tn)                ; Clear out high part
324       (inst nop)
325       (inst nop)
326       (inst nop)
327
328       (inst udiv q x y)
329       ;; Compute remainder
330       (inst umul r q y)
331       (inst sub rem x r)
332       (unless (location= quo q)
333         (inst move quo q)))))
334
335 (define-vop (fast-v9-truncate/signed=>signed fast-safe-arith-op)
336   (:translate truncate)
337   (:args (x :scs (signed-reg))
338          (y :scs (signed-reg)))
339   (:arg-types signed-num signed-num)
340   (:results (quo :scs (signed-reg))
341             (rem :scs (signed-reg)))
342   (:result-types signed-num signed-num)
343   (:note "inline (signed-byte 32) arithmetic")
344   (:temporary (:scs (signed-reg) :target quo) q)
345   (:temporary (:scs (signed-reg)) r)
346   (:vop-var vop)
347   (:save-p :compute-only)
348   (:guard (member :sparc-64 *backend-subfeatures*))
349   (:generator 8
350     (let ((zero (generate-error-code vop division-by-zero-error x y)))
351       (inst cmp y zero-tn)
352       (inst b :eq zero :pn)
353       ;; Sign extend the numbers, just in case.
354       (inst sra x 0)
355       (inst sra y 0)
356       (inst sdivx q x y)
357       ;; Compute remainder
358       (inst mulx r q y)
359       (inst sub rem x r)
360       (unless (location= quo q)
361         (inst move quo q)))))
362
363 (define-vop (fast-v9-truncate/unsigned=>unsigned fast-safe-arith-op)
364   (:translate truncate)
365   (:args (x :scs (unsigned-reg))
366          (y :scs (unsigned-reg)))
367   (:arg-types unsigned-num unsigned-num)
368   (:results (quo :scs (unsigned-reg))
369             (rem :scs (unsigned-reg)))
370   (:result-types unsigned-num unsigned-num)
371   (:note "inline (unsigned-byte 32) arithmetic")
372   (:temporary (:scs (unsigned-reg) :target quo) q)
373   (:temporary (:scs (unsigned-reg)) r)
374   (:vop-var vop)
375   (:save-p :compute-only)
376   (:guard (member :sparc-64 *backend-subfeatures*))
377   (:generator 8
378     (let ((zero (generate-error-code vop division-by-zero-error x y)))
379       (inst cmp y zero-tn)
380       (inst b :eq zero :pn)
381       ;; Zap the higher 32 bits, just in case
382       (inst srl x 0)
383       (inst srl y 0)
384       (inst udivx q x y)
385       ;; Compute remainder
386       (inst mulx r q y)
387       (inst sub rem x r)
388       (unless (location= quo q)
389         (inst move quo q)))))
390
391 ;;; Shifting
392
393 (define-vop (fast-ash/signed=>signed)
394   (:note "inline ASH")
395   (:args (number :scs (signed-reg) :to :save)
396          (amount :scs (signed-reg) :to :save))
397   (:arg-types signed-num signed-num)
398   (:results (result :scs (signed-reg)))
399   (:result-types signed-num)
400   (:translate ash)
401   (:policy :fast-safe)
402   (:temporary (:sc non-descriptor-reg) ndesc)
403   (:generator 5
404     (let ((done (gen-label)))
405       (inst cmp amount)
406       (inst b :ge done)
407       ;; The result-type assures us that this shift will not
408       ;; overflow.
409       (inst sll result number amount)
410       (inst neg ndesc amount)
411       (inst cmp ndesc 31)
412       (if (member :sparc-v9 *backend-subfeatures*)
413           (progn
414             (inst cmove :ge ndesc 31)
415             (inst sra result number ndesc))
416           (progn
417             (inst b :le done)
418             (inst sra result number ndesc)
419             (inst sra result number 31)))
420       (emit-label done))))
421
422 (define-vop (fast-ash-c/signed=>signed)
423   (:note "inline constant ASH")
424   (:args (number :scs (signed-reg)))
425   (:info count)
426   (:arg-types signed-num (:constant integer))
427   (:results (result :scs (signed-reg)))
428   (:result-types signed-num)
429   (:translate ash)
430   (:policy :fast-safe)
431   (:generator 4
432     (cond
433       ((< count 0) (inst sra result number (min (- count) 31)))
434       ((> count 0) (inst sll result number (min count 31)))
435       (t (bug "identity ASH not transformed away")))))
436
437 (define-vop (fast-ash/unsigned=>unsigned)
438   (:note "inline ASH")
439   (:args (number :scs (unsigned-reg) :to :save)
440          (amount :scs (signed-reg) :to :save))
441   (:arg-types unsigned-num signed-num)
442   (:results (result :scs (unsigned-reg)))
443   (:result-types unsigned-num)
444   (:translate ash)
445   (:policy :fast-safe)
446   (:temporary (:sc non-descriptor-reg) ndesc)
447   (:generator 5
448     (let ((done (gen-label)))
449       (inst cmp amount)
450       (inst b :ge done)
451       ;; The result-type assures us that this shift will not
452       ;; overflow.
453       (inst sll result number amount)
454       (inst neg ndesc amount)
455       (inst cmp ndesc 32)
456       (if (member :sparc-v9 *backend-subfeatures*)
457           (progn
458             (inst srl result number ndesc)
459             (inst cmove :ge result zero-tn))
460           (progn
461             (inst b :lt done)
462             (inst srl result number ndesc)
463             (move result zero-tn)))
464       (emit-label done))))
465
466 (define-vop (fast-ash-c/unsigned=>unsigned)
467   (:note "inline constant ASH")
468   (:args (number :scs (unsigned-reg)))
469   (:info count)
470   (:arg-types unsigned-num (:constant integer))
471   (:results (result :scs (unsigned-reg)))
472   (:result-types unsigned-num)
473   (:translate ash)
474   (:policy :fast-safe)
475   (:generator 4
476     (cond
477       ((< count -31) (move result zero-tn))
478       ((< count 0) (inst srl result number (min (- count) 31)))
479       ((> count 0) (inst sll result number (min count 31)))
480       (t (bug "identity ASH not transformed away")))))
481
482 ;; Some special cases where we know we want a left shift.  Just do the
483 ;; shift, instead of checking for the sign of the shift.
484 (macrolet
485     ((def (name sc-type type result-type cost)
486        `(define-vop (,name)
487          (:note "inline ASH")
488          (:translate ash)
489          (:args (number :scs (,sc-type))
490                 (amount :scs (signed-reg unsigned-reg immediate)))
491          (:arg-types ,type positive-fixnum)
492          (:results (result :scs (,result-type)))
493          (:result-types ,type)
494          (:policy :fast-safe)
495          (:generator ,cost
496           ;; The result-type assures us that this shift will not
497           ;; overflow. And for fixnums, the zero bits that get
498           ;; shifted in are just fine for the fixnum tag.
499           (sc-case amount
500            ((signed-reg unsigned-reg)
501             (inst sll result number amount))
502            (immediate
503             (let ((amount (tn-value amount)))
504               (aver (>= amount 0))
505               (inst sll result number amount))))))))
506   (def fast-ash-left/signed=>signed signed-reg signed-num signed-reg 3)
507   (def fast-ash-left/fixnum=>fixnum any-reg tagged-num any-reg 2)
508   (def fast-ash-left/unsigned=>unsigned unsigned-reg unsigned-num unsigned-reg 3))
509
510 \f
511 (define-vop (signed-byte-32-len)
512   (:translate integer-length)
513   (:note "inline (signed-byte 32) integer-length")
514   (:policy :fast-safe)
515   (:args (arg :scs (signed-reg) :target shift))
516   (:arg-types signed-num)
517   (:results (res :scs (any-reg)))
518   (:result-types positive-fixnum)
519   (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) shift)
520   (:generator 30
521     (let ((loop (gen-label))
522           (test (gen-label)))
523       (inst addcc shift zero-tn arg)
524       (inst b :ge test)
525       (move res zero-tn)
526       (inst b test)
527       (inst not shift)
528
529       (emit-label loop)
530       (inst add res (fixnumize 1))
531
532       (emit-label test)
533       (inst cmp shift)
534       (inst b :ne loop)
535       (inst srl shift 1))))
536
537 (define-vop (unsigned-byte-32-count)
538   (:translate logcount)
539   (:note "inline (unsigned-byte 32) logcount")
540   (:policy :fast-safe)
541   (:args (arg :scs (unsigned-reg)))
542   (:arg-types unsigned-num)
543   (:results (res :scs (unsigned-reg)))
544   (:result-types positive-fixnum)
545   (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) mask temp)
546   (:generator 35
547       (move res arg)
548
549       (dolist (stuff '((1 #x55555555) (2 #x33333333) (4 #x0f0f0f0f)
550                        (8 #x00ff00ff) (16 #x0000ffff)))
551         (destructuring-bind (shift bit-mask)
552             stuff
553           ;; Set mask
554           (inst sethi mask (ldb (byte 22 10) bit-mask))
555           (inst add mask (ldb (byte 10 0) bit-mask))
556
557           (inst and temp res mask)
558           (inst srl res shift)
559           (inst and res mask)
560           (inst add res temp)))))
561
562
563 ;;; Multiply and Divide.
564
565 (define-vop (fast-v8-*/fixnum=>fixnum fast-fixnum-binop)
566   (:temporary (:scs (non-descriptor-reg)) temp)
567   (:translate *)
568   (:guard (or (member :sparc-v8 *backend-subfeatures*)
569               (and (member :sparc-v9 *backend-subfeatures*)
570                    (not (member :sparc-64 *backend-subfeatures*)))))
571   (:generator 2
572     ;; The cost here should be less than the cost for
573     ;; */signed=>signed.  Why?  A fixnum product using signed=>signed
574     ;; has to convert both args to signed-nums.  But using this, we
575     ;; don't have to and that saves an instruction.
576     (inst sra temp y n-fixnum-tag-bits)
577     (inst smul r x temp)))
578
579 (define-vop (fast-v8-*-c/fixnum=>fixnum fast-safe-arith-op)
580   (:args (x :target r :scs (any-reg zero)))
581   (:info y)
582   (:arg-types tagged-num
583               (:constant (and (signed-byte 13) (not (integer 0 0)))))
584   (:results (r :scs (any-reg)))
585   (:result-types tagged-num)
586   (:note "inline fixnum arithmetic")
587   (:translate *)
588   (:guard (or (member :sparc-v8 *backend-subfeatures*)
589               (and (member :sparc-v9 *backend-subfeatures*)
590                    (not (member :sparc-64 *backend-subfeatures*)))))
591   (:generator 1
592     (inst smul r x y)))
593
594 (define-vop (fast-v8-*/signed=>signed fast-signed-binop)
595   (:translate *)
596   (:guard (or (member :sparc-v8 *backend-subfeatures*)
597               (and (member :sparc-v9 *backend-subfeatures*)
598                    (not (member :sparc-64 *backend-subfeatures*)))))
599   (:generator 3
600     (inst smul r x y)))
601
602 (define-vop (fast-v8-*-c/signed=>signed fast-signed-binop-c)
603   (:translate *)
604   (:guard (or (member :sparc-v8 *backend-subfeatures*)
605               (and (member :sparc-v9 *backend-subfeatures*)
606                    (not (member :sparc-64 *backend-subfeatures*)))))
607   (:generator 2
608     (inst smul r x y)))
609
610 (define-vop (fast-v8-*/unsigned=>unsigned fast-unsigned-binop)
611   (:translate *)
612   (:guard (or (member :sparc-v8 *backend-subfeatures*)
613               (and (member :sparc-v9 *backend-subfeatures*)
614                    (not (member :sparc-64 *backend-subfeatures*)))))
615   (:generator 3
616     (inst umul r x y)))
617
618 (define-vop (fast-v8-*-c/unsigned=>unsigned fast-unsigned-binop-c)
619   (:translate *)
620   (:guard (or (member :sparc-v8 *backend-subfeatures*)
621               (and (member :sparc-v9 *backend-subfeatures*)
622                    (not (member :sparc-64 *backend-subfeatures*)))))
623   (:generator 2
624     (inst umul r x y)))
625
626 ;; The smul and umul instructions are deprecated on the Sparc V9.  Use
627 ;; mulx instead.
628 (define-vop (fast-v9-*/fixnum=>fixnum fast-fixnum-binop)
629   (:temporary (:scs (non-descriptor-reg)) temp)
630   (:translate *)
631   (:guard (member :sparc-64 *backend-subfeatures*))
632   (:generator 4
633     (inst sra temp y n-fixnum-tag-bits)
634     (inst mulx r x temp)))
635
636 (define-vop (fast-v9-*/signed=>signed fast-signed-binop)
637   (:translate *)
638   (:guard (member :sparc-64 *backend-subfeatures*))
639   (:generator 3
640     (inst mulx r x y)))
641
642 (define-vop (fast-v9-*/unsigned=>unsigned fast-unsigned-binop)
643   (:translate *)
644   (:guard (member :sparc-64 *backend-subfeatures*))
645   (:generator 3
646     (inst mulx r x y)))
647
648 \f
649 ;;;; Modular functions:
650 (define-modular-fun lognot-mod32 (x) lognot :untagged nil 32)
651 (define-vop (lognot-mod32/unsigned=>unsigned)
652   (:translate lognot-mod32)
653   (:args (x :scs (unsigned-reg)))
654   (:arg-types unsigned-num)
655   (:results (res :scs (unsigned-reg)))
656   (:result-types unsigned-num)
657   (:policy :fast-safe)
658   (:generator 1
659     (inst not res x)))
660
661 (macrolet
662     ((define-modular-backend (fun &optional constantp)
663        (let ((mfun-name (symbolicate fun '-mod32))
664              (modvop (symbolicate 'fast- fun '-mod32/unsigned=>unsigned))
665              (modcvop (symbolicate 'fast- fun '-mod32-c/unsigned=>unsigned))
666              (vop (symbolicate 'fast- fun '/unsigned=>unsigned))
667              (cvop (symbolicate 'fast- fun '-c/unsigned=>unsigned)))
668          `(progn
669             (define-modular-fun ,mfun-name (x y) ,fun :untagged nil 32)
670             (define-vop (,modvop ,vop)
671               (:translate ,mfun-name))
672             ,@(when constantp
673                 `((define-vop (,modcvop ,cvop)
674                     (:translate ,mfun-name))))))))
675   (define-modular-backend + t)
676   (define-modular-backend - t)
677   (define-modular-backend logeqv t)
678   (define-modular-backend logandc1)
679   (define-modular-backend logandc2 t)
680   (define-modular-backend logorc1)
681   (define-modular-backend logorc2 t))
682
683 (define-source-transform lognand (x y)
684   `(lognot (logand ,x ,y)))
685 (define-source-transform lognor (x y)
686   `(lognot (logior ,x ,y)))
687
688 (define-vop (fast-ash-left-mod32-c/unsigned=>unsigned
689              fast-ash-c/unsigned=>unsigned)
690   (:translate ash-left-mod32))
691
692 (define-vop (fast-ash-left-mod32/unsigned=>unsigned
693              fast-ash-left/unsigned=>unsigned))
694 (deftransform ash-left-mod32 ((integer count)
695                               ((unsigned-byte 32) (unsigned-byte 5)))
696   (when (sb!c::constant-lvar-p count)
697     (sb!c::give-up-ir1-transform))
698   '(%primitive fast-ash-left-mod32/unsigned=>unsigned integer count))
699 \f
700 ;;;; Binary conditional VOPs:
701
702 (define-vop (fast-conditional)
703   (:conditional)
704   (:info target not-p)
705   (:effects)
706   (:affected)
707   (:policy :fast-safe))
708
709 (define-vop (fast-conditional/fixnum fast-conditional)
710   (:args (x :scs (any-reg zero))
711          (y :scs (any-reg zero)))
712   (:arg-types tagged-num tagged-num)
713   (:note "inline fixnum comparison"))
714
715 (define-vop (fast-conditional-c/fixnum fast-conditional/fixnum)
716   (:args (x :scs (any-reg zero)))
717   (:arg-types tagged-num (:constant (signed-byte 11)))
718   (:info target not-p y))
719
720 (define-vop (fast-conditional/signed fast-conditional)
721   (:args (x :scs (signed-reg zero))
722          (y :scs (signed-reg zero)))
723   (:arg-types signed-num signed-num)
724   (:note "inline (signed-byte 32) comparison"))
725
726 (define-vop (fast-conditional-c/signed fast-conditional/signed)
727   (:args (x :scs (signed-reg zero)))
728   (:arg-types signed-num (:constant (signed-byte 13)))
729   (:info target not-p y))
730
731 (define-vop (fast-conditional/unsigned fast-conditional)
732   (:args (x :scs (unsigned-reg zero))
733          (y :scs (unsigned-reg zero)))
734   (:arg-types unsigned-num unsigned-num)
735   (:note "inline (unsigned-byte 32) comparison"))
736
737 (define-vop (fast-conditional-c/unsigned fast-conditional/unsigned)
738   (:args (x :scs (unsigned-reg zero)))
739   (:arg-types unsigned-num (:constant (unsigned-byte 12)))
740   (:info target not-p y))
741
742
743 (defmacro define-conditional-vop (tran cond unsigned not-cond not-unsigned)
744   `(progn
745      ,@(mapcar (lambda (suffix cost signed)
746                  (unless (and (member suffix '(/fixnum -c/fixnum))
747                               (eq tran 'eql))
748                    `(define-vop (,(intern (format nil "~:@(FAST-IF-~A~A~)"
749                                                   tran suffix))
750                                  ,(intern
751                                    (format nil "~:@(FAST-CONDITIONAL~A~)"
752                                            suffix)))
753                      (:translate ,tran)
754                      (:generator ,cost
755                       (inst cmp x
756                        ,(if (eq suffix '-c/fixnum) '(fixnumize y) 'y))
757                       (inst b (if not-p
758                                   ,(if signed not-cond not-unsigned)
759                                   ,(if signed cond unsigned))
760                        target)
761                       (inst nop)))))
762                '(/fixnum -c/fixnum /signed -c/signed /unsigned -c/unsigned)
763                '(4 3 6 5 6 5)
764                '(t t t t nil nil))))
765
766 (define-conditional-vop < :lt :ltu :ge :geu)
767
768 (define-conditional-vop > :gt :gtu :le :leu)
769
770 (define-conditional-vop eql :eq :eq :ne :ne)
771
772 ;;; EQL/FIXNUM is funny because the first arg can be of any type, not just a
773 ;;; known fixnum.
774
775 ;;; These versions specify a fixnum restriction on their first arg.  We have
776 ;;; also generic-eql/fixnum VOPs which are the same, but have no restriction on
777 ;;; the first arg and a higher cost.  The reason for doing this is to prevent
778 ;;; fixnum specific operations from being used on word integers, spuriously
779 ;;; consing the argument.
780 ;;;
781
782 (define-vop (fast-eql/fixnum fast-conditional)
783   (:args (x :scs (any-reg zero))
784          (y :scs (any-reg zero)))
785   (:arg-types tagged-num tagged-num)
786   (:note "inline fixnum comparison")
787   (:translate eql)
788   (:generator 4
789     (inst cmp x y)
790     (inst b (if not-p :ne :eq) target)
791     (inst nop)))
792 ;;;
793 (define-vop (generic-eql/fixnum fast-eql/fixnum)
794   (:args (x :scs (any-reg descriptor-reg))
795          (y :scs (any-reg)))
796   (:arg-types * tagged-num)
797   (:variant-cost 7))
798
799 (define-vop (fast-eql-c/fixnum fast-conditional/fixnum)
800   (:args (x :scs (any-reg zero)))
801   (:arg-types tagged-num (:constant (signed-byte 11)))
802   (:info target not-p y)
803   (:translate eql)
804   (:generator 2
805     (inst cmp x (fixnumize y))
806     (inst b (if not-p :ne :eq) target)
807     (inst nop)))
808 ;;;
809 (define-vop (generic-eql-c/fixnum fast-eql-c/fixnum)
810   (:args (x :scs (any-reg descriptor-reg)))
811   (:arg-types * (:constant (signed-byte 11)))
812   (:variant-cost 6))
813
814 \f
815 ;;;; 32-bit logical operations
816
817 (define-vop (shift-towards-someplace)
818   (:policy :fast-safe)
819   (:args (num :scs (unsigned-reg))
820          (amount :scs (signed-reg)))
821   (:arg-types unsigned-num tagged-num)
822   (:results (r :scs (unsigned-reg)))
823   (:result-types unsigned-num))
824
825 (define-vop (shift-towards-start shift-towards-someplace)
826   (:translate shift-towards-start)
827   (:note "shift-towards-start")
828   (:generator 1
829     (inst sll r num amount)))
830
831 (define-vop (shift-towards-end shift-towards-someplace)
832   (:translate shift-towards-end)
833   (:note "shift-towards-end")
834   (:generator 1
835     (inst srl r num amount)))
836 \f
837 ;;;; Bignum stuff.
838 (define-vop (bignum-length get-header-data)
839   (:translate sb!bignum:%bignum-length)
840   (:policy :fast-safe))
841
842 (define-vop (bignum-set-length set-header-data)
843   (:translate sb!bignum:%bignum-set-length)
844   (:policy :fast-safe))
845
846 (define-vop (bignum-ref word-index-ref)
847   (:variant bignum-digits-offset other-pointer-lowtag)
848   (:translate sb!bignum:%bignum-ref)
849   (:results (value :scs (unsigned-reg)))
850   (:result-types unsigned-num))
851
852 (define-vop (bignum-set word-index-set)
853   (:variant bignum-digits-offset other-pointer-lowtag)
854   (:translate sb!bignum:%bignum-set)
855   (:args (object :scs (descriptor-reg))
856          (index :scs (any-reg immediate zero))
857          (value :scs (unsigned-reg)))
858   (:arg-types t positive-fixnum unsigned-num)
859   (:results (result :scs (unsigned-reg)))
860   (:result-types unsigned-num))
861
862 (define-vop (digit-0-or-plus)
863   (:translate sb!bignum:%digit-0-or-plusp)
864   (:policy :fast-safe)
865   (:args (digit :scs (unsigned-reg)))
866   (:arg-types unsigned-num)
867   (:results (result :scs (descriptor-reg)))
868   (:guard (not (member :sparc-v9 *backend-subfeatures*)))
869   (:generator 3
870     (let ((done (gen-label)))
871       (inst cmp digit)
872       (inst b :lt done)
873       (move result null-tn)
874       (load-symbol result t)
875       (emit-label done))))
876
877 (define-vop (v9-digit-0-or-plus-cmove)
878   (:translate sb!bignum:%digit-0-or-plusp)
879   (:policy :fast-safe)
880   (:args (digit :scs (unsigned-reg)))
881   (:arg-types unsigned-num)
882   (:results (result :scs (descriptor-reg)))
883   (:guard (member :sparc-v9 *backend-subfeatures*))
884   (:generator 3
885     (inst cmp digit)
886     (load-symbol result t)
887     (inst cmove :lt result null-tn)))
888
889 ;; This doesn't work?
890 #+nil
891 (define-vop (v9-digit-0-or-plus-movr)
892   (:translate sb!bignum:%digit-0-or-plusp)
893   (:policy :fast-safe)
894   (:args (digit :scs (unsigned-reg)))
895   (:arg-types unsigned-num)
896   (:results (result :scs (descriptor-reg)))
897   (:temporary (:scs (descriptor-reg)) temp)
898   (:guard #!+:sparc-v9 t #!-:sparc-v9 nil)
899   (:generator 2
900     (load-symbol temp t)
901     (inst movr result null-tn digit :lz)
902     (inst movr result temp digit :gez)))
903
904 (define-vop (add-w/carry)
905   (:translate sb!bignum:%add-with-carry)
906   (:policy :fast-safe)
907   (:args (a :scs (unsigned-reg))
908          (b :scs (unsigned-reg))
909          (c :scs (any-reg)))
910   (:arg-types unsigned-num unsigned-num positive-fixnum)
911   (:results (result :scs (unsigned-reg))
912             (carry :scs (unsigned-reg)))
913   (:result-types unsigned-num positive-fixnum)
914   (:generator 3
915     (inst addcc zero-tn c -1)
916     (inst addxcc result a b)
917     (inst addx carry zero-tn zero-tn)))
918
919 (define-vop (sub-w/borrow)
920   (:translate sb!bignum:%subtract-with-borrow)
921   (:policy :fast-safe)
922   (:args (a :scs (unsigned-reg))
923          (b :scs (unsigned-reg))
924          (c :scs (any-reg)))
925   (:arg-types unsigned-num unsigned-num positive-fixnum)
926   (:results (result :scs (unsigned-reg))
927             (borrow :scs (unsigned-reg)))
928   (:result-types unsigned-num positive-fixnum)
929   (:generator 4
930     (inst subcc zero-tn c 1)
931     (inst subxcc result a b)
932     (inst addx borrow zero-tn zero-tn)
933     (inst xor borrow 1)))
934
935 ;;; EMIT-MULTIPLY -- This is used both for bignum stuff and in assembly
936 ;;; routines.
937 ;;;
938 (defun emit-multiply (multiplier multiplicand result-high result-low)
939   "Emit code to multiply MULTIPLIER with MULTIPLICAND, putting the result
940   in RESULT-HIGH and RESULT-LOW.  KIND is either :signed or :unsigned.
941   Note: the lifetimes of MULTIPLICAND and RESULT-HIGH overlap."
942   (declare (type tn multiplier result-high result-low)
943            (type (or tn (signed-byte 13)) multiplicand))
944   ;; It seems that emit-multiply is only used to do an unsigned
945   ;; multiply, so the code only does an unsigned multiply.
946   (cond
947     ((member :sparc-64 *backend-subfeatures*)
948      ;; Take advantage of V9's 64-bit multiplier.
949      ;;
950      ;; Make sure the multiplier and multiplicand are really
951      ;; unsigned 64-bit numbers.
952      (inst srl multiplier 0)
953      (inst srl multiplicand 0)
954
955      ;; Multiply the two numbers and put the result in
956      ;; result-high.  Copy the low 32-bits to result-low.  Then
957      ;; shift result-high so the high 32-bits end up in the low
958      ;; 32-bits.
959      (inst mulx result-high multiplier multiplicand)
960      (inst move result-low result-high)
961      (inst srax result-high 32))
962     ((or (member :sparc-v8 *backend-subfeatures*)
963          (member :sparc-v9 *backend-subfeatures*))
964      ;; V8 has a multiply instruction.  This should also work for
965      ;; the V9, but umul and the Y register is deprecated on the
966      ;; V9.
967      (inst umul result-low multiplier multiplicand)
968      (inst rdy result-high))
969     (t
970      (let ((label (gen-label)))
971        (inst wry multiplier)
972        (inst andcc result-high zero-tn)
973        ;; Note: we can't use the Y register until three insts
974        ;; after it's written.
975        (inst nop)
976        (inst nop)
977        (dotimes (i 32)
978          (inst mulscc result-high multiplicand))
979        (inst mulscc result-high zero-tn)
980        (inst cmp multiplicand)
981        (inst b :ge label)
982        (inst nop)
983        (inst add result-high multiplier)
984        (emit-label label)
985        (inst rdy result-low)))))
986
987 (define-vop (bignum-mult-and-add-3-arg)
988   (:translate sb!bignum:%multiply-and-add)
989   (:policy :fast-safe)
990   (:args (x :scs (unsigned-reg) :to (:eval 1))
991          (y :scs (unsigned-reg) :to (:eval 1))
992          (carry-in :scs (unsigned-reg) :to (:eval 2)))
993   (:arg-types unsigned-num unsigned-num unsigned-num)
994   (:results (hi :scs (unsigned-reg) :from (:eval 0))
995             (lo :scs (unsigned-reg) :from (:eval 1)))
996   (:result-types unsigned-num unsigned-num)
997   (:generator 40
998     (emit-multiply x y hi lo)
999     (inst addcc lo carry-in)
1000     (inst addx hi zero-tn)))
1001
1002 (define-vop (bignum-mult-and-add-4-arg)
1003   (:translate sb!bignum:%multiply-and-add)
1004   (:policy :fast-safe)
1005   (:args (x :scs (unsigned-reg) :to (:eval 1))
1006          (y :scs (unsigned-reg) :to (:eval 1))
1007          (prev :scs (unsigned-reg) :to (:eval 2))
1008          (carry-in :scs (unsigned-reg) :to (:eval 2)))
1009   (:arg-types unsigned-num unsigned-num unsigned-num unsigned-num)
1010   (:results (hi :scs (unsigned-reg) :from (:eval 0))
1011             (lo :scs (unsigned-reg) :from (:eval 1)))
1012   (:result-types unsigned-num unsigned-num)
1013   (:generator 40
1014     (emit-multiply x y hi lo)
1015     (inst addcc lo carry-in)
1016     (inst addx hi zero-tn)
1017     (inst addcc lo prev)
1018     (inst addx hi zero-tn)))
1019
1020 (define-vop (bignum-mult)
1021   (:translate sb!bignum:%multiply)
1022   (:policy :fast-safe)
1023   (:args (x :scs (unsigned-reg) :to (:result 1))
1024          (y :scs (unsigned-reg) :to (:result 1)))
1025   (:arg-types unsigned-num unsigned-num)
1026   (:results (hi :scs (unsigned-reg))
1027             (lo :scs (unsigned-reg)))
1028   (:result-types unsigned-num unsigned-num)
1029   (:generator 40
1030     (emit-multiply x y hi lo)))
1031
1032 (define-vop (bignum-lognot lognot-mod32/unsigned=>unsigned)
1033   (:translate sb!bignum:%lognot))
1034
1035 (define-vop (fixnum-to-digit)
1036   (:translate sb!bignum:%fixnum-to-digit)
1037   (:policy :fast-safe)
1038   (:args (fixnum :scs (any-reg)))
1039   (:arg-types tagged-num)
1040   (:results (digit :scs (unsigned-reg)))
1041   (:result-types unsigned-num)
1042   (:generator 1
1043     (inst sra digit fixnum n-fixnum-tag-bits)))
1044
1045 (define-vop (bignum-floor)
1046   (:translate sb!bignum:%bigfloor)
1047   (:policy :fast-safe)
1048   (:args (div-high :scs (unsigned-reg) :target rem)
1049          (div-low :scs (unsigned-reg) :target quo)
1050          (divisor :scs (unsigned-reg)))
1051   (:arg-types unsigned-num unsigned-num unsigned-num)
1052   (:results (quo :scs (unsigned-reg) :from (:argument 1))
1053             (rem :scs (unsigned-reg) :from (:argument 0)))
1054   (:result-types unsigned-num unsigned-num)
1055   (:generator 300
1056     (move rem div-high)
1057     (move quo div-low)
1058     (dotimes (i 33)
1059       (let ((label (gen-label)))
1060         (inst cmp rem divisor)
1061         (inst b :ltu label)
1062         (inst addxcc quo quo)
1063         (inst sub rem divisor)
1064         (emit-label label)
1065         (unless (= i 32)
1066           (inst addx rem rem))))
1067     (inst not quo)))
1068
1069 (define-vop (bignum-floor-v8)
1070   (:translate sb!bignum:%bigfloor)
1071   (:policy :fast-safe)
1072   (:args (div-high :scs (unsigned-reg) :target rem)
1073          (div-low :scs (unsigned-reg) :target quo)
1074          (divisor :scs (unsigned-reg)))
1075   (:arg-types unsigned-num unsigned-num unsigned-num)
1076   (:results (quo :scs (unsigned-reg) :from (:argument 1))
1077             (rem :scs (unsigned-reg) :from (:argument 0)))
1078   (:result-types unsigned-num unsigned-num)
1079   (:temporary (:scs (unsigned-reg) :target quo) q)
1080   ;; This vop is for a v8 or v9, provided we're also not using
1081   ;; sparc-64, for which there a special sparc-64 vop.
1082   (:guard (or (member :sparc-v8 *backend-subfeatures*)
1083               (member :sparc-v9 *backend-subfeatures*)))
1084   (:generator 15
1085     (inst wry div-high)
1086     (inst nop)
1087     (inst nop)
1088     (inst nop)
1089     ;; Compute the quotient [Y, div-low] / divisor
1090     (inst udiv q div-low divisor)
1091     ;; Compute the remainder.  The high part of the result is in the Y
1092     ;; register.
1093     (inst umul rem q divisor)
1094     (inst sub rem div-low rem)
1095     (unless (location= quo q)
1096       (move quo q))))
1097
1098 (define-vop (bignum-floor-v9)
1099   (:translate sb!bignum:%bigfloor)
1100   (:policy :fast-safe)
1101   (:args (div-high :scs (unsigned-reg))
1102          (div-low :scs (unsigned-reg))
1103          (divisor :scs (unsigned-reg) :to (:result 1)))
1104   (:arg-types unsigned-num unsigned-num unsigned-num)
1105   (:temporary (:sc unsigned-reg :from (:argument 0)) dividend)
1106   (:results (quo :scs (unsigned-reg))
1107             (rem :scs (unsigned-reg)))
1108   (:result-types unsigned-num unsigned-num)
1109   (:guard (member :sparc-64 *backend-subfeatures*))
1110   (:generator 5
1111     ;; Set dividend to be div-high and div-low
1112     (inst sllx dividend div-high 32)
1113     (inst add dividend div-low)
1114     ;; Compute quotient
1115     (inst udivx quo dividend divisor)
1116     ;; Compute the remainder
1117     (inst mulx rem quo divisor)
1118     (inst sub rem dividend rem)))
1119
1120 (define-vop (signify-digit)
1121   (:translate sb!bignum:%fixnum-digit-with-correct-sign)
1122   (:policy :fast-safe)
1123   (:args (digit :scs (unsigned-reg) :target res))
1124   (:arg-types unsigned-num)
1125   (:results (res :scs (any-reg signed-reg)))
1126   (:result-types signed-num)
1127   (:generator 1
1128     (sc-case res
1129       (any-reg
1130        (inst sll res digit n-fixnum-tag-bits))
1131       (signed-reg
1132        (move res digit)))))
1133
1134 (define-vop (digit-ashr)
1135   (:translate sb!bignum:%ashr)
1136   (:policy :fast-safe)
1137   (:args (digit :scs (unsigned-reg))
1138          (count :scs (unsigned-reg)))
1139   (:arg-types unsigned-num positive-fixnum)
1140   (:results (result :scs (unsigned-reg)))
1141   (:result-types unsigned-num)
1142   (:generator 1
1143     (inst sra result digit count)))
1144
1145 (define-vop (digit-lshr digit-ashr)
1146   (:translate sb!bignum:%digit-logical-shift-right)
1147   (:generator 1
1148     (inst srl result digit count)))
1149
1150 (define-vop (digit-ashl digit-ashr)
1151   (:translate sb!bignum:%ashl)
1152   (:generator 1
1153     (inst sll result digit count)))
1154
1155 \f
1156 ;;;; Static functions.
1157
1158 (define-static-fun two-arg-gcd (x y) :translate gcd)
1159 (define-static-fun two-arg-lcm (x y) :translate lcm)
1160
1161 (define-static-fun two-arg-+ (x y) :translate +)
1162 (define-static-fun two-arg-- (x y) :translate -)
1163 (define-static-fun two-arg-* (x y) :translate *)
1164 (define-static-fun two-arg-/ (x y) :translate /)
1165
1166 (define-static-fun two-arg-< (x y) :translate <)
1167 (define-static-fun two-arg-<= (x y) :translate <=)
1168 (define-static-fun two-arg-> (x y) :translate >)
1169 (define-static-fun two-arg->= (x y) :translate >=)
1170 (define-static-fun two-arg-= (x y) :translate =)
1171 (define-static-fun two-arg-/= (x y) :translate /=)
1172
1173 (define-static-fun %negate (x) :translate %negate)
1174
1175 (define-static-fun two-arg-and (x y) :translate logand)
1176 (define-static-fun two-arg-ior (x y) :translate logior)
1177 (define-static-fun two-arg-xor (x y) :translate logxor)
1178 (define-static-fun two-arg-eqv (x y) :translate logeqv)
1179
1180 \f
1181 (in-package "SB!C")
1182
1183 (deftransform * ((x y)
1184                  ((unsigned-byte 32) (constant-arg (unsigned-byte 32)))
1185                  (unsigned-byte 32))
1186   "recode as shifts and adds"
1187   (let ((y (lvar-value y)))
1188     (multiple-value-bind (result adds shifts)
1189         (ub32-strength-reduce-constant-multiply 'x y)
1190       (cond
1191         ;; we assume, perhaps foolishly, that good SPARCs don't have an
1192         ;; issue with multiplications.  (Remember that there's a
1193         ;; different transform for converting x*2^k to a shift).
1194         ((member :sparc-64 *backend-subfeatures*) (give-up-ir1-transform))
1195         ((or (member :sparc-v9 *backend-subfeatures*)
1196              (member :sparc-v8 *backend-subfeatures*))
1197          ;; breakeven point as measured by Raymond Toy
1198          (when (> (+ adds shifts) 9)
1199            (give-up-ir1-transform))))
1200       (or result 0))))