1 ;;;; various primitive memory access VOPs for the x86 VM
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
14 ;;;; 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 immediate
)))
27 (:info name offset lowtag
)
31 (storew (encode-value-if-immediate value
) object offset lowtag
)))
33 (define-vop (compare-and-swap-slot)
34 (:args
(object :scs
(descriptor-reg) :to
:eval
)
35 (old :scs
(descriptor-reg any-reg
) :target eax
)
36 (new :scs
(descriptor-reg any-reg
)))
37 (:temporary
(:sc descriptor-reg
:offset eax-offset
38 :from
(:argument
1) :to
:result
:target result
)
40 (:info name offset lowtag
)
42 (:results
(result :scs
(descriptor-reg any-reg
)))
47 (inst cmpxchg
(make-ea :dword
:base object
48 :disp
(- (* offset n-word-bytes
) lowtag
))
52 ;;;; symbol hacking VOPs
54 (define-vop (%compare-and-swap-symbol-value
)
55 (:translate %compare-and-swap-symbol-value
)
56 (:args
(symbol :scs
(descriptor-reg) :to
(:result
1))
57 (old :scs
(descriptor-reg any-reg
) :target eax
)
58 (new :scs
(descriptor-reg any-reg
)))
59 (:temporary
(:sc descriptor-reg
:offset eax-offset
) eax
)
61 (:temporary
(:sc descriptor-reg
) tls
)
62 (:results
(result :scs
(descriptor-reg any-reg
)))
66 ;; This code has to pathological cases: NO-TLS-VALUE-MARKER
67 ;; or UNBOUND-MARKER as NEW: in either case we would end up
68 ;; doing possible damage with CMPXCHG -- so don't do that!
69 (let ((unbound (generate-error-code vop
'unbound-symbol-error symbol
))
74 (loadw tls symbol symbol-tls-index-slot other-pointer-lowtag
)
75 ;; Thread-local area, no LOCK needed.
76 (inst fs-segment-prefix
)
77 (inst cmpxchg
(make-ea :dword
:base tls
) new
)
78 (inst cmp eax no-tls-value-marker-widetag
)
82 (inst cmpxchg
(make-ea :dword
:base symbol
83 :disp
(- (* symbol-value-slot n-word-bytes
)
84 other-pointer-lowtag
))
88 (inst cmp result unbound-marker-widetag
)
89 (inst jmp
:e unbound
))))
91 ;;; these next two cf the sparc version, by jrd.
92 ;;; FIXME: Deref this ^ reference.
95 ;;; The compiler likes to be able to directly SET symbols.
98 (:args
(symbol :scs
(descriptor-reg))
99 (value :scs
(descriptor-reg any-reg
)))
100 (:temporary
(:sc descriptor-reg
) tls
)
101 ;;(:policy :fast-safe)
103 (let ((global-val (gen-label))
105 (loadw tls symbol symbol-tls-index-slot other-pointer-lowtag
)
106 (inst fs-segment-prefix
)
107 (inst cmp
(make-ea :dword
:base tls
) no-tls-value-marker-widetag
)
108 (inst jmp
:z global-val
)
109 (inst fs-segment-prefix
)
110 (inst mov
(make-ea :dword
:base tls
) value
)
112 (emit-label global-val
)
113 (storew value symbol symbol-value-slot other-pointer-lowtag
)
116 ;; unithreaded it's a lot simpler ...
118 (define-vop (set cell-set
)
119 (:variant symbol-value-slot other-pointer-lowtag
))
121 ;;; With Symbol-Value, we check that the value isn't the trap object. So
122 ;;; Symbol-Value of NIL is NIL.
124 (define-vop (symbol-value)
125 (:translate symbol-value
)
127 (:args
(object :scs
(descriptor-reg) :to
(:result
1)))
128 (:results
(value :scs
(descriptor-reg any-reg
)))
130 (:save-p
:compute-only
)
132 (let* ((check-unbound-label (gen-label))
133 (err-lab (generate-error-code vop
'unbound-symbol-error object
))
134 (ret-lab (gen-label)))
135 (loadw value object symbol-tls-index-slot other-pointer-lowtag
)
136 (inst fs-segment-prefix
)
137 (inst mov value
(make-ea :dword
:base value
))
138 (inst cmp value no-tls-value-marker-widetag
)
139 (inst jmp
:ne check-unbound-label
)
140 (loadw value object symbol-value-slot other-pointer-lowtag
)
141 (emit-label check-unbound-label
)
142 (inst cmp value unbound-marker-widetag
)
143 (inst jmp
:e err-lab
)
144 (emit-label ret-lab
))))
147 (define-vop (fast-symbol-value symbol-value
)
148 ;; KLUDGE: not really fast, in fact, because we're going to have to
149 ;; do a full lookup of the thread-local area anyway. But half of
150 ;; the meaning of FAST-SYMBOL-VALUE is "do not signal an error if
151 ;; unbound", which is used in the implementation of COPY-SYMBOL. --
154 (:translate symbol-value
)
156 (let ((ret-lab (gen-label)))
157 (loadw value object symbol-tls-index-slot other-pointer-lowtag
)
158 (inst fs-segment-prefix
)
159 (inst mov value
(make-ea :dword
:base value
))
160 (inst cmp value no-tls-value-marker-widetag
)
161 (inst jmp
:ne ret-lab
)
162 (loadw value object symbol-value-slot other-pointer-lowtag
)
163 (emit-label ret-lab
))))
166 (define-vop (symbol-value)
167 (:translate symbol-value
)
169 (:args
(object :scs
(descriptor-reg) :to
(:result
1)))
170 (:results
(value :scs
(descriptor-reg any-reg
)))
172 (:save-p
:compute-only
)
174 (let ((err-lab (generate-error-code vop
'unbound-symbol-error object
)))
175 (loadw value object symbol-value-slot other-pointer-lowtag
)
176 (inst cmp value unbound-marker-widetag
)
177 (inst jmp
:e err-lab
))))
180 (define-vop (fast-symbol-value cell-ref
)
181 (:variant symbol-value-slot other-pointer-lowtag
)
183 (:translate symbol-value
))
185 (defknown locked-symbol-global-value-add
(symbol fixnum
) fixnum
())
187 (define-vop (locked-symbol-global-value-add)
188 (:args
(object :scs
(descriptor-reg) :to
:result
)
189 (value :scs
(any-reg) :target result
))
190 (:arg-types
* tagged-num
)
191 (:results
(result :scs
(any-reg) :from
(:argument
1)))
193 (:translate locked-symbol-global-value-add
)
194 (:result-types tagged-num
)
199 (inst add
(make-ea-for-object-slot object symbol-value-slot
200 other-pointer-lowtag
)
207 (:args
(object :scs
(descriptor-reg)))
210 (:temporary
(:sc descriptor-reg
#+nil
(:from
(:argument
0))) value
)
212 (let ((check-unbound-label (gen-label)))
213 (loadw value object symbol-tls-index-slot other-pointer-lowtag
)
214 (inst fs-segment-prefix
)
215 (inst mov value
(make-ea :dword
:base value
))
216 (inst cmp value no-tls-value-marker-widetag
)
217 (inst jmp
:ne check-unbound-label
)
218 (loadw value object symbol-value-slot other-pointer-lowtag
)
219 (emit-label check-unbound-label
)
220 (inst cmp value unbound-marker-widetag
)
221 (inst jmp
(if not-p
:e
:ne
) target
))))
227 (:args
(object :scs
(descriptor-reg)))
231 (inst cmp
(make-ea-for-object-slot object symbol-value-slot
232 other-pointer-lowtag
)
233 unbound-marker-widetag
)
234 (inst jmp
(if not-p
:e
:ne
) target
)))
237 (define-vop (symbol-hash)
239 (:translate symbol-hash
)
240 (:args
(symbol :scs
(descriptor-reg)))
241 (:results
(res :scs
(any-reg)))
242 (:result-types positive-fixnum
)
244 ;; The symbol-hash slot of NIL holds NIL because it is also the
245 ;; cdr slot, so we have to strip off the two low bits to make sure
246 ;; it is a fixnum. The lowtag selection magic that is required to
247 ;; ensure this is explained in the comment in objdef.lisp
248 (loadw res symbol symbol-hash-slot other-pointer-lowtag
)
249 (inst and res
(lognot #b11
))))
251 ;;;; fdefinition (FDEFN) objects
253 (define-vop (fdefn-fun cell-ref
) ; /pfw - alpha
254 (:variant fdefn-fun-slot other-pointer-lowtag
))
256 (define-vop (safe-fdefn-fun)
257 (:args
(object :scs
(descriptor-reg) :to
(:result
1)))
258 (:results
(value :scs
(descriptor-reg any-reg
)))
260 (:save-p
:compute-only
)
262 (loadw value object fdefn-fun-slot other-pointer-lowtag
)
263 (inst cmp value nil-value
)
264 (let ((err-lab (generate-error-code vop
'undefined-fun-error object
)))
265 (inst jmp
:e err-lab
))))
267 (define-vop (set-fdefn-fun)
269 (:translate
(setf fdefn-fun
))
270 (:args
(function :scs
(descriptor-reg) :target result
)
271 (fdefn :scs
(descriptor-reg)))
272 (:temporary
(:sc unsigned-reg
) raw
)
273 (:temporary
(:sc byte-reg
) type
)
274 (:results
(result :scs
(descriptor-reg)))
276 (load-type type function
(- fun-pointer-lowtag
))
278 (make-ea-for-object-slot function simple-fun-code-offset
280 (inst cmp type simple-fun-header-widetag
)
281 (inst jmp
:e normal-fn
)
282 (inst lea raw
(make-fixup "closure_tramp" :foreign
))
284 (storew function fdefn fdefn-fun-slot other-pointer-lowtag
)
285 (storew raw fdefn fdefn-raw-addr-slot other-pointer-lowtag
)
286 (move result function
)))
288 (define-vop (fdefn-makunbound)
290 (:translate fdefn-makunbound
)
291 (:args
(fdefn :scs
(descriptor-reg) :target result
))
292 (:results
(result :scs
(descriptor-reg)))
294 (storew nil-value fdefn fdefn-fun-slot other-pointer-lowtag
)
295 (storew (make-fixup "undefined_tramp" :foreign
)
296 fdefn fdefn-raw-addr-slot other-pointer-lowtag
)
297 (move result fdefn
)))
299 ;;;; binding and unbinding
301 ;;; BIND -- Establish VAL as a binding for SYMBOL. Save the old value and
302 ;;; the symbol on the binding stack and stuff the new value into the
305 ;;; FIXME: Split into DYNBIND and BIND: DYNBIND needs to ensure
306 ;;; TLS-INDEX, whereas BIND should assume it is already in place. Make
307 ;;; LET &co compile into BIND, and PROGV into DYNBIND, plus ensure
308 ;;; TLS-INDEX at compile-time, and make loader and dumper preserve
309 ;;; the existence of a TLS-INDEX.
312 (:args
(val :scs
(any-reg descriptor-reg
))
313 (symbol :scs
(descriptor-reg)))
314 (:temporary
(:sc unsigned-reg
) tls-index bsp
)
316 (let ((tls-index-valid (gen-label)))
317 (load-binding-stack-pointer bsp
)
318 (loadw tls-index symbol symbol-tls-index-slot other-pointer-lowtag
)
319 (inst add bsp
(* binding-size n-word-bytes
))
320 (store-binding-stack-pointer bsp
)
321 (inst or tls-index tls-index
)
322 (inst jmp
:ne tls-index-valid
)
323 (inst mov tls-index symbol
)
324 (inst call
(make-fixup
325 (ecase (tn-offset tls-index
)
326 (#.eax-offset
'alloc-tls-index-in-eax
)
327 (#.ebx-offset
'alloc-tls-index-in-ebx
)
328 (#.ecx-offset
'alloc-tls-index-in-ecx
)
329 (#.edx-offset
'alloc-tls-index-in-edx
)
330 (#.edi-offset
'alloc-tls-index-in-edi
)
331 (#.esi-offset
'alloc-tls-index-in-esi
))
333 (emit-label tls-index-valid
)
334 (inst fs-segment-prefix
)
335 (inst push
(make-ea :dword
:base tls-index
))
336 (popw bsp
(- binding-value-slot binding-size
))
337 (storew symbol bsp
(- binding-symbol-slot binding-size
))
338 (inst fs-segment-prefix
)
339 (inst mov
(make-ea :dword
:base tls-index
) val
))))
343 (:args
(val :scs
(any-reg descriptor-reg
))
344 (symbol :scs
(descriptor-reg)))
345 (:temporary
(:sc unsigned-reg
) temp bsp
)
347 (load-symbol-value bsp
*binding-stack-pointer
*)
348 (loadw temp symbol symbol-value-slot other-pointer-lowtag
)
349 (inst add bsp
(* binding-size n-word-bytes
))
350 (store-symbol-value bsp
*binding-stack-pointer
*)
351 (storew temp bsp
(- binding-value-slot binding-size
))
352 (storew symbol bsp
(- binding-symbol-slot binding-size
))
353 (storew val symbol symbol-value-slot other-pointer-lowtag
)))
357 (:temporary
(:sc unsigned-reg
) temp bsp tls-index
)
359 (load-binding-stack-pointer bsp
)
360 ;; Load SYMBOL from stack, and get the TLS-INDEX.
361 (loadw temp bsp
(- binding-symbol-slot binding-size
))
362 (loadw tls-index temp symbol-tls-index-slot other-pointer-lowtag
)
363 ;; Load VALUE from stack, then restore it to the TLS area.
364 (loadw temp bsp
(- binding-value-slot binding-size
))
365 (inst fs-segment-prefix
)
366 (inst mov
(make-ea :dword
:base tls-index
) temp
)
367 ;; Zero out the stack.
368 (storew 0 bsp
(- binding-symbol-slot binding-size
))
369 (storew 0 bsp
(- binding-value-slot binding-size
))
370 (inst sub bsp
(* binding-size n-word-bytes
))
371 (store-binding-stack-pointer bsp
)))
375 (:temporary
(:sc unsigned-reg
) symbol value bsp
)
377 (load-symbol-value bsp
*binding-stack-pointer
*)
378 (loadw symbol bsp
(- binding-symbol-slot binding-size
))
379 (loadw value bsp
(- binding-value-slot binding-size
))
380 (storew value symbol symbol-value-slot other-pointer-lowtag
)
381 (storew 0 bsp
(- binding-symbol-slot binding-size
))
382 (storew 0 bsp
(- binding-value-slot binding-size
))
383 (inst sub bsp
(* binding-size n-word-bytes
))
384 (store-symbol-value bsp
*binding-stack-pointer
*)))
387 (define-vop (unbind-to-here)
388 (:args
(where :scs
(descriptor-reg any-reg
)))
389 (:temporary
(:sc unsigned-reg
) symbol value bsp
#!+sb-thread tls-index
)
391 (load-binding-stack-pointer bsp
)
396 (loadw symbol bsp
(- binding-symbol-slot binding-size
))
397 (inst or symbol symbol
)
399 ;; Bind stack debug sentinels have the unbound marker in the symbol slot
400 (inst cmp symbol unbound-marker-widetag
)
402 (loadw value bsp
(- binding-value-slot binding-size
))
403 #!-sb-thread
(storew value symbol symbol-value-slot other-pointer-lowtag
)
406 tls-index symbol symbol-tls-index-slot other-pointer-lowtag
)
407 #!+sb-thread
(inst fs-segment-prefix
)
408 #!+sb-thread
(inst mov
(make-ea :dword
:base tls-index
) value
)
409 (storew 0 bsp
(- binding-symbol-slot binding-size
))
412 (storew 0 bsp
(- binding-value-slot binding-size
))
413 (inst sub bsp
(* binding-size n-word-bytes
))
416 (store-binding-stack-pointer bsp
)
420 (define-vop (bind-sentinel)
421 (:temporary
(:sc unsigned-reg
) bsp
)
423 (load-binding-stack-pointer bsp
)
424 (inst add bsp
(* binding-size n-word-bytes
))
425 (storew unbound-marker-widetag bsp
(- binding-symbol-slot binding-size
))
426 (storew ebp-tn bsp
(- binding-value-slot binding-size
))
427 (store-binding-stack-pointer bsp
)))
429 (define-vop (unbind-sentinel)
430 (:temporary
(:sc unsigned-reg
) bsp
)
432 (load-binding-stack-pointer bsp
)
433 (storew 0 bsp
(- binding-value-slot binding-size
))
434 (storew 0 bsp
(- binding-symbol-slot binding-size
))
435 (inst sub bsp
(* binding-size n-word-bytes
))
436 (store-binding-stack-pointer bsp
)))
440 ;;;; closure indexing
442 (define-full-reffer closure-index-ref
*
443 closure-info-offset fun-pointer-lowtag
444 (any-reg descriptor-reg
) * %closure-index-ref
)
446 (define-full-setter set-funcallable-instance-info
*
447 funcallable-instance-info-offset fun-pointer-lowtag
448 (any-reg descriptor-reg
) * %set-funcallable-instance-info
)
450 (define-full-reffer funcallable-instance-info
*
451 funcallable-instance-info-offset fun-pointer-lowtag
452 (descriptor-reg any-reg
) * %funcallable-instance-info
)
454 (define-vop (closure-ref slot-ref
)
455 (:variant closure-info-offset fun-pointer-lowtag
))
457 (define-vop (closure-init slot-set
)
458 (:variant closure-info-offset fun-pointer-lowtag
))
460 ;;;; value cell hackery
462 (define-vop (value-cell-ref cell-ref
)
463 (:variant value-cell-value-slot other-pointer-lowtag
))
465 (define-vop (value-cell-set cell-set
)
466 (:variant value-cell-value-slot other-pointer-lowtag
))
468 ;;;; structure hackery
470 (define-vop (instance-length)
472 (:translate %instance-length
)
473 (:args
(struct :scs
(descriptor-reg)))
474 (:results
(res :scs
(unsigned-reg)))
475 (:result-types positive-fixnum
)
477 (loadw res struct
0 instance-pointer-lowtag
)
478 (inst shr res n-widetag-bits
)))
480 (define-full-reffer instance-index-ref
*
481 instance-slots-offset instance-pointer-lowtag
482 (any-reg descriptor-reg
) *
485 (define-full-setter instance-index-set
*
486 instance-slots-offset instance-pointer-lowtag
487 (any-reg descriptor-reg
) *
490 (define-full-compare-and-swap %compare-and-swap-instance-ref instance
491 instance-slots-offset instance-pointer-lowtag
492 (any-reg descriptor-reg
) *
493 %compare-and-swap-instance-ref
)
495 ;;;; code object frobbing
497 (define-full-reffer code-header-ref
* 0 other-pointer-lowtag
498 (any-reg descriptor-reg
) * code-header-ref
)
500 (define-full-setter code-header-set
* 0 other-pointer-lowtag
501 (any-reg descriptor-reg
) * code-header-set
)
503 ;;;; raw instance slot accessors
505 (defun make-ea-for-raw-slot (object index instance-length n-words
)
506 (flet ((make-ea-using-value (value)
507 (make-ea :dword
:base object
508 :index instance-length
510 :disp
(- (* (- instance-slots-offset n-words
)
512 instance-pointer-lowtag
513 (fixnumize value
)))))
514 (if (typep index
'tn
)
516 (any-reg (make-ea :dword
518 :index instance-length
519 :disp
(- (* (- instance-slots-offset n-words
)
521 instance-pointer-lowtag
)))
522 (immediate (make-ea-using-value (tn-value index
))))
523 (make-ea-using-value index
))))
525 (define-vop (raw-instance-ref/word
)
526 (:translate %raw-instance-ref
/word
)
528 (:args
(object :scs
(descriptor-reg)) (index :scs
(any-reg immediate
)))
529 (:arg-types
* tagged-num
)
530 (:temporary
(:sc unsigned-reg
) tmp
)
531 (:results
(value :scs
(unsigned-reg)))
532 (:result-types unsigned-num
)
534 (loadw tmp object
0 instance-pointer-lowtag
)
535 (inst shr tmp n-widetag-bits
)
536 (when (sc-is index any-reg
)
538 (inst sub tmp index
))
539 (inst mov value
(make-ea-for-raw-slot object index tmp
1))))
541 (define-vop (raw-instance-set/word
)
542 (:translate %raw-instance-set
/word
)
544 (:args
(object :scs
(descriptor-reg))
545 (index :scs
(any-reg immediate
))
546 (value :scs
(unsigned-reg) :target result
))
547 (:arg-types
* tagged-num unsigned-num
)
548 (:temporary
(:sc unsigned-reg
) tmp
)
549 (:results
(result :scs
(unsigned-reg)))
550 (:result-types unsigned-num
)
552 (loadw tmp object
0 instance-pointer-lowtag
)
553 (inst shr tmp n-widetag-bits
)
554 (when (sc-is index any-reg
)
556 (inst sub tmp index
))
557 (inst mov
(make-ea-for-raw-slot object index tmp
1) value
)
558 (move result value
)))
560 (define-vop (raw-instance-init/word
)
561 (:args
(object :scs
(descriptor-reg))
562 (value :scs
(unsigned-reg)))
563 (:arg-types
* unsigned-num
)
565 (:temporary
(:sc unsigned-reg
) tmp
)
567 (loadw tmp object
0 instance-pointer-lowtag
)
568 (inst shr tmp n-widetag-bits
)
569 (inst mov
(make-ea-for-raw-slot object index tmp
1) value
)))
571 (define-vop (raw-instance-ref/single
)
572 (:translate %raw-instance-ref
/single
)
574 (:args
(object :scs
(descriptor-reg)) (index :scs
(any-reg immediate
)))
575 (:arg-types
* tagged-num
)
576 (:temporary
(:sc unsigned-reg
) tmp
)
577 (:results
(value :scs
(single-reg)))
578 (:result-types single-float
)
580 (loadw tmp object
0 instance-pointer-lowtag
)
581 (inst shr tmp n-widetag-bits
)
582 (when (sc-is index any-reg
)
584 (inst sub tmp index
))
585 (with-empty-tn@fp-top
(value)
586 (inst fld
(make-ea-for-raw-slot object index tmp
1)))))
588 (define-vop (raw-instance-set/single
)
589 (:translate %raw-instance-set
/single
)
591 (:args
(object :scs
(descriptor-reg))
592 (index :scs
(any-reg immediate
))
593 (value :scs
(single-reg) :target result
))
594 (:arg-types
* tagged-num single-float
)
595 (:temporary
(:sc unsigned-reg
) tmp
)
596 (:results
(result :scs
(single-reg)))
597 (:result-types single-float
)
599 (loadw tmp object
0 instance-pointer-lowtag
)
600 (inst shr tmp n-widetag-bits
)
601 (when (sc-is index any-reg
)
603 (inst sub tmp index
))
604 (unless (zerop (tn-offset value
))
606 (inst fst
(make-ea-for-raw-slot object index tmp
1))
608 ((zerop (tn-offset value
))
609 (unless (zerop (tn-offset result
))
611 ((zerop (tn-offset result
))
614 (unless (location= value result
)
616 (inst fxch value
)))))
618 (define-vop (raw-instance-init/single
)
619 (:args
(object :scs
(descriptor-reg))
620 (value :scs
(single-reg)))
621 (:arg-types
* single-float
)
623 (:temporary
(:sc unsigned-reg
) tmp
)
625 (loadw tmp object
0 instance-pointer-lowtag
)
626 (inst shr tmp n-widetag-bits
)
627 (with-tn@fp-top
(value)
628 (inst fst
(make-ea-for-raw-slot object index tmp
1)))))
630 (define-vop (raw-instance-ref/double
)
631 (:translate %raw-instance-ref
/double
)
633 (:args
(object :scs
(descriptor-reg)) (index :scs
(any-reg immediate
)))
634 (:arg-types
* tagged-num
)
635 (:temporary
(:sc unsigned-reg
) tmp
)
636 (:results
(value :scs
(double-reg)))
637 (:result-types double-float
)
639 (loadw tmp object
0 instance-pointer-lowtag
)
640 (inst shr tmp n-widetag-bits
)
641 (when (sc-is index any-reg
)
643 (inst sub tmp index
))
644 (with-empty-tn@fp-top
(value)
645 (inst fldd
(make-ea-for-raw-slot object index tmp
2)))))
647 (define-vop (raw-instance-set/double
)
648 (:translate %raw-instance-set
/double
)
650 (:args
(object :scs
(descriptor-reg))
651 (index :scs
(any-reg immediate
))
652 (value :scs
(double-reg) :target result
))
653 (:arg-types
* tagged-num double-float
)
654 (:temporary
(:sc unsigned-reg
) tmp
)
655 (:results
(result :scs
(double-reg)))
656 (:result-types double-float
)
658 (loadw tmp object
0 instance-pointer-lowtag
)
659 (inst shr tmp n-widetag-bits
)
660 (when (sc-is index any-reg
)
662 (inst sub tmp index
))
663 (unless (zerop (tn-offset value
))
665 (inst fstd
(make-ea-for-raw-slot object index tmp
2))
667 ((zerop (tn-offset value
))
668 (unless (zerop (tn-offset result
))
670 ((zerop (tn-offset result
))
673 (unless (location= value result
)
675 (inst fxch value
)))))
677 (define-vop (raw-instance-init/double
)
678 (:args
(object :scs
(descriptor-reg))
679 (value :scs
(double-reg)))
680 (:arg-types
* double-float
)
682 (:temporary
(:sc unsigned-reg
) tmp
)
684 (loadw tmp object
0 instance-pointer-lowtag
)
685 (inst shr tmp n-widetag-bits
)
686 (with-tn@fp-top
(value)
687 (inst fstd
(make-ea-for-raw-slot object index tmp
2)))))
689 (define-vop (raw-instance-ref/complex-single
)
690 (:translate %raw-instance-ref
/complex-single
)
692 (:args
(object :scs
(descriptor-reg))
693 (index :scs
(any-reg immediate
)))
694 (:arg-types
* positive-fixnum
)
695 (:temporary
(:sc unsigned-reg
) tmp
)
696 (:results
(value :scs
(complex-single-reg)))
697 (:result-types complex-single-float
)
699 (loadw tmp object
0 instance-pointer-lowtag
)
700 (inst shr tmp n-widetag-bits
)
701 (when (sc-is index any-reg
)
703 (inst sub tmp index
))
704 (let ((real-tn (complex-single-reg-real-tn value
)))
705 (with-empty-tn@fp-top
(real-tn)
706 (inst fld
(make-ea-for-raw-slot object index tmp
2))))
707 (let ((imag-tn (complex-single-reg-imag-tn value
)))
708 (with-empty-tn@fp-top
(imag-tn)
709 (inst fld
(make-ea-for-raw-slot object index tmp
1))))))
711 (define-vop (raw-instance-set/complex-single
)
712 (:translate %raw-instance-set
/complex-single
)
714 (:args
(object :scs
(descriptor-reg))
715 (index :scs
(any-reg immediate
))
716 (value :scs
(complex-single-reg) :target result
))
717 (:arg-types
* positive-fixnum complex-single-float
)
718 (:temporary
(:sc unsigned-reg
) tmp
)
719 (:results
(result :scs
(complex-single-reg)))
720 (:result-types complex-single-float
)
722 (loadw tmp object
0 instance-pointer-lowtag
)
723 (inst shr tmp n-widetag-bits
)
724 (when (sc-is index any-reg
)
726 (inst sub tmp index
))
727 (let ((value-real (complex-single-reg-real-tn value
))
728 (result-real (complex-single-reg-real-tn result
)))
729 (cond ((zerop (tn-offset value-real
))
731 (inst fst
(make-ea-for-raw-slot object index tmp
2))
732 (unless (zerop (tn-offset result-real
))
733 ;; Value is in ST0 but not result.
734 (inst fst result-real
)))
736 ;; Value is not in ST0.
737 (inst fxch value-real
)
738 (inst fst
(make-ea-for-raw-slot object index tmp
2))
739 (cond ((zerop (tn-offset result-real
))
740 ;; The result is in ST0.
741 (inst fst value-real
))
743 ;; Neither value or result are in ST0
744 (unless (location= value-real result-real
)
745 (inst fst result-real
))
746 (inst fxch value-real
))))))
747 (let ((value-imag (complex-single-reg-imag-tn value
))
748 (result-imag (complex-single-reg-imag-tn result
)))
749 (inst fxch value-imag
)
750 (inst fst
(make-ea-for-raw-slot object index tmp
1))
751 (unless (location= value-imag result-imag
)
752 (inst fst result-imag
))
753 (inst fxch value-imag
))))
755 (define-vop (raw-instance-init/complex-single
)
756 (:args
(object :scs
(descriptor-reg))
757 (value :scs
(complex-single-reg)))
758 (:arg-types
* complex-single-float
)
760 (:temporary
(:sc unsigned-reg
) tmp
)
762 (loadw tmp object
0 instance-pointer-lowtag
)
763 (inst shr tmp n-widetag-bits
)
764 (let ((value-real (complex-single-reg-real-tn value
)))
765 (with-tn@fp-top
(value-real)
766 (inst fst
(make-ea-for-raw-slot object index tmp
2))))
767 (let ((value-imag (complex-single-reg-imag-tn value
)))
768 (with-tn@fp-top
(value-imag)
769 (inst fst
(make-ea-for-raw-slot object index tmp
1))))))
771 (define-vop (raw-instance-ref/complex-double
)
772 (:translate %raw-instance-ref
/complex-double
)
774 (:args
(object :scs
(descriptor-reg))
775 (index :scs
(any-reg immediate
)))
776 (:arg-types
* positive-fixnum
)
777 (:temporary
(:sc unsigned-reg
) tmp
)
778 (:results
(value :scs
(complex-double-reg)))
779 (:result-types complex-double-float
)
781 (loadw tmp object
0 instance-pointer-lowtag
)
782 (inst shr tmp n-widetag-bits
)
783 (when (sc-is index any-reg
)
785 (inst sub tmp index
))
786 (let ((real-tn (complex-double-reg-real-tn value
)))
787 (with-empty-tn@fp-top
(real-tn)
788 (inst fldd
(make-ea-for-raw-slot object index tmp
4))))
789 (let ((imag-tn (complex-double-reg-imag-tn value
)))
790 (with-empty-tn@fp-top
(imag-tn)
791 (inst fldd
(make-ea-for-raw-slot object index tmp
2))))))
793 (define-vop (raw-instance-set/complex-double
)
794 (:translate %raw-instance-set
/complex-double
)
796 (:args
(object :scs
(descriptor-reg))
797 (index :scs
(any-reg immediate
))
798 (value :scs
(complex-double-reg) :target result
))
799 (:arg-types
* positive-fixnum complex-double-float
)
800 (:temporary
(:sc unsigned-reg
) tmp
)
801 (:results
(result :scs
(complex-double-reg)))
802 (:result-types complex-double-float
)
804 (loadw tmp object
0 instance-pointer-lowtag
)
805 (inst shr tmp n-widetag-bits
)
806 (when (sc-is index any-reg
)
808 (inst sub tmp index
))
809 (let ((value-real (complex-double-reg-real-tn value
))
810 (result-real (complex-double-reg-real-tn result
)))
811 (cond ((zerop (tn-offset value-real
))
813 (inst fstd
(make-ea-for-raw-slot object index tmp
4))
814 (unless (zerop (tn-offset result-real
))
815 ;; Value is in ST0 but not result.
816 (inst fstd result-real
)))
818 ;; Value is not in ST0.
819 (inst fxch value-real
)
820 (inst fstd
(make-ea-for-raw-slot object index tmp
4))
821 (cond ((zerop (tn-offset result-real
))
822 ;; The result is in ST0.
823 (inst fstd value-real
))
825 ;; Neither value or result are in ST0
826 (unless (location= value-real result-real
)
827 (inst fstd result-real
))
828 (inst fxch value-real
))))))
829 (let ((value-imag (complex-double-reg-imag-tn value
))
830 (result-imag (complex-double-reg-imag-tn result
)))
831 (inst fxch value-imag
)
832 (inst fstd
(make-ea-for-raw-slot object index tmp
2))
833 (unless (location= value-imag result-imag
)
834 (inst fstd result-imag
))
835 (inst fxch value-imag
))))
837 (define-vop (raw-instance-init/complex-double
)
838 (:args
(object :scs
(descriptor-reg))
839 (value :scs
(complex-double-reg)))
840 (:arg-types
* complex-double-float
)
842 (:temporary
(:sc unsigned-reg
) tmp
)
844 (loadw tmp object
0 instance-pointer-lowtag
)
845 (inst shr tmp n-widetag-bits
)
846 (let ((value-real (complex-double-reg-real-tn value
)))
847 (with-tn@fp-top
(value-real)
848 (inst fstd
(make-ea-for-raw-slot object index tmp
4))))
849 (let ((value-imag (complex-double-reg-imag-tn value
)))
850 (with-tn@fp-top
(value-imag)
851 (inst fstd
(make-ea-for-raw-slot object index tmp
2))))))