1 ;;;; the PPC 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.
15 ;;;; Moves and coercions:
17 ;;; Move a tagged SAP to an untagged representation.
18 (define-vop (move-to-sap)
19 (:args (x :scs (any-reg descriptor-reg)))
20 (:results (y :scs (sap-reg)))
21 (:note "pointer to SAP coercion")
23 (loadw y x sap-pointer-slot other-pointer-lowtag)))
25 (define-move-vop move-to-sap :move
26 (descriptor-reg) (sap-reg))
29 ;;; Move an untagged SAP to a tagged representation.
30 (define-vop (move-from-sap)
31 (:args (sap :scs (sap-reg) :to :save))
32 (:temporary (:scs (non-descriptor-reg)) ndescr)
33 (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
34 (:results (res :scs (descriptor-reg)))
35 (:note "SAP to pointer coercion")
37 (with-fixed-allocation (res pa-flag ndescr sap-widetag sap-size)
38 (storew sap res sap-pointer-slot other-pointer-lowtag))))
40 (define-move-vop move-from-sap :move
41 (sap-reg) (descriptor-reg))
43 ;;; Move untagged sap values.
44 (define-vop (sap-move)
47 :load-if (not (location= x y))))
48 (:results (y :scs (sap-reg)
49 :load-if (not (location= x y))))
56 (define-move-vop sap-move :move
60 ;;; Move untagged sap arguments/return-values.
61 (define-vop (move-sap-arg)
65 :load-if (not (sc-is y sap-reg))))
67 (:note "SAP argument move")
73 (storew x fp (tn-offset y))))))
75 (define-move-vop move-sap-arg :move-arg
76 (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
85 (:args (sap :scs (sap-reg) :target int))
86 (:arg-types system-area-pointer)
87 (:results (int :scs (unsigned-reg)))
88 (:result-types unsigned-num)
95 (:args (int :scs (unsigned-reg) :target sap))
96 (:arg-types unsigned-num)
97 (:results (sap :scs (sap-reg)))
98 (:result-types system-area-pointer)
104 ;;;; POINTER+ and POINTER-
105 (define-vop (pointer+)
107 (:args (ptr :scs (sap-reg))
108 (offset :scs (signed-reg)))
109 (:arg-types system-area-pointer signed-num)
110 (:results (res :scs (sap-reg)))
111 (:result-types system-area-pointer)
114 (inst add res ptr offset)))
116 (define-vop (pointer+-c)
118 (:args (ptr :scs (sap-reg)))
120 (:arg-types system-area-pointer (:constant (signed-byte 16)))
121 (:results (res :scs (sap-reg)))
122 (:result-types system-area-pointer)
125 (inst addi res ptr offset)))
127 (define-vop (pointer-)
129 (:args (ptr1 :scs (sap-reg))
130 (ptr2 :scs (sap-reg)))
131 (:arg-types system-area-pointer system-area-pointer)
133 (:results (res :scs (signed-reg)))
134 (:result-types signed-num)
136 (inst sub res ptr1 ptr2)))
138 ;;;; mumble-SYSTEM-REF and mumble-SYSTEM-SET
139 (macrolet ((def-system-ref-and-set
140 (ref-name set-name sc type size &optional signed)
141 (let ((ref-name-c (symbolicate ref-name "-C"))
142 (set-name-c (symbolicate set-name "-C")))
144 (define-vop (,ref-name)
145 (:translate ,ref-name)
147 (:args (sap :scs (sap-reg))
148 (offset :scs (signed-reg)))
149 (:arg-types system-area-pointer signed-num)
150 (:results (result :scs (,sc)))
151 (:result-types ,type)
155 (:short (if signed 'lhax 'lhzx))
160 ,@(when (and (eq size :byte) signed)
161 '((inst extsb result result)))))
162 (define-vop (,ref-name-c)
163 (:translate ,ref-name)
165 (:args (sap :scs (sap-reg)))
166 (:arg-types system-area-pointer (:constant (signed-byte 16)))
168 (:results (result :scs (,sc)))
169 (:result-types ,type)
173 (:short (if signed 'lha 'lhz))
178 ,@(when (and (eq size :byte) signed)
179 '((inst extsb result result)))))
180 (define-vop (,set-name)
181 (:translate ,set-name)
183 (:args (sap :scs (sap-reg))
184 (offset :scs (signed-reg))
185 (value :scs (,sc) :target result))
186 (:arg-types system-area-pointer signed-num ,type)
187 (:results (result :scs (,sc)))
188 (:result-types ,type)
197 (unless (location= result value)
200 '((inst frsp result value)))
202 '((inst fmr result value)))
204 '((inst mr result value)))))))
205 (define-vop (,set-name-c)
206 (:translate ,set-name)
208 (:args (sap :scs (sap-reg))
209 (value :scs (,sc) :target result))
210 (:arg-types system-area-pointer (:constant (signed-byte 16)) ,type)
212 (:results (result :scs (,sc)))
213 (:result-types ,type)
222 (unless (location= result value)
225 '((inst frsp result value)))
227 '((inst fmr result value)))
229 '((inst mr result value)))))))))))
230 (def-system-ref-and-set sap-ref-8 %set-sap-ref-8
231 unsigned-reg positive-fixnum :byte nil)
232 (def-system-ref-and-set signed-sap-ref-8 %set-signed-sap-ref-8
233 signed-reg tagged-num :byte t)
234 (def-system-ref-and-set sap-ref-16 %set-sap-ref-16
235 unsigned-reg positive-fixnum :short nil)
236 (def-system-ref-and-set signed-sap-ref-16 %set-signed-sap-ref-16
237 signed-reg tagged-num :short t)
238 (def-system-ref-and-set sap-ref-32 %set-sap-ref-32
239 unsigned-reg unsigned-num :long nil)
240 (def-system-ref-and-set signed-sap-ref-32 %set-signed-sap-ref-32
241 signed-reg signed-num :long t)
242 (def-system-ref-and-set sap-ref-sap %set-sap-ref-sap
243 sap-reg system-area-pointer :long)
244 (def-system-ref-and-set sap-ref-single %set-sap-ref-single
245 single-reg single-float :single)
246 (def-system-ref-and-set sap-ref-double %set-sap-ref-double
247 double-reg double-float :double))
249 ;;; Noise to convert normal lisp data objects into SAPs.
250 (define-vop (vector-sap)
251 (:translate vector-sap)
253 (:args (vector :scs (descriptor-reg)))
254 (:results (sap :scs (sap-reg)))
255 (:result-types system-area-pointer)
257 (inst addi sap vector
258 (- (* vector-data-offset n-word-bytes) other-pointer-lowtag))))