1 ;;;; the SPARC VM definition of SAP operations
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 ;;;; moves and coercions:
16 ;;; Move a tagged SAP to an untagged representation.
17 (define-vop (move-to-sap)
18 (:args (x :scs (descriptor-reg)))
19 (:results (y :scs (sap-reg)))
20 (:note "pointer to SAP coercion")
22 (loadw y x sap-pointer-slot other-pointer-lowtag)))
24 (define-move-vop move-to-sap :move
25 (descriptor-reg) (sap-reg))
28 ;;; Move an untagged SAP to a tagged representation.
29 (define-vop (move-from-sap)
30 (:args (sap :scs (sap-reg) :to :save))
31 (:temporary (:scs (non-descriptor-reg)) ndescr)
32 (:results (res :scs (descriptor-reg)))
33 (:note "SAP to pointer coercion")
35 (with-fixed-allocation (res ndescr sap-widetag sap-size)
36 (storew sap res sap-pointer-slot other-pointer-lowtag))))
38 (define-move-vop move-from-sap :move
39 (sap-reg) (descriptor-reg))
42 ;;; Move untagged SAP values.
43 (define-vop (sap-move)
46 :load-if (not (location= x y))))
47 (:results (y :scs (sap-reg)
48 :load-if (not (location= x y))))
55 (define-move-vop sap-move :move
59 ;;; Move untagged SAP arguments/return-values.
60 (define-vop (move-sap-arg)
64 :load-if (not (sc-is y sap-reg))))
66 (:note "SAP argument move")
72 (storew x fp (tn-offset y))))))
74 (define-move-vop move-sap-arg :move-arg
75 (descriptor-reg sap-reg) (sap-reg))
78 ;;; Use standard MOVE-ARG + coercion to move an untagged SAP to a
79 ;;; descriptor passing location.
80 (define-move-vop move-arg :move-arg
81 (sap-reg) (descriptor-reg))
83 ;;;; SAP-INT and INT-SAP
86 (:args (sap :scs (sap-reg) :target int))
87 (:arg-types system-area-pointer)
88 (:results (int :scs (unsigned-reg)))
89 (:result-types unsigned-num)
96 (:args (int :scs (unsigned-reg) :target sap))
97 (:arg-types unsigned-num)
98 (:results (sap :scs (sap-reg)))
99 (:result-types system-area-pointer)
105 ;;;; POINTER+ and POINTER-
107 (define-vop (pointer+)
109 (:args (ptr :scs (sap-reg))
110 (offset :scs (signed-reg)))
111 (:arg-types system-area-pointer signed-num)
112 (:results (res :scs (sap-reg)))
113 (:result-types system-area-pointer)
116 (inst add res ptr offset)))
118 (define-vop (pointer+-c)
120 (:args (ptr :scs (sap-reg)))
122 (:arg-types system-area-pointer (:constant (signed-byte 13)))
123 (:results (res :scs (sap-reg)))
124 (:result-types system-area-pointer)
127 (inst add res ptr offset)))
129 (define-vop (pointer-)
131 (:args (ptr1 :scs (sap-reg))
132 (ptr2 :scs (sap-reg)))
133 (:arg-types system-area-pointer system-area-pointer)
135 (:results (res :scs (signed-reg)))
136 (:result-types signed-num)
138 (inst sub res ptr1 ptr2)))
140 ;;;; mumble-SYSTEM-REF and mumble-SYSTEM-SET
142 (macrolet ((def-system-ref-and-set (ref-name set-name sc type size &optional signed)
143 (let ((ref-name-c (symbolicate ref-name "-C"))
144 (set-name-c (symbolicate set-name "-C")))
146 (define-vop (,ref-name)
147 (:translate ,ref-name)
149 (:args (sap :scs (sap-reg))
150 (offset :scs (signed-reg)))
151 (:arg-types system-area-pointer signed-num)
152 (:results (result :scs (,sc)))
153 (:result-types ,type)
155 ,@(if (eql size :long-float)
156 '((load-long-reg result sap offset t))
158 (:byte (if signed 'ldsb 'ldub))
159 (:short (if signed 'ldsh 'lduh))
163 result sap offset)))))
164 (define-vop (,ref-name-c)
165 (:translate ,ref-name)
167 (:args (sap :scs (sap-reg)))
168 (:arg-types system-area-pointer (:constant (signed-byte 13)))
170 (:results (result :scs (,sc)))
171 (:result-types ,type)
173 ,@(if (eql size :long-float)
174 '((load-long-reg result sap offset t))
176 (:byte (if signed 'ldsb 'ldub))
177 (:short (if signed 'ldsh 'lduh))
181 result sap offset)))))
182 (define-vop (,set-name)
183 (:translate ,set-name)
185 (:args (sap :scs (sap-reg))
186 (offset :scs (signed-reg))
187 (value :scs (,sc) :target result))
188 (:arg-types system-area-pointer signed-num ,type)
189 (:results (result :scs (,sc)))
190 (:result-types ,type)
192 ,@(if (eql size :long-float)
193 '((store-long-reg value sap offset t))
201 (unless (location= result value)
204 '((inst fmovs result value)))
206 '((move-double-reg result value)))
208 '((move-long-reg result value)))
210 '((inst move result value)))))))
211 (define-vop (,set-name-c)
212 (:translate ,set-name)
214 (:args (sap :scs (sap-reg))
215 (value :scs (,sc) :target result))
216 (:arg-types system-area-pointer (:constant (signed-byte 13)) ,type)
218 (:results (result :scs (,sc)))
219 (:result-types ,type)
221 ,@(if (eql size :long-float)
222 '((store-long-reg value sap offset t))
230 (unless (location= result value)
233 '((inst fmovs result value)))
235 '((move-double-reg result value)))
237 '((move-long-reg result value)))
239 '((inst move result value)))))))))))
241 (def-system-ref-and-set sap-ref-8 %set-sap-ref-8
242 unsigned-reg positive-fixnum :byte nil)
243 (def-system-ref-and-set signed-sap-ref-8 %set-signed-sap-ref-8
244 signed-reg tagged-num :byte t)
245 (def-system-ref-and-set sap-ref-16 %set-sap-ref-16
246 unsigned-reg positive-fixnum :short nil)
247 (def-system-ref-and-set signed-sap-ref-16 %set-signed-sap-ref-16
248 signed-reg tagged-num :short t)
249 (def-system-ref-and-set sap-ref-32 %set-sap-ref-32
250 unsigned-reg unsigned-num :long nil)
251 (def-system-ref-and-set signed-sap-ref-32 %set-signed-sap-ref-32
252 signed-reg signed-num :long t)
253 (def-system-ref-and-set sap-ref-sap %set-sap-ref-sap
254 sap-reg system-area-pointer :long)
255 (def-system-ref-and-set sap-ref-lispobj %set-sap-ref-lispobj
256 descriptor-reg * :long)
257 (def-system-ref-and-set sap-ref-single %set-sap-ref-single
258 single-reg single-float :single)
259 (def-system-ref-and-set sap-ref-double %set-sap-ref-double
260 double-reg double-float :double)
262 (def-system-ref-and-set sap-ref-long %set-sap-ref-long
263 long-reg long-float :long-float)
266 ;;; noise to convert normal lisp data objects into SAPs.
268 (define-vop (vector-sap)
269 (:translate vector-sap)
271 (:args (vector :scs (descriptor-reg)))
272 (:results (sap :scs (sap-reg)))
273 (:result-types system-area-pointer)
276 (- (* vector-data-offset n-word-bytes) other-pointer-lowtag))))