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 (if (sc-is value immediate
)
32 (let ((val (tn-value value
)))
36 (make-ea :dword
:base object
37 :disp
(- (* offset n-word-bytes
) lowtag
))
41 (make-ea :dword
:base object
42 :disp
(- (* offset n-word-bytes
) lowtag
))
43 (+ nil-value
(static-symbol-offset val
))))
46 (make-ea :dword
:base object
47 :disp
(- (* offset n-word-bytes
) lowtag
))
48 (logior (ash (char-code val
) n-widetag-bits
)
49 base-char-widetag
)))))
50 ;; Else, value not immediate.
51 (storew value object offset lowtag
))))
55 ;;;; symbol hacking VOPs
57 ;;; these next two cf the sparc version, by jrd.
58 ;;; FIXME: Deref this ^ reference.
61 ;;; The compiler likes to be able to directly SET symbols.
64 (:args
(symbol :scs
(descriptor-reg))
65 (value :scs
(descriptor-reg any-reg
)))
66 (:translate sb
!kernel
:%set-symbol-value
)
67 (:temporary
(:sc descriptor-reg
) tls
)
68 ;;(:policy :fast-safe)
70 (let ((global-val (gen-label))
72 (loadw tls symbol symbol-tls-index-slot other-pointer-lowtag
)
74 (inst jmp
:z global-val
)
75 (inst fs-segment-prefix
)
76 (inst cmp
(make-ea :dword
:scale
1 :index tls
) unbound-marker-widetag
)
77 (inst jmp
:z global-val
)
78 (inst fs-segment-prefix
)
79 (inst mov
(make-ea :dword
:scale
1 :index tls
) value
)
81 (emit-label global-val
)
82 (storew value symbol symbol-value-slot other-pointer-lowtag
)
85 ;; unithreaded it's a lot simpler ...
87 (define-vop (set cell-set
)
88 (:variant symbol-value-slot other-pointer-lowtag
))
90 ;;; Do a cell ref with an error check for being unbound.
91 ;;; XXX stil used? I can't see where -dan
92 (define-vop (checked-cell-ref)
93 (:args
(object :scs
(descriptor-reg) :target obj-temp
))
94 (:results
(value :scs
(descriptor-reg any-reg
)))
97 (:save-p
:compute-only
)
98 (:temporary
(:sc descriptor-reg
:from
(:argument
0)) obj-temp
))
100 ;;; With Symbol-Value, we check that the value isn't the trap object. So
101 ;;; Symbol-Value of NIL is NIL.
103 (define-vop (symbol-value)
104 (:translate symbol-value
)
106 (:args
(object :scs
(descriptor-reg) :to
(:result
1)))
107 (:results
(value :scs
(descriptor-reg any-reg
)))
109 (:save-p
:compute-only
)
111 (let* ((err-lab (generate-error-code vop unbound-symbol-error object
))
112 (ret-lab (gen-label)))
113 (loadw value object symbol-tls-index-slot other-pointer-lowtag
)
114 (inst fs-segment-prefix
)
115 (inst mov value
(make-ea :dword
:index value
:scale
1))
116 (inst cmp value unbound-marker-widetag
)
117 (inst jmp
:ne ret-lab
)
118 (loadw value object symbol-value-slot other-pointer-lowtag
)
119 (inst cmp value unbound-marker-widetag
)
120 (inst jmp
:e err-lab
)
121 (emit-label ret-lab
))))
124 (define-vop (fast-symbol-value symbol-value
)
125 ;; KLUDGE: not really fast, in fact, because we're going to have to
126 ;; do a full lookup of the thread-local area anyway. But half of
127 ;; the meaning of FAST-SYMBOL-VALUE is "do not signal an error if
128 ;; unbound", which is used in the implementation of COPY-SYMBOL. --
131 (:translate symbol-value
)
133 (let ((ret-lab (gen-label)))
134 (loadw value object symbol-tls-index-slot other-pointer-lowtag
)
135 (inst fs-segment-prefix
)
136 (inst mov value
(make-ea :dword
:index value
:scale
1))
137 (inst cmp value unbound-marker-widetag
)
138 (inst jmp
:ne ret-lab
)
139 (loadw value object symbol-value-slot other-pointer-lowtag
)
140 (emit-label ret-lab
))))
143 (define-vop (symbol-value)
144 (:translate symbol-value
)
146 (:args
(object :scs
(descriptor-reg) :to
(:result
1)))
147 (:results
(value :scs
(descriptor-reg any-reg
)))
149 (:save-p
:compute-only
)
151 (let ((err-lab (generate-error-code vop unbound-symbol-error object
)))
152 (loadw value object symbol-value-slot other-pointer-lowtag
)
153 (inst cmp value unbound-marker-widetag
)
154 (inst jmp
:e err-lab
))))
157 (define-vop (fast-symbol-value cell-ref
)
158 (:variant symbol-value-slot other-pointer-lowtag
)
160 (:translate symbol-value
))
162 (defknown locked-symbol-global-value-add
(symbol fixnum
) fixnum
())
164 (define-vop (locked-symbol-global-value-add)
165 (:args
(object :scs
(descriptor-reg) :to
:result
)
166 (value :scs
(any-reg) :target result
))
167 (:arg-types
* tagged-num
)
168 (:results
(result :scs
(any-reg) :from
(:argument
1)))
170 (:translate locked-symbol-global-value-add
)
171 (:result-types tagged-num
)
176 (inst add
(make-ea :dword
:base object
177 :disp
(- (* symbol-value-slot n-word-bytes
)
178 other-pointer-lowtag
))
185 (:args
(object :scs
(descriptor-reg)))
188 (:temporary
(:sc descriptor-reg
#+nil
(:from
(:argument
0))) value
)
191 (let ((not-target (gen-label)))
192 (loadw value object symbol-value-slot other-pointer-lowtag
)
193 (inst cmp value unbound-marker-widetag
)
194 (inst jmp
:ne not-target
)
195 (loadw value object symbol-tls-index-slot other-pointer-lowtag
)
196 (inst fs-segment-prefix
)
197 (inst cmp
(make-ea :dword
:index value
:scale
1) unbound-marker-widetag
)
199 (emit-label not-target
))
201 (loadw value object symbol-value-slot other-pointer-lowtag
)
202 (inst cmp value unbound-marker-widetag
)
203 (inst jmp
:ne target
)
204 (loadw value object symbol-tls-index-slot other-pointer-lowtag
)
205 (inst fs-segment-prefix
)
206 (inst cmp
(make-ea :dword
:index value
:scale
1) unbound-marker-widetag
)
207 (inst jmp
:ne target
)))))
213 (:args
(object :scs
(descriptor-reg)))
216 (:temporary
(:sc descriptor-reg
:from
(:argument
0)) value
)
218 (loadw value object symbol-value-slot other-pointer-lowtag
)
219 (inst cmp value unbound-marker-widetag
)
220 (inst jmp
(if not-p
:e
:ne
) target
)))
223 (define-vop (symbol-hash)
225 (:translate symbol-hash
)
226 (:args
(symbol :scs
(descriptor-reg)))
227 (:results
(res :scs
(any-reg)))
228 (:result-types positive-fixnum
)
230 ;; The symbol-hash slot of NIL holds NIL because it is also the
231 ;; cdr slot, so we have to strip off the two low bits to make sure
232 ;; it is a fixnum. The lowtag selection magic that is required to
233 ;; ensure this is explained in the comment in objdef.lisp
234 (loadw res symbol symbol-hash-slot other-pointer-lowtag
)
235 (inst and res
(lognot #b11
))))
237 ;;;; fdefinition (FDEFN) objects
239 (define-vop (fdefn-fun cell-ref
) ; /pfw - alpha
240 (:variant fdefn-fun-slot other-pointer-lowtag
))
242 (define-vop (safe-fdefn-fun)
243 (:args
(object :scs
(descriptor-reg) :to
(:result
1)))
244 (:results
(value :scs
(descriptor-reg any-reg
)))
246 (:save-p
:compute-only
)
248 (loadw value object fdefn-fun-slot other-pointer-lowtag
)
249 (inst cmp value nil-value
)
250 (let ((err-lab (generate-error-code vop undefined-fun-error object
)))
251 (inst jmp
:e err-lab
))))
253 (define-vop (set-fdefn-fun)
255 (:translate
(setf fdefn-fun
))
256 (:args
(function :scs
(descriptor-reg) :target result
)
257 (fdefn :scs
(descriptor-reg)))
258 (:temporary
(:sc unsigned-reg
) raw
)
259 (:temporary
(:sc byte-reg
) type
)
260 (:results
(result :scs
(descriptor-reg)))
262 (load-type type function
(- fun-pointer-lowtag
))
264 (make-ea :byte
:base function
265 :disp
(- (* simple-fun-code-offset n-word-bytes
)
266 fun-pointer-lowtag
)))
267 (inst cmp type simple-fun-header-widetag
)
268 (inst jmp
:e normal-fn
)
269 (inst lea raw
(make-fixup (extern-alien-name "closure_tramp") :foreign
))
271 (storew function fdefn fdefn-fun-slot other-pointer-lowtag
)
272 (storew raw fdefn fdefn-raw-addr-slot other-pointer-lowtag
)
273 (move result function
)))
275 (define-vop (fdefn-makunbound)
277 (:translate fdefn-makunbound
)
278 (:args
(fdefn :scs
(descriptor-reg) :target result
))
279 (:results
(result :scs
(descriptor-reg)))
281 (storew nil-value fdefn fdefn-fun-slot other-pointer-lowtag
)
282 (storew (make-fixup (extern-alien-name "undefined_tramp") :foreign
)
283 fdefn fdefn-raw-addr-slot other-pointer-lowtag
)
284 (move result fdefn
)))
286 ;;;; binding and unbinding
288 ;;; BIND -- Establish VAL as a binding for SYMBOL. Save the old value and
289 ;;; the symbol on the binding stack and stuff the new value into the
294 (:args
(val :scs
(any-reg descriptor-reg
))
295 (symbol :scs
(descriptor-reg)))
296 (:temporary
(:sc unsigned-reg
) tls-index temp bsp
)
298 (let ((tls-index-valid (gen-label)))
299 (load-tl-symbol-value bsp
*binding-stack-pointer
*)
300 (loadw tls-index symbol symbol-tls-index-slot other-pointer-lowtag
)
301 (inst add bsp
(* binding-size n-word-bytes
))
302 (store-tl-symbol-value bsp
*binding-stack-pointer
* temp
)
304 (inst or tls-index tls-index
)
305 (inst jmp
:ne tls-index-valid
)
306 ;; allocate a new tls-index
307 (load-symbol-value tls-index
*free-tls-index
*)
308 (inst add tls-index
4) ;XXX surely we can do this more
309 (store-symbol-value tls-index
*free-tls-index
*) ;succintly
310 (inst sub tls-index
4)
311 (storew tls-index symbol symbol-tls-index-slot other-pointer-lowtag
)
312 (emit-label tls-index-valid
)
313 (inst fs-segment-prefix
)
314 (inst mov temp
(make-ea :dword
:scale
1 :index tls-index
))
315 (storew temp bsp
(- binding-value-slot binding-size
))
316 (storew symbol bsp
(- binding-symbol-slot binding-size
))
317 (inst fs-segment-prefix
)
318 (inst mov
(make-ea :dword
:scale
1 :index tls-index
) val
))))
322 (:args
(val :scs
(any-reg descriptor-reg
))
323 (symbol :scs
(descriptor-reg)))
324 (:temporary
(:sc unsigned-reg
) temp bsp
)
326 (load-symbol-value bsp
*binding-stack-pointer
*)
327 (loadw temp symbol symbol-value-slot other-pointer-lowtag
)
328 (inst add bsp
(* binding-size n-word-bytes
))
329 (store-symbol-value bsp
*binding-stack-pointer
*)
330 (storew temp bsp
(- binding-value-slot binding-size
))
331 (storew symbol bsp
(- binding-symbol-slot binding-size
))
332 (storew val symbol symbol-value-slot other-pointer-lowtag
)))
338 (:temporary
(:sc unsigned-reg
) symbol value bsp tls-index
)
340 (load-tl-symbol-value bsp
*binding-stack-pointer
*)
341 (loadw symbol bsp
(- binding-symbol-slot binding-size
))
342 (loadw value bsp
(- binding-value-slot binding-size
))
344 (loadw tls-index symbol symbol-tls-index-slot other-pointer-lowtag
)
345 (inst fs-segment-prefix
)
346 (inst mov
(make-ea :dword
:scale
1 :index tls-index
) value
)
348 (storew 0 bsp
(- binding-symbol-slot binding-size
))
349 (inst sub bsp
(* binding-size n-word-bytes
))
350 ;; we're done with value, so we can use it as a temp here
351 (store-tl-symbol-value bsp
*binding-stack-pointer
* value
)))
355 (:temporary
(:sc unsigned-reg
) symbol value bsp
)
357 (load-symbol-value bsp
*binding-stack-pointer
*)
358 (loadw symbol bsp
(- binding-symbol-slot binding-size
))
359 (loadw value bsp
(- binding-value-slot binding-size
))
360 (storew value symbol symbol-value-slot other-pointer-lowtag
)
361 (storew 0 bsp
(- binding-symbol-slot binding-size
))
362 (inst sub bsp
(* binding-size n-word-bytes
))
363 (store-symbol-value bsp
*binding-stack-pointer
*)))
366 (define-vop (unbind-to-here)
367 (:args
(where :scs
(descriptor-reg any-reg
)))
368 (:temporary
(:sc unsigned-reg
) symbol value bsp
#!+sb-thread tls-index
)
370 (load-tl-symbol-value bsp
*binding-stack-pointer
*)
375 (loadw symbol bsp
(- binding-symbol-slot binding-size
))
376 (inst or symbol symbol
)
378 (loadw value bsp
(- binding-value-slot binding-size
))
379 #!-sb-thread
(storew value symbol symbol-value-slot other-pointer-lowtag
)
382 tls-index symbol symbol-tls-index-slot other-pointer-lowtag
)
383 #!+sb-thread
(inst fs-segment-prefix
)
384 #!+sb-thread
(inst mov
(make-ea :dword
:scale
1 :index tls-index
) value
)
385 (storew 0 bsp
(- binding-symbol-slot binding-size
))
388 (inst sub bsp
(* binding-size n-word-bytes
))
391 ;; we're done with value, so can use it as a temporary
392 (store-tl-symbol-value bsp
*binding-stack-pointer
* value
)
398 ;;;; closure indexing
400 (define-full-reffer closure-index-ref
*
401 closure-info-offset fun-pointer-lowtag
402 (any-reg descriptor-reg
) * %closure-index-ref
)
404 (define-full-setter set-funcallable-instance-info
*
405 funcallable-instance-info-offset fun-pointer-lowtag
406 (any-reg descriptor-reg
) * %set-funcallable-instance-info
)
408 (define-full-reffer funcallable-instance-info
*
409 funcallable-instance-info-offset fun-pointer-lowtag
410 (descriptor-reg any-reg
) * %funcallable-instance-info
)
412 (define-vop (funcallable-instance-lexenv cell-ref
)
413 (:variant funcallable-instance-lexenv-slot fun-pointer-lowtag
))
415 (define-vop (closure-ref slot-ref
)
416 (:variant closure-info-offset fun-pointer-lowtag
))
418 (define-vop (closure-init slot-set
)
419 (:variant closure-info-offset fun-pointer-lowtag
))
421 ;;;; value cell hackery
423 (define-vop (value-cell-ref cell-ref
)
424 (:variant value-cell-value-slot other-pointer-lowtag
))
426 (define-vop (value-cell-set cell-set
)
427 (:variant value-cell-value-slot other-pointer-lowtag
))
429 ;;;; structure hackery
431 (define-vop (instance-length)
433 (:translate %instance-length
)
434 (:args
(struct :scs
(descriptor-reg)))
435 (:results
(res :scs
(unsigned-reg)))
436 (:result-types positive-fixnum
)
438 (loadw res struct
0 instance-pointer-lowtag
)
439 (inst shr res n-widetag-bits
)))
441 (define-vop (instance-ref slot-ref
)
442 (:variant instance-slots-offset instance-pointer-lowtag
)
444 (:translate %instance-ref
)
445 (:arg-types instance
(:constant index
)))
447 (define-vop (instance-set slot-set
)
449 (:translate %instance-set
)
450 (:variant instance-slots-offset instance-pointer-lowtag
)
451 (:arg-types instance
(:constant index
) *))
453 (define-full-reffer instance-index-ref
* instance-slots-offset
454 instance-pointer-lowtag
(any-reg descriptor-reg
) * %instance-ref
)
456 (define-full-setter instance-index-set
* instance-slots-offset
457 instance-pointer-lowtag
(any-reg descriptor-reg
) * %instance-set
)
460 (defknown %instance-set-conditional
(instance index t t
) t
463 (define-vop (instance-set-conditional)
464 (:translate %instance-set-conditional
)
465 (:args
(object :scs
(descriptor-reg) :to
:eval
)
466 (slot :scs
(any-reg) :to
:result
)
467 (old-value :scs
(descriptor-reg any-reg
) :target eax
)
468 (new-value :scs
(descriptor-reg any-reg
)))
469 (:arg-types instance positive-fixnum
* *)
470 (:temporary
(:sc descriptor-reg
:offset eax-offset
471 :from
(:argument
2) :to
:result
:target result
) eax
)
472 (:results
(result :scs
(descriptor-reg any-reg
)))
473 ;(:guard (backend-featurep :i486))
478 (inst cmpxchg
(make-ea :dword
:base object
:index slot
:scale
1
479 :disp
(- (* instance-slots-offset n-word-bytes
)
480 instance-pointer-lowtag
))
486 ;;;; code object frobbing
488 (define-full-reffer code-header-ref
* 0 other-pointer-lowtag
489 (any-reg descriptor-reg
) * code-header-ref
)
491 (define-full-setter code-header-set
* 0 other-pointer-lowtag
492 (any-reg descriptor-reg
) * code-header-set
)