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.
17 (:args (object :scs (descriptor-reg)))
18 (:info name offset lowtag)
20 (:results (result :scs (descriptor-reg any-reg)))
22 (loadw result object offset lowtag)))
24 (define-vop (set-slot)
25 (:args (object :scs (descriptor-reg))
26 (value :scs (descriptor-reg any-reg)))
27 (:info name offset lowtag)
31 (storew value object offset lowtag)))
33 ;;;; Symbol hacking VOPs:
35 ;;; The compiler likes to be able to directly SET symbols.
36 (define-vop (set cell-set)
37 (:variant symbol-value-slot other-pointer-lowtag))
39 ;;; Do a cell ref with an error check for being unbound.
40 (define-vop (checked-cell-ref)
41 (:args (object :scs (descriptor-reg) :target obj-temp))
42 (:results (value :scs (descriptor-reg any-reg)))
45 (:save-p :compute-only)
46 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp))
48 ;;; With Symbol-Value, we check that the value isn't the trap object.
49 ;;; So Symbol-Value of NIL is NIL.
50 (define-vop (symbol-value checked-cell-ref)
51 (:translate symbol-value)
53 (move obj-temp object)
54 (loadw value obj-temp symbol-value-slot other-pointer-lowtag)
55 (let ((err-lab (generate-error-code vop unbound-symbol-error obj-temp)))
56 (inst cmp value unbound-marker-widetag)
60 ;;; Like CHECKED-CELL-REF, only we are a predicate to see if the cell
62 (define-vop (boundp-frob)
63 (:args (object :scs (descriptor-reg)))
67 (:temporary (:scs (descriptor-reg)) value))
69 (define-vop (boundp boundp-frob)
72 (loadw value object symbol-value-slot other-pointer-lowtag)
73 (inst cmp value unbound-marker-widetag)
74 (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 andn res res fixnum-tag-mask)))
96 ;;;; FDEFINITION (fdefn) objects.
97 (define-vop (fdefn-fun cell-ref)
98 (:variant fdefn-fun-slot other-pointer-lowtag))
100 (define-vop (safe-fdefn-fun)
101 (:args (object :scs (descriptor-reg) :target obj-temp))
102 (:results (value :scs (descriptor-reg any-reg)))
104 (:save-p :compute-only)
105 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp)
107 (move obj-temp object)
108 (loadw value obj-temp fdefn-fun-slot other-pointer-lowtag)
109 (inst cmp value null-tn)
110 (let ((err-lab (generate-error-code vop undefined-fun-error obj-temp)))
111 (inst b :eq 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 cmp type simple-fun-header-widetag)
126 (inst b :eq normal-fn)
127 (inst move lip function)
128 (inst li lip (make-fixup "closure_tramp" :foreign))
129 (emit-label normal-fn)
130 (storew function fdefn fdefn-fun-slot other-pointer-lowtag)
131 (storew lip fdefn fdefn-raw-addr-slot other-pointer-lowtag)
132 (move result function))))
134 (define-vop (fdefn-makunbound)
136 (:translate fdefn-makunbound)
137 (:args (fdefn :scs (descriptor-reg) :target result))
138 (:temporary (:scs (non-descriptor-reg)) temp)
139 (:results (result :scs (descriptor-reg)))
141 (storew null-tn fdefn fdefn-fun-slot other-pointer-lowtag)
142 (inst li temp (make-fixup "undefined_tramp" :foreign))
143 (storew temp fdefn fdefn-raw-addr-slot other-pointer-lowtag)
144 (move result fdefn)))
148 ;;;; Binding and Unbinding.
150 ;;; Establish VAL as a binding for SYMBOL. Save the old value and the
151 ;;; symbol on the binding stack and stuff the new value into the
154 (:args (val :scs (any-reg descriptor-reg))
155 (symbol :scs (descriptor-reg)))
156 (:temporary (:scs (descriptor-reg)) temp)
158 (loadw temp symbol symbol-value-slot other-pointer-lowtag)
159 (inst add bsp-tn bsp-tn (* 2 n-word-bytes))
160 (storew temp bsp-tn (- binding-value-slot binding-size))
161 (storew symbol bsp-tn (- binding-symbol-slot binding-size))
162 (storew val symbol symbol-value-slot other-pointer-lowtag)))
165 (:temporary (:scs (descriptor-reg)) symbol value)
167 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
168 (loadw value bsp-tn (- binding-value-slot binding-size))
169 (storew value symbol symbol-value-slot other-pointer-lowtag)
170 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
171 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
172 (inst sub bsp-tn bsp-tn (* 2 n-word-bytes))))
174 (define-vop (unbind-to-here)
175 (:args (arg :scs (descriptor-reg any-reg) :target where))
176 (:temporary (:scs (any-reg) :from (:argument 0)) where)
177 (:temporary (:scs (descriptor-reg)) symbol value)
179 (let ((loop (gen-label))
183 (inst cmp where bsp-tn)
188 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
191 (loadw value bsp-tn (- binding-value-slot binding-size))
192 (storew value symbol symbol-value-slot other-pointer-lowtag)
193 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
194 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
197 (inst sub bsp-tn bsp-tn (* 2 n-word-bytes))
198 (inst cmp where bsp-tn)
204 ;;;; closure indexing.
206 (define-vop (closure-index-ref word-index-ref)
207 (:variant closure-info-offset fun-pointer-lowtag)
208 (:translate %closure-index-ref))
210 (define-vop (funcallable-instance-info word-index-ref)
211 (:variant funcallable-instance-info-offset fun-pointer-lowtag)
212 (:translate %funcallable-instance-info))
214 (define-vop (set-funcallable-instance-info word-index-set)
215 (:variant funcallable-instance-info-offset fun-pointer-lowtag)
216 (:translate %set-funcallable-instance-info))
218 (define-vop (funcallable-instance-lexenv cell-ref)
219 (:variant funcallable-instance-lexenv-slot fun-pointer-lowtag))
222 (define-vop (closure-ref slot-ref)
223 (:variant closure-info-offset fun-pointer-lowtag))
225 (define-vop (closure-init slot-set)
226 (:variant closure-info-offset fun-pointer-lowtag))
228 ;;;; value cell hackery.
230 (define-vop (value-cell-ref cell-ref)
231 (:variant value-cell-value-slot other-pointer-lowtag))
233 (define-vop (value-cell-set cell-set)
234 (:variant value-cell-value-slot other-pointer-lowtag))
236 ;;;; instance hackery:
238 (define-vop (instance-length)
240 (:translate %instance-length)
241 (:args (struct :scs (descriptor-reg)))
242 (:temporary (:scs (non-descriptor-reg)) temp)
243 (:results (res :scs (unsigned-reg)))
244 (:result-types positive-fixnum)
246 (loadw temp struct 0 instance-pointer-lowtag)
247 (inst srl res temp n-widetag-bits)))
249 (define-vop (instance-ref slot-ref)
250 (:variant instance-slots-offset instance-pointer-lowtag)
252 (:translate %instance-ref)
253 (:arg-types * (:constant index)))
255 ;;; This VOP has no :results; however, %instance-set must return a
256 ;;; value. This caused, in the forward port to 0.7.x, an error in
257 ;;; !fdefn-cold-init: "argument X is not a REAL: NIL". This VOP is
258 ;;; commented out for now, pending the addition of checking code to
259 ;;; the define-vop machinery to ascertain that this was indeed the
260 ;;; problem. -- CSR, 2002-02-12
262 (define-vop (instance-set slot-set)
264 (:translate %instance-set)
265 (:variant instance-slots-offset instance-pointer-lowtag)
266 (:arg-types * (:constant index) *))
268 (define-vop (instance-index-ref word-index-ref)
270 (:translate %instance-ref)
271 (:variant instance-slots-offset instance-pointer-lowtag)
272 (:arg-types * positive-fixnum))
274 (define-vop (instance-index-set word-index-set)
276 (:translate %instance-set)
277 (:variant instance-slots-offset instance-pointer-lowtag)
278 (:arg-types * positive-fixnum *))
280 ;;;; Code object frobbing.
282 (define-vop (code-header-ref word-index-ref)
283 (:translate code-header-ref)
285 (:variant 0 other-pointer-lowtag))
287 (define-vop (code-header-set word-index-set)
288 (:translate code-header-set)
290 (:variant 0 other-pointer-lowtag))
294 ;;;; raw instance slot accessors
296 (define-vop (raw-instance-ref/word)
297 (:translate %raw-instance-ref/word)
299 (:args (object :scs (descriptor-reg))
300 (index :scs (any-reg)))
301 (:arg-types * positive-fixnum)
302 (:results (value :scs (unsigned-reg)))
303 (:temporary (:scs (non-descriptor-reg)) offset)
304 (:result-types unsigned-num)
306 (loadw offset object 0 instance-pointer-lowtag)
307 (inst srl offset offset n-widetag-bits)
308 (inst sll offset offset 2)
309 (inst sub offset offset index)
313 (- (* (1- instance-slots-offset) n-word-bytes)
314 instance-pointer-lowtag))
315 (inst ld value object offset)))
317 (define-vop (raw-instance-set/word)
318 (:translate %raw-instance-set/word)
320 (:args (object :scs (descriptor-reg))
321 (index :scs (any-reg))
322 (value :scs (unsigned-reg)))
323 (:arg-types * positive-fixnum unsigned-num)
324 (:results (result :scs (unsigned-reg)))
325 (:temporary (:scs (non-descriptor-reg)) offset)
326 (:result-types unsigned-num)
328 (loadw offset object 0 instance-pointer-lowtag)
329 (inst srl offset offset n-widetag-bits)
330 (inst sll offset offset 2)
331 (inst sub offset offset index)
335 (- (* (1- instance-slots-offset) n-word-bytes)
336 instance-pointer-lowtag))
337 (inst st value object offset)
338 (move result value)))
340 (define-vop (raw-instance-ref/single)
341 (:translate %raw-instance-ref/single)
343 (:args (object :scs (descriptor-reg))
344 (index :scs (any-reg)))
345 (:arg-types * positive-fixnum)
346 (:results (value :scs (single-reg)))
347 (:temporary (:scs (non-descriptor-reg)) offset)
348 (:result-types single-float)
350 (loadw offset object 0 instance-pointer-lowtag)
351 (inst srl offset offset n-widetag-bits)
352 (inst sll offset offset 2)
353 (inst sub offset offset index)
357 (- (* (1- instance-slots-offset) n-word-bytes)
358 instance-pointer-lowtag))
359 (inst ldf value object offset)))
361 (define-vop (raw-instance-set/single)
362 (:translate %raw-instance-set/single)
364 (:args (object :scs (descriptor-reg))
365 (index :scs (any-reg))
366 (value :scs (single-reg) :target result))
367 (:arg-types * positive-fixnum single-float)
368 (:results (result :scs (single-reg)))
369 (:result-types single-float)
370 (:temporary (:scs (non-descriptor-reg)) offset)
372 (loadw offset object 0 instance-pointer-lowtag)
373 (inst srl offset offset n-widetag-bits)
374 (inst sll offset offset 2)
375 (inst sub offset offset index)
379 (- (* (1- instance-slots-offset) n-word-bytes)
380 instance-pointer-lowtag))
381 (inst stf value object offset)
382 (unless (location= result value)
383 (inst fmovs result value))))
385 (define-vop (raw-instance-ref/double)
386 (:translate %raw-instance-ref/double)
388 (:args (object :scs (descriptor-reg))
389 (index :scs (any-reg)))
390 (:arg-types * positive-fixnum)
391 (:results (value :scs (double-reg)))
392 (:temporary (:scs (non-descriptor-reg)) offset)
393 (:result-types double-float)
395 (loadw offset object 0 instance-pointer-lowtag)
396 (inst srl offset offset n-widetag-bits)
397 (inst sll offset offset 2)
398 (inst sub offset offset index)
402 (- (* (- instance-slots-offset 2) n-word-bytes)
403 instance-pointer-lowtag))
404 (inst lddf value object offset)))
406 (define-vop (raw-instance-set/double)
407 (:translate %raw-instance-set/double)
409 (:args (object :scs (descriptor-reg))
410 (index :scs (any-reg))
411 (value :scs (double-reg) :target result))
412 (:arg-types * positive-fixnum double-float)
413 (:results (result :scs (double-reg)))
414 (:result-types double-float)
415 (:temporary (:scs (non-descriptor-reg)) offset)
417 (loadw offset object 0 instance-pointer-lowtag)
418 (inst srl offset offset n-widetag-bits)
419 (inst sll offset offset 2)
420 (inst sub offset offset index)
424 (- (* (- instance-slots-offset 2) n-word-bytes)
425 instance-pointer-lowtag))
426 (inst stdf value object offset)
427 (unless (location= result value)
428 (move-double-reg result value))))
430 (define-vop (raw-instance-ref/complex-single)
431 (:translate %raw-instance-ref/complex-single)
433 (:args (object :scs (descriptor-reg))
434 (index :scs (any-reg)))
435 (:arg-types * positive-fixnum)
436 (:results (value :scs (complex-single-reg)))
437 (:temporary (:scs (non-descriptor-reg)) offset)
438 (:result-types complex-single-float)
440 (loadw offset object 0 instance-pointer-lowtag)
441 (inst srl offset offset n-widetag-bits)
442 (inst sll offset offset 2)
443 (inst sub offset offset index)
447 (- (* (- instance-slots-offset 2) n-word-bytes)
448 instance-pointer-lowtag))
449 (inst ldf (complex-single-reg-real-tn value) object offset)
450 (inst add offset offset n-word-bytes)
451 (inst ldf (complex-single-reg-imag-tn value) object offset)))
453 (define-vop (raw-instance-set/complex-single)
454 (:translate %raw-instance-set/complex-single)
456 (:args (object :scs (descriptor-reg))
457 (index :scs (any-reg))
458 (value :scs (complex-single-reg) :target result))
459 (:arg-types * positive-fixnum complex-single-float)
460 (:results (result :scs (complex-single-reg)))
461 (:result-types complex-single-float)
462 (:temporary (:scs (non-descriptor-reg)) offset)
464 (loadw offset object 0 instance-pointer-lowtag)
465 (inst srl offset offset n-widetag-bits)
466 (inst sll offset offset 2)
467 (inst sub offset offset index)
471 (- (* (- instance-slots-offset 2) n-word-bytes)
472 instance-pointer-lowtag))
473 (let ((value-real (complex-single-reg-real-tn value))
474 (result-real (complex-single-reg-real-tn result)))
475 (inst stf value-real object offset)
476 (unless (location= result-real value-real)
477 (inst fmovs result-real value-real)))
478 (inst add offset offset n-word-bytes)
479 (let ((value-imag (complex-single-reg-imag-tn value))
480 (result-imag (complex-single-reg-imag-tn result)))
481 (inst stf value-imag object offset)
482 (unless (location= result-imag value-imag)
483 (inst fmovs result-imag value-imag)))))
485 (define-vop (raw-instance-ref/complex-double)
486 (:translate %raw-instance-ref/complex-double)
488 (:args (object :scs (descriptor-reg))
489 (index :scs (any-reg)))
490 (:arg-types * positive-fixnum)
491 (:results (value :scs (complex-double-reg)))
492 (:temporary (:scs (non-descriptor-reg)) offset)
493 (:result-types complex-double-float)
495 (loadw offset object 0 instance-pointer-lowtag)
496 (inst srl offset offset n-widetag-bits)
497 (inst sll offset offset 2)
498 (inst sub offset offset index)
502 (- (* (- instance-slots-offset 4) n-word-bytes)
503 instance-pointer-lowtag))
504 (inst lddf (complex-double-reg-real-tn value) object offset)
505 (inst add offset offset (* 2 n-word-bytes))
506 (inst lddf (complex-double-reg-imag-tn value) object offset)))
508 (define-vop (raw-instance-set/complex-double)
509 (:translate %raw-instance-set/complex-double)
511 (:args (object :scs (descriptor-reg))
512 (index :scs (any-reg))
513 (value :scs (complex-double-reg) :target result))
514 (:arg-types * positive-fixnum complex-double-float)
515 (:results (result :scs (complex-double-reg)))
516 (:result-types complex-double-float)
517 (:temporary (:scs (non-descriptor-reg)) offset)
519 (loadw offset object 0 instance-pointer-lowtag)
520 (inst srl offset offset n-widetag-bits)
521 (inst sll offset offset 2)
522 (inst sub offset offset index)
526 (- (* (- instance-slots-offset 4) n-word-bytes)
527 instance-pointer-lowtag))
528 (let ((value-real (complex-double-reg-real-tn value))
529 (result-real (complex-double-reg-real-tn result)))
530 (inst stdf value-real object offset)
531 (unless (location= result-real value-real)
532 (move-double-reg result-real value-real)))
533 (inst add offset offset (* 2 n-word-bytes))
534 (let ((value-imag (complex-double-reg-imag-tn value))
535 (result-imag (complex-double-reg-imag-tn result)))
536 (inst stdf value-imag object offset)
537 (unless (location= result-imag value-imag)
538 (move-double-reg result-imag value-imag)))))