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)))
35 ;;;; Symbol hacking VOPs:
37 ;;; The compiler likes to be able to directly SET symbols.
39 (define-vop (set cell-set)
40 (:variant symbol-value-slot other-pointer-lowtag))
42 ;;; Do a cell ref with an error check for being unbound.
44 (define-vop (checked-cell-ref)
45 (:args (object :scs (descriptor-reg) :target obj-temp))
46 (:results (value :scs (descriptor-reg any-reg)))
49 (:save-p :compute-only)
50 (:temporary (:scs (non-descriptor-reg)) temp)
51 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp))
53 ;;; With Symbol-Value, we check that the value isn't the trap object. So
54 ;;; Symbol-Value of NIL is NIL.
56 (define-vop (symbol-value checked-cell-ref)
57 (:translate symbol-value)
59 (move obj-temp object)
60 (loadw value obj-temp symbol-value-slot other-pointer-lowtag)
61 (let ((err-lab (generate-error-code vop unbound-symbol-error obj-temp)))
62 (inst xor temp value unbound-marker-widetag)
63 (inst beq temp err-lab)
66 ;;; Like CHECKED-CELL-REF, only we are a predicate to see if the cell is bound.
67 (define-vop (boundp-frob)
68 (:args (object :scs (descriptor-reg)))
72 (:temporary (:scs (descriptor-reg)) value)
73 (:temporary (:scs (non-descriptor-reg)) temp))
75 (define-vop (boundp boundp-frob)
78 (loadw value object symbol-value-slot other-pointer-lowtag)
79 (inst xor temp value unbound-marker-widetag)
81 (inst beq temp target)
82 (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 (:temporary (:scs (non-descriptor-reg)) temp)
95 (:results (res :scs (any-reg)))
96 (:result-types positive-fixnum)
98 ;; The symbol-hash slot of NIL holds NIL because it is also the
99 ;; cdr slot, so we have to strip off the two low bits to make sure
100 ;; it is a fixnum. The lowtag selection magic that is required to
101 ;; ensure this is explained in the comment in objdef.lisp
102 (loadw temp symbol symbol-hash-slot other-pointer-lowtag)
103 (inst srl temp n-fixnum-tag-bits)
104 (inst sll res temp n-fixnum-tag-bits)))
106 ;;; On unithreaded builds these are just copies of the non-global versions.
107 (define-vop (%set-symbol-global-value set))
108 (define-vop (symbol-global-value symbol-value)
109 (:translate symbol-global-value))
110 (define-vop (fast-symbol-global-value fast-symbol-value)
111 (:translate symbol-global-value))
113 ;;;; Fdefinition (fdefn) objects.
115 (define-vop (fdefn-fun cell-ref)
116 (:variant fdefn-fun-slot other-pointer-lowtag))
118 (define-vop (safe-fdefn-fun)
119 (:args (object :scs (descriptor-reg) :target obj-temp))
120 (:results (value :scs (descriptor-reg any-reg)))
122 (:save-p :compute-only)
123 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp)
125 (move obj-temp object)
126 (loadw value obj-temp fdefn-fun-slot other-pointer-lowtag)
127 (let ((err-lab (generate-error-code vop undefined-fun-error obj-temp)))
128 (inst beq value null-tn err-lab))
131 (define-vop (set-fdefn-fun)
133 (:translate (setf fdefn-fun))
134 (:args (function :scs (descriptor-reg) :target result)
135 (fdefn :scs (descriptor-reg)))
136 (:temporary (:scs (interior-reg)) lip)
137 (:temporary (:scs (non-descriptor-reg)) type)
138 (:results (result :scs (descriptor-reg)))
140 (let ((normal-fn (gen-label)))
141 (load-type type function (- fun-pointer-lowtag))
143 (inst xor type simple-fun-header-widetag)
144 (inst beq type normal-fn)
145 (inst addu lip function
146 (- (ash simple-fun-code-offset word-shift)
148 (inst li lip (make-fixup "closure_tramp" :foreign))
149 (emit-label normal-fn)
150 (storew lip fdefn fdefn-raw-addr-slot other-pointer-lowtag)
151 (storew function fdefn fdefn-fun-slot other-pointer-lowtag)
152 (move result function))))
154 (define-vop (fdefn-makunbound)
156 (:translate fdefn-makunbound)
157 (:args (fdefn :scs (descriptor-reg) :target result))
158 (:temporary (:scs (non-descriptor-reg)) temp)
159 (:results (result :scs (descriptor-reg)))
161 (storew null-tn fdefn fdefn-fun-slot other-pointer-lowtag)
162 (inst li temp (make-fixup "undefined_tramp" :foreign))
163 (storew temp fdefn fdefn-raw-addr-slot other-pointer-lowtag)
164 (move result fdefn)))
168 ;;;; Binding and Unbinding.
170 ;;; BIND -- Establish VAL as a binding for SYMBOL. Save the old value and
171 ;;; the symbol on the binding stack and stuff the new value into the
175 (:args (val :scs (any-reg descriptor-reg))
176 (symbol :scs (descriptor-reg)))
177 (:temporary (:scs (descriptor-reg)) temp)
179 (loadw temp symbol symbol-value-slot other-pointer-lowtag)
180 (inst addu bsp-tn bsp-tn (* 2 n-word-bytes))
181 (storew temp bsp-tn (- binding-value-slot binding-size))
182 (storew symbol bsp-tn (- binding-symbol-slot binding-size))
183 (storew val symbol symbol-value-slot other-pointer-lowtag)))
187 (:temporary (:scs (descriptor-reg)) symbol value)
189 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
190 (loadw value bsp-tn (- binding-value-slot binding-size))
191 (storew value symbol symbol-value-slot other-pointer-lowtag)
192 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
193 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
194 (inst addu bsp-tn bsp-tn (* -2 n-word-bytes))))
197 (define-vop (unbind-to-here)
198 (:args (arg :scs (descriptor-reg any-reg) :target where))
199 (:temporary (:scs (any-reg) :from (:argument 0)) where)
200 (:temporary (:scs (descriptor-reg)) symbol value)
202 (let ((loop (gen-label))
206 (inst beq where bsp-tn done)
210 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
211 (inst beq symbol skip)
212 (loadw value bsp-tn (- binding-value-slot binding-size))
213 (storew value symbol symbol-value-slot other-pointer-lowtag)
214 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
217 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
218 (inst addu bsp-tn bsp-tn (* -2 n-word-bytes))
219 (inst bne where bsp-tn loop)
226 ;;;; Closure indexing.
228 (define-full-reffer closure-index-ref *
229 closure-info-offset fun-pointer-lowtag
230 (descriptor-reg any-reg) * %closure-index-ref)
232 (define-full-setter set-funcallable-instance-info *
233 funcallable-instance-info-offset fun-pointer-lowtag
234 (descriptor-reg any-reg null zero) * %set-funcallable-instance-info)
236 (define-full-reffer funcallable-instance-info *
237 funcallable-instance-info-offset fun-pointer-lowtag
238 (descriptor-reg any-reg) * %funcallable-instance-info)
240 (define-vop (closure-ref slot-ref)
241 (:variant closure-info-offset fun-pointer-lowtag))
243 (define-vop (closure-init slot-set)
244 (:variant closure-info-offset fun-pointer-lowtag))
246 ;;;; Value Cell hackery.
248 (define-vop (value-cell-ref cell-ref)
249 (:variant value-cell-value-slot other-pointer-lowtag))
251 (define-vop (value-cell-set cell-set)
252 (:variant value-cell-value-slot other-pointer-lowtag))
256 ;;;; Instance hackery:
258 (define-vop (instance-length)
260 (:translate %instance-length)
261 (:args (struct :scs (descriptor-reg)))
262 (:temporary (:scs (non-descriptor-reg)) temp)
263 (:results (res :scs (unsigned-reg)))
264 (:result-types positive-fixnum)
266 (loadw temp struct 0 instance-pointer-lowtag)
267 (inst srl res temp n-widetag-bits)))
269 (define-full-reffer instance-index-ref * instance-slots-offset
270 instance-pointer-lowtag (descriptor-reg any-reg) * %instance-ref)
272 (define-full-setter instance-index-set * instance-slots-offset
273 instance-pointer-lowtag (descriptor-reg any-reg null zero) * %instance-set)
277 ;;;; Code object frobbing.
279 (define-full-reffer code-header-ref * 0 other-pointer-lowtag
280 (descriptor-reg any-reg) * code-header-ref)
282 (define-full-setter code-header-set * 0 other-pointer-lowtag
283 (descriptor-reg any-reg null zero) * code-header-set)
287 ;;;; raw instance slot accessors
289 (define-vop (raw-instance-ref/word)
290 (:translate %raw-instance-ref/word)
292 (:args (object :scs (descriptor-reg))
293 (index :scs (any-reg)))
294 (:arg-types * positive-fixnum)
295 (:results (value :scs (unsigned-reg)))
296 (:temporary (:scs (non-descriptor-reg)) offset)
297 (:temporary (:scs (interior-reg)) lip)
298 (:result-types unsigned-num)
300 (loadw offset object 0 instance-pointer-lowtag)
301 (inst srl offset n-widetag-bits)
302 (inst sll offset n-fixnum-tag-bits)
303 (inst subu offset index)
304 (inst subu offset n-word-bytes)
305 (inst addu lip offset object)
306 (inst lw value lip (- (* instance-slots-offset n-word-bytes)
307 instance-pointer-lowtag))))
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) :target result))
315 (:arg-types * positive-fixnum unsigned-num)
316 (:results (result :scs (unsigned-reg)))
317 (:temporary (:scs (non-descriptor-reg)) offset)
318 (:temporary (:scs (interior-reg)) lip)
319 (:result-types unsigned-num)
321 (loadw offset object 0 instance-pointer-lowtag)
322 (inst srl offset n-widetag-bits)
323 (inst sll offset n-fixnum-tag-bits)
324 (inst subu offset index)
325 (inst subu offset n-word-bytes)
326 (inst addu lip offset object)
327 (inst sw value lip (- (* instance-slots-offset n-word-bytes)
328 instance-pointer-lowtag))
329 (move result value)))
331 (define-vop (raw-instance-ref/single)
332 (:translate %raw-instance-ref/single)
334 (:args (object :scs (descriptor-reg))
335 (index :scs (any-reg)))
336 (:arg-types * positive-fixnum)
337 (:results (value :scs (single-reg)))
338 (:temporary (:scs (non-descriptor-reg)) offset)
339 (:temporary (:scs (interior-reg)) lip)
340 (:result-types single-float)
342 (loadw offset object 0 instance-pointer-lowtag)
343 (inst srl offset n-widetag-bits)
344 (inst sll offset n-fixnum-tag-bits)
345 (inst subu offset index)
346 (inst subu offset n-word-bytes)
347 (inst addu lip offset object)
348 (inst lwc1 value lip (- (* instance-slots-offset n-word-bytes)
349 instance-pointer-lowtag))))
351 (define-vop (raw-instance-set/single)
352 (:translate %raw-instance-set/single)
354 (:args (object :scs (descriptor-reg))
355 (index :scs (any-reg))
356 (value :scs (single-reg) :target result))
357 (:arg-types * positive-fixnum single-float)
358 (:results (result :scs (single-reg)))
359 (:temporary (:scs (non-descriptor-reg)) offset)
360 (:temporary (:scs (interior-reg)) lip)
361 (:result-types single-float)
363 (loadw offset object 0 instance-pointer-lowtag)
364 (inst srl offset n-widetag-bits)
365 (inst sll offset n-fixnum-tag-bits)
366 (inst subu offset index)
367 (inst subu offset n-word-bytes)
368 (inst addu lip offset object)
369 (inst swc1 value lip (- (* instance-slots-offset n-word-bytes)
370 instance-pointer-lowtag))
371 (unless (location= result value)
372 (inst fmove :single result value))))
374 (define-vop (raw-instance-ref/double)
375 (:translate %raw-instance-ref/double)
377 (:args (object :scs (descriptor-reg))
378 (index :scs (any-reg)))
379 (:arg-types * positive-fixnum)
380 (:results (value :scs (double-reg)))
381 (:temporary (:scs (non-descriptor-reg)) offset)
382 (:temporary (:scs (interior-reg)) lip)
383 (:result-types double-float)
385 (loadw offset object 0 instance-pointer-lowtag)
386 (inst srl offset n-widetag-bits)
387 (inst sll offset n-fixnum-tag-bits)
388 (inst subu offset index)
389 (inst subu offset (* 2 n-word-bytes))
390 (inst addu lip offset object)
391 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
392 instance-pointer-lowtag)))
393 (ecase *backend-byte-order*
394 (:big-endian (inst lwc1 value lip immediate-offset))
395 (:little-endian (inst lwc1-odd value lip immediate-offset))))
396 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
397 instance-pointer-lowtag)))
398 (ecase *backend-byte-order*
399 (:big-endian (inst lwc1-odd value lip immediate-offset))
400 (:little-endian (inst lwc1 value lip immediate-offset))))))
402 (define-vop (raw-instance-set/double)
403 (:translate %raw-instance-set/double)
405 (:args (object :scs (descriptor-reg))
406 (index :scs (any-reg))
407 (value :scs (double-reg) :target result))
408 (:arg-types * positive-fixnum double-float)
409 (:results (result :scs (double-reg)))
410 (:temporary (:scs (non-descriptor-reg)) offset)
411 (:temporary (:scs (interior-reg)) lip)
412 (:result-types double-float)
414 (loadw offset object 0 instance-pointer-lowtag)
415 (inst srl offset n-widetag-bits)
416 (inst sll offset n-fixnum-tag-bits)
417 (inst subu offset index)
418 (inst subu offset (* 2 n-word-bytes))
419 (inst addu lip offset object)
420 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
421 instance-pointer-lowtag)))
422 (ecase *backend-byte-order*
423 (:big-endian (inst swc1 value lip immediate-offset))
424 (:little-endian (inst swc1-odd value lip immediate-offset))))
425 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
426 instance-pointer-lowtag)))
427 (ecase *backend-byte-order*
428 (:big-endian (inst swc1-odd value lip immediate-offset))
429 (:little-endian (inst swc1 value lip immediate-offset))))
430 (unless (location= result value)
431 (inst fmove :double result value))))
433 (define-vop (raw-instance-ref/complex-single)
434 (:translate %raw-instance-ref/complex-single)
436 (:args (object :scs (descriptor-reg))
437 (index :scs (any-reg)))
438 (:arg-types * positive-fixnum)
439 (:results (value :scs (complex-single-reg)))
440 (:temporary (:scs (non-descriptor-reg)) offset)
441 (:temporary (:scs (interior-reg)) lip)
442 (:result-types complex-single-float)
444 (loadw offset object 0 instance-pointer-lowtag)
445 (inst srl offset n-widetag-bits)
446 (inst sll offset n-fixnum-tag-bits)
447 (inst subu offset index)
448 (inst subu offset (* 2 n-word-bytes))
449 (inst addu lip offset object)
451 (complex-single-reg-real-tn value)
453 (- (* instance-slots-offset n-word-bytes)
454 instance-pointer-lowtag))
456 (complex-single-reg-imag-tn value)
458 (- (* (1+ instance-slots-offset) n-word-bytes)
459 instance-pointer-lowtag))))
461 (define-vop (raw-instance-set/complex-single)
462 (:translate %raw-instance-set/complex-single)
464 (:args (object :scs (descriptor-reg))
465 (index :scs (any-reg))
466 (value :scs (complex-single-reg) :target result))
467 (:arg-types * positive-fixnum complex-single-float)
468 (:results (result :scs (complex-single-reg)))
469 (:temporary (:scs (non-descriptor-reg)) offset)
470 (:temporary (:scs (interior-reg)) lip)
471 (:result-types complex-single-float)
473 (loadw offset object 0 instance-pointer-lowtag)
474 (inst srl offset n-widetag-bits)
475 (inst sll offset n-fixnum-tag-bits)
476 (inst subu offset index)
477 (inst subu offset (* 2 n-word-bytes))
478 (inst addu lip offset object)
479 (let ((value-real (complex-single-reg-real-tn value))
480 (result-real (complex-single-reg-real-tn result)))
484 (- (* instance-slots-offset n-word-bytes)
485 instance-pointer-lowtag))
486 (unless (location= result-real value-real)
487 (inst fmove :single result-real value-real)))
488 (let ((value-imag (complex-single-reg-imag-tn value))
489 (result-imag (complex-single-reg-imag-tn result)))
493 (- (* (1+ instance-slots-offset) n-word-bytes)
494 instance-pointer-lowtag))
495 (unless (location= result-imag value-imag)
496 (inst fmove :single result-imag value-imag)))))
498 (define-vop (raw-instance-ref/complex-double)
499 (:translate %raw-instance-ref/complex-double)
501 (:args (object :scs (descriptor-reg))
502 (index :scs (any-reg)))
503 (:arg-types * positive-fixnum)
504 (:results (value :scs (complex-double-reg)))
505 (:temporary (:scs (non-descriptor-reg)) offset)
506 (:temporary (:scs (interior-reg)) lip)
507 (:result-types complex-double-float)
509 (loadw offset object 0 instance-pointer-lowtag)
510 (inst srl offset n-widetag-bits)
511 (inst sll offset n-fixnum-tag-bits)
512 (inst subu offset index)
513 (inst subu offset (* 4 n-word-bytes))
514 (inst addu lip offset object)
515 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
516 instance-pointer-lowtag)))
517 (ecase *backend-byte-order*
518 (:big-endian (inst lwc1
519 (complex-double-reg-real-tn value)
522 (:little-endian (inst lwc1-odd
523 (complex-double-reg-real-tn value)
526 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
527 instance-pointer-lowtag)))
528 (ecase *backend-byte-order*
529 (:big-endian (inst lwc1-odd
530 (complex-double-reg-real-tn value)
533 (:little-endian (inst lwc1
534 (complex-double-reg-real-tn value)
537 (let ((immediate-offset (- (* (+ instance-slots-offset 2) n-word-bytes)
538 instance-pointer-lowtag)))
539 (ecase *backend-byte-order*
540 (:big-endian (inst lwc1
541 (complex-double-reg-imag-tn value)
544 (:little-endian (inst lwc1-odd
545 (complex-double-reg-imag-tn value)
548 (let ((immediate-offset (- (* (+ instance-slots-offset 3) n-word-bytes)
549 instance-pointer-lowtag)))
550 (ecase *backend-byte-order*
551 (:big-endian (inst lwc1-odd
552 (complex-double-reg-imag-tn value)
555 (:little-endian (inst lwc1
556 (complex-double-reg-imag-tn value)
558 immediate-offset))))))
560 (define-vop (raw-instance-set/complex-double)
561 (:translate %raw-instance-set/complex-double)
563 (:args (object :scs (descriptor-reg))
564 (index :scs (any-reg))
565 (value :scs (complex-double-reg) :target result))
566 (:arg-types * positive-fixnum complex-double-float)
567 (:results (result :scs (complex-double-reg)))
568 (:temporary (:scs (non-descriptor-reg)) offset)
569 (:temporary (:scs (interior-reg)) lip)
570 (:result-types complex-double-float)
572 (loadw offset object 0 instance-pointer-lowtag)
573 (inst srl offset n-widetag-bits)
574 (inst sll offset n-fixnum-tag-bits)
575 (inst subu offset index)
576 (inst subu offset (* 4 n-word-bytes))
577 (inst addu lip offset object)
578 (let ((value-real (complex-double-reg-real-tn value))
579 (result-real (complex-double-reg-real-tn result)))
580 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
581 instance-pointer-lowtag)))
582 (ecase *backend-byte-order*
583 (:big-endian (inst swc1
587 (:little-endian (inst swc1-odd
591 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
592 instance-pointer-lowtag)))
593 (ecase *backend-byte-order*
594 (:big-endian (inst swc1-odd
598 (:little-endian (inst swc1
602 (unless (location= result-real value-real)
603 (inst fmove :double result-real value-real)))
604 (let ((value-imag (complex-double-reg-imag-tn value))
605 (result-imag (complex-double-reg-imag-tn result)))
606 (let ((immediate-offset (- (* (+ instance-slots-offset 2) n-word-bytes)
607 instance-pointer-lowtag)))
608 (ecase *backend-byte-order*
609 (:big-endian (inst swc1
613 (:little-endian (inst swc1-odd
617 (let ((immediate-offset (- (* (+ instance-slots-offset 3) n-word-bytes)
618 instance-pointer-lowtag)))
619 (ecase *backend-byte-order*
620 (:big-endian (inst swc1-odd
624 (:little-endian (inst swc1
628 (unless (location= result-imag value-imag)
629 (inst fmove :double result-imag value-imag)))))