3cad61b780c31d3f4d4ff46550ac3cac339f1230
[sbcl.git] / src / compiler / sparc / cell.lisp
1 ;;;; the VM definition of various primitive memory access VOPs for the
2 ;;;; Sparc
3
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
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.
12
13 (in-package "SB!VM")
14 \f
15 ;;;; data object ref/set stuff.
16 (define-vop (slot)
17   (:args (object :scs (descriptor-reg)))
18   (:info name offset lowtag)
19   (:ignore name)
20   (:results (result :scs (descriptor-reg any-reg)))
21   (:generator 1
22     (loadw result object offset lowtag)))
23
24 (define-vop (set-slot)
25   (:args (object :scs (descriptor-reg))
26          (value :scs (descriptor-reg any-reg)))
27   (:info name offset lowtag)
28   (:ignore name)
29   (:results)
30   (:generator 1
31     (storew value object offset lowtag)))
32 \f
33 ;;;; Symbol hacking VOPs:
34
35 ;;; The compiler likes to be able to directly SET symbols.
36 (define-vop (set cell-set)
37   (:variant symbol-value-slot other-pointer-lowtag))
38
39 ;;; Do a cell ref with an error check for being unbound.
40 (define-vop (checked-cell-ref)
41   (:args (object :scs (descriptor-reg) :target obj-temp))
42   (:results (value :scs (descriptor-reg any-reg)))
43   (:policy :fast-safe)
44   (:vop-var vop)
45   (:save-p :compute-only)
46   (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp))
47
48 ;;; With Symbol-Value, we check that the value isn't the trap object.
49 ;;; So Symbol-Value of NIL is NIL.
50 (define-vop (symbol-value checked-cell-ref)
51   (:translate symbol-value)
52   (:generator 9
53     (move obj-temp object)
54     (loadw value obj-temp symbol-value-slot other-pointer-lowtag)
55     (let ((err-lab (generate-error-code vop unbound-symbol-error obj-temp)))
56       (inst cmp value unbound-marker-widetag)
57       (inst b :eq err-lab)
58       (inst nop))))
59
60 ;;; Like CHECKED-CELL-REF, only we are a predicate to see if the cell
61 ;;; is bound.
62 (define-vop (boundp-frob)
63   (:args (object :scs (descriptor-reg)))
64   (:conditional)
65   (:info target not-p)
66   (:policy :fast-safe)
67   (:temporary (:scs (descriptor-reg)) value))
68
69 (define-vop (boundp boundp-frob)
70   (:translate boundp)
71   (:generator 9
72     (loadw value object symbol-value-slot other-pointer-lowtag)
73     (inst cmp value unbound-marker-widetag)
74     (inst b (if not-p :eq :ne) target)
75     (inst nop)))
76
77 (define-vop (fast-symbol-value cell-ref)
78   (:variant symbol-value-slot other-pointer-lowtag)
79   (:policy :fast)
80   (:translate symbol-value))
81
82 (define-vop (symbol-hash)
83   (:policy :fast-safe)
84   (:translate symbol-hash)
85   (:args (symbol :scs (descriptor-reg)))
86   (:results (res :scs (any-reg)))
87   (:result-types positive-fixnum)
88   (:generator 2
89     ;; The symbol-hash slot of NIL holds NIL because it is also the
90     ;; cdr slot, so we have to strip off the two low bits to make sure
91     ;; it is a fixnum.  The lowtag selection magic that is required to
92     ;; ensure this is explained in the comment in objdef.lisp
93     (loadw res symbol symbol-hash-slot other-pointer-lowtag)
94     (inst andn res res fixnum-tag-mask)))
95 \f
96 ;;;; FDEFINITION (fdefn) objects.
97 (define-vop (fdefn-fun cell-ref)
98   (:variant fdefn-fun-slot other-pointer-lowtag))
99
100 (define-vop (safe-fdefn-fun)
101   (:args (object :scs (descriptor-reg) :target obj-temp))
102   (:results (value :scs (descriptor-reg any-reg)))
103   (:vop-var vop)
104   (:save-p :compute-only)
105   (:temporary (:scs (descriptor-reg) :from (:argument 0)) obj-temp)
106   (:generator 10
107     (move obj-temp object)
108     (loadw value obj-temp fdefn-fun-slot other-pointer-lowtag)
109     (inst cmp value null-tn)
110     (let ((err-lab (generate-error-code vop undefined-fun-error obj-temp)))
111       (inst b :eq err-lab))
112     (inst nop)))
113
114 (define-vop (set-fdefn-fun)
115   (:policy :fast-safe)
116   (:translate (setf fdefn-fun))
117   (:args (function :scs (descriptor-reg) :target result)
118          (fdefn :scs (descriptor-reg)))
119   (:temporary (:scs (interior-reg)) lip)
120   (:temporary (:scs (non-descriptor-reg)) type)
121   (:results (result :scs (descriptor-reg)))
122   (:generator 38
123     (let ((normal-fn (gen-label)))
124       (load-type type function (- fun-pointer-lowtag))
125       (inst cmp type simple-fun-header-widetag)
126       (inst b :eq normal-fn)
127       (inst move lip function)
128       (inst li lip (make-fixup "closure_tramp" :foreign))
129       (emit-label normal-fn)
130       (storew function fdefn fdefn-fun-slot other-pointer-lowtag)
131       (storew lip fdefn fdefn-raw-addr-slot other-pointer-lowtag)
132       (move result function))))
133
134 (define-vop (fdefn-makunbound)
135   (:policy :fast-safe)
136   (:translate fdefn-makunbound)
137   (:args (fdefn :scs (descriptor-reg) :target result))
138   (:temporary (:scs (non-descriptor-reg)) temp)
139   (:results (result :scs (descriptor-reg)))
140   (:generator 38
141     (storew null-tn fdefn fdefn-fun-slot other-pointer-lowtag)
142     (inst li temp (make-fixup "undefined_tramp" :foreign))
143     (storew temp fdefn fdefn-raw-addr-slot other-pointer-lowtag)
144     (move result fdefn)))
145
146
147 \f
148 ;;;; Binding and Unbinding.
149
150 ;;; Establish VAL as a binding for SYMBOL.  Save the old value and the
151 ;;; symbol on the binding stack and stuff the new value into the
152 ;;; symbol.
153 (define-vop (bind)
154   (:args (val :scs (any-reg descriptor-reg))
155          (symbol :scs (descriptor-reg)))
156   (:temporary (:scs (descriptor-reg)) temp)
157   (:generator 5
158     (loadw temp symbol symbol-value-slot other-pointer-lowtag)
159     (inst add bsp-tn bsp-tn (* 2 n-word-bytes))
160     (storew temp bsp-tn (- binding-value-slot binding-size))
161     (storew symbol bsp-tn (- binding-symbol-slot binding-size))
162     (storew val symbol symbol-value-slot other-pointer-lowtag)))
163
164 (define-vop (unbind)
165   (:temporary (:scs (descriptor-reg)) symbol value)
166   (:generator 0
167     (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
168     (loadw value bsp-tn (- binding-value-slot binding-size))
169     (storew value symbol symbol-value-slot other-pointer-lowtag)
170     (storew zero-tn bsp-tn (- binding-symbol-slot binding-size))
171     (inst sub bsp-tn bsp-tn (* 2 n-word-bytes))))
172
173 (define-vop (unbind-to-here)
174   (:args (arg :scs (descriptor-reg any-reg) :target where))
175   (:temporary (:scs (any-reg) :from (:argument 0)) where)
176   (:temporary (:scs (descriptor-reg)) symbol value)
177   (:generator 0
178     (let ((loop (gen-label))
179           (skip (gen-label))
180           (done (gen-label)))
181       (move where arg)
182       (inst cmp where bsp-tn)
183       (inst b :eq done)
184       (inst nop)
185
186       (emit-label loop)
187       (loadw symbol bsp-tn (- binding-symbol-slot binding-size))
188       (inst cmp symbol)
189       (inst b :eq skip)
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
194       (emit-label skip)
195       (inst sub bsp-tn bsp-tn (* 2 n-word-bytes))
196       (inst cmp where bsp-tn)
197       (inst b :ne loop)
198       (inst nop)
199
200       (emit-label done))))
201 \f
202 ;;;; closure indexing.
203
204 (define-vop (closure-index-ref word-index-ref)
205   (:variant closure-info-offset fun-pointer-lowtag)
206   (:translate %closure-index-ref))
207
208 (define-vop (funcallable-instance-info word-index-ref)
209   (:variant funcallable-instance-info-offset fun-pointer-lowtag)
210   (:translate %funcallable-instance-info))
211
212 (define-vop (set-funcallable-instance-info word-index-set)
213   (:variant funcallable-instance-info-offset fun-pointer-lowtag)
214   (:translate %set-funcallable-instance-info))
215
216 (define-vop (funcallable-instance-lexenv cell-ref)
217   (:variant funcallable-instance-lexenv-slot fun-pointer-lowtag))
218
219
220 (define-vop (closure-ref slot-ref)
221   (:variant closure-info-offset fun-pointer-lowtag))
222
223 (define-vop (closure-init slot-set)
224   (:variant closure-info-offset fun-pointer-lowtag))
225 \f
226 ;;;; value cell hackery.
227
228 (define-vop (value-cell-ref cell-ref)
229   (:variant value-cell-value-slot other-pointer-lowtag))
230
231 (define-vop (value-cell-set cell-set)
232   (:variant value-cell-value-slot other-pointer-lowtag))
233 \f
234 ;;;; instance hackery:
235
236 (define-vop (instance-length)
237   (:policy :fast-safe)
238   (:translate %instance-length)
239   (:args (struct :scs (descriptor-reg)))
240   (:temporary (:scs (non-descriptor-reg)) temp)
241   (:results (res :scs (unsigned-reg)))
242   (:result-types positive-fixnum)
243   (:generator 4
244     (loadw temp struct 0 instance-pointer-lowtag)
245     (inst srl res temp n-widetag-bits)))
246
247 (define-vop (instance-ref slot-ref)
248   (:variant instance-slots-offset instance-pointer-lowtag)
249   (:policy :fast-safe)
250   (:translate %instance-ref)
251   (:arg-types * (:constant index)))
252
253 ;;; This VOP has no :results; however, %instance-set must return a
254 ;;; value. This caused, in the forward port to 0.7.x, an error in
255 ;;; !fdefn-cold-init: "argument X is not a REAL: NIL". This VOP is
256 ;;; commented out for now, pending the addition of checking code to
257 ;;; the define-vop machinery to ascertain that this was indeed the
258 ;;; problem. -- CSR, 2002-02-12
259 #+nil
260 (define-vop (instance-set slot-set)
261   (:policy :fast-safe)
262   (:translate %instance-set)
263   (:variant instance-slots-offset instance-pointer-lowtag)
264   (:arg-types * (:constant index) *))
265
266 (define-vop (instance-index-ref word-index-ref)
267   (:policy :fast-safe) 
268   (:translate %instance-ref)
269   (:variant instance-slots-offset instance-pointer-lowtag)
270   (:arg-types * positive-fixnum))
271
272 (define-vop (instance-index-set word-index-set)
273   (:policy :fast-safe) 
274   (:translate %instance-set)
275   (:variant instance-slots-offset instance-pointer-lowtag)
276   (:arg-types * positive-fixnum *))
277 \f
278 ;;;; Code object frobbing.
279
280 (define-vop (code-header-ref word-index-ref)
281   (:translate code-header-ref)
282   (:policy :fast-safe)
283   (:variant 0 other-pointer-lowtag))
284
285 (define-vop (code-header-set word-index-set)
286   (:translate code-header-set)
287   (:policy :fast-safe)
288   (:variant 0 other-pointer-lowtag))
289