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 (: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 add bsp-tn bsp-tn (* 2 n-word-bytes))
169 (storew temp bsp-tn (- binding-value-slot binding-size))
170 (storew symbol bsp-tn (- binding-symbol-slot binding-size))
171 (storew val symbol symbol-value-slot other-pointer-lowtag)))
174 (:temporary (:scs (descriptor-reg)) symbol value)
176 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
177 (loadw value bsp-tn (- binding-value-slot binding-size))
178 (storew value symbol symbol-value-slot other-pointer-lowtag)
179 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
180 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
181 (inst sub bsp-tn bsp-tn (* 2 n-word-bytes))))
183 (define-vop (unbind-to-here)
184 (:args (arg :scs (descriptor-reg any-reg) :target where))
185 (:temporary (:scs (any-reg) :from (:argument 0)) where)
186 (:temporary (:scs (descriptor-reg)) symbol value)
188 (let ((loop (gen-label))
192 (inst cmp where bsp-tn)
197 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
200 (loadw value bsp-tn (- binding-value-slot binding-size))
201 (storew value symbol symbol-value-slot other-pointer-lowtag)
202 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
205 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
206 (inst sub bsp-tn bsp-tn (* 2 n-word-bytes))
207 (inst cmp where bsp-tn)
213 ;;;; closure indexing.
215 (define-vop (closure-index-ref word-index-ref)
216 (:variant closure-info-offset fun-pointer-lowtag)
217 (:translate %closure-index-ref))
219 (define-vop (funcallable-instance-info word-index-ref)
220 (:variant funcallable-instance-info-offset fun-pointer-lowtag)
221 (:translate %funcallable-instance-info))
223 (define-vop (set-funcallable-instance-info word-index-set)
224 (:variant funcallable-instance-info-offset fun-pointer-lowtag)
225 (:translate %set-funcallable-instance-info))
227 (define-vop (closure-ref slot-ref)
228 (:variant closure-info-offset fun-pointer-lowtag))
230 (define-vop (closure-init slot-set)
231 (:variant closure-info-offset fun-pointer-lowtag))
233 (define-vop (closure-init-from-fp)
234 (:args (object :scs (descriptor-reg)))
237 (storew cfp-tn object (+ closure-info-offset offset) fun-pointer-lowtag)))
239 ;;;; value cell hackery.
241 (define-vop (value-cell-ref cell-ref)
242 (:variant value-cell-value-slot other-pointer-lowtag))
244 (define-vop (value-cell-set cell-set)
245 (: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 srl 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 * 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 * positive-fixnum *))
272 ;;;; Code object frobbing.
274 (define-vop (code-header-ref word-index-ref)
275 (:translate code-header-ref)
277 (:variant 0 other-pointer-lowtag))
279 (define-vop (code-header-set word-index-set)
280 (:translate code-header-set)
282 (:variant 0 other-pointer-lowtag))
286 ;;;; raw instance slot accessors
288 (define-vop (raw-instance-ref/word)
289 (:translate %raw-instance-ref/word)
291 (:args (object :scs (descriptor-reg))
292 (index :scs (any-reg)))
293 (:arg-types * positive-fixnum)
294 (:results (value :scs (unsigned-reg)))
295 (:temporary (:scs (non-descriptor-reg)) offset)
296 (:result-types unsigned-num)
298 (loadw offset object 0 instance-pointer-lowtag)
299 (inst srl offset offset n-widetag-bits)
300 (inst sll offset offset n-fixnum-tag-bits)
301 (inst sub offset offset index)
305 (- (* (1- instance-slots-offset) n-word-bytes)
306 instance-pointer-lowtag))
307 (inst ld value object offset)))
309 (define-vop (raw-instance-set/word)
310 (:translate %raw-instance-set/word)
312 (:args (object :scs (descriptor-reg))
313 (index :scs (any-reg))
314 (value :scs (unsigned-reg)))
315 (:arg-types * positive-fixnum unsigned-num)
316 (:results (result :scs (unsigned-reg)))
317 (:temporary (:scs (non-descriptor-reg)) offset)
318 (:result-types unsigned-num)
320 (loadw offset object 0 instance-pointer-lowtag)
321 (inst srl offset offset n-widetag-bits)
322 (inst sll offset offset n-fixnum-tag-bits)
323 (inst sub offset offset index)
327 (- (* (1- instance-slots-offset) n-word-bytes)
328 instance-pointer-lowtag))
329 (inst st value object offset)
330 (move result value)))
332 (define-vop (raw-instance-ref/single)
333 (:translate %raw-instance-ref/single)
335 (:args (object :scs (descriptor-reg))
336 (index :scs (any-reg)))
337 (:arg-types * positive-fixnum)
338 (:results (value :scs (single-reg)))
339 (:temporary (:scs (non-descriptor-reg)) offset)
340 (:result-types single-float)
342 (loadw offset object 0 instance-pointer-lowtag)
343 (inst srl offset offset n-widetag-bits)
344 (inst sll offset offset n-fixnum-tag-bits)
345 (inst sub offset offset index)
349 (- (* (1- instance-slots-offset) n-word-bytes)
350 instance-pointer-lowtag))
351 (inst ldf value object offset)))
353 (define-vop (raw-instance-set/single)
354 (:translate %raw-instance-set/single)
356 (:args (object :scs (descriptor-reg))
357 (index :scs (any-reg))
358 (value :scs (single-reg) :target result))
359 (:arg-types * positive-fixnum single-float)
360 (:results (result :scs (single-reg)))
361 (:result-types single-float)
362 (:temporary (:scs (non-descriptor-reg)) offset)
364 (loadw offset object 0 instance-pointer-lowtag)
365 (inst srl offset offset n-widetag-bits)
366 (inst sll offset offset n-fixnum-tag-bits)
367 (inst sub offset offset index)
371 (- (* (1- instance-slots-offset) n-word-bytes)
372 instance-pointer-lowtag))
373 (inst stf value object offset)
374 (unless (location= result value)
375 (inst fmovs result value))))
377 (define-vop (raw-instance-ref/double)
378 (:translate %raw-instance-ref/double)
380 (:args (object :scs (descriptor-reg))
381 (index :scs (any-reg)))
382 (:arg-types * positive-fixnum)
383 (:results (value :scs (double-reg)))
384 (:temporary (:scs (non-descriptor-reg)) offset)
385 (:result-types double-float)
387 (loadw offset object 0 instance-pointer-lowtag)
388 (inst srl offset offset n-widetag-bits)
389 (inst sll offset offset n-fixnum-tag-bits)
390 (inst sub offset offset index)
394 (- (* (- instance-slots-offset 2) n-word-bytes)
395 instance-pointer-lowtag))
396 (inst lddf value object offset)))
398 (define-vop (raw-instance-set/double)
399 (:translate %raw-instance-set/double)
401 (:args (object :scs (descriptor-reg))
402 (index :scs (any-reg))
403 (value :scs (double-reg) :target result))
404 (:arg-types * positive-fixnum double-float)
405 (:results (result :scs (double-reg)))
406 (:result-types double-float)
407 (:temporary (:scs (non-descriptor-reg)) offset)
409 (loadw offset object 0 instance-pointer-lowtag)
410 (inst srl offset offset n-widetag-bits)
411 (inst sll offset offset n-fixnum-tag-bits)
412 (inst sub offset offset index)
416 (- (* (- instance-slots-offset 2) n-word-bytes)
417 instance-pointer-lowtag))
418 (inst stdf value object offset)
419 (unless (location= result value)
420 (move-double-reg result value))))
422 (define-vop (raw-instance-ref/complex-single)
423 (:translate %raw-instance-ref/complex-single)
425 (:args (object :scs (descriptor-reg))
426 (index :scs (any-reg)))
427 (:arg-types * positive-fixnum)
428 (:results (value :scs (complex-single-reg)))
429 (:temporary (:scs (non-descriptor-reg)) offset)
430 (:result-types complex-single-float)
432 (loadw offset object 0 instance-pointer-lowtag)
433 (inst srl offset offset n-widetag-bits)
434 (inst sll offset offset n-fixnum-tag-bits)
435 (inst sub offset offset index)
439 (- (* (- instance-slots-offset 2) n-word-bytes)
440 instance-pointer-lowtag))
441 (inst ldf (complex-single-reg-real-tn value) object offset)
442 (inst add offset offset n-word-bytes)
443 (inst ldf (complex-single-reg-imag-tn value) object offset)))
445 (define-vop (raw-instance-set/complex-single)
446 (:translate %raw-instance-set/complex-single)
448 (:args (object :scs (descriptor-reg))
449 (index :scs (any-reg))
450 (value :scs (complex-single-reg) :target result))
451 (:arg-types * positive-fixnum complex-single-float)
452 (:results (result :scs (complex-single-reg)))
453 (:result-types complex-single-float)
454 (:temporary (:scs (non-descriptor-reg)) offset)
456 (loadw offset object 0 instance-pointer-lowtag)
457 (inst srl offset offset n-widetag-bits)
458 (inst sll offset offset n-fixnum-tag-bits)
459 (inst sub offset offset index)
463 (- (* (- instance-slots-offset 2) n-word-bytes)
464 instance-pointer-lowtag))
465 (let ((value-real (complex-single-reg-real-tn value))
466 (result-real (complex-single-reg-real-tn result)))
467 (inst stf value-real object offset)
468 (unless (location= result-real value-real)
469 (inst fmovs result-real value-real)))
470 (inst add offset offset n-word-bytes)
471 (let ((value-imag (complex-single-reg-imag-tn value))
472 (result-imag (complex-single-reg-imag-tn result)))
473 (inst stf value-imag object offset)
474 (unless (location= result-imag value-imag)
475 (inst fmovs result-imag value-imag)))))
477 (define-vop (raw-instance-ref/complex-double)
478 (:translate %raw-instance-ref/complex-double)
480 (:args (object :scs (descriptor-reg))
481 (index :scs (any-reg)))
482 (:arg-types * positive-fixnum)
483 (:results (value :scs (complex-double-reg)))
484 (:temporary (:scs (non-descriptor-reg)) offset)
485 (:result-types complex-double-float)
487 (loadw offset object 0 instance-pointer-lowtag)
488 (inst srl offset offset n-widetag-bits)
489 (inst sll offset offset n-fixnum-tag-bits)
490 (inst sub offset offset index)
494 (- (* (- instance-slots-offset 4) n-word-bytes)
495 instance-pointer-lowtag))
496 (inst lddf (complex-double-reg-real-tn value) object offset)
497 (inst add offset offset (* 2 n-word-bytes))
498 (inst lddf (complex-double-reg-imag-tn value) object offset)))
500 (define-vop (raw-instance-set/complex-double)
501 (:translate %raw-instance-set/complex-double)
503 (:args (object :scs (descriptor-reg))
504 (index :scs (any-reg))
505 (value :scs (complex-double-reg) :target result))
506 (:arg-types * positive-fixnum complex-double-float)
507 (:results (result :scs (complex-double-reg)))
508 (:result-types complex-double-float)
509 (:temporary (:scs (non-descriptor-reg)) offset)
511 (loadw offset object 0 instance-pointer-lowtag)
512 (inst srl offset offset n-widetag-bits)
513 (inst sll offset offset n-fixnum-tag-bits)
514 (inst sub offset offset index)
518 (- (* (- instance-slots-offset 4) n-word-bytes)
519 instance-pointer-lowtag))
520 (let ((value-real (complex-double-reg-real-tn value))
521 (result-real (complex-double-reg-real-tn result)))
522 (inst stdf value-real object offset)
523 (unless (location= result-real value-real)
524 (move-double-reg result-real value-real)))
525 (inst add offset offset (* 2 n-word-bytes))
526 (let ((value-imag (complex-double-reg-imag-tn value))
527 (result-imag (complex-double-reg-imag-tn result)))
528 (inst stdf value-imag object offset)
529 (unless (location= result-imag value-imag)
530 (move-double-reg result-imag value-imag)))))