1 ;;;; the VM definition of various primitive memory access VOPs for
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)
32 (storew value object offset lowtag)))
34 (define-vop (init-slot set-slot))
36 ;;;; Symbol hacking VOPs:
38 ;;; The compiler likes to be able to directly SET symbols.
40 (define-vop (set cell-set)
41 (:variant symbol-value-slot other-pointer-lowtag))
43 ;;; Do a cell ref with an error check for being unbound.
45 (define-vop (checked-cell-ref)
46 (:args (object :scs (descriptor-reg) :target obj-temp))
47 (:results (value :scs (descriptor-reg any-reg)))
50 (:save-p :compute-only)
51 (:temporary (:scs (non-descriptor-reg)) temp)
52 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp))
54 ;;; With Symbol-Value, we check that the value isn't the trap object. So
55 ;;; Symbol-Value of NIL is NIL.
57 (define-vop (symbol-value checked-cell-ref)
58 (:translate symbol-value)
60 (move obj-temp object)
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 temp value unbound-marker-widetag)
64 (inst beq temp err-lab)
67 ;;; Like CHECKED-CELL-REF, only we are a predicate to see if the cell is bound.
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 temp value unbound-marker-widetag)
82 (inst beq temp target)
83 (inst bne temp target))
86 (define-vop (fast-symbol-value cell-ref)
87 (:variant symbol-value-slot other-pointer-lowtag)
89 (:translate symbol-value))
91 (define-vop (symbol-hash)
93 (:translate symbol-hash)
94 (:args (symbol :scs (descriptor-reg)))
95 (:temporary (:scs (non-descriptor-reg)) temp)
96 (:results (res :scs (any-reg)))
97 (:result-types positive-fixnum)
99 ;; The symbol-hash slot of NIL holds NIL because it is also the
100 ;; cdr slot, so we have to strip off the two low bits to make sure
101 ;; it is a fixnum. The lowtag selection magic that is required to
102 ;; ensure this is explained in the comment in objdef.lisp
103 (loadw temp symbol symbol-hash-slot other-pointer-lowtag)
104 (inst srl temp n-fixnum-tag-bits)
105 (inst sll res temp n-fixnum-tag-bits)))
107 ;;; On unithreaded builds these are just copies of the non-global versions.
108 (define-vop (%set-symbol-global-value set))
109 (define-vop (symbol-global-value symbol-value)
110 (:translate symbol-global-value))
111 (define-vop (fast-symbol-global-value fast-symbol-value)
112 (:translate symbol-global-value))
114 ;;;; Fdefinition (fdefn) objects.
116 (define-vop (fdefn-fun cell-ref)
117 (:variant fdefn-fun-slot other-pointer-lowtag))
119 (define-vop (safe-fdefn-fun)
120 (:args (object :scs (descriptor-reg) :target obj-temp))
121 (:results (value :scs (descriptor-reg any-reg)))
123 (:save-p :compute-only)
124 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp)
126 (move obj-temp object)
127 (loadw value obj-temp fdefn-fun-slot other-pointer-lowtag)
128 (let ((err-lab (generate-error-code vop undefined-fun-error obj-temp)))
129 (inst beq value null-tn err-lab))
132 (define-vop (set-fdefn-fun)
134 (:translate (setf fdefn-fun))
135 (:args (function :scs (descriptor-reg) :target result)
136 (fdefn :scs (descriptor-reg)))
137 (:temporary (:scs (interior-reg)) lip)
138 (:temporary (:scs (non-descriptor-reg)) type)
139 (:results (result :scs (descriptor-reg)))
141 (let ((normal-fn (gen-label)))
142 (load-type type function (- fun-pointer-lowtag))
144 (inst xor type simple-fun-header-widetag)
145 (inst beq type normal-fn)
146 (inst addu lip function
147 (- (ash simple-fun-code-offset word-shift)
149 (inst li lip (make-fixup "closure_tramp" :foreign))
150 (emit-label normal-fn)
151 (storew lip fdefn fdefn-raw-addr-slot other-pointer-lowtag)
152 (storew function fdefn fdefn-fun-slot other-pointer-lowtag)
153 (move result function))))
155 (define-vop (fdefn-makunbound)
157 (:translate fdefn-makunbound)
158 (:args (fdefn :scs (descriptor-reg) :target result))
159 (:temporary (:scs (non-descriptor-reg)) temp)
160 (:results (result :scs (descriptor-reg)))
162 (storew null-tn fdefn fdefn-fun-slot other-pointer-lowtag)
163 (inst li temp (make-fixup "undefined_tramp" :foreign))
164 (storew temp fdefn fdefn-raw-addr-slot other-pointer-lowtag)
165 (move result fdefn)))
169 ;;;; Binding and Unbinding.
171 ;;; BIND -- Establish VAL as a binding for SYMBOL. Save the old value and
172 ;;; the symbol on the binding stack and stuff the new value into the
176 (:args (val :scs (any-reg descriptor-reg))
177 (symbol :scs (descriptor-reg)))
178 (:temporary (:scs (descriptor-reg)) temp)
180 (loadw temp symbol symbol-value-slot other-pointer-lowtag)
181 (inst addu bsp-tn bsp-tn (* 2 n-word-bytes))
182 (storew temp bsp-tn (- binding-value-slot binding-size))
183 (storew symbol bsp-tn (- binding-symbol-slot binding-size))
184 (storew val symbol symbol-value-slot other-pointer-lowtag)))
188 (:temporary (:scs (descriptor-reg)) symbol value)
190 (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-symbol-slot binding-size))
194 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
195 (inst addu bsp-tn bsp-tn (* -2 n-word-bytes))))
198 (define-vop (unbind-to-here)
199 (:args (arg :scs (descriptor-reg any-reg) :target where))
200 (:temporary (:scs (any-reg) :from (:argument 0)) where)
201 (:temporary (:scs (descriptor-reg)) symbol value)
203 (let ((loop (gen-label))
207 (inst beq where bsp-tn done)
211 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
212 (inst beq symbol skip)
213 (loadw value bsp-tn (- binding-value-slot binding-size))
214 (storew value symbol symbol-value-slot other-pointer-lowtag)
215 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
218 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
219 (inst addu bsp-tn bsp-tn (* -2 n-word-bytes))
220 (inst bne where bsp-tn loop)
227 ;;;; Closure indexing.
229 (define-full-reffer closure-index-ref *
230 closure-info-offset fun-pointer-lowtag
231 (descriptor-reg any-reg) * %closure-index-ref)
233 (define-full-setter set-funcallable-instance-info *
234 funcallable-instance-info-offset fun-pointer-lowtag
235 (descriptor-reg any-reg null zero) * %set-funcallable-instance-info)
237 (define-full-reffer funcallable-instance-info *
238 funcallable-instance-info-offset fun-pointer-lowtag
239 (descriptor-reg any-reg) * %funcallable-instance-info)
241 (define-vop (closure-ref slot-ref)
242 (:variant closure-info-offset fun-pointer-lowtag))
244 (define-vop (closure-init slot-set)
245 (:variant closure-info-offset fun-pointer-lowtag))
247 (define-vop (closure-init-from-fp)
248 (:args (object :scs (descriptor-reg)))
251 (storew cfp-tn object (+ closure-info-offset offset) fun-pointer-lowtag)))
253 ;;;; Value Cell hackery.
255 (define-vop (value-cell-ref cell-ref)
256 (:variant value-cell-value-slot other-pointer-lowtag))
258 (define-vop (value-cell-set cell-set)
259 (:variant value-cell-value-slot other-pointer-lowtag))
263 ;;;; Instance hackery:
265 (define-vop (instance-length)
267 (:translate %instance-length)
268 (:args (struct :scs (descriptor-reg)))
269 (:temporary (:scs (non-descriptor-reg)) temp)
270 (:results (res :scs (unsigned-reg)))
271 (:result-types positive-fixnum)
273 (loadw temp struct 0 instance-pointer-lowtag)
274 (inst srl res temp n-widetag-bits)))
276 (define-full-reffer instance-index-ref * instance-slots-offset
277 instance-pointer-lowtag (descriptor-reg any-reg) * %instance-ref)
279 (define-full-setter instance-index-set * instance-slots-offset
280 instance-pointer-lowtag (descriptor-reg any-reg null zero) * %instance-set)
284 ;;;; Code object frobbing.
286 (define-full-reffer code-header-ref * 0 other-pointer-lowtag
287 (descriptor-reg any-reg) * code-header-ref)
289 (define-full-setter code-header-set * 0 other-pointer-lowtag
290 (descriptor-reg any-reg null zero) * code-header-set)
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 (:temporary (:scs (interior-reg)) lip)
305 (:result-types unsigned-num)
307 (loadw offset object 0 instance-pointer-lowtag)
308 (inst srl offset n-widetag-bits)
309 (inst sll offset n-fixnum-tag-bits)
310 (inst subu offset index)
311 (inst subu offset n-word-bytes)
312 (inst addu lip offset object)
313 (inst lw value lip (- (* instance-slots-offset n-word-bytes)
314 instance-pointer-lowtag))))
316 (define-vop (raw-instance-set/word)
317 (:translate %raw-instance-set/word)
319 (:args (object :scs (descriptor-reg))
320 (index :scs (any-reg))
321 (value :scs (unsigned-reg) :target result))
322 (:arg-types * positive-fixnum unsigned-num)
323 (:results (result :scs (unsigned-reg)))
324 (:temporary (:scs (non-descriptor-reg)) offset)
325 (:temporary (:scs (interior-reg)) lip)
326 (:result-types unsigned-num)
328 (loadw offset object 0 instance-pointer-lowtag)
329 (inst srl offset n-widetag-bits)
330 (inst sll offset n-fixnum-tag-bits)
331 (inst subu offset index)
332 (inst subu offset n-word-bytes)
333 (inst addu lip offset object)
334 (inst sw value lip (- (* instance-slots-offset n-word-bytes)
335 instance-pointer-lowtag))
336 (move result value)))
338 (define-vop (raw-instance-ref/single)
339 (:translate %raw-instance-ref/single)
341 (:args (object :scs (descriptor-reg))
342 (index :scs (any-reg)))
343 (:arg-types * positive-fixnum)
344 (:results (value :scs (single-reg)))
345 (:temporary (:scs (non-descriptor-reg)) offset)
346 (:temporary (:scs (interior-reg)) lip)
347 (:result-types single-float)
349 (loadw offset object 0 instance-pointer-lowtag)
350 (inst srl offset n-widetag-bits)
351 (inst sll offset n-fixnum-tag-bits)
352 (inst subu offset index)
353 (inst subu offset n-word-bytes)
354 (inst addu lip offset object)
355 (inst lwc1 value lip (- (* instance-slots-offset n-word-bytes)
356 instance-pointer-lowtag))))
358 (define-vop (raw-instance-set/single)
359 (:translate %raw-instance-set/single)
361 (:args (object :scs (descriptor-reg))
362 (index :scs (any-reg))
363 (value :scs (single-reg) :target result))
364 (:arg-types * positive-fixnum single-float)
365 (:results (result :scs (single-reg)))
366 (:temporary (:scs (non-descriptor-reg)) offset)
367 (:temporary (:scs (interior-reg)) lip)
368 (:result-types single-float)
370 (loadw offset object 0 instance-pointer-lowtag)
371 (inst srl offset n-widetag-bits)
372 (inst sll offset n-fixnum-tag-bits)
373 (inst subu offset index)
374 (inst subu offset n-word-bytes)
375 (inst addu lip offset object)
376 (inst swc1 value lip (- (* instance-slots-offset n-word-bytes)
377 instance-pointer-lowtag))
378 (unless (location= result value)
379 (inst fmove :single result value))))
381 (define-vop (raw-instance-ref/double)
382 (:translate %raw-instance-ref/double)
384 (:args (object :scs (descriptor-reg))
385 (index :scs (any-reg)))
386 (:arg-types * positive-fixnum)
387 (:results (value :scs (double-reg)))
388 (:temporary (:scs (non-descriptor-reg)) offset)
389 (:temporary (:scs (interior-reg)) lip)
390 (:result-types double-float)
392 (loadw offset object 0 instance-pointer-lowtag)
393 (inst srl offset n-widetag-bits)
394 (inst sll offset n-fixnum-tag-bits)
395 (inst subu offset index)
396 (inst subu offset (* 2 n-word-bytes))
397 (inst addu lip offset object)
398 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
399 instance-pointer-lowtag)))
400 (ecase *backend-byte-order*
401 (:big-endian (inst lwc1 value lip immediate-offset))
402 (:little-endian (inst lwc1-odd value lip immediate-offset))))
403 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
404 instance-pointer-lowtag)))
405 (ecase *backend-byte-order*
406 (:big-endian (inst lwc1-odd value lip immediate-offset))
407 (:little-endian (inst lwc1 value lip immediate-offset))))))
409 (define-vop (raw-instance-set/double)
410 (:translate %raw-instance-set/double)
412 (:args (object :scs (descriptor-reg))
413 (index :scs (any-reg))
414 (value :scs (double-reg) :target result))
415 (:arg-types * positive-fixnum double-float)
416 (:results (result :scs (double-reg)))
417 (:temporary (:scs (non-descriptor-reg)) offset)
418 (:temporary (:scs (interior-reg)) lip)
419 (:result-types double-float)
421 (loadw offset object 0 instance-pointer-lowtag)
422 (inst srl offset n-widetag-bits)
423 (inst sll offset n-fixnum-tag-bits)
424 (inst subu offset index)
425 (inst subu offset (* 2 n-word-bytes))
426 (inst addu lip offset object)
427 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
428 instance-pointer-lowtag)))
429 (ecase *backend-byte-order*
430 (:big-endian (inst swc1 value lip immediate-offset))
431 (:little-endian (inst swc1-odd value lip immediate-offset))))
432 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
433 instance-pointer-lowtag)))
434 (ecase *backend-byte-order*
435 (:big-endian (inst swc1-odd value lip immediate-offset))
436 (:little-endian (inst swc1 value lip immediate-offset))))
437 (unless (location= result value)
438 (inst fmove :double result value))))
440 (define-vop (raw-instance-ref/complex-single)
441 (:translate %raw-instance-ref/complex-single)
443 (:args (object :scs (descriptor-reg))
444 (index :scs (any-reg)))
445 (:arg-types * positive-fixnum)
446 (:results (value :scs (complex-single-reg)))
447 (:temporary (:scs (non-descriptor-reg)) offset)
448 (:temporary (:scs (interior-reg)) lip)
449 (:result-types complex-single-float)
451 (loadw offset object 0 instance-pointer-lowtag)
452 (inst srl offset n-widetag-bits)
453 (inst sll offset n-fixnum-tag-bits)
454 (inst subu offset index)
455 (inst subu offset (* 2 n-word-bytes))
456 (inst addu lip offset object)
458 (complex-single-reg-real-tn value)
460 (- (* instance-slots-offset n-word-bytes)
461 instance-pointer-lowtag))
463 (complex-single-reg-imag-tn value)
465 (- (* (1+ instance-slots-offset) n-word-bytes)
466 instance-pointer-lowtag))))
468 (define-vop (raw-instance-set/complex-single)
469 (:translate %raw-instance-set/complex-single)
471 (:args (object :scs (descriptor-reg))
472 (index :scs (any-reg))
473 (value :scs (complex-single-reg) :target result))
474 (:arg-types * positive-fixnum complex-single-float)
475 (:results (result :scs (complex-single-reg)))
476 (:temporary (:scs (non-descriptor-reg)) offset)
477 (:temporary (:scs (interior-reg)) lip)
478 (:result-types complex-single-float)
480 (loadw offset object 0 instance-pointer-lowtag)
481 (inst srl offset n-widetag-bits)
482 (inst sll offset n-fixnum-tag-bits)
483 (inst subu offset index)
484 (inst subu offset (* 2 n-word-bytes))
485 (inst addu lip offset object)
486 (let ((value-real (complex-single-reg-real-tn value))
487 (result-real (complex-single-reg-real-tn result)))
491 (- (* instance-slots-offset n-word-bytes)
492 instance-pointer-lowtag))
493 (unless (location= result-real value-real)
494 (inst fmove :single result-real value-real)))
495 (let ((value-imag (complex-single-reg-imag-tn value))
496 (result-imag (complex-single-reg-imag-tn result)))
500 (- (* (1+ instance-slots-offset) n-word-bytes)
501 instance-pointer-lowtag))
502 (unless (location= result-imag value-imag)
503 (inst fmove :single result-imag value-imag)))))
505 (define-vop (raw-instance-ref/complex-double)
506 (:translate %raw-instance-ref/complex-double)
508 (:args (object :scs (descriptor-reg))
509 (index :scs (any-reg)))
510 (:arg-types * positive-fixnum)
511 (:results (value :scs (complex-double-reg)))
512 (:temporary (:scs (non-descriptor-reg)) offset)
513 (:temporary (:scs (interior-reg)) lip)
514 (:result-types complex-double-float)
516 (loadw offset object 0 instance-pointer-lowtag)
517 (inst srl offset n-widetag-bits)
518 (inst sll offset n-fixnum-tag-bits)
519 (inst subu offset index)
520 (inst subu offset (* 4 n-word-bytes))
521 (inst addu lip offset object)
522 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
523 instance-pointer-lowtag)))
524 (ecase *backend-byte-order*
525 (:big-endian (inst lwc1
526 (complex-double-reg-real-tn value)
529 (:little-endian (inst lwc1-odd
530 (complex-double-reg-real-tn value)
533 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
534 instance-pointer-lowtag)))
535 (ecase *backend-byte-order*
536 (:big-endian (inst lwc1-odd
537 (complex-double-reg-real-tn value)
540 (:little-endian (inst lwc1
541 (complex-double-reg-real-tn value)
544 (let ((immediate-offset (- (* (+ instance-slots-offset 2) n-word-bytes)
545 instance-pointer-lowtag)))
546 (ecase *backend-byte-order*
547 (:big-endian (inst lwc1
548 (complex-double-reg-imag-tn value)
551 (:little-endian (inst lwc1-odd
552 (complex-double-reg-imag-tn value)
555 (let ((immediate-offset (- (* (+ instance-slots-offset 3) n-word-bytes)
556 instance-pointer-lowtag)))
557 (ecase *backend-byte-order*
558 (:big-endian (inst lwc1-odd
559 (complex-double-reg-imag-tn value)
562 (:little-endian (inst lwc1
563 (complex-double-reg-imag-tn value)
565 immediate-offset))))))
567 (define-vop (raw-instance-set/complex-double)
568 (:translate %raw-instance-set/complex-double)
570 (:args (object :scs (descriptor-reg))
571 (index :scs (any-reg))
572 (value :scs (complex-double-reg) :target result))
573 (:arg-types * positive-fixnum complex-double-float)
574 (:results (result :scs (complex-double-reg)))
575 (:temporary (:scs (non-descriptor-reg)) offset)
576 (:temporary (:scs (interior-reg)) lip)
577 (:result-types complex-double-float)
579 (loadw offset object 0 instance-pointer-lowtag)
580 (inst srl offset n-widetag-bits)
581 (inst sll offset n-fixnum-tag-bits)
582 (inst subu offset index)
583 (inst subu offset (* 4 n-word-bytes))
584 (inst addu lip offset object)
585 (let ((value-real (complex-double-reg-real-tn value))
586 (result-real (complex-double-reg-real-tn result)))
587 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
588 instance-pointer-lowtag)))
589 (ecase *backend-byte-order*
590 (:big-endian (inst swc1
594 (:little-endian (inst swc1-odd
598 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
599 instance-pointer-lowtag)))
600 (ecase *backend-byte-order*
601 (:big-endian (inst swc1-odd
605 (:little-endian (inst swc1
609 (unless (location= result-real value-real)
610 (inst fmove :double result-real value-real)))
611 (let ((value-imag (complex-double-reg-imag-tn value))
612 (result-imag (complex-double-reg-imag-tn result)))
613 (let ((immediate-offset (- (* (+ instance-slots-offset 2) n-word-bytes)
614 instance-pointer-lowtag)))
615 (ecase *backend-byte-order*
616 (:big-endian (inst swc1
620 (:little-endian (inst swc1-odd
624 (let ((immediate-offset (- (* (+ instance-slots-offset 3) n-word-bytes)
625 instance-pointer-lowtag)))
626 (ecase *backend-byte-order*
627 (:big-endian (inst swc1-odd
631 (:little-endian (inst swc1
635 (unless (location= result-imag value-imag)
636 (inst fmove :double result-imag value-imag)))))