1 ;;;; the ARM 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 (defun lowest-set-bit-index (integer-value)
15 (max 0 (1- (integer-length (logand integer-value
(- integer-value
))))))
17 ;; FIXME: This load-immediate-word stuff could me more clever. The
18 ;; decision on loading positive or negative shouldn't depend on the sign
19 ;; of the value, it should depend on the logcount of the two's complement
20 ;; representation (or maybe an even smarter selection criterion).
22 (defun load-immediate-word (y val
)
24 (composite-immediate-instruction bic y y val
:first-op mvn
:first-no-source t
:invert-y t
)
25 (composite-immediate-instruction orr y y val
:first-op mov
:first-no-source t
)))
27 (define-move-fun (load-immediate 1) (vop x y
)
29 (any-reg descriptor-reg
))
30 (let ((val (tn-value x
)))
33 ;; This is a FIXNUM, as IMMEDIATE-CONSTANT-SC only
34 ;; accepts integers if they are FIXNUMs.
35 (load-immediate-word y
(fixnumize val
)))
37 (let* ((codepoint (char-code val
))
38 (encoded-character (dpb codepoint
(byte 24 8) character-widetag
)))
39 (load-immediate-word y encoded-character
)))
43 (load-symbol y val
)))))
45 (define-move-fun (load-number 1) (vop x y
)
47 (signed-reg unsigned-reg
))
48 (load-immediate-word y
(tn-value x
)))
50 (define-move-fun (load-character 1) (vop x y
)
51 ((immediate) (character-reg))
52 (inst mov y
(char-code (tn-value x
))))
54 (define-move-fun (load-system-area-pointer 1) (vop x y
)
55 ((immediate) (sap-reg))
56 (let ((immediate-label (gen-label)))
57 (assemble (*elsewhere
*)
58 (emit-label immediate-label
)
59 (inst word
(sap-int (tn-value x
))))
60 (inst ldr y
(@ immediate-label
))))
62 (define-move-fun (load-constant 5) (vop x y
)
63 ((constant) (descriptor-reg))
64 (loadw y code-tn
(tn-offset x
) other-pointer-lowtag
))
66 (define-move-fun (load-stack 5) (vop x y
)
67 ((control-stack) (any-reg descriptor-reg
))
70 (define-move-fun (load-number-stack 5) (vop x y
)
71 ((character-stack) (character-reg)
73 (signed-stack) (signed-reg)
74 (unsigned-stack) (unsigned-reg))
75 (let ((nfp (current-nfp-tn vop
)))
76 (loadw y nfp
(tn-offset x
))))
78 (define-move-fun (store-stack 5) (vop x y
)
79 ((any-reg descriptor-reg
) (control-stack))
82 (define-move-fun (store-number-stack 5) (vop x y
)
83 ((character-reg) (character-stack)
85 (signed-reg) (signed-stack)
86 (unsigned-reg) (unsigned-stack))
87 (let ((nfp (current-nfp-tn vop
)))
88 (storew x nfp
(tn-offset y
))))
94 :scs
(any-reg descriptor-reg null
)
95 :load-if
(not (location= x y
))))
96 (:results
(y :scs
(any-reg descriptor-reg
)
97 :load-if
(not (location= x y
))))
103 (define-move-vop move
:move
104 (any-reg descriptor-reg
)
105 (any-reg descriptor-reg
))
107 ;;; Make MOVE the check VOP for T so that type check generation
108 ;;; doesn't think it is a hairy type. This also allows checking of a
109 ;;; few of the values in a continuation to fall out.
110 (primitive-type-vop move
(:check
) t
)
112 ;;; The MOVE-ARG VOP is used for moving descriptor values into another
113 ;;; frame for argument or known value passing.
114 (define-vop (move-arg)
116 :scs
(any-reg descriptor-reg null
))
118 :load-if
(not (sc-is y any-reg descriptor-reg
))))
122 ((any-reg descriptor-reg
)
125 (storew x fp
(tn-offset y
))))))
127 (define-move-vop move-arg
:move-arg
128 (any-reg descriptor-reg
)
129 (any-reg descriptor-reg
))
135 ;;; This VOP exists just to begin the lifetime of a TN that couldn't
136 ;;; be written legally due to a type error. An error is signalled
137 ;;; before this VOP is so we don't need to do anything (not that there
138 ;;; would be anything sensible to do anyway.)
139 (define-vop (illegal-move)
144 (:save-p
:compute-only
)
146 (error-call vop
'object-not-type-error x type
)))
148 ;;;; Moves and coercions:
150 ;;; These MOVE-TO-WORD VOPs move a tagged integer to a raw full-word
151 ;;; representation. Similarly, the MOVE-FROM-WORD VOPs converts a raw integer
152 ;;; to a tagged bignum or fixnum.
154 ;;; ARG is a fixnum, so just shift it. We need a type restriction because some
155 ;;; possible arg SCs (control-stack) overlap with possible bignum arg SCs.
156 (define-vop (move-to-word/fixnum
)
157 (:args
(x :scs
(any-reg descriptor-reg
)))
158 (:results
(y :scs
(signed-reg unsigned-reg
)))
159 (:arg-types tagged-num
)
160 (:note
"fixnum untagging")
162 (inst mov y
(asr x n-fixnum-tag-bits
))))
163 (define-move-vop move-to-word
/fixnum
:move
164 (any-reg descriptor-reg
) (signed-reg unsigned-reg
))
166 ;;; ARG is a non-immediate constant; load it.
167 (define-vop (move-to-word-c)
168 (:args
(x :scs
(constant)))
169 (:results
(y :scs
(signed-reg unsigned-reg
)))
170 (:note
"constant load")
172 (cond ((sb!c
::tn-leaf x
)
173 (load-immediate-word y
(tn-value x
)))
175 (loadw y code-tn
(tn-offset x
) other-pointer-lowtag
)
176 (inst mov y
(asr y n-fixnum-tag-bits
))))))
177 (define-move-vop move-to-word-c
:move
178 (constant) (signed-reg unsigned-reg
))
180 ;;; ARG is a fixnum or bignum; figure out which and load if necessary.
181 (define-vop (move-to-word/integer
)
182 (:args
(x :scs
(descriptor-reg)))
183 (:results
(y :scs
(signed-reg unsigned-reg
)))
184 (:note
"integer to untagged word coercion")
186 (inst tst x fixnum-tag-mask
)
189 (inst mov
:eq y
(asr x n-fixnum-tag-bits
)))
191 (inst mov
:eq y
(lsr x n-fixnum-tag-bits
))))
192 (loadw y x bignum-digits-offset other-pointer-lowtag
:ne
)))
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 mov y
(lsl x n-fixnum-tag-bits
))))
206 (define-move-vop move-from-word
/fixnum
:move
207 (signed-reg unsigned-reg
) (any-reg descriptor-reg
))
210 ;;; RESULT may be a bignum, so we have to check. Use a worst-case
211 ;;; cost to make sure people know they may be number consing.
212 (define-vop (move-from-signed)
213 (:args
(arg :scs
(signed-reg unsigned-reg
) :target x
))
214 (:results
(y :scs
(any-reg descriptor-reg
)))
215 (:temporary
(:scs
(non-descriptor-reg) :from
(:argument
0)) x
)
216 (:temporary
(:sc non-descriptor-reg
:offset ocfp-offset
) pa-flag
)
217 (:note
"signed word to integer coercion")
220 (inst adds pa-flag x x
)
221 (inst adds
:vc y pa-flag pa-flag
)
224 (with-fixed-allocation (y pa-flag bignum-widetag
(1+ bignum-digits-offset
))
225 (storew x y bignum-digits-offset other-pointer-lowtag
))
227 (define-move-vop move-from-signed
:move
228 (signed-reg) (descriptor-reg))
230 ;;; Check for fixnum, and possibly allocate one or two word bignum
231 ;;; result. Use a worst-case cost to make sure people know they may
232 ;;; be number consing.
233 (define-vop (move-from-unsigned)
234 (:args
(arg :scs
(signed-reg unsigned-reg
) :target x
))
235 (:results
(y :scs
(any-reg descriptor-reg
)))
236 (:temporary
(:scs
(non-descriptor-reg) :from
(:argument
0)) x
)
237 (:temporary
(:sc non-descriptor-reg
:offset ocfp-offset
) pa-flag
)
238 (:note
"unsigned word to integer coercion")
241 (inst tst x
(ash (1- (ash 1 (- n-word-bits
242 n-positive-fixnum-bits
)))
243 n-positive-fixnum-bits
))
244 (inst mov y
(lsl x n-fixnum-tag-bits
))
247 (with-fixed-allocation
248 (y pa-flag bignum-widetag
(+ 2 bignum-digits-offset
))
249 ;; WITH-FIXED-ALLOCATION, when using a supplied type-code,
250 ;; leaves PA-FLAG containing the computed header value. In our
251 ;; case, configured for a 2-word bignum. If the sign bit in the
252 ;; value we're boxing is CLEAR, we need to shrink the bignum by
253 ;; one word, hence the following:
255 (inst sub
:pl pa-flag pa-flag
#x100
)
256 (storew pa-flag y
0 other-pointer-lowtag
:pl
)
257 (storew x y bignum-digits-offset other-pointer-lowtag
))
259 (define-move-vop move-from-unsigned
:move
260 (unsigned-reg) (descriptor-reg))
263 ;;; Move untagged numbers.
264 (define-vop (word-move)
266 :scs
(signed-reg unsigned-reg
)
267 :load-if
(not (location= x y
))))
268 (:results
(y :scs
(signed-reg unsigned-reg
)
269 :load-if
(not (location= x y
))))
272 (:note
"word integer move")
275 (define-move-vop word-move
:move
276 (signed-reg unsigned-reg
) (signed-reg unsigned-reg
))
279 ;;; Move untagged number arguments/return-values.
280 (define-vop (move-word-arg)
282 :scs
(signed-reg unsigned-reg
))
284 :load-if
(not (sc-is y sap-reg
))))
286 (:note
"word integer argument move")
289 ((signed-reg unsigned-reg
)
291 ((signed-stack unsigned-stack
)
292 (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
))
296 ;;; Use standard MOVE-ARG + coercion to move an untagged number to a
297 ;;; descriptor passing location.
298 (define-move-vop move-arg
:move-arg
299 (signed-reg unsigned-reg
) (any-reg descriptor-reg
))