Merge PPC port
[sbcl/lichteblau.git] / src / compiler / ppc / sap.lisp
bloba143546e92f2e9d5512d70c0396a4e6fe3091e56
1 ;;;
2 ;;; Written by William Lott.
3 ;;;
4 (in-package "SB!VM")
6 \f
7 ;;;; Moves and coercions:
9 ;;; Move a tagged SAP to an untagged representation.
10 ;;;
11 (define-vop (move-to-sap)
12 (:args (x :scs (any-reg descriptor-reg)))
13 (:results (y :scs (sap-reg)))
14 (:note "pointer to SAP coercion")
15 (:generator 1
16 (loadw y x sap-pointer-slot other-pointer-lowtag)))
18 ;;;
19 (define-move-vop move-to-sap :move
20 (descriptor-reg) (sap-reg))
23 ;;; Move an untagged SAP to a tagged representation.
24 ;;;
25 (define-vop (move-from-sap)
26 (:args (sap :scs (sap-reg) :to :save))
27 (:temporary (:scs (non-descriptor-reg)) ndescr)
28 (:temporary (:sc non-descriptor-reg :offset nl3-offset) pa-flag)
29 (:results (res :scs (descriptor-reg)))
30 (:note "SAP to pointer coercion")
31 (:generator 20
32 (with-fixed-allocation (res pa-flag ndescr sap-widetag sap-size)
33 (storew sap res sap-pointer-slot other-pointer-lowtag))))
34 ;;;
35 (define-move-vop move-from-sap :move
36 (sap-reg) (descriptor-reg))
39 ;;; Move untagged sap values.
40 ;;;
41 (define-vop (sap-move)
42 (:args (x :target y
43 :scs (sap-reg)
44 :load-if (not (location= x y))))
45 (:results (y :scs (sap-reg)
46 :load-if (not (location= x y))))
47 (:note "SAP move")
48 (:effects)
49 (:affected)
50 (:generator 0
51 (move y x)))
52 ;;;
53 (define-move-vop sap-move :move
54 (sap-reg) (sap-reg))
57 ;;; Move untagged sap arguments/return-values.
58 ;;;
59 (define-vop (move-sap-arg)
60 (:args (x :target y
61 :scs (sap-reg))
62 (fp :scs (any-reg)
63 :load-if (not (sc-is y sap-reg))))
64 (:results (y))
65 (:note "SAP argument move")
66 (:generator 0
67 (sc-case y
68 (sap-reg
69 (move y x))
70 (sap-stack
71 (storew x fp (tn-offset y))))))
72 ;;;
73 (define-move-vop move-sap-arg :move-arg
74 (descriptor-reg sap-reg) (sap-reg))
77 ;;; Use standard MOVE-ARG + coercion to move an untagged sap to a
78 ;;; descriptor passing location.
79 ;;;
80 (define-move-vop move-arg :move-arg
81 (sap-reg) (descriptor-reg))
85 ;;;; SAP-INT and INT-SAP
87 (define-vop (sap-int)
88 (:args (sap :scs (sap-reg) :target int))
89 (:arg-types system-area-pointer)
90 (:results (int :scs (unsigned-reg)))
91 (:result-types unsigned-num)
92 (:translate sap-int)
93 (:policy :fast-safe)
94 (:generator 1
95 (move int sap)))
97 (define-vop (int-sap)
98 (:args (int :scs (unsigned-reg) :target sap))
99 (:arg-types unsigned-num)
100 (:results (sap :scs (sap-reg)))
101 (:result-types system-area-pointer)
102 (:translate int-sap)
103 (:policy :fast-safe)
104 (:generator 1
105 (move sap int)))
109 ;;;; POINTER+ and POINTER-
111 (define-vop (pointer+)
112 (:translate sap+)
113 (:args (ptr :scs (sap-reg))
114 (offset :scs (signed-reg)))
115 (:arg-types system-area-pointer signed-num)
116 (:results (res :scs (sap-reg)))
117 (:result-types system-area-pointer)
118 (:policy :fast-safe)
119 (:generator 2
120 (inst add res ptr offset)))
122 (define-vop (pointer+-c)
123 (:translate sap+)
124 (:args (ptr :scs (sap-reg)))
125 (:info offset)
126 (:arg-types system-area-pointer (:constant (signed-byte 16)))
127 (:results (res :scs (sap-reg)))
128 (:result-types system-area-pointer)
129 (:policy :fast-safe)
130 (:generator 1
131 (inst addi res ptr offset)))
133 (define-vop (pointer-)
134 (:translate sap-)
135 (:args (ptr1 :scs (sap-reg))
136 (ptr2 :scs (sap-reg)))
137 (:arg-types system-area-pointer system-area-pointer)
138 (:policy :fast-safe)
139 (:results (res :scs (signed-reg)))
140 (:result-types signed-num)
141 (:generator 1
142 (inst sub res ptr1 ptr2)))
146 ;;;; mumble-SYSTEM-REF and mumble-SYSTEM-SET
148 (macrolet ((def-system-ref-and-set
149 (ref-name set-name sc type size &optional signed)
150 (let ((ref-name-c (symbolicate ref-name "-C"))
151 (set-name-c (symbolicate set-name "-C")))
152 `(progn
153 (define-vop (,ref-name)
154 (:translate ,ref-name)
155 (:policy :fast-safe)
156 (:args (sap :scs (sap-reg))
157 (offset :scs (signed-reg)))
158 (:arg-types system-area-pointer signed-num)
159 (:results (result :scs (,sc)))
160 (:result-types ,type)
161 (:generator 5
162 (inst ,(ecase size
163 (:byte 'lbzx)
164 (:short (if signed 'lhax 'lhzx))
165 (:long 'lwzx)
166 (:single 'lfsx)
167 (:double 'lfdx))
168 result sap offset)
169 ,@(when (and (eq size :byte) signed)
170 '((inst extsb result result)))))
171 (define-vop (,ref-name-c)
172 (:translate ,ref-name)
173 (:policy :fast-safe)
174 (:args (sap :scs (sap-reg)))
175 (:arg-types system-area-pointer (:constant (signed-byte 16)))
176 (:info offset)
177 (:results (result :scs (,sc)))
178 (:result-types ,type)
179 (:generator 4
180 (inst ,(ecase size
181 (:byte 'lbz)
182 (:short (if signed 'lha 'lhz))
183 (:long 'lwz)
184 (:single 'lfs)
185 (:double 'lfd))
186 result sap offset)
187 ,@(when (and (eq size :byte) signed)
188 '((inst extsb result result)))))
189 (define-vop (,set-name)
190 (:translate ,set-name)
191 (:policy :fast-safe)
192 (:args (sap :scs (sap-reg))
193 (offset :scs (signed-reg))
194 (value :scs (,sc) :target result))
195 (:arg-types system-area-pointer signed-num ,type)
196 (:results (result :scs (,sc)))
197 (:result-types ,type)
198 (:generator 5
199 (inst ,(ecase size
200 (:byte 'stbx)
201 (:short 'sthx)
202 (:long 'stwx)
203 (:single 'stfsx)
204 (:double 'stfdx))
205 value sap offset)
206 (unless (location= result value)
207 ,@(case size
208 (:single
209 '((inst frsp result value)))
210 (:double
211 '((inst fmr result value)))
213 '((inst mr result value)))))))
214 (define-vop (,set-name-c)
215 (:translate ,set-name)
216 (:policy :fast-safe)
217 (:args (sap :scs (sap-reg))
218 (value :scs (,sc) :target result))
219 (:arg-types system-area-pointer (:constant (signed-byte 16)) ,type)
220 (:info offset)
221 (:results (result :scs (,sc)))
222 (:result-types ,type)
223 (:generator 4
224 (inst ,(ecase size
225 (:byte 'stb)
226 (:short 'sth)
227 (:long 'stw)
228 (:single 'stfs)
229 (:double 'stfd))
230 value sap offset)
231 (unless (location= result value)
232 ,@(case size
233 (:single
234 '((inst frsp result value)))
235 (:double
236 '((inst fmr result value)))
238 '((inst mr result value)))))))))))
239 (def-system-ref-and-set sap-ref-8 %set-sap-ref-8
240 unsigned-reg positive-fixnum :byte nil)
241 (def-system-ref-and-set signed-sap-ref-8 %set-signed-sap-ref-8
242 signed-reg tagged-num :byte t)
243 (def-system-ref-and-set sap-ref-16 %set-sap-ref-16
244 unsigned-reg positive-fixnum :short nil)
245 (def-system-ref-and-set signed-sap-ref-16 %set-signed-sap-ref-16
246 signed-reg tagged-num :short t)
247 (def-system-ref-and-set sap-ref-32 %set-sap-ref-32
248 unsigned-reg unsigned-num :long nil)
249 (def-system-ref-and-set signed-sap-ref-32 %set-signed-sap-ref-32
250 signed-reg signed-num :long t)
251 (def-system-ref-and-set sap-ref-sap %set-sap-ref-sap
252 sap-reg system-area-pointer :long)
253 (def-system-ref-and-set sap-ref-single %set-sap-ref-single
254 single-reg single-float :single)
255 (def-system-ref-and-set sap-ref-double %set-sap-ref-double
256 double-reg double-float :double))
260 ;;; Noise to convert normal lisp data objects into SAPs.
262 (define-vop (vector-sap)
263 (:translate vector-sap)
264 (:policy :fast-safe)
265 (:args (vector :scs (descriptor-reg)))
266 (:results (sap :scs (sap-reg)))
267 (:result-types system-area-pointer)
268 (:generator 2
269 (inst addi sap vector
270 (- (* vector-data-offset n-word-bytes) other-pointer-lowtag))))
273 ;;; Transforms for 64-bit SAP accessors.
275 (deftransform sap-ref-64 ((sap offset) (* *))
276 '(logior (ash (sap-ref-32 sap offset) 32)
277 (sap-ref-32 sap (+ offset 4))))
279 (deftransform signed-sap-ref-64 ((sap offset) (* *))
280 '(logior (ash (signed-sap-ref-32 sap offset) 32)
281 (sap-ref-32 sap (+ 4 offset))))
283 (deftransform %set-sap-ref-64 ((sap offset value) (* * *))
284 '(progn
285 (%set-sap-ref-32 sap offset (ash value -32))
286 (%set-sap-ref-32 sap (+ offset 4) (logand value #xffffffff))))
288 (deftransform %set-signed-sap-ref-64 ((sap offset value) (* * *))
289 '(progn
290 (%set-signed-sap-ref-32 sap offset (ash value -32))
291 (%set-sap-ref-32 sap (+ 4 offset) (logand value #xffffffff))))