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 (define-vop (init-slot set-slot))
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 cmp value unbound-marker-widetag)
62 ;;; Like CHECKED-CELL-REF, only we are a predicate to see if the cell
64 (define-vop (boundp-frob)
65 (:args (object :scs (descriptor-reg)))
69 (:temporary (:scs (descriptor-reg)) value))
71 (define-vop (boundp boundp-frob)
74 (loadw value object symbol-value-slot other-pointer-lowtag)
75 (inst cmp value unbound-marker-widetag)
76 (inst b (if not-p :eq :ne) target)
79 (define-vop (fast-symbol-value cell-ref)
80 (:variant symbol-value-slot other-pointer-lowtag)
82 (:translate symbol-value))
84 (define-vop (symbol-hash)
86 (:translate symbol-hash)
87 (:args (symbol :scs (descriptor-reg)))
88 (:results (res :scs (any-reg)))
89 (:result-types positive-fixnum)
91 ;; The symbol-hash slot of NIL holds NIL because it is also the
92 ;; cdr slot, so we have to strip off the two low bits to make sure
93 ;; it is a fixnum. The lowtag selection magic that is required to
94 ;; ensure this is explained in the comment in objdef.lisp
95 (loadw res symbol symbol-hash-slot other-pointer-lowtag)
96 (inst andn res res fixnum-tag-mask)))
98 ;;; On unithreaded builds these are just copies of the non-global versions.
99 (define-vop (%set-symbol-global-value set))
100 (define-vop (symbol-global-value symbol-value)
101 (:translate symbol-global-value))
102 (define-vop (fast-symbol-global-value fast-symbol-value)
103 (:translate symbol-global-value))
105 ;;;; 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)
116 (move obj-temp object)
117 (loadw value obj-temp fdefn-fun-slot other-pointer-lowtag)
118 (inst cmp value null-tn)
119 (let ((err-lab (generate-error-code vop undefined-fun-error obj-temp)))
120 (inst b :eq 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 cmp type simple-fun-header-widetag)
135 (inst b :eq normal-fn)
136 (inst move lip function)
137 (inst li lip (make-fixup "closure_tramp" :foreign))
138 (emit-label normal-fn)
139 (storew function fdefn fdefn-fun-slot other-pointer-lowtag)
140 (storew lip fdefn fdefn-raw-addr-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 li 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 ;;; Establish VAL as a binding for SYMBOL. Save the old value and the
160 ;;; symbol on the binding stack and stuff the new value into the
163 ;;; See the "Chapter 9: Specials" of the SBCL Internals Manual.
166 (:args (val :scs (any-reg descriptor-reg))
167 (symbol :scs (descriptor-reg)))
168 (:temporary (:scs (descriptor-reg)) temp)
170 (loadw temp symbol symbol-value-slot other-pointer-lowtag)
171 (inst add bsp-tn bsp-tn (* 2 n-word-bytes))
172 (storew temp bsp-tn (- binding-value-slot binding-size))
173 (storew symbol bsp-tn (- binding-symbol-slot binding-size))
174 (storew val symbol symbol-value-slot other-pointer-lowtag)))
177 (:temporary (:scs (descriptor-reg)) symbol value)
179 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
180 (loadw value bsp-tn (- binding-value-slot binding-size))
181 (storew 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 sub 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 cmp where bsp-tn)
200 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
203 (loadw value bsp-tn (- binding-value-slot binding-size))
204 (storew value symbol symbol-value-slot other-pointer-lowtag)
205 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
208 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
209 (inst sub bsp-tn bsp-tn (* 2 n-word-bytes))
210 (inst cmp 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))
236 (define-vop (closure-init-from-fp)
237 (:args (object :scs (descriptor-reg)))
240 (storew cfp-tn object (+ closure-info-offset offset) fun-pointer-lowtag)))
242 ;;;; value cell hackery.
244 (define-vop (value-cell-ref cell-ref)
245 (:variant value-cell-value-slot other-pointer-lowtag))
247 (define-vop (value-cell-set cell-set)
248 (:variant value-cell-value-slot other-pointer-lowtag))
250 ;;;; instance hackery:
252 (define-vop (instance-length)
254 (:translate %instance-length)
255 (:args (struct :scs (descriptor-reg)))
256 (:temporary (:scs (non-descriptor-reg)) temp)
257 (:results (res :scs (unsigned-reg)))
258 (:result-types positive-fixnum)
260 (loadw temp struct 0 instance-pointer-lowtag)
261 (inst srl res temp n-widetag-bits)))
263 (define-vop (instance-index-ref word-index-ref)
265 (:translate %instance-ref)
266 (:variant instance-slots-offset instance-pointer-lowtag)
267 (:arg-types * positive-fixnum))
269 (define-vop (instance-index-set word-index-set)
271 (:translate %instance-set)
272 (:variant instance-slots-offset instance-pointer-lowtag)
273 (:arg-types * 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 (inst srl offset offset n-widetag-bits)
303 (inst sll offset offset n-fixnum-tag-bits)
304 (inst sub offset offset index)
308 (- (* (1- instance-slots-offset) n-word-bytes)
309 instance-pointer-lowtag))
310 (inst ld 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 (inst srl offset offset n-widetag-bits)
325 (inst sll offset offset n-fixnum-tag-bits)
326 (inst sub offset offset index)
330 (- (* (1- instance-slots-offset) n-word-bytes)
331 instance-pointer-lowtag))
332 (inst st 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 (inst srl offset offset n-widetag-bits)
347 (inst sll offset offset n-fixnum-tag-bits)
348 (inst sub offset offset index)
352 (- (* (1- instance-slots-offset) n-word-bytes)
353 instance-pointer-lowtag))
354 (inst ldf 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 (inst srl offset offset n-widetag-bits)
369 (inst sll offset offset n-fixnum-tag-bits)
370 (inst sub offset offset index)
374 (- (* (1- instance-slots-offset) n-word-bytes)
375 instance-pointer-lowtag))
376 (inst stf value object offset)
377 (unless (location= result value)
378 (inst fmovs 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 (inst srl offset offset n-widetag-bits)
392 (inst sll offset offset n-fixnum-tag-bits)
393 (inst sub offset offset index)
397 (- (* (- instance-slots-offset 2) n-word-bytes)
398 instance-pointer-lowtag))
399 (inst lddf 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 (inst srl offset offset n-widetag-bits)
414 (inst sll offset offset n-fixnum-tag-bits)
415 (inst sub offset offset index)
419 (- (* (- instance-slots-offset 2) n-word-bytes)
420 instance-pointer-lowtag))
421 (inst stdf value object offset)
422 (unless (location= result value)
423 (move-double-reg 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 (inst srl offset offset n-widetag-bits)
437 (inst sll offset offset n-fixnum-tag-bits)
438 (inst sub offset offset index)
442 (- (* (- instance-slots-offset 2) n-word-bytes)
443 instance-pointer-lowtag))
444 (inst ldf (complex-single-reg-real-tn value) object offset)
445 (inst add offset offset n-word-bytes)
446 (inst ldf (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 (inst srl offset offset n-widetag-bits)
461 (inst sll offset offset n-fixnum-tag-bits)
462 (inst sub offset offset index)
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 stf value-real object offset)
471 (unless (location= result-real value-real)
472 (inst fmovs result-real value-real)))
473 (inst add 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 stf value-imag object offset)
477 (unless (location= result-imag value-imag)
478 (inst fmovs 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 (inst srl offset offset n-widetag-bits)
492 (inst sll offset offset n-fixnum-tag-bits)
493 (inst sub offset offset index)
497 (- (* (- instance-slots-offset 4) n-word-bytes)
498 instance-pointer-lowtag))
499 (inst lddf (complex-double-reg-real-tn value) object offset)
500 (inst add offset offset (* 2 n-word-bytes))
501 (inst lddf (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 (inst srl offset offset n-widetag-bits)
516 (inst sll offset offset n-fixnum-tag-bits)
517 (inst sub offset offset index)
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 stdf value-real object offset)
526 (unless (location= result-real value-real)
527 (move-double-reg result-real value-real)))
528 (inst add 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 stdf value-imag object offset)
532 (unless (location= result-imag value-imag)
533 (move-double-reg result-imag value-imag)))))