1 ;;;; the Sparc 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 immediate zero)
16 (any-reg descriptor-reg))
17 (let ((val (tn-value x)))
20 (inst li y (fixnumize val)))
26 (inst li y (logior (ash (char-code val) n-widetag-bits)
27 character-widetag))))))
29 (define-move-fun (load-number 1) (vop x y)
31 (signed-reg unsigned-reg))
32 (inst li y (tn-value x)))
34 (define-move-fun (load-character 1) (vop x y)
35 ((immediate) (character-reg))
36 (inst li y (char-code (tn-value x))))
38 (define-move-fun (load-system-area-pointer 1) (vop x y)
39 ((immediate) (sap-reg))
40 (inst li y (sap-int (tn-value x))))
42 (define-move-fun (load-constant 5) (vop x y)
43 ((constant) (descriptor-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)
53 (signed-stack) (signed-reg)
54 (unsigned-stack) (unsigned-reg))
55 (let ((nfp (current-nfp-tn vop)))
56 (loadw y nfp (tn-offset x))))
58 (define-move-fun (store-stack 5) (vop x y)
59 ((any-reg descriptor-reg) (control-stack))
62 (define-move-fun (store-number-stack 5) (vop x y)
63 ((character-reg) (character-stack)
65 (signed-reg) (signed-stack)
66 (unsigned-reg) (unsigned-stack))
67 (let ((nfp (current-nfp-tn vop)))
68 (storew x nfp (tn-offset y))))
75 :scs (any-reg descriptor-reg zero null)
76 :load-if (not (location= x y))))
77 (:results (y :scs (any-reg descriptor-reg)
78 :load-if (not (location= x y))))
84 (define-move-vop move :move
85 (any-reg descriptor-reg)
86 (any-reg descriptor-reg))
88 ;;; Make Move the check VOP for T so that type check generation
89 ;;; doesn't think it is a hairy type. This also allows checking of a
90 ;;; few of the values in a continuation to fall out.
91 (primitive-type-vop move (:check) t)
93 ;;; The Move-Arg VOP is used for moving descriptor values into
94 ;;; another frame for argument or known value passing.
95 (define-vop (move-arg)
97 :scs (any-reg descriptor-reg zero null))
99 :load-if (not (sc-is y any-reg descriptor-reg))))
103 ((any-reg descriptor-reg)
106 (storew x fp (tn-offset y))))))
108 (define-move-vop move-arg :move-arg
109 (any-reg descriptor-reg)
110 (any-reg descriptor-reg))
114 ;;; This VOP exists just to begin the lifetime of a TN that couldn't
115 ;;; be written legally due to a type error. An error is signalled
116 ;;; before this VOP is so we don't need to do anything (not that there
117 ;;; would be anything sensible to do anyway.)
118 (define-vop (illegal-move)
123 (:save-p :compute-only)
125 (error-call vop object-not-type-error x type)))
127 ;;;; moves and coercions:
129 ;;; These MOVE-TO-WORD VOPs move a tagged integer to a raw full-word
130 ;;; representation. Similarly, the MOVE-FROM-WORD VOPs converts a raw
131 ;;; integer to a tagged bignum or fixnum.
133 ;;; Arg is a fixnum, so just shift it. We need a type restriction
134 ;;; because some possible arg SCs (control-stack) overlap with
135 ;;; possible bignum arg SCs.
136 (define-vop (move-to-word/fixnum)
137 (:args (x :scs (any-reg descriptor-reg)))
138 (:results (y :scs (signed-reg unsigned-reg)))
139 (:arg-types tagged-num)
140 (:note "fixnum untagging")
142 (inst sra y x n-fixnum-tag-bits)))
144 (define-move-vop move-to-word/fixnum :move
145 (any-reg descriptor-reg) (signed-reg unsigned-reg))
147 ;;; Arg is a non-immediate constant, load it.
148 (define-vop (move-to-word-c)
149 (:args (x :scs (constant)))
150 (:results (y :scs (signed-reg unsigned-reg)))
151 (:note "constant load")
153 (inst li y (tn-value x))))
155 (define-move-vop move-to-word-c :move
156 (constant) (signed-reg unsigned-reg))
159 ;;; Arg is a fixnum or bignum, figure out which and load if necessary.
160 (define-vop (move-to-word/integer)
161 (:args (x :scs (descriptor-reg)))
162 (:results (y :scs (signed-reg unsigned-reg)))
163 (:note "integer to untagged word coercion")
164 (:temporary (:scs (non-descriptor-reg)) temp)
166 (let ((done (gen-label)))
167 (inst andcc temp x fixnum-tag-mask)
169 (inst sra y x n-fixnum-tag-bits)
171 (loadw y x bignum-digits-offset other-pointer-lowtag)
175 (define-move-vop move-to-word/integer :move
176 (descriptor-reg) (signed-reg unsigned-reg))
178 ;;; Result is a fixnum, so we can just shift. We need the result type
179 ;;; restriction because of the control-stack ambiguity noted above.
180 (define-vop (move-from-word/fixnum)
181 (:args (x :scs (signed-reg unsigned-reg)))
182 (:results (y :scs (any-reg descriptor-reg)))
183 (:result-types tagged-num)
184 (:note "fixnum tagging")
186 (inst sll y x n-fixnum-tag-bits)))
188 (define-move-vop move-from-word/fixnum :move
189 (signed-reg unsigned-reg) (any-reg descriptor-reg))
192 ;;; Result may be a bignum, so we have to check. Use a worst-case
193 ;;; cost to make sure people know they may be number consing.
194 (define-vop (move-from-signed)
195 (:args (arg :scs (signed-reg unsigned-reg) :target x))
196 (:results (y :scs (any-reg descriptor-reg)))
197 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) x temp)
198 (:note "signed word to integer coercion")
201 (let ((fixnum (gen-label))
203 (inst sra temp x n-positive-fixnum-bits)
206 (inst orncc temp zero-tn temp)
208 (inst sll y x n-fixnum-tag-bits)
210 (with-fixed-allocation
211 (y temp bignum-widetag (1+ bignum-digits-offset))
212 (storew x y bignum-digits-offset other-pointer-lowtag))
217 (inst sll y x n-fixnum-tag-bits)
220 (define-move-vop move-from-signed :move
221 (signed-reg) (descriptor-reg))
224 ;;; Check for fixnum, and possibly allocate one or two word bignum
225 ;;; result. Use a worst-case cost to make sure people know they may
226 ;;; be number consing.
227 (define-vop (move-from-unsigned)
228 (:args (arg :scs (signed-reg unsigned-reg) :target x))
229 (:results (y :scs (any-reg descriptor-reg)))
230 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) x temp)
231 (:note "unsigned word to integer coercion")
234 (let ((done (gen-label))
235 (one-word (gen-label)))
236 (inst sra temp x n-positive-fixnum-bits)
239 (inst sll y x n-fixnum-tag-bits)
241 ;; We always allocate 2 words even if we don't need it. (The
242 ;; copying GC will take care of freeing the unused extra word.)
243 (with-fixed-allocation
244 (y temp bignum-widetag (+ 2 bignum-digits-offset))
246 (inst b :ge one-word)
247 (inst li temp (logior (ash 1 n-widetag-bits) bignum-widetag))
248 (inst li temp (logior (ash 2 n-widetag-bits) bignum-widetag))
249 (emit-label one-word)
250 ;; Set the header word, then the actual digit. The extra
251 ;; digit, if any, is automatically set to zero, so we don't
253 (storew temp y 0 other-pointer-lowtag)
254 (storew x y bignum-digits-offset other-pointer-lowtag))
257 (define-move-vop move-from-unsigned :move
258 (unsigned-reg) (descriptor-reg))
261 ;;; Move untagged numbers.
262 (define-vop (word-move)
264 :scs (signed-reg unsigned-reg)
265 :load-if (not (location= x y))))
266 (:results (y :scs (signed-reg unsigned-reg)
267 :load-if (not (location= x y))))
270 (:note "word integer move")
274 (define-move-vop word-move :move
275 (signed-reg unsigned-reg) (signed-reg unsigned-reg))
278 ;;; Move untagged number arguments/return-values.
279 (define-vop (move-word-arg)
281 :scs (signed-reg unsigned-reg))
283 :load-if (not (sc-is y sap-reg))))
285 (:note "word integer argument move")
288 ((signed-reg unsigned-reg)
290 ((signed-stack unsigned-stack)
291 (storew x fp (tn-offset y))))))
293 (define-move-vop move-word-arg :move-arg
294 (descriptor-reg any-reg signed-reg unsigned-reg) (signed-reg unsigned-reg))
297 ;;; Use standard MOVE-ARGUMENT + coercion to move an untagged number
298 ;;; to a descriptor passing location.
299 (define-move-vop move-arg :move-arg
300 (signed-reg unsigned-reg) (any-reg descriptor-reg))