1 ;;;; the Alpha VM definition of operand loading/saving and the Move VOP
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 (define-move-fun (load-immediate 1) (vop x y)
15 ((null zero immediate)
16 (any-reg descriptor-reg))
17 (let ((val (tn-value x)))
20 (inst li (fixnumize val) y))
26 (inst li (logior (ash (char-code val) n-widetag-bits) character-widetag)
29 (define-move-fun (load-number 1) (vop x y)
31 (signed-reg unsigned-reg))
32 (inst li (tn-value x) y))
34 (define-move-fun (load-character 1) (vop x y)
35 ((immediate) (character-reg))
36 (inst li (char-code (tn-value x)) y))
38 (define-move-fun (load-system-area-pointer 1) (vop x y)
39 ((immediate) (sap-reg))
40 (inst li (sap-int (tn-value x)) y))
42 (define-move-fun (load-constant 5) (vop x y)
43 ((constant) (descriptor-reg any-reg))
44 (loadw y code-tn (tn-offset x) other-pointer-lowtag))
46 (define-move-fun (load-stack 5) (vop x y)
47 ((control-stack) (any-reg descriptor-reg))
50 (define-move-fun (load-number-stack 5) (vop x y)
51 ((character-stack) (character-reg))
52 (let ((nfp (current-nfp-tn vop)))
53 (loadw y nfp (tn-offset x))))
55 (define-move-fun (load-number-stack-64 5) (vop x y)
56 ((sap-stack) (sap-reg)
57 (signed-stack) (signed-reg)
58 (unsigned-stack) (unsigned-reg))
59 (let ((nfp (current-nfp-tn vop)))
60 (loadq y nfp (tn-offset x))))
62 (define-move-fun (store-stack 5) (vop x y)
63 ((any-reg descriptor-reg null zero) (control-stack))
66 (define-move-fun (store-number-stack 5) (vop x y)
67 ((character-reg) (character-stack))
68 (let ((nfp (current-nfp-tn vop)))
69 (storew x nfp (tn-offset y))))
71 (define-move-fun (store-number-stack-64 5) (vop x y)
72 ((sap-reg) (sap-stack)
73 (signed-reg) (signed-stack)
74 (unsigned-reg) (unsigned-stack))
75 (let ((nfp (current-nfp-tn vop)))
76 (storeq x nfp (tn-offset y))))
82 :scs (any-reg descriptor-reg zero null)
83 :load-if (not (location= x y))))
84 (:results (y :scs (any-reg descriptor-reg control-stack)
85 :load-if (not (location= x y))))
89 (unless (location= x y)
91 ((any-reg descriptor-reg)
94 (store-stack-tn y x))))))
96 (define-move-vop move :move
97 (any-reg descriptor-reg zero null)
98 (any-reg descriptor-reg))
100 ;;; Make MOVE the check VOP for T so that type check generation
101 ;;; doesn't think it is a hairy type. This also allows checking of a
102 ;;; few of the values in a continuation to fall out.
103 (primitive-type-vop move (:check) t)
105 ;;; The MOVE-ARG VOP is used for moving descriptor values into
106 ;;; another frame for argument or known value passing.
107 (define-vop (move-arg)
109 :scs (any-reg descriptor-reg null zero))
111 :load-if (not (sc-is y any-reg descriptor-reg))))
115 ((any-reg descriptor-reg)
118 (storew x fp (tn-offset y))))))
120 (define-move-vop move-arg :move-arg
121 (any-reg descriptor-reg null zero)
122 (any-reg descriptor-reg))
126 ;;; This VOP exists just to begin the lifetime of a TN that couldn't
127 ;;; be written legally due to a type error. An error is signalled
128 ;;; before this VOP is so we don't need to do anything (not that there
129 ;;; would be anything sensible to do anyway.)
130 (define-vop (illegal-move)
135 (:save-p :compute-only)
137 (error-call vop object-not-type-error x type)))
139 ;;;; moves and coercions
141 ;;;; These MOVE-TO-WORD VOPs move a tagged integer to a raw full-word
142 ;;;; representation. Similarly, the MOVE-FROM-WORD VOPs converts a raw
143 ;;;; integer to a tagged bignum or fixnum.
145 ;;; ARG is a fixnum, so just shift it. We need a type restriction
146 ;;; because some possible arg SCs (control-stack) overlap with
147 ;;; possible bignum arg SCs.
148 (define-vop (move-to-word/fixnum)
149 (:args (x :scs (any-reg descriptor-reg)))
150 (:results (y :scs (signed-reg unsigned-reg)))
151 (:arg-types tagged-num)
152 (:note "fixnum untagging")
154 (inst sra x n-fixnum-tag-bits y)))
155 (define-move-vop move-to-word/fixnum :move
156 (any-reg descriptor-reg) (signed-reg unsigned-reg))
158 ;;; ARG is a non-immediate constant, load it.
159 (define-vop (move-to-word-c)
160 (:args (x :scs (constant)))
161 (:results (y :scs (signed-reg unsigned-reg)))
162 (:note "constant load")
164 (cond ((sb!c::tn-leaf x)
165 (inst li (tn-value x) y))
167 (loadw y code-tn (tn-offset x) other-pointer-lowtag)
168 (inst sra y n-fixnum-tag-bits y)))))
169 (define-move-vop move-to-word-c :move
170 (constant) (signed-reg unsigned-reg))
172 ;;; ARG is a fixnum or bignum, figure out which and load if necessary.
173 (define-vop (move-to-word/integer)
174 (:args (x :scs (descriptor-reg)))
175 (:results (y :scs (signed-reg unsigned-reg)))
176 (:note "integer to untagged word coercion")
177 (:temporary (:sc non-descriptor-reg) header)
178 (:temporary (:scs (non-descriptor-reg)) temp)
180 (inst and x fixnum-tag-mask temp)
181 (inst sra x n-fixnum-tag-bits y)
184 (loadw header x 0 other-pointer-lowtag)
185 (inst srl header (1+ n-widetag-bits) header)
186 (loadw y x bignum-digits-offset other-pointer-lowtag)
187 (inst beq header one)
189 (loadw header x (1+ bignum-digits-offset) other-pointer-lowtag)
190 (inst sll header 32 header)
192 (inst bis header y y)
193 (inst br zero-tn done)
195 (when (sc-is y unsigned-reg)
198 (define-move-vop move-to-word/integer :move
199 (descriptor-reg) (signed-reg unsigned-reg))
201 ;;; RESULT is a fixnum, so we can just shift. We need the result type
202 ;;; restriction because of the control-stack ambiguity noted above.
203 (define-vop (move-from-word/fixnum)
204 (:args (x :scs (signed-reg unsigned-reg)))
205 (:results (y :scs (any-reg descriptor-reg)))
206 (:result-types tagged-num)
207 (:note "fixnum tagging")
209 (inst sll x n-fixnum-tag-bits y)))
210 (define-move-vop move-from-word/fixnum :move
211 (signed-reg unsigned-reg) (any-reg descriptor-reg))
213 ;;; RESULT may be a bignum, so we have to check. Use a worst-case cost
214 ;;; to make sure people know they may be number consing.
215 (define-vop (move-from-signed)
216 (:args (arg :scs (signed-reg unsigned-reg) :target x))
217 (:results (y :scs (any-reg descriptor-reg)))
218 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) x temp)
219 (:temporary (:sc non-descriptor-reg) header)
220 (:note "signed word to integer coercion")
223 (inst sra x n-positive-fixnum-bits temp)
224 (inst sll x n-fixnum-tag-bits y)
231 (inst cmoveq temp 1 header)
233 (inst cmoveq temp 1 header)
234 (inst sll header n-widetag-bits header)
235 (inst bis header bignum-widetag header)
237 (pseudo-atomic (:extra (pad-data-block (+ bignum-digits-offset 3)))
238 (inst bis alloc-tn other-pointer-lowtag y)
239 (storew header y 0 other-pointer-lowtag)
240 (storew x y bignum-digits-offset other-pointer-lowtag)
242 (storew temp y (1+ bignum-digits-offset) other-pointer-lowtag))
244 (define-move-vop move-from-signed :move
245 (signed-reg) (descriptor-reg))
247 ;;; Check for fixnum, and possibly allocate one or two word bignum
248 ;;; result. Use a worst-case cost to make sure people know they may be
250 (define-vop (move-from-unsigned)
251 (:args (arg :scs (signed-reg unsigned-reg) :target x))
252 (:results (y :scs (any-reg descriptor-reg)))
253 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) x temp)
254 (:temporary (:sc non-descriptor-reg) temp1)
255 (:note "unsigned word to integer coercion")
258 (inst srl x n-positive-fixnum-bits temp)
259 (inst sll x n-fixnum-tag-bits y)
263 (inst cmovge x 2 temp)
264 (inst srl x 31 temp1)
265 (inst cmoveq temp1 1 temp)
266 (inst sll temp n-widetag-bits temp)
267 (inst bis temp bignum-widetag temp)
269 (pseudo-atomic (:extra (pad-data-block (+ bignum-digits-offset 3)))
270 (inst bis alloc-tn other-pointer-lowtag y)
271 (storew temp y 0 other-pointer-lowtag)
272 (storew x y bignum-digits-offset other-pointer-lowtag)
274 (storew temp y (1+ bignum-digits-offset) other-pointer-lowtag))
276 (define-move-vop move-from-unsigned :move
277 (unsigned-reg) (descriptor-reg))
279 ;;; Move untagged numbers.
280 (define-vop (word-move)
282 :scs (signed-reg unsigned-reg)
283 :load-if (not (location= x y))))
284 (:results (y :scs (signed-reg unsigned-reg)
285 :load-if (not (location= x y))))
288 (:note "word integer move")
291 (define-move-vop word-move :move
292 (signed-reg unsigned-reg) (signed-reg unsigned-reg))
294 ;;; Move untagged number arguments/return-values.
295 (define-vop (move-word-arg)
297 :scs (signed-reg unsigned-reg))
299 :load-if (not (sc-is y sap-reg))))
301 (:note "word integer argument move")
304 ((signed-reg unsigned-reg)
306 ((signed-stack unsigned-stack)
307 (storeq x fp (tn-offset y))))))
308 (define-move-vop move-word-arg :move-arg
309 (descriptor-reg any-reg signed-reg unsigned-reg) (signed-reg unsigned-reg))
312 ;;; Use standard MOVE-ARG + coercion to move an untagged number
313 ;;; to a descriptor passing location.
314 (define-move-vop move-arg :move-arg
315 (signed-reg unsigned-reg) (any-reg descriptor-reg))