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 word-bytes) lowtag))
41 (make-ea :dword :base object
42 :disp (- (* offset word-bytes) lowtag))
43 (+ nil-value (static-symbol-offset val))))
46 (make-ea :dword :base object
47 :disp (- (* offset word-bytes) lowtag))
48 (logior (ash (char-code val) type-bits)
50 ;; Else, value not immediate.
51 (storew value object offset lowtag))))
53 ;;;; symbol hacking VOPs
55 ;;; these next two cf the sparc version, by jrd.
56 ;;; FIXME: Deref this ^ reference.
58 ;;; The compiler likes to be able to directly SET symbols.
59 (define-vop (set cell-set)
60 (:variant symbol-value-slot other-pointer-type))
62 ;;; Do a cell ref with an error check for being unbound.
63 (define-vop (checked-cell-ref)
64 (:args (object :scs (descriptor-reg) :target obj-temp))
65 (:results (value :scs (descriptor-reg any-reg)))
68 (:save-p :compute-only)
69 (:temporary (:sc descriptor-reg :from (:argument 0)) obj-temp))
71 ;;; With Symbol-Value, we check that the value isn't the trap object. So
72 ;;; Symbol-Value of NIL is NIL.
73 (define-vop (symbol-value)
74 (:translate symbol-value)
76 (:args (object :scs (descriptor-reg) :to (:result 1)))
77 (:results (value :scs (descriptor-reg any-reg)))
79 (:save-p :compute-only)
81 (let ((err-lab (generate-error-code vop unbound-symbol-error object)))
82 (loadw value object symbol-value-slot other-pointer-type)
83 (inst cmp value unbound-marker-type)
84 (inst jmp :e err-lab))))
86 (define-vop (fast-symbol-value cell-ref)
87 (:variant symbol-value-slot other-pointer-type)
89 (:translate symbol-value))
91 (defknown fast-symbol-value-xadd (symbol fixnum) fixnum ())
92 (define-vop (fast-symbol-value-xadd cell-xadd)
93 (:variant symbol-value-slot other-pointer-type)
95 (:translate fast-symbol-value-xadd)
96 (:arg-types * tagged-num))
101 (:args (object :scs (descriptor-reg)))
104 (:temporary (:sc descriptor-reg :from (:argument 0)) value)
106 (loadw value object symbol-value-slot other-pointer-type)
107 (inst cmp value unbound-marker-type)
108 (inst jmp (if not-p :e :ne) target)))
110 (define-vop (symbol-hash)
112 (:translate symbol-hash)
113 (:args (symbol :scs (descriptor-reg)))
114 (:results (res :scs (any-reg)))
115 (:result-types positive-fixnum)
117 ;; The symbol-hash slot of NIL holds NIL because it is also the cdr slot,
118 ;; so we have to strip off the two low bits to make sure it is a fixnum.
120 ;; FIXME: Is this still true? It seems to me from my reading of
121 ;; the DEFINE-PRIMITIVE-OBJECT in objdef.lisp that the symbol-hash
122 ;; is the second slot, and offset 0 = tags and stuff (and CAR slot in
123 ;; a CONS), offset 1 = value slot (and CDR slot in a CONS), and
124 ;; offset 2 = hash slot.
125 (loadw res symbol symbol-hash-slot other-pointer-type)
126 (inst and res (lognot #b11))))
128 ;;;; fdefinition (fdefn) objects
130 (define-vop (fdefn-function cell-ref) ; /pfw - alpha
131 (:variant fdefn-function-slot other-pointer-type))
133 (define-vop (safe-fdefn-function)
134 (:args (object :scs (descriptor-reg) :to (:result 1)))
135 (:results (value :scs (descriptor-reg any-reg)))
137 (:save-p :compute-only)
139 (loadw value object fdefn-function-slot other-pointer-type)
140 (inst cmp value nil-value)
141 ;; FIXME: UNDEFINED-SYMBOL-ERROR seems to actually be for symbols with no
142 ;; function value, not, as the name might suggest, symbols with no ordinary
143 ;; value. Perhaps the name could be made more mnemonic?
144 (let ((err-lab (generate-error-code vop undefined-symbol-error object)))
145 (inst jmp :e err-lab))))
147 (define-vop (set-fdefn-function)
149 (:translate (setf fdefn-function))
150 (:args (function :scs (descriptor-reg) :target result)
151 (fdefn :scs (descriptor-reg)))
152 (:temporary (:sc unsigned-reg) raw)
153 (:temporary (:sc byte-reg) type)
154 (:results (result :scs (descriptor-reg)))
156 (load-type type function (- function-pointer-type))
158 (make-ea :byte :base function
159 :disp (- (* function-code-offset word-bytes)
160 function-pointer-type)))
161 (inst cmp type function-header-type)
162 (inst jmp :e normal-fn)
163 (inst lea raw (make-fixup (extern-alien-name "closure_tramp") :foreign))
165 (storew function fdefn fdefn-function-slot other-pointer-type)
166 (storew raw fdefn fdefn-raw-addr-slot other-pointer-type)
167 (move result function)))
169 (define-vop (fdefn-makunbound)
171 (:translate fdefn-makunbound)
172 (:args (fdefn :scs (descriptor-reg) :target result))
173 (:results (result :scs (descriptor-reg)))
175 (storew nil-value fdefn fdefn-function-slot other-pointer-type)
176 (storew (make-fixup (extern-alien-name "undefined_tramp") :foreign)
177 fdefn fdefn-raw-addr-slot other-pointer-type)
178 (move result fdefn)))
180 ;;;; binding and unbinding
182 ;;; BIND -- Establish VAL as a binding for SYMBOL. Save the old value and
183 ;;; the symbol on the binding stack and stuff the new value into the
187 (:args (val :scs (any-reg descriptor-reg))
188 (symbol :scs (descriptor-reg)))
189 (:temporary (:sc unsigned-reg) temp bsp)
191 (load-symbol-value bsp *binding-stack-pointer*)
192 (loadw temp symbol symbol-value-slot other-pointer-type)
193 (inst add bsp (* binding-size word-bytes))
194 (store-symbol-value bsp *binding-stack-pointer*)
195 (storew temp bsp (- binding-value-slot binding-size))
196 (storew symbol bsp (- binding-symbol-slot binding-size))
197 (storew val symbol symbol-value-slot other-pointer-type)))
200 (:temporary (:sc unsigned-reg) symbol value bsp)
202 (load-symbol-value bsp *binding-stack-pointer*)
203 (loadw symbol bsp (- binding-symbol-slot binding-size))
204 (loadw value bsp (- binding-value-slot binding-size))
205 (storew value symbol symbol-value-slot other-pointer-type)
206 (storew 0 bsp (- binding-symbol-slot binding-size))
207 (inst sub bsp (* binding-size word-bytes))
208 (store-symbol-value bsp *binding-stack-pointer*)))
210 (define-vop (unbind-to-here)
211 (:args (where :scs (descriptor-reg any-reg)))
212 (:temporary (:sc unsigned-reg) symbol value bsp)
214 (load-symbol-value bsp *binding-stack-pointer*)
219 (loadw symbol bsp (- binding-symbol-slot binding-size))
220 (inst or symbol symbol)
222 (loadw value bsp (- binding-value-slot binding-size))
223 (storew value symbol symbol-value-slot other-pointer-type)
224 (storew 0 bsp (- binding-symbol-slot binding-size))
227 (inst sub bsp (* binding-size word-bytes))
230 (store-symbol-value bsp *binding-stack-pointer*)
234 ;;;; closure indexing
236 (define-full-reffer closure-index-ref *
237 closure-info-offset function-pointer-type
238 (any-reg descriptor-reg) * %closure-index-ref)
240 (define-full-setter set-funcallable-instance-info *
241 funcallable-instance-info-offset function-pointer-type
242 (any-reg descriptor-reg) * %set-funcallable-instance-info)
244 (define-full-reffer funcallable-instance-info *
245 funcallable-instance-info-offset function-pointer-type
246 (descriptor-reg any-reg) * %funcallable-instance-info)
248 (define-vop (funcallable-instance-lexenv cell-ref)
249 (:variant funcallable-instance-lexenv-slot function-pointer-type))
251 (define-vop (closure-ref slot-ref)
252 (:variant closure-info-offset function-pointer-type))
254 (define-vop (closure-init slot-set)
255 (:variant closure-info-offset function-pointer-type))
257 ;;;; value cell hackery
259 (define-vop (value-cell-ref cell-ref)
260 (:variant value-cell-value-slot other-pointer-type))
262 (define-vop (value-cell-set cell-set)
263 (:variant value-cell-value-slot other-pointer-type))
265 ;;;; structure hackery
267 (define-vop (instance-length)
269 (:translate %instance-length)
270 (:args (struct :scs (descriptor-reg)))
271 (:results (res :scs (unsigned-reg)))
272 (:result-types positive-fixnum)
274 (loadw res struct 0 instance-pointer-type)
275 (inst shr res type-bits)))
277 (define-vop (instance-ref slot-ref)
278 (:variant instance-slots-offset instance-pointer-type)
280 (:translate %instance-ref)
281 (:arg-types instance (:constant index)))
283 (define-vop (instance-set slot-set)
285 (:translate %instance-set)
286 (:variant instance-slots-offset instance-pointer-type)
287 (:arg-types instance (:constant index) *))
289 (define-full-reffer instance-index-ref * instance-slots-offset
290 instance-pointer-type (any-reg descriptor-reg) * %instance-ref)
292 (define-full-setter instance-index-set * instance-slots-offset
293 instance-pointer-type (any-reg descriptor-reg) * %instance-set)
295 (defknown sb!kernel::%instance-set-conditional (instance index t t) t
298 (define-vop (instance-set-conditional-c slot-set-conditional)
300 (:translate sb!kernel::%instance-set-conditional)
301 (:variant instance-slots-offset instance-pointer-type)
302 (:arg-types instance (:constant index) * *))
304 (define-vop (instance-set-conditional)
305 (:translate sb!kernel::%instance-set-conditional)
306 (:args (object :scs (descriptor-reg) :to :eval)
307 (slot :scs (any-reg) :to :result)
308 (old-value :scs (descriptor-reg any-reg) :target eax)
309 (new-value :scs (descriptor-reg any-reg) :target temp))
310 (:arg-types instance positive-fixnum * *)
311 (:temporary (:sc descriptor-reg :offset eax-offset
312 :from (:argument 1) :to :result :target result) eax)
313 (:temporary (:sc descriptor-reg :from (:argument 2) :to :result) temp)
314 (:results (result :scs (descriptor-reg)))
318 (move temp new-value)
319 (inst cmpxchg (make-ea :dword :base object :index slot :scale 1
320 :disp (- (* instance-slots-offset word-bytes)
321 instance-pointer-type))
325 (defknown %instance-xadd (instance index fixnum) fixnum ())
326 (define-vop (instance-xadd-c slot-xadd)
328 (:translate %instance-xadd)
329 (:variant instance-slots-offset instance-pointer-type)
330 (:arg-types instance (:constant index) tagged-num))
332 ;;;; code object frobbing
334 (define-full-reffer code-header-ref * 0 other-pointer-type
335 (any-reg descriptor-reg) * code-header-ref)
337 (define-full-setter code-header-set * 0 other-pointer-type
338 (any-reg descriptor-reg) * code-header-set)