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 ;;; On unithreaded builds these are just copies of the non-global versions.
97 (define-vop (%set-symbol-global-value set))
98 (define-vop (symbol-global-value symbol-value)
99 (:translate symbol-global-value))
100 (define-vop (fast-symbol-global-value fast-symbol-value)
101 (:translate symbol-global-value))
103 ;;;; Fdefinition (fdefn) objects.
105 (define-vop (fdefn-fun cell-ref)
106 (:variant fdefn-fun-slot other-pointer-lowtag))
108 (define-vop (safe-fdefn-fun)
109 (:args (object :scs (descriptor-reg) :target obj-temp))
110 (:results (value :scs (descriptor-reg any-reg)))
112 (:save-p :compute-only)
113 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp)
115 (move obj-temp object)
116 (loadw value obj-temp fdefn-fun-slot other-pointer-lowtag)
117 (inst cmpw value null-tn)
118 (let ((err-lab (generate-error-code vop 'undefined-fun-error obj-temp)))
119 (inst beq err-lab))))
121 (define-vop (set-fdefn-fun)
123 (:translate (setf fdefn-fun))
124 (:args (function :scs (descriptor-reg) :target result)
125 (fdefn :scs (descriptor-reg)))
126 (:temporary (:scs (interior-reg)) lip)
127 (:temporary (:scs (non-descriptor-reg)) type)
128 (:results (result :scs (descriptor-reg)))
130 (let ((normal-fn (gen-label)))
131 (load-type type function (- fun-pointer-lowtag))
132 (inst cmpwi type simple-fun-header-widetag)
133 ;;(inst mr lip function)
134 (inst addi lip function
135 (- (ash simple-fun-code-offset word-shift) fun-pointer-lowtag))
137 (inst lr lip (make-fixup "closure_tramp" :foreign))
138 (emit-label normal-fn)
139 (storew lip fdefn fdefn-raw-addr-slot other-pointer-lowtag)
140 (storew function fdefn fdefn-fun-slot other-pointer-lowtag)
141 (move result function))))
143 (define-vop (fdefn-makunbound)
145 (:translate fdefn-makunbound)
146 (:args (fdefn :scs (descriptor-reg) :target result))
147 (:temporary (:scs (non-descriptor-reg)) temp)
148 (:results (result :scs (descriptor-reg)))
150 (storew null-tn fdefn fdefn-fun-slot other-pointer-lowtag)
151 (inst lr temp (make-fixup "undefined_tramp" :foreign))
152 (storew temp fdefn fdefn-raw-addr-slot other-pointer-lowtag)
153 (move result fdefn)))
157 ;;;; Binding and Unbinding.
159 ;;; BIND -- Establish VAL as a binding for SYMBOL. Save the old value and
160 ;;; the symbol on the binding stack and stuff the new value into the
164 (:args (val :scs (any-reg descriptor-reg))
165 (symbol :scs (descriptor-reg)))
166 (:temporary (:scs (descriptor-reg)) temp)
168 (loadw temp symbol symbol-value-slot other-pointer-lowtag)
169 (inst addi bsp-tn bsp-tn (* 2 n-word-bytes))
170 (storew temp bsp-tn (- binding-value-slot binding-size))
171 (storew symbol bsp-tn (- binding-symbol-slot binding-size))
172 (storew val symbol symbol-value-slot other-pointer-lowtag)))
176 (:temporary (:scs (descriptor-reg)) symbol value)
178 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
179 (loadw value bsp-tn (- binding-value-slot binding-size))
180 (storew value symbol symbol-value-slot other-pointer-lowtag)
181 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
182 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
183 (inst subi bsp-tn bsp-tn (* 2 n-word-bytes))))
186 (define-vop (unbind-to-here)
187 (:args (arg :scs (descriptor-reg any-reg) :target where))
188 (:temporary (:scs (any-reg) :from (:argument 0)) where)
189 (:temporary (:scs (descriptor-reg)) symbol value)
191 (let ((loop (gen-label))
195 (inst cmpw where bsp-tn)
199 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
200 (inst cmpwi symbol 0)
202 (loadw value bsp-tn (- binding-value-slot binding-size))
203 (storew value symbol symbol-value-slot other-pointer-lowtag)
204 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
207 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
208 (inst subi bsp-tn bsp-tn (* 2 n-word-bytes))
209 (inst cmpw where bsp-tn)
216 ;;;; Closure indexing.
218 (define-vop (closure-index-ref word-index-ref)
219 (:variant closure-info-offset fun-pointer-lowtag)
220 (:translate %closure-index-ref))
222 (define-vop (funcallable-instance-info word-index-ref)
223 (:variant funcallable-instance-info-offset fun-pointer-lowtag)
224 (:translate %funcallable-instance-info))
226 (define-vop (set-funcallable-instance-info word-index-set)
227 (:variant funcallable-instance-info-offset fun-pointer-lowtag)
228 (:translate %set-funcallable-instance-info))
230 (define-vop (closure-ref slot-ref)
231 (:variant closure-info-offset fun-pointer-lowtag))
233 (define-vop (closure-init slot-set)
234 (:variant closure-info-offset fun-pointer-lowtag))
237 ;;;; Value Cell hackery.
239 (define-vop (value-cell-ref cell-ref)
240 (:variant value-cell-value-slot other-pointer-lowtag))
242 (define-vop (value-cell-set cell-set)
243 (:variant value-cell-value-slot other-pointer-lowtag))
247 ;;;; Instance hackery:
249 (define-vop (instance-length)
251 (:translate %instance-length)
252 (:args (struct :scs (descriptor-reg)))
253 (:temporary (:scs (non-descriptor-reg)) temp)
254 (:results (res :scs (unsigned-reg)))
255 (:result-types positive-fixnum)
257 (loadw temp struct 0 instance-pointer-lowtag)
258 (inst srwi res temp n-widetag-bits)))
260 (define-vop (instance-index-ref word-index-ref)
262 (:translate %instance-ref)
263 (:variant instance-slots-offset instance-pointer-lowtag)
264 (:arg-types instance positive-fixnum))
266 (define-vop (instance-index-set word-index-set)
268 (:translate %instance-set)
269 (:variant instance-slots-offset instance-pointer-lowtag)
270 (:arg-types instance positive-fixnum *))
275 ;;;; Code object frobbing.
277 (define-vop (code-header-ref word-index-ref)
278 (:translate code-header-ref)
280 (:variant 0 other-pointer-lowtag))
282 (define-vop (code-header-set word-index-set)
283 (:translate code-header-set)
285 (:variant 0 other-pointer-lowtag))
289 ;;;; raw instance slot accessors
291 (define-vop (raw-instance-ref/word)
292 (:translate %raw-instance-ref/word)
294 (:args (object :scs (descriptor-reg))
295 (index :scs (any-reg)))
296 (:arg-types * positive-fixnum)
297 (:results (value :scs (unsigned-reg)))
298 (:temporary (:scs (non-descriptor-reg)) offset)
299 (:result-types unsigned-num)
301 (loadw offset object 0 instance-pointer-lowtag)
302 ;; offset = (offset >> n-widetag-bits) << 2
303 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
304 (inst subf offset index offset)
308 (- (* (1- instance-slots-offset) n-word-bytes)
309 instance-pointer-lowtag))
310 (inst lwzx value object offset)))
312 (define-vop (raw-instance-set/word)
313 (:translate %raw-instance-set/word)
315 (:args (object :scs (descriptor-reg))
316 (index :scs (any-reg))
317 (value :scs (unsigned-reg)))
318 (:arg-types * positive-fixnum unsigned-num)
319 (:results (result :scs (unsigned-reg)))
320 (:temporary (:scs (non-descriptor-reg)) offset)
321 (:result-types unsigned-num)
323 (loadw offset object 0 instance-pointer-lowtag)
324 ;; offset = (offset >> n-widetag-bits) << 2
325 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
326 (inst subf offset index offset)
330 (- (* (1- instance-slots-offset) n-word-bytes)
331 instance-pointer-lowtag))
332 (inst stwx value object offset)
333 (move result value)))
335 (define-vop (raw-instance-ref/single)
336 (:translate %raw-instance-ref/single)
338 (:args (object :scs (descriptor-reg))
339 (index :scs (any-reg)))
340 (:arg-types * positive-fixnum)
341 (:results (value :scs (single-reg)))
342 (:temporary (:scs (non-descriptor-reg)) offset)
343 (:result-types single-float)
345 (loadw offset object 0 instance-pointer-lowtag)
346 ;; offset = (offset >> n-widetag-bits) << 2
347 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
348 (inst subf offset index offset)
352 (- (* (1- instance-slots-offset) n-word-bytes)
353 instance-pointer-lowtag))
354 (inst lfsx value object offset)))
356 (define-vop (raw-instance-set/single)
357 (:translate %raw-instance-set/single)
359 (:args (object :scs (descriptor-reg))
360 (index :scs (any-reg))
361 (value :scs (single-reg) :target result))
362 (:arg-types * positive-fixnum single-float)
363 (:results (result :scs (single-reg)))
364 (:result-types single-float)
365 (:temporary (:scs (non-descriptor-reg)) offset)
367 (loadw offset object 0 instance-pointer-lowtag)
368 ;; offset = (offset >> n-widetag-bits) << 2
369 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
370 (inst subf offset index offset)
374 (- (* (1- instance-slots-offset) n-word-bytes)
375 instance-pointer-lowtag))
376 (inst stfsx value object offset)
377 (unless (location= result value)
378 (inst frsp result value))))
380 (define-vop (raw-instance-ref/double)
381 (:translate %raw-instance-ref/double)
383 (:args (object :scs (descriptor-reg))
384 (index :scs (any-reg)))
385 (:arg-types * positive-fixnum)
386 (:results (value :scs (double-reg)))
387 (:temporary (:scs (non-descriptor-reg)) offset)
388 (:result-types double-float)
390 (loadw offset object 0 instance-pointer-lowtag)
391 ;; offset = (offset >> n-widetag-bits) << 2
392 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
393 (inst subf offset index offset)
397 (- (* (- instance-slots-offset 2) n-word-bytes)
398 instance-pointer-lowtag))
399 (inst lfdx value object offset)))
401 (define-vop (raw-instance-set/double)
402 (:translate %raw-instance-set/double)
404 (:args (object :scs (descriptor-reg))
405 (index :scs (any-reg))
406 (value :scs (double-reg) :target result))
407 (:arg-types * positive-fixnum double-float)
408 (:results (result :scs (double-reg)))
409 (:result-types double-float)
410 (:temporary (:scs (non-descriptor-reg)) offset)
412 (loadw offset object 0 instance-pointer-lowtag)
413 ;; offset = (offset >> n-widetag-bits) << 2
414 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
415 (inst subf offset index offset)
419 (- (* (- instance-slots-offset 2) n-word-bytes)
420 instance-pointer-lowtag))
421 (inst stfdx value object offset)
422 (unless (location= result value)
423 (inst fmr result value))))
425 (define-vop (raw-instance-ref/complex-single)
426 (:translate %raw-instance-ref/complex-single)
428 (:args (object :scs (descriptor-reg))
429 (index :scs (any-reg)))
430 (:arg-types * positive-fixnum)
431 (:results (value :scs (complex-single-reg)))
432 (:temporary (:scs (non-descriptor-reg)) offset)
433 (:result-types complex-single-float)
435 (loadw offset object 0 instance-pointer-lowtag)
436 ;; offset = (offset >> n-widetag-bits) << 2
437 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
438 (inst subf offset index offset)
442 (- (* (- instance-slots-offset 2) n-word-bytes)
443 instance-pointer-lowtag))
444 (inst lfsx (complex-single-reg-real-tn value) object offset)
445 (inst addi offset offset n-word-bytes)
446 (inst lfsx (complex-single-reg-imag-tn value) object offset)))
448 (define-vop (raw-instance-set/complex-single)
449 (:translate %raw-instance-set/complex-single)
451 (:args (object :scs (descriptor-reg))
452 (index :scs (any-reg))
453 (value :scs (complex-single-reg) :target result))
454 (:arg-types * positive-fixnum complex-single-float)
455 (:results (result :scs (complex-single-reg)))
456 (:result-types complex-single-float)
457 (:temporary (:scs (non-descriptor-reg)) offset)
459 (loadw offset object 0 instance-pointer-lowtag)
460 ;; offset = (offset >> n-widetag-bits) << 2
461 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
462 (inst subf offset index offset)
466 (- (* (- instance-slots-offset 2) n-word-bytes)
467 instance-pointer-lowtag))
468 (let ((value-real (complex-single-reg-real-tn value))
469 (result-real (complex-single-reg-real-tn result)))
470 (inst stfsx value-real object offset)
471 (unless (location= result-real value-real)
472 (inst frsp result-real value-real)))
473 (inst addi offset offset n-word-bytes)
474 (let ((value-imag (complex-single-reg-imag-tn value))
475 (result-imag (complex-single-reg-imag-tn result)))
476 (inst stfsx value-imag object offset)
477 (unless (location= result-imag value-imag)
478 (inst frsp result-imag value-imag)))))
480 (define-vop (raw-instance-ref/complex-double)
481 (:translate %raw-instance-ref/complex-double)
483 (:args (object :scs (descriptor-reg))
484 (index :scs (any-reg)))
485 (:arg-types * positive-fixnum)
486 (:results (value :scs (complex-double-reg)))
487 (:temporary (:scs (non-descriptor-reg)) offset)
488 (:result-types complex-double-float)
490 (loadw offset object 0 instance-pointer-lowtag)
491 ;; offset = (offset >> n-widetag-bits) << 2
492 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
493 (inst subf offset index offset)
497 (- (* (- instance-slots-offset 4) n-word-bytes)
498 instance-pointer-lowtag))
499 (inst lfdx (complex-double-reg-real-tn value) object offset)
500 (inst addi offset offset (* 2 n-word-bytes))
501 (inst lfdx (complex-double-reg-imag-tn value) object offset)))
503 (define-vop (raw-instance-set/complex-double)
504 (:translate %raw-instance-set/complex-double)
506 (:args (object :scs (descriptor-reg))
507 (index :scs (any-reg))
508 (value :scs (complex-double-reg) :target result))
509 (:arg-types * positive-fixnum complex-double-float)
510 (:results (result :scs (complex-double-reg)))
511 (:result-types complex-double-float)
512 (:temporary (:scs (non-descriptor-reg)) offset)
514 (loadw offset object 0 instance-pointer-lowtag)
515 ;; offset = (offset >> n-widetag-bits) << 2
516 (inst rlwinm offset offset (- 32 (- n-widetag-bits 2)) (- n-widetag-bits 2) 29)
517 (inst subf offset index offset)
521 (- (* (- instance-slots-offset 4) n-word-bytes)
522 instance-pointer-lowtag))
523 (let ((value-real (complex-double-reg-real-tn value))
524 (result-real (complex-double-reg-real-tn result)))
525 (inst stfdx value-real object offset)
526 (unless (location= result-real value-real)
527 (inst fmr result-real value-real)))
528 (inst addi offset offset (* 2 n-word-bytes))
529 (let ((value-imag (complex-double-reg-imag-tn value))
530 (result-imag (complex-double-reg-imag-tn result)))
531 (inst stfdx value-imag object offset)
532 (unless (location= result-imag value-imag)
533 (inst fmr result-imag value-imag)))))