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 null zero)))
28 (:info name offset lowtag #!+gengc remember)
34 (storew-and-remember-slot value object offset lowtag)
35 (storew value object offset lowtag))
37 (storew value object offset lowtag)))
39 ;;;; symbol hacking VOPs
41 ;;; The compiler likes to be able to directly SET symbols.
42 (define-vop (set cell-set)
43 (:variant symbol-value-slot other-pointer-lowtag))
45 ;;; Do a cell ref with an error check for being unbound.
46 (define-vop (checked-cell-ref)
47 (:args (object :scs (descriptor-reg) :target obj-temp))
48 (:results (value :scs (descriptor-reg any-reg)))
51 (:save-p :compute-only)
52 (:temporary (:scs (non-descriptor-reg)) temp)
53 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp))
55 ;;; With SYMBOL-VALUE, we check that the value isn't the trap object.
56 ;;; So SYMBOL-VALUE of NIL is NIL.
57 (define-vop (symbol-value checked-cell-ref)
58 (:translate symbol-value)
60 (move object obj-temp)
61 (loadw value obj-temp symbol-value-slot other-pointer-lowtag)
62 (let ((err-lab (generate-error-code vop unbound-symbol-error obj-temp)))
63 (inst xor value unbound-marker-widetag temp)
64 (inst beq temp err-lab))))
66 ;;; like CHECKED-CELL-REF, only we are a predicate to see if the cell
68 (define-vop (boundp-frob)
69 (:args (object :scs (descriptor-reg)))
73 (:temporary (:scs (descriptor-reg)) value)
74 (:temporary (:scs (non-descriptor-reg)) temp))
76 (define-vop (boundp boundp-frob)
79 (loadw value object symbol-value-slot other-pointer-lowtag)
80 (inst xor value unbound-marker-widetag temp)
82 (inst beq temp target)
83 (inst bne temp target))))
85 (define-vop (fast-symbol-value cell-ref)
86 (:variant symbol-value-slot other-pointer-lowtag)
88 (:translate symbol-value))
90 (define-vop (symbol-hash)
92 (:translate symbol-hash)
93 (:args (symbol :scs (descriptor-reg)))
94 (:results (res :scs (any-reg)))
95 (:result-types positive-fixnum)
97 ;; The symbol-hash slot of NIL holds NIL because it is also the
98 ;; cdr slot, so we have to strip off the two low bits to make sure
99 ;; it is a fixnum. The lowtag selection magic that is required to
100 ;; ensure this is explained in the comment in objdef.lisp
101 (loadw res symbol symbol-hash-slot other-pointer-lowtag)
102 (inst bic res #.(ash lowtag-mask -1) res)))
104 ;;;; fdefinition (FDEFN) objects
106 (define-vop (fdefn-fun cell-ref)
107 (:variant fdefn-fun-slot other-pointer-lowtag))
109 (define-vop (safe-fdefn-fun)
110 (:args (object :scs (descriptor-reg) :target obj-temp))
111 (:results (value :scs (descriptor-reg any-reg)))
113 (:save-p :compute-only)
114 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp)
115 (:temporary (:scs (non-descriptor-reg)) temp)
117 (move object obj-temp)
118 (loadw value obj-temp fdefn-fun-slot other-pointer-lowtag)
119 (let ((err-lab (generate-error-code vop undefined-fun-error obj-temp)))
120 (inst cmpeq value null-tn temp)
121 (inst bne temp err-lab))))
123 (define-vop (set-fdefn-fun)
125 (:translate (setf fdefn-fun))
126 (:args (function :scs (descriptor-reg) :target result)
127 (fdefn :scs (descriptor-reg)))
128 (:temporary (:scs (interior-reg)) lip)
129 (:temporary (:scs (non-descriptor-reg)) type)
130 (:results (result :scs (descriptor-reg)))
132 (let ((normal-fn (gen-label)))
133 (load-type type function (- fun-pointer-lowtag))
134 (inst xor type simple-fun-header-widetag type)
136 (- (ash simple-fun-code-offset word-shift) fun-pointer-lowtag)
138 (inst beq type normal-fn)
139 (inst li (make-fixup "closure_tramp" :foreign) lip)
140 (emit-label normal-fn)
141 (storew lip fdefn fdefn-raw-addr-slot other-pointer-lowtag)
142 (storew function fdefn fdefn-fun-slot other-pointer-lowtag)
143 (move function result))))
146 (define-vop (fdefn-makunbound)
148 (:translate fdefn-makunbound)
149 (:args (fdefn :scs (descriptor-reg) :target result))
150 (:temporary (:scs (non-descriptor-reg)) temp)
151 (:results (result :scs (descriptor-reg)))
153 (storew null-tn fdefn fdefn-fun-slot other-pointer-lowtag)
154 (inst li (make-fixup "undefined_tramp" :foreign) temp)
156 (storew temp fdefn fdefn-raw-addr-slot other-pointer-lowtag)))
158 ;;;; binding and Unbinding
160 ;;; Establish VAL as a binding for SYMBOL. Save the old value and the
161 ;;; symbol on the binding stack and stuff the new value into the symbol.
163 (:args (val :scs (any-reg descriptor-reg))
164 (symbol :scs (descriptor-reg)))
165 (:temporary (:scs (descriptor-reg)) temp)
167 (loadw temp symbol symbol-value-slot other-pointer-lowtag)
168 (inst addq bsp-tn (* 2 n-word-bytes) bsp-tn)
169 (storew temp bsp-tn (- binding-value-slot binding-size))
170 (storew symbol bsp-tn (- binding-symbol-slot binding-size))
171 (#!+gengc storew-and-remember-slot #!-gengc storew
172 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 (#!+gengc storew-and-remember-slot #!-gengc storew
181 value symbol symbol-value-slot other-pointer-lowtag)
182 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
183 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
184 (inst subq bsp-tn (* 2 n-word-bytes) bsp-tn)))
187 (define-vop (unbind-to-here)
188 (:args (arg :scs (descriptor-reg any-reg) :target where))
189 (:temporary (:scs (any-reg) :from (:argument 0)) where)
190 (:temporary (:scs (descriptor-reg)) symbol value)
191 (:temporary (:scs (non-descriptor-reg)) temp)
193 (let ((loop (gen-label))
197 (inst cmpeq where bsp-tn temp)
201 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
202 (loadw value bsp-tn (- binding-value-slot binding-size))
203 (inst beq symbol skip)
204 (#!+gengc storew-and-remember-slot #!-gengc storew
205 value symbol symbol-value-slot other-pointer-lowtag)
206 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
209 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
210 (inst subq bsp-tn (* 2 n-word-bytes) bsp-tn)
211 (inst cmpeq where bsp-tn temp)
216 ;;;; closure indexing
218 (define-full-reffer closure-index-ref *
219 closure-info-offset fun-pointer-lowtag
220 (descriptor-reg any-reg) * %closure-index-ref)
222 (define-full-setter set-funcallable-instance-info *
223 funcallable-instance-info-offset fun-pointer-lowtag
224 (descriptor-reg any-reg null zero) * %set-funcallable-instance-info)
226 (define-full-reffer funcallable-instance-info *
227 funcallable-instance-info-offset fun-pointer-lowtag
228 (descriptor-reg any-reg) * %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))
236 ;;;; value cell hackery
238 (define-vop (value-cell-ref cell-ref)
239 (:variant value-cell-value-slot other-pointer-lowtag))
241 (define-vop (value-cell-set cell-set)
242 (:variant value-cell-value-slot other-pointer-lowtag))
244 ;;;; instance hackery
246 (define-vop (instance-length)
248 (:translate %instance-length)
249 (:args (struct :scs (descriptor-reg)))
250 (:results (res :scs (unsigned-reg)))
251 (:result-types positive-fixnum)
253 (loadw res struct 0 instance-pointer-lowtag)
254 (inst srl res n-widetag-bits res)))
256 (define-full-reffer instance-index-ref * instance-slots-offset
257 instance-pointer-lowtag (descriptor-reg any-reg) * %instance-ref)
259 (define-full-setter instance-index-set * instance-slots-offset
260 instance-pointer-lowtag (descriptor-reg any-reg null zero) * %instance-set)
262 ;;;; code object frobbing
264 (define-full-reffer code-header-ref * 0 other-pointer-lowtag
265 (descriptor-reg any-reg) * code-header-ref)
267 (define-full-setter code-header-set * 0 other-pointer-lowtag
268 (descriptor-reg any-reg null zero) * code-header-set)
270 ;;;; mutator accessing
275 (eval-when (:compile-toplevel :load-toplevel :execute)
276 ;; SBCL has never had GENGC. Now that we have Alpha support, it
277 ;; would probably be nice to restore GENGC support so that the Alpha
278 ;; doesn't have to crawl along with stop'n'copy. When we do, the CMU
279 ;; CL code below will need updating to the SBCL way of looking at
280 ;; things, e.g. at least using "SB-KERNEL" or "SB!KERNEL" instead of
281 ;; :KERNEL. -- WHN 2001-05-08
282 (error "This code is stale as of sbcl-0.6.12."))
284 (define-vop (mutator-ub32-ref)
287 (:results (res :scs (unsigned-reg)))
288 (:result-types unsigned-num)
291 (loadw res mutator-tn slot)))
293 (define-vop (mutator-descriptor-ref mutator-ub32-ref)
294 (:results (res :scs (any-reg descriptor-reg)))
297 (define-vop (mutator-sap-ref mutator-ub32-ref)
298 (:results (res :scs (sap-reg)))
299 (:result-types system-area-pointer))
302 (define-vop (mutator-ub32-set)
304 (:args (arg :scs (unsigned-reg) :target res))
305 (:arg-types unsigned-num)
306 (:results (res :scs (unsigned-reg)))
307 (:result-types unsigned-num)
310 (storew arg mutator-tn slot)
313 (define-vop (mutator-descriptor-set mutator-ub32-set)
314 (:args (arg :scs (any-reg descriptor-reg null zero) :target res))
316 (:results (res :scs (any-reg descriptor-reg)))
319 (define-vop (mutator-sap-set mutator-ub32-set)
320 (:args (arg :scs (sap-reg) :target res))
321 (:arg-types system-area-pointer)
322 (:results (res :scs (sap-reg)))
323 (:result-types system-area-pointer))
326 (macrolet ((define-mutator-accessors (slot type writable)
327 (let ((ref (symbolicate "MUTATOR-" slot "-REF"))
328 (set (and writable (symbolicate "MUTATOR-" slot "-SET")))
329 (offset (symbolicate "MUTATOR-" slot "-SLOT"))
331 (let ((*package* (find-package :kernel)))
332 (symbolicate "MUTATOR-" slot))))
334 (lisp-type ref-vop set-vop)
338 'mutator-descriptor-ref
339 'mutator-descriptor-set))
341 (values '(unsigned-byte 32)
345 (values 'system-area-pointer
349 (export ',fn :kernel)
350 (defknown ,fn () ,lisp-type (flushable))
351 (define-vop (,ref ,ref-vop)
355 `((defknown ((setf ,fn)) (,lisp-type) ,lisp-type
357 (define-vop (,set ,set-vop)
358 (:translate (setf ,fn))
359 (:variant ,offset)))))))))
360 (define-mutator-accessors thread :des t)
361 (define-mutator-accessors suspends-disabled-count :ub32 t)
362 (define-mutator-accessors suspend-pending :ub32 t)
363 (define-mutator-accessors control-stack-base :sap nil)
364 (define-mutator-accessors control-stack-end :sap nil)
365 (define-mutator-accessors current-unwind-protect :sap nil)
366 (define-mutator-accessors current-catch-block :sap nil)
367 (define-mutator-accessors binding-stack-base :sap nil)
368 (define-mutator-accessors binding-stack-end :sap nil)
369 (define-mutator-accessors number-stack-base :sap nil)
370 (define-mutator-accessors number-stack-end :sap nil)
371 (define-mutator-accessors nursery-start :sap nil)
372 (define-mutator-accessors nursery-end :sap nil)
373 (define-mutator-accessors storebuf-start :sap nil)
374 (define-mutator-accessors storebuf-end :sap nil)
375 (define-mutator-accessors words-consed :ub32 nil))
381 ;;;; raw instance slot accessors
383 (define-vop (raw-instance-ref/word)
384 (:translate %raw-instance-ref/word)
386 (:args (object :scs (descriptor-reg))
387 (index :scs (any-reg)))
388 (:arg-types * positive-fixnum)
389 (:results (value :scs (unsigned-reg)))
390 (:temporary (:scs (non-descriptor-reg)) offset)
391 (:temporary (:scs (interior-reg)) lip)
392 (:result-types unsigned-num)
394 (loadw offset object 0 instance-pointer-lowtag)
395 (inst srl offset n-widetag-bits offset)
396 (inst sll offset 2 offset)
397 (inst subq offset index offset)
398 (inst subq offset n-word-bytes offset)
399 (inst addq object offset lip)
402 (- (* instance-slots-offset n-word-bytes)
403 instance-pointer-lowtag)
405 (inst mskll value 4 value)))
407 (define-vop (raw-instance-set/word)
408 (:translate %raw-instance-set/word)
410 (:args (object :scs (descriptor-reg))
411 (index :scs (any-reg))
412 (value :scs (unsigned-reg)))
413 (:arg-types * positive-fixnum unsigned-num)
414 (:results (result :scs (unsigned-reg)))
415 (:temporary (:scs (non-descriptor-reg)) offset)
416 (:temporary (:scs (interior-reg)) lip)
417 (:result-types unsigned-num)
419 (loadw offset object 0 instance-pointer-lowtag)
420 (inst srl offset n-widetag-bits offset)
421 (inst sll offset 2 offset)
422 (inst subq offset index offset)
423 (inst subq offset n-word-bytes offset)
424 (inst addq object offset lip)
427 (- (* instance-slots-offset n-word-bytes)
428 instance-pointer-lowtag)
430 (move value result)))
432 (define-vop (raw-instance-ref/single)
433 (:translate %raw-instance-ref/single)
435 (:args (object :scs (descriptor-reg))
436 (index :scs (any-reg)))
437 (:arg-types * positive-fixnum)
438 (:results (value :scs (single-reg)))
439 (:temporary (:scs (non-descriptor-reg)) offset)
440 (:temporary (:scs (interior-reg)) lip)
441 (:result-types single-float)
443 (loadw offset object 0 instance-pointer-lowtag)
444 (inst srl offset n-widetag-bits offset)
445 (inst sll offset 2 offset)
446 (inst subq offset index offset)
447 (inst subq offset n-word-bytes offset)
448 (inst addq object offset lip)
451 (- (* instance-slots-offset n-word-bytes)
452 instance-pointer-lowtag)
455 (define-vop (raw-instance-set/single)
456 (:translate %raw-instance-set/single)
458 (:args (object :scs (descriptor-reg))
459 (index :scs (any-reg))
460 (value :scs (single-reg)))
461 (:arg-types * positive-fixnum single-float)
462 (:results (result :scs (single-reg)))
463 (:temporary (:scs (non-descriptor-reg)) offset)
464 (:temporary (:scs (interior-reg)) lip)
465 (:result-types single-float)
467 (loadw offset object 0 instance-pointer-lowtag)
468 (inst srl offset n-widetag-bits offset)
469 (inst sll offset 2 offset)
470 (inst subq offset index offset)
471 (inst subq offset n-word-bytes offset)
472 (inst addq object offset lip)
475 (- (* instance-slots-offset n-word-bytes)
476 instance-pointer-lowtag)
478 (unless (location= result value)
479 (inst fmove value result))))
481 (define-vop (raw-instance-ref/double)
482 (:translate %raw-instance-ref/double)
484 (:args (object :scs (descriptor-reg))
485 (index :scs (any-reg)))
486 (:arg-types * positive-fixnum)
487 (:results (value :scs (double-reg)))
488 (:temporary (:scs (non-descriptor-reg)) offset)
489 (:temporary (:scs (interior-reg)) lip)
490 (:result-types double-float)
492 (loadw offset object 0 instance-pointer-lowtag)
493 (inst srl offset n-widetag-bits offset)
494 (inst sll offset 2 offset)
495 (inst subq offset index offset)
496 (inst subq offset (* 2 n-word-bytes) offset)
497 (inst addq object offset lip)
500 (- (* instance-slots-offset n-word-bytes)
501 instance-pointer-lowtag)
504 (define-vop (raw-instance-set/double)
505 (:translate %raw-instance-set/double)
507 (:args (object :scs (descriptor-reg))
508 (index :scs (any-reg))
509 (value :scs (double-reg)))
510 (:arg-types * positive-fixnum double-float)
511 (:results (result :scs (double-reg)))
512 (:temporary (:scs (non-descriptor-reg)) offset)
513 (:temporary (:scs (interior-reg)) lip)
514 (:result-types double-float)
516 (loadw offset object 0 instance-pointer-lowtag)
517 (inst srl offset n-widetag-bits offset)
518 (inst sll offset 2 offset)
519 (inst subq offset index offset)
520 (inst subq offset (* 2 n-word-bytes) offset)
521 (inst addq object offset lip)
524 (- (* instance-slots-offset n-word-bytes)
525 instance-pointer-lowtag)
527 (unless (location= result value)
528 (inst fmove value result))))
530 (define-vop (raw-instance-ref/complex-single)
531 (:translate %raw-instance-ref/complex-single)
533 (:args (object :scs (descriptor-reg))
534 (index :scs (any-reg)))
535 (:arg-types * positive-fixnum)
536 (:results (value :scs (complex-single-reg)))
537 (:temporary (:scs (non-descriptor-reg)) offset)
538 (:temporary (:scs (interior-reg)) lip)
539 (:result-types complex-single-float)
541 (loadw offset object 0 instance-pointer-lowtag)
542 (inst srl offset n-widetag-bits offset)
543 (inst sll offset 2 offset)
544 (inst subq offset index offset)
545 (inst subq offset (* 2 n-word-bytes) offset)
546 (inst addq object offset lip)
548 (complex-double-reg-real-tn value)
549 (- (* instance-slots-offset n-word-bytes)
550 instance-pointer-lowtag)
553 (complex-double-reg-imag-tn value)
554 (- (* (1+ instance-slots-offset) n-word-bytes)
555 instance-pointer-lowtag)
558 (define-vop (raw-instance-set/complex-single)
559 (:translate %raw-instance-set/complex-single)
561 (:args (object :scs (descriptor-reg))
562 (index :scs (any-reg))
563 (value :scs (complex-single-reg)))
564 (:arg-types * positive-fixnum complex-single-float)
565 (:results (result :scs (complex-single-reg)))
566 (:temporary (:scs (non-descriptor-reg)) offset)
567 (:temporary (:scs (interior-reg)) lip)
568 (:result-types complex-single-float)
570 (loadw offset object 0 instance-pointer-lowtag)
571 (inst srl offset n-widetag-bits offset)
572 (inst sll offset 2 offset)
573 (inst subq offset index offset)
574 (inst subq offset (* 2 n-word-bytes) offset)
575 (inst addq object offset lip)
576 (let ((value-real (complex-single-reg-real-tn value))
577 (result-real (complex-single-reg-real-tn result)))
580 (- (* instance-slots-offset n-word-bytes)
581 instance-pointer-lowtag)
583 (unless (location= result-real value-real)
584 (inst fmove value-real result-real)))
585 (let ((value-imag (complex-single-reg-imag-tn value))
586 (result-imag (complex-single-reg-imag-tn result)))
589 (- (* (1+ instance-slots-offset) n-word-bytes)
590 instance-pointer-lowtag)
592 (unless (location= result-imag value-imag)
593 (inst fmove value-imag result-imag)))))
595 (define-vop (raw-instance-ref/complex-double)
596 (:translate %raw-instance-ref/complex-double)
598 (:args (object :scs (descriptor-reg))
599 (index :scs (any-reg)))
600 (:arg-types * positive-fixnum)
601 (:results (value :scs (complex-double-reg)))
602 (:temporary (:scs (non-descriptor-reg)) offset)
603 (:temporary (:scs (interior-reg)) lip)
604 (:result-types complex-double-float)
606 (loadw offset object 0 instance-pointer-lowtag)
607 (inst srl offset n-widetag-bits offset)
608 (inst sll offset 2 offset)
609 (inst subq offset index offset)
610 (inst subq offset (* 4 n-word-bytes) offset)
611 (inst addq object offset lip)
613 (complex-double-reg-real-tn value)
614 (- (* instance-slots-offset n-word-bytes)
615 instance-pointer-lowtag)
618 (complex-double-reg-imag-tn value)
619 (- (* (+ instance-slots-offset 2) n-word-bytes)
620 instance-pointer-lowtag)
623 (define-vop (raw-instance-set/complex-double)
624 (:translate %raw-instance-set/complex-double)
626 (:args (object :scs (descriptor-reg))
627 (index :scs (any-reg))
628 (value :scs (complex-double-reg)))
629 (:arg-types * positive-fixnum complex-double-float)
630 (:results (result :scs (complex-double-reg)))
631 (:temporary (:scs (non-descriptor-reg)) offset)
632 (:temporary (:scs (interior-reg)) lip)
633 (:result-types complex-double-float)
635 (loadw offset object 0 instance-pointer-lowtag)
636 (inst srl offset n-widetag-bits offset)
637 (inst sll offset 2 offset)
638 (inst subq offset index offset)
639 (inst subq offset (* 4 n-word-bytes) offset)
640 (inst addq object offset lip)
641 (let ((value-real (complex-double-reg-real-tn value))
642 (result-real (complex-double-reg-real-tn result)))
645 (- (* instance-slots-offset n-word-bytes)
646 instance-pointer-lowtag)
648 (unless (location= result-real value-real)
649 (inst fmove value-real result-real)))
650 (let ((value-imag (complex-double-reg-imag-tn value))
651 (result-imag (complex-double-reg-imag-tn result)))
654 (- (* (+ instance-slots-offset 2) n-word-bytes)
655 instance-pointer-lowtag)
657 (unless (location= result-imag value-imag)
658 (inst fmove value-imag result-imag)))))