1 ;;;; the PPC 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 lr y (fixnumize val)))
26 (inst lr 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 lr 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 lr 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))))
74 :scs (any-reg descriptor-reg zero null)
75 :load-if (not (location= x y))))
76 (:results (y :scs (any-reg descriptor-reg)
77 :load-if (not (location= x y))))
83 (define-move-vop move :move
84 (any-reg descriptor-reg)
85 (any-reg descriptor-reg))
87 ;;; Make MOVE the check VOP for T so that type check generation
88 ;;; doesn't think it is a hairy type. This also allows checking of a
89 ;;; few of the values in a continuation to fall out.
90 (primitive-type-vop move (:check) t)
92 ;;; The MOVE-ARG VOP is used for moving descriptor values into another
93 ;;; frame for argument or known value passing.
94 (define-vop (move-arg)
96 :scs (any-reg descriptor-reg zero null))
98 :load-if (not (sc-is y any-reg descriptor-reg))))
102 ((any-reg descriptor-reg)
105 (storew x fp (tn-offset y))))))
107 (define-move-vop move-arg :move-arg
108 (any-reg descriptor-reg)
109 (any-reg descriptor-reg))
115 ;;; This VOP exists just to begin the lifetime of a TN that couldn't
116 ;;; be written legally due to a type error. An error is signalled
117 ;;; before this VOP is so we don't need to do anything (not that there
118 ;;; would be anything sensible to do anyway.)
119 (define-vop (illegal-move)
124 (:save-p :compute-only)
126 (error-call vop 'object-not-type-error x type)))
130 ;;;; Moves and coercions:
132 ;;; These MOVE-TO-WORD VOPs move a tagged integer to a raw full-word
133 ;;; representation. Similarly, the MOVE-FROM-WORD VOPs converts a raw integer
134 ;;; to a tagged bignum or fixnum.
136 ;;; ARG is a fixnum, so just shift it. We need a type restriction because some
137 ;;; possible arg SCs (control-stack) overlap with possible bignum arg SCs.
138 (define-vop (move-to-word/fixnum)
139 (:args (x :scs (any-reg descriptor-reg)))
140 (:results (y :scs (signed-reg unsigned-reg)))
141 (:arg-types tagged-num)
142 (:note "fixnum untagging")
144 (inst srawi y x n-fixnum-tag-bits)))
145 (define-move-vop move-to-word/fixnum :move
146 (any-reg descriptor-reg) (signed-reg unsigned-reg))
148 ;;; ARG is a non-immediate constant; load it.
149 (define-vop (move-to-word-c)
150 (:args (x :scs (constant)))
151 (:results (y :scs (signed-reg unsigned-reg)))
152 (:note "constant load")
154 (cond ((sb!c::tn-leaf x)
155 (inst lr y (tn-value x)))
157 (loadw y code-tn (tn-offset x) other-pointer-lowtag)
158 (inst srawi y y n-fixnum-tag-bits)))))
159 (define-move-vop move-to-word-c :move
160 (constant) (signed-reg unsigned-reg))
162 ;;; ARG is a fixnum or bignum; figure out which and load if necessary.
163 (define-vop (move-to-word/integer)
164 (:args (x :scs (descriptor-reg)))
165 (:results (y :scs (signed-reg unsigned-reg)))
166 (:note "integer to untagged word coercion")
167 (:temporary (:scs (non-descriptor-reg)) temp)
169 (let ((done (gen-label)))
170 (inst andi. temp x 3)
178 (loadw y x bignum-digits-offset other-pointer-lowtag)
181 (define-move-vop move-to-word/integer :move
182 (descriptor-reg) (signed-reg unsigned-reg))
184 ;;; RESULT is a fixnum, so we can just shift. We need the result type
185 ;;; restriction because of the control-stack ambiguity noted above.
186 (define-vop (move-from-word/fixnum)
187 (:args (x :scs (signed-reg unsigned-reg)))
188 (:results (y :scs (any-reg descriptor-reg)))
189 (:result-types tagged-num)
190 (:note "fixnum tagging")
193 (define-move-vop move-from-word/fixnum :move
194 (signed-reg unsigned-reg) (any-reg descriptor-reg))
196 ;;; RESULT may be a bignum, so we have to check. Use a worst-case
197 ;;; cost to make sure people know they may be number consing.
198 (define-vop (move-from-signed)
199 (:args (arg :scs (signed-reg unsigned-reg) :target x))
200 (:results (y :scs (any-reg descriptor-reg)))
201 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) x temp)
202 (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
203 (:note "signed word to integer coercion")
206 (let ((done (gen-label)))
207 (inst mtxer zero-tn) ; clear sticky overflow bit in XER, CR0
208 (inst addo temp x x) ; set XER OV if top two bits differ
209 (inst addo. temp temp temp) ; set CR0 SO if any top three bits differ
210 (inst slwi y x 2) ; assume fixnum (tagged ok, maybe lost some high bits)
213 (with-fixed-allocation (y pa-flag temp bignum-widetag (1+ bignum-digits-offset))
214 (storew x y bignum-digits-offset other-pointer-lowtag))
216 (define-move-vop move-from-signed :move
217 (signed-reg) (descriptor-reg))
219 ;;; Check for fixnum, and possibly allocate one or two word bignum
220 ;;; result. Use a worst-case cost to make sure people know they may
221 ;;; be number consing.
222 (define-vop (move-from-unsigned)
223 (:args (arg :scs (signed-reg unsigned-reg) :target x))
224 (:results (y :scs (any-reg descriptor-reg)))
225 (:temporary (:scs (non-descriptor-reg) :from (:argument 0)) x temp)
226 (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
227 (:note "unsigned word to integer coercion")
230 (let ((done (gen-label))
231 (one-word (gen-label)))
232 (inst srawi. temp x 29)
236 (with-fixed-allocation
237 (y pa-flag temp bignum-widetag (+ 2 bignum-digits-offset))
239 (inst li temp (logior (ash 1 n-widetag-bits) bignum-widetag))
241 (inst li temp (logior (ash 2 n-widetag-bits) bignum-widetag))
242 (emit-label one-word)
243 (storew temp y 0 other-pointer-lowtag)
244 (storew x y bignum-digits-offset other-pointer-lowtag))
246 (define-move-vop move-from-unsigned :move
247 (unsigned-reg) (descriptor-reg))
250 ;;; Move untagged numbers.
251 (define-vop (word-move)
253 :scs (signed-reg unsigned-reg)
254 :load-if (not (location= x y))))
255 (:results (y :scs (signed-reg unsigned-reg)
256 :load-if (not (location= x y))))
259 (: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.
267 (define-vop (move-word-arg)
269 :scs (signed-reg unsigned-reg))
271 :load-if (not (sc-is y sap-reg))))
273 (:note "word integer argument move")
276 ((signed-reg unsigned-reg)
278 ((signed-stack unsigned-stack)
279 (storew x fp (tn-offset y))))))
280 (define-move-vop move-word-arg :move-arg
281 (descriptor-reg any-reg signed-reg unsigned-reg) (signed-reg unsigned-reg))
283 ;;; Use standard MOVE-ARG + coercion to move an untagged number to a
284 ;;; descriptor passing location.
285 (define-move-vop move-arg :move-arg
286 (signed-reg unsigned-reg) (any-reg descriptor-reg))