3 (define-move-fun (load-immediate 1) (vop x y
)
5 (any-reg descriptor-reg
))
6 (let ((val (tn-value x
)))
9 (inst li
(fixnumize val
) y
))
15 (inst li
(logior (ash (char-code val
) n-widetag-bits
)
19 (define-move-fun (load-number 1) (vop x y
)
21 (signed-reg unsigned-reg
))
22 (let ((x (tn-value x
)))
23 (inst li
(if (>= x
(ash 1 31)) (logior (ash -
1 32) x
) x
) y
)))
25 (define-move-fun (load-base-char 1) (vop x y
)
26 ((immediate) (base-char-reg))
27 (inst li
(char-code (tn-value x
)) y
))
29 (define-move-fun (load-system-area-pointer 1) (vop x y
)
30 ((immediate) (sap-reg))
31 (inst li
(sap-int (tn-value x
)) y
))
33 (define-move-fun (load-constant 5) (vop x y
)
34 ((constant) (descriptor-reg))
35 (loadw y code-tn
(tn-offset x
) other-pointer-lowtag
))
37 (define-move-fun (load-stack 5) (vop x y
)
38 ((control-stack) (any-reg descriptor-reg
))
41 (define-move-fun (load-number-stack 5) (vop x y
)
42 ((base-char-stack) (base-char-reg)
44 (signed-stack) (signed-reg)
45 (unsigned-stack) (unsigned-reg))
46 (let ((nfp (current-nfp-tn vop
)))
47 (loadw y nfp
(tn-offset x
))))
49 (define-move-fun (store-stack 5) (vop x y
)
50 ((any-reg descriptor-reg
) (control-stack))
53 (define-move-fun (store-number-stack 5) (vop x y
)
54 ((base-char-reg) (base-char-stack)
56 (signed-reg) (signed-stack)
57 (unsigned-reg) (unsigned-stack))
58 (let ((nfp (current-nfp-tn vop
)))
59 (storew x nfp
(tn-offset y
))))
66 :scs
(any-reg descriptor-reg
)
67 :load-if
(not (location= x y
))))
68 (:results
(y :scs
(any-reg descriptor-reg
)
69 :load-if
(not (location= x y
))))
75 (define-move-vop move
:move
76 (any-reg descriptor-reg
)
77 (any-reg descriptor-reg
))
79 ;;; Make Move the check VOP for T so that type check generation doesn't think
80 ;;; it is a hairy type. This also allows checking of a few of the values in a
81 ;;; continuation to fall out.
83 (primitive-type-vop move
(:check
) t
)
85 ;;; The Move-Argument VOP is used for moving descriptor values into another
86 ;;; frame for argument or known value passing.
88 (define-vop (move-argument)
90 :scs
(any-reg descriptor-reg
))
92 :load-if
(not (sc-is y any-reg descriptor-reg
))))
96 ((any-reg descriptor-reg
)
99 (storew x fp
(tn-offset y
))))))
101 (define-move-vop move-argument
:move-arg
102 (any-reg descriptor-reg
)
103 (any-reg descriptor-reg
))
109 ;;; This VOP exists just to begin the lifetime of a TN that couldn't be written
110 ;;; legally due to a type error. An error is signalled before this VOP is
111 ;;; so we don't need to do anything (not that there would be anything sensible
114 (define-vop (illegal-move)
119 (:save-p
:compute-only
)
121 (error-call vop object-not-type-error x type
)))
125 ;;;; Moves and coercions:
127 ;;; These MOVE-TO-WORD VOPs move a tagged integer to a raw full-word
128 ;;; representation. Similarly, the MOVE-FROM-WORD VOPs converts a raw integer
129 ;;; to a tagged bignum or fixnum.
131 ;;; Arg is a fixnum, so just shift it. We need a type restriction because some
132 ;;; possible arg SCs (control-stack) overlap with possible bignum arg SCs.
134 (define-vop (move-to-word/fixnum
)
135 (:args
(x :scs
(any-reg descriptor-reg
)))
136 (:results
(y :scs
(signed-reg unsigned-reg
)))
137 (:arg-types tagged-num
)
138 (:note
"fixnum untagging")
142 (define-move-vop move-to-word
/fixnum
:move
143 (any-reg descriptor-reg
) (signed-reg unsigned-reg
))
145 ;;; Arg is a non-immediate constant, load it.
146 (define-vop (move-to-word-c)
147 (:args
(x :scs
(constant)))
148 (:results
(y :scs
(signed-reg unsigned-reg
)))
149 (:note
"constant load")
151 (inst li
(tn-value x
) y
)))
153 (define-move-vop move-to-word-c
:move
154 (constant) (signed-reg unsigned-reg
))
156 ;;; Arg is a fixnum or bignum, figure out which and load if necessary.
157 (define-vop (move-to-word/integer
)
158 (:args
(x :scs
(descriptor-reg)))
159 (:results
(y :scs
(signed-reg unsigned-reg
)))
160 (:note
"integer to untagged word coercion")
162 (inst extru x
31 2 zero-tn
:<>)
164 (loadw y x bignum-digits-offset other-pointer-lowtag
)))
166 (define-move-vop move-to-word
/integer
:move
167 (descriptor-reg) (signed-reg unsigned-reg
))
169 ;;; Result is a fixnum, so we can just shift. We need the result type
170 ;;; restriction because of the control-stack ambiguity noted above.
172 (define-vop (move-from-word/fixnum
)
173 (:args
(x :scs
(signed-reg unsigned-reg
)))
174 (:results
(y :scs
(any-reg descriptor-reg
)))
175 (:result-types tagged-num
)
176 (:note
"fixnum tagging")
180 (define-move-vop move-from-word
/fixnum
:move
181 (signed-reg unsigned-reg
) (any-reg descriptor-reg
))
183 ;;; Result may be a bignum, so we have to check. Use a worst-case cost to make
184 ;;; sure people know they may be number consing.
186 (define-vop (move-from-signed)
187 (:args
(x :scs
(signed-reg unsigned-reg
) :to
(:eval
1)))
188 (:results
(y :scs
(any-reg descriptor-reg
) :from
(:eval
0)))
189 (:temporary
(:scs
(non-descriptor-reg)) temp
)
190 (:note
"signed word to integer coercion")
192 ;; Extract the top three bits.
193 (inst extrs x
2 3 temp
:=)
194 ;; Invert them (unless they are already zero).
195 (inst uaddcm zero-tn temp temp
)
196 ;; If we are left with zero, it will fit in a fixnum. So branch around
197 ;; the bignum-construction, doing the shift in the delay slot.
198 (inst comb
:= temp zero-tn done
)
200 ;; Make a single-digit bignum.
201 (with-fixed-allocation (y temp bignum-widetag
(1+ bignum-digits-offset
))
202 (storew x y bignum-digits-offset other-pointer-lowtag
))
205 (define-move-vop move-from-signed
:move
206 (signed-reg) (descriptor-reg))
209 ;;; Check for fixnum, and possibly allocate one or two word bignum result. Use
210 ;;; a worst-case cost to make sure people know they may be number consing.
212 (define-vop (move-from-unsigned)
213 (:args
(x :scs
(signed-reg unsigned-reg
) :to
(:eval
1)))
214 (:results
(y :scs
(any-reg descriptor-reg
) :from
(:eval
0)))
215 (:temporary
(:scs
(non-descriptor-reg)) temp
)
216 (:note
"unsigned word to integer coercion")
218 ;; Grab the top three bits.
219 (inst extrs x
2 3 temp
)
220 ;; If zero, it will fit as a fixnum.
221 (inst comib
:= 0 temp done
)
224 (pseudo-atomic (:extra
(pad-data-block (1+ bignum-digits-offset
)))
225 ;; Create the result pointer.
226 (inst move alloc-tn y
)
227 (inst dep other-pointer-lowtag
31 3 y
)
228 ;; Check the high bit, and skip the next instruction if it's 0.
229 (inst comclr x zero-tn zero-tn
:>=)
230 ;; The high bit is set, so allocate enough space for a two-word bignum.
231 ;; We always skip the following instruction, so it is only executed
232 ;; when we want one word.
233 (inst addi
(pad-data-block 1) alloc-tn alloc-tn
:tr
)
234 ;; Set up the header for one word. Use ADDI instead of LI so we can
235 ;; skip the next instruction.
236 (inst addi
(logior (ash 1 n-widetag-bits
) bignum-widetag
) zero-tn temp
:tr
)
237 ;; Set up the header for two words.
238 (inst li
(logior (ash 2 n-widetag-bits
) bignum-widetag
) temp
)
239 ;; Store the header and the data.
240 (storew temp y
0 other-pointer-lowtag
)
241 (storew x y bignum-digits-offset other-pointer-lowtag
))
244 (define-move-vop move-from-unsigned
:move
245 (unsigned-reg) (descriptor-reg))
248 ;;; Move untagged numbers.
250 (define-vop (word-move)
252 :scs
(signed-reg unsigned-reg
)
253 :load-if
(not (location= x y
))))
254 (:results
(y :scs
(signed-reg unsigned-reg
)
255 :load-if
(not (location= x y
))))
258 (:note
"word integer move")
262 (define-move-vop word-move
:move
263 (signed-reg unsigned-reg
) (signed-reg unsigned-reg
))
266 ;;; Move untagged number arguments/return-values.
268 (define-vop (move-word-argument)
270 :scs
(signed-reg unsigned-reg
))
272 :load-if
(not (sc-is y sap-reg
))))
274 (:note
"word integer argument move")
277 ((signed-reg unsigned-reg
)
279 ((signed-stack unsigned-stack
)
280 (storew x fp
(tn-offset y
))))))
282 (define-move-vop move-word-argument
:move-arg
283 (descriptor-reg any-reg signed-reg unsigned-reg
) (signed-reg unsigned-reg
))
286 ;;; Use standard MOVE-ARGUMENT + coercion to move an untagged number to a
287 ;;; descriptor passing location.
289 (define-move-vop move-argument
:move-arg
290 (signed-reg unsigned-reg
) (any-reg descriptor-reg
))