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 ;;;; Fdefinition (fdefn) objects.
108 (define-vop (fdefn-fun cell-ref)
109 (:variant fdefn-fun-slot other-pointer-lowtag))
111 (define-vop (safe-fdefn-fun)
112 (:args (object :scs (descriptor-reg) :target obj-temp))
113 (:results (value :scs (descriptor-reg any-reg)))
115 (:save-p :compute-only)
116 (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp)
118 (move obj-temp object)
119 (loadw value obj-temp fdefn-fun-slot other-pointer-lowtag)
120 (let ((err-lab (generate-error-code vop undefined-fun-error obj-temp)))
121 (inst beq value null-tn err-lab))
124 (define-vop (set-fdefn-fun)
126 (:translate (setf fdefn-fun))
127 (:args (function :scs (descriptor-reg) :target result)
128 (fdefn :scs (descriptor-reg)))
129 (:temporary (:scs (interior-reg)) lip)
130 (:temporary (:scs (non-descriptor-reg)) type)
131 (:results (result :scs (descriptor-reg)))
133 (let ((normal-fn (gen-label)))
134 (load-type type function (- fun-pointer-lowtag))
136 (inst xor type simple-fun-header-widetag)
137 (inst beq type normal-fn)
138 (inst addu lip function
139 (- (ash simple-fun-code-offset word-shift)
141 (inst li lip (make-fixup "closure_tramp" :foreign))
142 (emit-label normal-fn)
143 (storew lip fdefn fdefn-raw-addr-slot other-pointer-lowtag)
144 (storew function fdefn fdefn-fun-slot other-pointer-lowtag)
145 (move result function))))
147 (define-vop (fdefn-makunbound)
149 (:translate fdefn-makunbound)
150 (:args (fdefn :scs (descriptor-reg) :target result))
151 (:temporary (:scs (non-descriptor-reg)) temp)
152 (:results (result :scs (descriptor-reg)))
154 (storew null-tn fdefn fdefn-fun-slot other-pointer-lowtag)
155 (inst li temp (make-fixup "undefined_tramp" :foreign))
156 (storew temp fdefn fdefn-raw-addr-slot other-pointer-lowtag)
157 (move result fdefn)))
161 ;;;; Binding and Unbinding.
163 ;;; BIND -- Establish VAL as a binding for SYMBOL. Save the old value and
164 ;;; the symbol on the binding stack and stuff the new value into the
168 (:args (val :scs (any-reg descriptor-reg))
169 (symbol :scs (descriptor-reg)))
170 (:temporary (:scs (descriptor-reg)) temp)
172 (loadw temp symbol symbol-value-slot other-pointer-lowtag)
173 (inst addu bsp-tn bsp-tn (* 2 n-word-bytes))
174 (storew temp bsp-tn (- binding-value-slot binding-size))
175 (storew symbol bsp-tn (- binding-symbol-slot binding-size))
176 (storew val symbol symbol-value-slot other-pointer-lowtag)))
180 (:temporary (:scs (descriptor-reg)) symbol value)
182 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
183 (loadw value bsp-tn (- binding-value-slot binding-size))
184 (storew value symbol symbol-value-slot other-pointer-lowtag)
185 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
186 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
187 (inst addu bsp-tn bsp-tn (* -2 n-word-bytes))))
190 (define-vop (unbind-to-here)
191 (:args (arg :scs (descriptor-reg any-reg) :target where))
192 (:temporary (:scs (any-reg) :from (:argument 0)) where)
193 (:temporary (:scs (descriptor-reg)) symbol value)
195 (let ((loop (gen-label))
199 (inst beq where bsp-tn done)
203 (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
204 (inst beq symbol skip)
205 (loadw value bsp-tn (- binding-value-slot binding-size))
206 (storew value symbol symbol-value-slot other-pointer-lowtag)
207 (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
210 (storew zero-tn bsp-tn (- binding-value-slot binding-size))
211 (inst addu bsp-tn bsp-tn (* -2 n-word-bytes))
212 (inst bne where bsp-tn loop)
219 ;;;; Closure indexing.
221 (define-full-reffer closure-index-ref *
222 closure-info-offset fun-pointer-lowtag
223 (descriptor-reg any-reg) * %closure-index-ref)
225 (define-full-setter set-funcallable-instance-info *
226 funcallable-instance-info-offset fun-pointer-lowtag
227 (descriptor-reg any-reg null zero) * %set-funcallable-instance-info)
229 (define-full-reffer funcallable-instance-info *
230 funcallable-instance-info-offset fun-pointer-lowtag
231 (descriptor-reg any-reg) * %funcallable-instance-info)
233 (define-vop (closure-ref slot-ref)
234 (:variant closure-info-offset fun-pointer-lowtag))
236 (define-vop (closure-init slot-set)
237 (:variant closure-info-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))
249 ;;;; Instance hackery:
251 (define-vop (instance-length)
253 (:translate %instance-length)
254 (:args (struct :scs (descriptor-reg)))
255 (:temporary (:scs (non-descriptor-reg)) temp)
256 (:results (res :scs (unsigned-reg)))
257 (:result-types positive-fixnum)
259 (loadw temp struct 0 instance-pointer-lowtag)
260 (inst srl res temp n-widetag-bits)))
262 (define-full-reffer instance-index-ref * instance-slots-offset
263 instance-pointer-lowtag (descriptor-reg any-reg) * %instance-ref)
265 (define-full-setter instance-index-set * instance-slots-offset
266 instance-pointer-lowtag (descriptor-reg any-reg null zero) * %instance-set)
270 ;;;; Code object frobbing.
272 (define-full-reffer code-header-ref * 0 other-pointer-lowtag
273 (descriptor-reg any-reg) * code-header-ref)
275 (define-full-setter code-header-set * 0 other-pointer-lowtag
276 (descriptor-reg any-reg null zero) * code-header-set)
280 ;;;; raw instance slot accessors
282 (define-vop (raw-instance-ref/word)
283 (:translate %raw-instance-ref/word)
285 (:args (object :scs (descriptor-reg))
286 (index :scs (any-reg)))
287 (:arg-types * positive-fixnum)
288 (:results (value :scs (unsigned-reg)))
289 (:temporary (:scs (non-descriptor-reg)) offset)
290 (:temporary (:scs (interior-reg)) lip)
291 (:result-types unsigned-num)
293 (loadw offset object 0 instance-pointer-lowtag)
294 (inst srl offset n-widetag-bits)
295 (inst sll offset n-fixnum-tag-bits)
296 (inst subu offset index)
297 (inst subu offset n-word-bytes)
298 (inst addu lip offset object)
299 (inst lw value lip (- (* instance-slots-offset n-word-bytes)
300 instance-pointer-lowtag))))
302 (define-vop (raw-instance-set/word)
303 (:translate %raw-instance-set/word)
305 (:args (object :scs (descriptor-reg))
306 (index :scs (any-reg))
307 (value :scs (unsigned-reg) :target result))
308 (:arg-types * positive-fixnum unsigned-num)
309 (:results (result :scs (unsigned-reg)))
310 (:temporary (:scs (non-descriptor-reg)) offset)
311 (:temporary (:scs (interior-reg)) lip)
312 (:result-types unsigned-num)
314 (loadw offset object 0 instance-pointer-lowtag)
315 (inst srl offset n-widetag-bits)
316 (inst sll offset n-fixnum-tag-bits)
317 (inst subu offset index)
318 (inst subu offset n-word-bytes)
319 (inst addu lip offset object)
320 (inst sw value lip (- (* instance-slots-offset n-word-bytes)
321 instance-pointer-lowtag))
322 (move result value)))
324 (define-vop (raw-instance-ref/single)
325 (:translate %raw-instance-ref/single)
327 (:args (object :scs (descriptor-reg))
328 (index :scs (any-reg)))
329 (:arg-types * positive-fixnum)
330 (:results (value :scs (single-reg)))
331 (:temporary (:scs (non-descriptor-reg)) offset)
332 (:temporary (:scs (interior-reg)) lip)
333 (:result-types single-float)
335 (loadw offset object 0 instance-pointer-lowtag)
336 (inst srl offset n-widetag-bits)
337 (inst sll offset n-fixnum-tag-bits)
338 (inst subu offset index)
339 (inst subu offset n-word-bytes)
340 (inst addu lip offset object)
341 (inst lwc1 value lip (- (* instance-slots-offset n-word-bytes)
342 instance-pointer-lowtag))))
344 (define-vop (raw-instance-set/single)
345 (:translate %raw-instance-set/single)
347 (:args (object :scs (descriptor-reg))
348 (index :scs (any-reg))
349 (value :scs (single-reg) :target result))
350 (:arg-types * positive-fixnum single-float)
351 (:results (result :scs (single-reg)))
352 (:temporary (:scs (non-descriptor-reg)) offset)
353 (:temporary (:scs (interior-reg)) lip)
354 (:result-types single-float)
356 (loadw offset object 0 instance-pointer-lowtag)
357 (inst srl offset n-widetag-bits)
358 (inst sll offset n-fixnum-tag-bits)
359 (inst subu offset index)
360 (inst subu offset n-word-bytes)
361 (inst addu lip offset object)
362 (inst swc1 value lip (- (* instance-slots-offset n-word-bytes)
363 instance-pointer-lowtag))
364 (unless (location= result value)
365 (inst fmove :single result value))))
367 (define-vop (raw-instance-ref/double)
368 (:translate %raw-instance-ref/double)
370 (:args (object :scs (descriptor-reg))
371 (index :scs (any-reg)))
372 (:arg-types * positive-fixnum)
373 (:results (value :scs (double-reg)))
374 (:temporary (:scs (non-descriptor-reg)) offset)
375 (:temporary (:scs (interior-reg)) lip)
376 (:result-types double-float)
378 (loadw offset object 0 instance-pointer-lowtag)
379 (inst srl offset n-widetag-bits)
380 (inst sll offset n-fixnum-tag-bits)
381 (inst subu offset index)
382 (inst subu offset (* 2 n-word-bytes))
383 (inst addu lip offset object)
384 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
385 instance-pointer-lowtag)))
386 (ecase *backend-byte-order*
387 (:big-endian (inst lwc1 value lip immediate-offset))
388 (:little-endian (inst lwc1-odd value lip immediate-offset))))
389 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
390 instance-pointer-lowtag)))
391 (ecase *backend-byte-order*
392 (:big-endian (inst lwc1-odd value lip immediate-offset))
393 (:little-endian (inst lwc1 value lip immediate-offset))))))
395 (define-vop (raw-instance-set/double)
396 (:translate %raw-instance-set/double)
398 (:args (object :scs (descriptor-reg))
399 (index :scs (any-reg))
400 (value :scs (double-reg) :target result))
401 (:arg-types * positive-fixnum double-float)
402 (:results (result :scs (double-reg)))
403 (:temporary (:scs (non-descriptor-reg)) offset)
404 (:temporary (:scs (interior-reg)) lip)
405 (:result-types double-float)
407 (loadw offset object 0 instance-pointer-lowtag)
408 (inst srl offset n-widetag-bits)
409 (inst sll offset n-fixnum-tag-bits)
410 (inst subu offset index)
411 (inst subu offset (* 2 n-word-bytes))
412 (inst addu lip offset object)
413 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
414 instance-pointer-lowtag)))
415 (ecase *backend-byte-order*
416 (:big-endian (inst swc1 value lip immediate-offset))
417 (:little-endian (inst swc1-odd value lip immediate-offset))))
418 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
419 instance-pointer-lowtag)))
420 (ecase *backend-byte-order*
421 (:big-endian (inst swc1-odd value lip immediate-offset))
422 (:little-endian (inst swc1 value lip immediate-offset))))
423 (unless (location= result value)
424 (inst fmove :double result value))))
426 (define-vop (raw-instance-ref/complex-single)
427 (:translate %raw-instance-ref/complex-single)
429 (:args (object :scs (descriptor-reg))
430 (index :scs (any-reg)))
431 (:arg-types * positive-fixnum)
432 (:results (value :scs (complex-single-reg)))
433 (:temporary (:scs (non-descriptor-reg)) offset)
434 (:temporary (:scs (interior-reg)) lip)
435 (:result-types complex-single-float)
437 (loadw offset object 0 instance-pointer-lowtag)
438 (inst srl offset n-widetag-bits)
439 (inst sll offset n-fixnum-tag-bits)
440 (inst subu offset index)
441 (inst subu offset (* 2 n-word-bytes))
442 (inst addu lip offset object)
444 (complex-single-reg-real-tn value)
446 (- (* instance-slots-offset n-word-bytes)
447 instance-pointer-lowtag))
449 (complex-single-reg-imag-tn value)
451 (- (* (1+ instance-slots-offset) n-word-bytes)
452 instance-pointer-lowtag))))
454 (define-vop (raw-instance-set/complex-single)
455 (:translate %raw-instance-set/complex-single)
457 (:args (object :scs (descriptor-reg))
458 (index :scs (any-reg))
459 (value :scs (complex-single-reg) :target result))
460 (:arg-types * positive-fixnum complex-single-float)
461 (:results (result :scs (complex-single-reg)))
462 (:temporary (:scs (non-descriptor-reg)) offset)
463 (:temporary (:scs (interior-reg)) lip)
464 (:result-types complex-single-float)
466 (loadw offset object 0 instance-pointer-lowtag)
467 (inst srl offset n-widetag-bits)
468 (inst sll offset n-fixnum-tag-bits)
469 (inst subu offset index)
470 (inst subu offset (* 2 n-word-bytes))
471 (inst addu lip offset object)
472 (let ((value-real (complex-single-reg-real-tn value))
473 (result-real (complex-single-reg-real-tn result)))
477 (- (* instance-slots-offset n-word-bytes)
478 instance-pointer-lowtag))
479 (unless (location= result-real value-real)
480 (inst fmove :single result-real value-real)))
481 (let ((value-imag (complex-single-reg-imag-tn value))
482 (result-imag (complex-single-reg-imag-tn result)))
486 (- (* (1+ instance-slots-offset) n-word-bytes)
487 instance-pointer-lowtag))
488 (unless (location= result-imag value-imag)
489 (inst fmove :single result-imag value-imag)))))
491 (define-vop (raw-instance-ref/complex-double)
492 (:translate %raw-instance-ref/complex-double)
494 (:args (object :scs (descriptor-reg))
495 (index :scs (any-reg)))
496 (:arg-types * positive-fixnum)
497 (:results (value :scs (complex-double-reg)))
498 (:temporary (:scs (non-descriptor-reg)) offset)
499 (:temporary (:scs (interior-reg)) lip)
500 (:result-types complex-double-float)
502 (loadw offset object 0 instance-pointer-lowtag)
503 (inst srl offset n-widetag-bits)
504 (inst sll offset n-fixnum-tag-bits)
505 (inst subu offset index)
506 (inst subu offset (* 4 n-word-bytes))
507 (inst addu lip offset object)
508 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
509 instance-pointer-lowtag)))
510 (ecase *backend-byte-order*
511 (:big-endian (inst lwc1
512 (complex-double-reg-real-tn value)
515 (:little-endian (inst lwc1-odd
516 (complex-double-reg-real-tn value)
519 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
520 instance-pointer-lowtag)))
521 (ecase *backend-byte-order*
522 (:big-endian (inst lwc1-odd
523 (complex-double-reg-real-tn value)
526 (:little-endian (inst lwc1
527 (complex-double-reg-real-tn value)
530 (let ((immediate-offset (- (* (+ instance-slots-offset 2) n-word-bytes)
531 instance-pointer-lowtag)))
532 (ecase *backend-byte-order*
533 (:big-endian (inst lwc1
534 (complex-double-reg-imag-tn value)
537 (:little-endian (inst lwc1-odd
538 (complex-double-reg-imag-tn value)
541 (let ((immediate-offset (- (* (+ instance-slots-offset 3) n-word-bytes)
542 instance-pointer-lowtag)))
543 (ecase *backend-byte-order*
544 (:big-endian (inst lwc1-odd
545 (complex-double-reg-imag-tn value)
548 (:little-endian (inst lwc1
549 (complex-double-reg-imag-tn value)
551 immediate-offset))))))
553 (define-vop (raw-instance-set/complex-double)
554 (:translate %raw-instance-set/complex-double)
556 (:args (object :scs (descriptor-reg))
557 (index :scs (any-reg))
558 (value :scs (complex-double-reg) :target result))
559 (:arg-types * positive-fixnum complex-double-float)
560 (:results (result :scs (complex-double-reg)))
561 (:temporary (:scs (non-descriptor-reg)) offset)
562 (:temporary (:scs (interior-reg)) lip)
563 (:result-types complex-double-float)
565 (loadw offset object 0 instance-pointer-lowtag)
566 (inst srl offset n-widetag-bits)
567 (inst sll offset n-fixnum-tag-bits)
568 (inst subu offset index)
569 (inst subu offset (* 4 n-word-bytes))
570 (inst addu lip offset object)
571 (let ((value-real (complex-double-reg-real-tn value))
572 (result-real (complex-double-reg-real-tn result)))
573 (let ((immediate-offset (- (* instance-slots-offset n-word-bytes)
574 instance-pointer-lowtag)))
575 (ecase *backend-byte-order*
576 (:big-endian (inst swc1
580 (:little-endian (inst swc1-odd
584 (let ((immediate-offset (- (* (1+ instance-slots-offset) n-word-bytes)
585 instance-pointer-lowtag)))
586 (ecase *backend-byte-order*
587 (:big-endian (inst swc1-odd
591 (:little-endian (inst swc1
595 (unless (location= result-real value-real)
596 (inst fmove :double result-real value-real)))
597 (let ((value-imag (complex-double-reg-imag-tn value))
598 (result-imag (complex-double-reg-imag-tn result)))
599 (let ((immediate-offset (- (* (+ instance-slots-offset 2) n-word-bytes)
600 instance-pointer-lowtag)))
601 (ecase *backend-byte-order*
602 (:big-endian (inst swc1
606 (:little-endian (inst swc1-odd
610 (let ((immediate-offset (- (* (+ instance-slots-offset 3) n-word-bytes)
611 instance-pointer-lowtag)))
612 (ecase *backend-byte-order*
613 (:big-endian (inst swc1-odd
617 (:little-endian (inst swc1
621 (unless (location= result-imag value-imag)
622 (inst fmove :double result-imag value-imag)))))