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 (inst li (tn-value x) y)))
165 (define-move-vop move-to-word-c :move
166 (constant) (signed-reg unsigned-reg))
168 ;;; ARG is a fixnum or bignum, figure out which and load if necessary.
169 (define-vop (move-to-word/integer)
170 (:args (x :scs (descriptor-reg)))
171 (:results (y :scs (signed-reg unsigned-reg)))
172 (:note "integer to untagged word coercion")
173 (:temporary (:sc non-descriptor-reg) header)
174 (:temporary (:scs (non-descriptor-reg)) temp)
176 (inst and x fixnum-tag-mask temp)
177 (inst sra x n-fixnum-tag-bits y)
180 (loadw header x 0 other-pointer-lowtag)
181 (inst srl header (1+ n-widetag-bits) header)
182 (loadw y x bignum-digits-offset other-pointer-lowtag)
183 (inst beq header one)
185 (loadw header x (1+ bignum-digits-offset) other-pointer-lowtag)
186 (inst sll header 32 header)
188 (inst bis header y y)
189 (inst br zero-tn done)
191 (when (sc-is y unsigned-reg)
194 (define-move-vop move-to-word/integer :move
195 (descriptor-reg) (signed-reg unsigned-reg))
197 ;;; RESULT is a fixnum, so we can just shift. We need the result type
198 ;;; restriction because of the control-stack ambiguity noted above.
199 (define-vop (move-from-word/fixnum)
200 (:args (x :scs (signed-reg unsigned-reg)))
201 (:results (y :scs (any-reg descriptor-reg)))
202 (:result-types tagged-num)
203 (:note "fixnum tagging")
205 (inst sll x n-fixnum-tag-bits y)))
206 (define-move-vop move-from-word/fixnum :move
207 (signed-reg unsigned-reg) (any-reg descriptor-reg))
209 ;;; RESULT may be a bignum, so we have to check. Use a worst-case cost
210 ;;; to make sure people know they may be number consing.
211 (define-vop (move-from-signed)
212 (:args (arg :scs (signed-reg unsigned-reg) :target x))
213 (:results (y :scs (any-reg descriptor-reg)))
214 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) x temp)
215 (:temporary (:sc non-descriptor-reg) header)
216 (:note "signed word to integer coercion")
219 (inst sra x n-positive-fixnum-bits temp)
220 (inst sll x n-fixnum-tag-bits y)
227 (inst cmoveq temp 1 header)
229 (inst cmoveq temp 1 header)
230 (inst sll header n-widetag-bits header)
231 (inst bis header bignum-widetag header)
233 (pseudo-atomic (:extra (pad-data-block (+ bignum-digits-offset 3)))
234 (inst bis alloc-tn other-pointer-lowtag y)
235 (storew header y 0 other-pointer-lowtag)
236 (storew x y bignum-digits-offset other-pointer-lowtag)
238 (storew temp y (1+ bignum-digits-offset) other-pointer-lowtag))
240 (define-move-vop move-from-signed :move
241 (signed-reg) (descriptor-reg))
243 ;;; Check for fixnum, and possibly allocate one or two word bignum
244 ;;; result. Use a worst-case cost to make sure people know they may be
246 (define-vop (move-from-unsigned)
247 (:args (arg :scs (signed-reg unsigned-reg) :target x))
248 (:results (y :scs (any-reg descriptor-reg)))
249 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) x temp)
250 (:temporary (:sc non-descriptor-reg) temp1)
251 (:note "unsigned word to integer coercion")
254 (inst srl x n-positive-fixnum-bits temp)
255 (inst sll x n-fixnum-tag-bits y)
259 (inst cmovge x 2 temp)
260 (inst srl x 31 temp1)
261 (inst cmoveq temp1 1 temp)
262 (inst sll temp n-widetag-bits temp)
263 (inst bis temp bignum-widetag temp)
265 (pseudo-atomic (:extra (pad-data-block (+ bignum-digits-offset 3)))
266 (inst bis alloc-tn other-pointer-lowtag y)
267 (storew temp y 0 other-pointer-lowtag)
268 (storew x y bignum-digits-offset other-pointer-lowtag)
270 (storew temp y (1+ bignum-digits-offset) other-pointer-lowtag))
272 (define-move-vop move-from-unsigned :move
273 (unsigned-reg) (descriptor-reg))
275 ;;; Move untagged numbers.
276 (define-vop (word-move)
278 :scs (signed-reg unsigned-reg)
279 :load-if (not (location= x y))))
280 (:results (y :scs (signed-reg unsigned-reg)
281 :load-if (not (location= x y))))
284 (:note "word integer move")
287 (define-move-vop word-move :move
288 (signed-reg unsigned-reg) (signed-reg unsigned-reg))
290 ;;; Move untagged number arguments/return-values.
291 (define-vop (move-word-arg)
293 :scs (signed-reg unsigned-reg))
295 :load-if (not (sc-is y sap-reg))))
297 (:note "word integer argument move")
300 ((signed-reg unsigned-reg)
302 ((signed-stack unsigned-stack)
303 (storeq x fp (tn-offset y))))))
304 (define-move-vop move-word-arg :move-arg
305 (descriptor-reg any-reg signed-reg unsigned-reg) (signed-reg unsigned-reg))
308 ;;; Use standard MOVE-ARG + coercion to move an untagged number
309 ;;; to a descriptor passing location.
310 (define-move-vop move-arg :move-arg
311 (signed-reg unsigned-reg) (any-reg descriptor-reg))