1 ;;;; the VM definition of various primitive memory access VOPs for the
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
15 ;;;; Data object ref/set stuff.
18 (:args
(object :scs
(descriptor-reg)))
19 (:info name offset lowtag
)
21 (:results
(result :scs
(descriptor-reg any-reg
)))
23 (loadw result object offset lowtag
)))
25 (define-vop (set-slot)
26 (:args
(object :scs
(descriptor-reg))
27 (value :scs
(descriptor-reg any-reg
)))
28 (:info name offset lowtag
)
32 (storew value object offset lowtag
)))
35 ;;;; Symbol hacking VOPs:
37 ;;; The compiler likes to be able to directly SET symbols.
38 (define-vop (set cell-set
)
39 (:variant symbol-value-slot other-pointer-lowtag
))
41 ;;; Do a cell ref with an error check for being unbound.
42 (define-vop (checked-cell-ref)
43 (:args
(object :scs
(descriptor-reg) :target obj-temp
))
44 (:results
(value :scs
(descriptor-reg any-reg
)))
47 (:save-p
:compute-only
)
48 (:temporary
(:scs
(descriptor-reg) :from
(:argument
0)) obj-temp
))
50 ;;; With SYMBOL-VALUE, we check that the value isn't the trap object.
51 ;;; So SYMBOL-VALUE of NIL is NIL.
52 (define-vop (symbol-value checked-cell-ref
)
53 (:translate symbol-value
)
55 (move obj-temp object
)
56 (loadw value obj-temp symbol-value-slot other-pointer-lowtag
)
57 (let ((err-lab (generate-error-code vop unbound-symbol-error obj-temp
)))
58 (inst cmpwi value unbound-marker-widetag
)
61 ;;; Like CHECKED-CELL-REF, only we are a predicate to see if the cell
63 (define-vop (boundp-frob)
64 (:args
(object :scs
(descriptor-reg)))
68 (:temporary
(:scs
(descriptor-reg)) value
))
70 (define-vop (boundp boundp-frob
)
73 (loadw value object symbol-value-slot other-pointer-lowtag
)
74 (inst cmpwi value unbound-marker-widetag
)
75 (inst b?
(if not-p
:eq
:ne
) target
)))
77 (define-vop (fast-symbol-value cell-ref
)
78 (:variant symbol-value-slot other-pointer-lowtag
)
80 (:translate symbol-value
))
82 (define-vop (symbol-hash)
84 (:translate symbol-hash
)
85 (:args
(symbol :scs
(descriptor-reg)))
86 (:results
(res :scs
(any-reg)))
87 (:result-types positive-fixnum
)
89 ;; The symbol-hash slot of NIL holds NIL because it is also the
90 ;; cdr slot, so we have to strip off the two low bits to make sure
91 ;; it is a fixnum. The lowtag selection magic that is required to
92 ;; ensure this is explained in the comment in objdef.lisp
93 (loadw res symbol symbol-hash-slot other-pointer-lowtag
)
94 (inst clrrwi res res n-fixnum-tag-bits
)))
96 ;;;; Fdefinition (fdefn) objects.
98 (define-vop (fdefn-fun cell-ref
)
99 (:variant fdefn-fun-slot other-pointer-lowtag
))
101 (define-vop (safe-fdefn-fun)
102 (:args
(object :scs
(descriptor-reg) :target obj-temp
))
103 (:results
(value :scs
(descriptor-reg any-reg
)))
105 (:save-p
:compute-only
)
106 (:temporary
(:scs
(descriptor-reg) :from
(:argument
0)) obj-temp
)
108 (move obj-temp object
)
109 (loadw value obj-temp fdefn-fun-slot other-pointer-lowtag
)
110 (inst cmpw value null-tn
)
111 (let ((err-lab (generate-error-code vop undefined-fun-error obj-temp
)))
112 (inst beq err-lab
))))
114 (define-vop (set-fdefn-fun)
116 (:translate
(setf fdefn-fun
))
117 (:args
(function :scs
(descriptor-reg) :target result
)
118 (fdefn :scs
(descriptor-reg)))
119 (:temporary
(:scs
(interior-reg)) lip
)
120 (:temporary
(:scs
(non-descriptor-reg)) type
)
121 (:results
(result :scs
(descriptor-reg)))
123 (let ((normal-fn (gen-label)))
124 (load-type type function
(- fun-pointer-lowtag
))
125 (inst cmpwi type simple-fun-header-widetag
)
126 ;;(inst mr lip function)
127 (inst addi lip function
128 (- (ash simple-fun-code-offset word-shift
) fun-pointer-lowtag
))
130 (inst lr lip
(make-fixup "closure_tramp" :foreign
))
131 (emit-label normal-fn
)
132 (storew lip fdefn fdefn-raw-addr-slot other-pointer-lowtag
)
133 (storew function fdefn fdefn-fun-slot other-pointer-lowtag
)
134 (move result function
))))
136 (define-vop (fdefn-makunbound)
138 (:translate fdefn-makunbound
)
139 (:args
(fdefn :scs
(descriptor-reg) :target result
))
140 (:temporary
(:scs
(non-descriptor-reg)) temp
)
141 (:results
(result :scs
(descriptor-reg)))
143 (storew null-tn fdefn fdefn-fun-slot other-pointer-lowtag
)
144 (inst lr temp
(make-fixup "undefined_tramp" :foreign
))
145 (storew temp fdefn fdefn-raw-addr-slot other-pointer-lowtag
)
146 (move result fdefn
)))
150 ;;;; Binding and Unbinding.
152 ;;; BIND -- Establish VAL as a binding for SYMBOL. Save the old value and
153 ;;; the symbol on the binding stack and stuff the new value into the
157 (:args
(val :scs
(any-reg descriptor-reg
))
158 (symbol :scs
(descriptor-reg)))
159 (:temporary
(:scs
(descriptor-reg)) temp
)
161 (loadw temp symbol symbol-value-slot other-pointer-lowtag
)
162 (inst addi bsp-tn bsp-tn
(* 2 n-word-bytes
))
163 (storew temp bsp-tn
(- binding-value-slot binding-size
))
164 (storew symbol bsp-tn
(- binding-symbol-slot binding-size
))
165 (storew val symbol symbol-value-slot other-pointer-lowtag
)))
169 (:temporary
(:scs
(descriptor-reg)) symbol value
)
171 (loadw symbol bsp-tn
(- binding-symbol-slot binding-size
))
172 (loadw value bsp-tn
(- binding-value-slot binding-size
))
173 (storew value symbol symbol-value-slot other-pointer-lowtag
)
174 (storew zero-tn bsp-tn
(- binding-symbol-slot binding-size
))
175 (storew zero-tn bsp-tn
(- binding-value-slot binding-size
))
176 (inst subi bsp-tn bsp-tn
(* 2 n-word-bytes
))))
179 (define-vop (unbind-to-here)
180 (:args
(arg :scs
(descriptor-reg any-reg
) :target where
))
181 (:temporary
(:scs
(any-reg) :from
(:argument
0)) where
)
182 (:temporary
(:scs
(descriptor-reg)) symbol value
)
184 (let ((loop (gen-label))
188 (inst cmpw where bsp-tn
)
192 (loadw symbol bsp-tn
(- binding-symbol-slot binding-size
))
193 (inst cmpwi symbol
0)
195 (loadw value bsp-tn
(- binding-value-slot binding-size
))
196 (storew value symbol symbol-value-slot other-pointer-lowtag
)
197 (storew zero-tn bsp-tn
(- binding-symbol-slot binding-size
))
200 (storew zero-tn bsp-tn
(- binding-value-slot binding-size
))
201 (inst subi bsp-tn bsp-tn
(* 2 n-word-bytes
))
202 (inst cmpw where bsp-tn
)
209 ;;;; Closure indexing.
211 (define-vop (closure-index-ref word-index-ref
)
212 (:variant closure-info-offset fun-pointer-lowtag
)
213 (:translate %closure-index-ref
))
215 (define-vop (funcallable-instance-info word-index-ref
)
216 (:variant funcallable-instance-info-offset fun-pointer-lowtag
)
217 (:translate %funcallable-instance-info
))
219 (define-vop (set-funcallable-instance-info word-index-set
)
220 (:variant funcallable-instance-info-offset fun-pointer-lowtag
)
221 (:translate %set-funcallable-instance-info
))
223 (define-vop (closure-ref slot-ref
)
224 (:variant closure-info-offset fun-pointer-lowtag
))
226 (define-vop (closure-init slot-set
)
227 (:variant closure-info-offset fun-pointer-lowtag
))
230 ;;;; Value Cell hackery.
232 (define-vop (value-cell-ref cell-ref
)
233 (:variant value-cell-value-slot other-pointer-lowtag
))
235 (define-vop (value-cell-set cell-set
)
236 (:variant value-cell-value-slot other-pointer-lowtag
))
240 ;;;; Instance hackery:
242 (define-vop (instance-length)
244 (:translate %instance-length
)
245 (:args
(struct :scs
(descriptor-reg)))
246 (:temporary
(:scs
(non-descriptor-reg)) temp
)
247 (:results
(res :scs
(unsigned-reg)))
248 (:result-types positive-fixnum
)
250 (loadw temp struct
0 instance-pointer-lowtag
)
251 (inst srwi res temp n-widetag-bits
)))
253 (define-vop (instance-index-ref word-index-ref
)
255 (:translate %instance-ref
)
256 (:variant instance-slots-offset instance-pointer-lowtag
)
257 (:arg-types instance positive-fixnum
))
259 (define-vop (instance-index-set word-index-set
)
261 (:translate %instance-set
)
262 (:variant instance-slots-offset instance-pointer-lowtag
)
263 (:arg-types instance positive-fixnum
*))
268 ;;;; Code object frobbing.
270 (define-vop (code-header-ref word-index-ref
)
271 (:translate code-header-ref
)
273 (:variant
0 other-pointer-lowtag
))
275 (define-vop (code-header-set word-index-set
)
276 (:translate code-header-set
)
278 (:variant
0 other-pointer-lowtag
))
282 ;;;; raw instance slot accessors
284 (define-vop (raw-instance-ref/word
)
285 (:translate %raw-instance-ref
/word
)
287 (:args
(object :scs
(descriptor-reg))
288 (index :scs
(any-reg)))
289 (:arg-types
* positive-fixnum
)
290 (:results
(value :scs
(unsigned-reg)))
291 (:temporary
(:scs
(non-descriptor-reg)) offset
)
292 (:result-types unsigned-num
)
294 (loadw offset object
0 instance-pointer-lowtag
)
295 ;; offset = (offset >> n-widetag-bits) << 2
296 (inst rlwinm offset offset
(- 32 (- n-widetag-bits
2)) (- n-widetag-bits
2) 29)
297 (inst subf offset index offset
)
301 (- (* (1- instance-slots-offset
) n-word-bytes
)
302 instance-pointer-lowtag
))
303 (inst lwzx value object offset
)))
305 (define-vop (raw-instance-set/word
)
306 (:translate %raw-instance-set
/word
)
308 (:args
(object :scs
(descriptor-reg))
309 (index :scs
(any-reg))
310 (value :scs
(unsigned-reg)))
311 (:arg-types
* positive-fixnum unsigned-num
)
312 (:results
(result :scs
(unsigned-reg)))
313 (:temporary
(:scs
(non-descriptor-reg)) offset
)
314 (:result-types unsigned-num
)
316 (loadw offset object
0 instance-pointer-lowtag
)
317 ;; offset = (offset >> n-widetag-bits) << 2
318 (inst rlwinm offset offset
(- 32 (- n-widetag-bits
2)) (- n-widetag-bits
2) 29)
319 (inst subf offset index offset
)
323 (- (* (1- instance-slots-offset
) n-word-bytes
)
324 instance-pointer-lowtag
))
325 (inst stwx value object offset
)
326 (move result value
)))
328 (define-vop (raw-instance-ref/single
)
329 (:translate %raw-instance-ref
/single
)
331 (:args
(object :scs
(descriptor-reg))
332 (index :scs
(any-reg)))
333 (:arg-types
* positive-fixnum
)
334 (:results
(value :scs
(single-reg)))
335 (:temporary
(:scs
(non-descriptor-reg)) offset
)
336 (:result-types single-float
)
338 (loadw offset object
0 instance-pointer-lowtag
)
339 ;; offset = (offset >> n-widetag-bits) << 2
340 (inst rlwinm offset offset
(- 32 (- n-widetag-bits
2)) (- n-widetag-bits
2) 29)
341 (inst subf offset index offset
)
345 (- (* (1- instance-slots-offset
) n-word-bytes
)
346 instance-pointer-lowtag
))
347 (inst lfsx value object offset
)))
349 (define-vop (raw-instance-set/single
)
350 (:translate %raw-instance-set
/single
)
352 (:args
(object :scs
(descriptor-reg))
353 (index :scs
(any-reg))
354 (value :scs
(single-reg) :target result
))
355 (:arg-types
* positive-fixnum single-float
)
356 (:results
(result :scs
(single-reg)))
357 (:result-types single-float
)
358 (:temporary
(:scs
(non-descriptor-reg)) offset
)
360 (loadw offset object
0 instance-pointer-lowtag
)
361 ;; offset = (offset >> n-widetag-bits) << 2
362 (inst rlwinm offset offset
(- 32 (- n-widetag-bits
2)) (- n-widetag-bits
2) 29)
363 (inst subf offset index offset
)
367 (- (* (1- instance-slots-offset
) n-word-bytes
)
368 instance-pointer-lowtag
))
369 (inst stfsx value object offset
)
370 (unless (location= result value
)
371 (inst frsp result value
))))
373 (define-vop (raw-instance-ref/double
)
374 (:translate %raw-instance-ref
/double
)
376 (:args
(object :scs
(descriptor-reg))
377 (index :scs
(any-reg)))
378 (:arg-types
* positive-fixnum
)
379 (:results
(value :scs
(double-reg)))
380 (:temporary
(:scs
(non-descriptor-reg)) offset
)
381 (:result-types double-float
)
383 (loadw offset object
0 instance-pointer-lowtag
)
384 ;; offset = (offset >> n-widetag-bits) << 2
385 (inst rlwinm offset offset
(- 32 (- n-widetag-bits
2)) (- n-widetag-bits
2) 29)
386 (inst subf offset index offset
)
390 (- (* (- instance-slots-offset
2) n-word-bytes
)
391 instance-pointer-lowtag
))
392 (inst lfdx value object offset
)))
394 (define-vop (raw-instance-set/double
)
395 (:translate %raw-instance-set
/double
)
397 (:args
(object :scs
(descriptor-reg))
398 (index :scs
(any-reg))
399 (value :scs
(double-reg) :target result
))
400 (:arg-types
* positive-fixnum double-float
)
401 (:results
(result :scs
(double-reg)))
402 (:result-types double-float
)
403 (:temporary
(:scs
(non-descriptor-reg)) offset
)
405 (loadw offset object
0 instance-pointer-lowtag
)
406 ;; offset = (offset >> n-widetag-bits) << 2
407 (inst rlwinm offset offset
(- 32 (- n-widetag-bits
2)) (- n-widetag-bits
2) 29)
408 (inst subf offset index offset
)
412 (- (* (- instance-slots-offset
2) n-word-bytes
)
413 instance-pointer-lowtag
))
414 (inst stfdx value object offset
)
415 (unless (location= result value
)
416 (inst fmr result value
))))
418 (define-vop (raw-instance-ref/complex-single
)
419 (:translate %raw-instance-ref
/complex-single
)
421 (:args
(object :scs
(descriptor-reg))
422 (index :scs
(any-reg)))
423 (:arg-types
* positive-fixnum
)
424 (:results
(value :scs
(complex-single-reg)))
425 (:temporary
(:scs
(non-descriptor-reg)) offset
)
426 (:result-types complex-single-float
)
428 (loadw offset object
0 instance-pointer-lowtag
)
429 ;; offset = (offset >> n-widetag-bits) << 2
430 (inst rlwinm offset offset
(- 32 (- n-widetag-bits
2)) (- n-widetag-bits
2) 29)
431 (inst subf offset index offset
)
435 (- (* (- instance-slots-offset
2) n-word-bytes
)
436 instance-pointer-lowtag
))
437 (inst lfsx
(complex-single-reg-real-tn value
) object offset
)
438 (inst addi offset offset n-word-bytes
)
439 (inst lfsx
(complex-single-reg-imag-tn value
) object offset
)))
441 (define-vop (raw-instance-set/complex-single
)
442 (:translate %raw-instance-set
/complex-single
)
444 (:args
(object :scs
(descriptor-reg))
445 (index :scs
(any-reg))
446 (value :scs
(complex-single-reg) :target result
))
447 (:arg-types
* positive-fixnum complex-single-float
)
448 (:results
(result :scs
(complex-single-reg)))
449 (:result-types complex-single-float
)
450 (:temporary
(:scs
(non-descriptor-reg)) offset
)
452 (loadw offset object
0 instance-pointer-lowtag
)
453 ;; offset = (offset >> n-widetag-bits) << 2
454 (inst rlwinm offset offset
(- 32 (- n-widetag-bits
2)) (- n-widetag-bits
2) 29)
455 (inst subf offset index offset
)
459 (- (* (- instance-slots-offset
2) n-word-bytes
)
460 instance-pointer-lowtag
))
461 (let ((value-real (complex-single-reg-real-tn value
))
462 (result-real (complex-single-reg-real-tn result
)))
463 (inst stfsx value-real object offset
)
464 (unless (location= result-real value-real
)
465 (inst frsp result-real value-real
)))
466 (inst addi offset offset n-word-bytes
)
467 (let ((value-imag (complex-single-reg-imag-tn value
))
468 (result-imag (complex-single-reg-imag-tn result
)))
469 (inst stfsx value-imag object offset
)
470 (unless (location= result-imag value-imag
)
471 (inst frsp result-imag value-imag
)))))
473 (define-vop (raw-instance-ref/complex-double
)
474 (:translate %raw-instance-ref
/complex-double
)
476 (:args
(object :scs
(descriptor-reg))
477 (index :scs
(any-reg)))
478 (:arg-types
* positive-fixnum
)
479 (:results
(value :scs
(complex-double-reg)))
480 (:temporary
(:scs
(non-descriptor-reg)) offset
)
481 (:result-types complex-double-float
)
483 (loadw offset object
0 instance-pointer-lowtag
)
484 ;; offset = (offset >> n-widetag-bits) << 2
485 (inst rlwinm offset offset
(- 32 (- n-widetag-bits
2)) (- n-widetag-bits
2) 29)
486 (inst subf offset index offset
)
490 (- (* (- instance-slots-offset
4) n-word-bytes
)
491 instance-pointer-lowtag
))
492 (inst lfdx
(complex-double-reg-real-tn value
) object offset
)
493 (inst addi offset offset
(* 2 n-word-bytes
))
494 (inst lfdx
(complex-double-reg-imag-tn value
) object offset
)))
496 (define-vop (raw-instance-set/complex-double
)
497 (:translate %raw-instance-set
/complex-double
)
499 (:args
(object :scs
(descriptor-reg))
500 (index :scs
(any-reg))
501 (value :scs
(complex-double-reg) :target result
))
502 (:arg-types
* positive-fixnum complex-double-float
)
503 (:results
(result :scs
(complex-double-reg)))
504 (:result-types complex-double-float
)
505 (:temporary
(:scs
(non-descriptor-reg)) offset
)
507 (loadw offset object
0 instance-pointer-lowtag
)
508 ;; offset = (offset >> n-widetag-bits) << 2
509 (inst rlwinm offset offset
(- 32 (- n-widetag-bits
2)) (- n-widetag-bits
2) 29)
510 (inst subf offset index offset
)
514 (- (* (- instance-slots-offset
4) n-word-bytes
)
515 instance-pointer-lowtag
))
516 (let ((value-real (complex-double-reg-real-tn value
))
517 (result-real (complex-double-reg-real-tn result
)))
518 (inst stfdx value-real object offset
)
519 (unless (location= result-real value-real
)
520 (inst fmr result-real value-real
)))
521 (inst addi offset offset
(* 2 n-word-bytes
))
522 (let ((value-imag (complex-double-reg-imag-tn value
))
523 (result-imag (complex-double-reg-imag-tn result
)))
524 (inst stfdx value-imag object offset
)
525 (unless (location= result-imag value-imag
)
526 (inst fmr result-imag value-imag
)))))