62d6f4c867355dd01766d727130b0daec0c16e57
[sbcl.git] / src / compiler / sparc / system.lisp
1 ;;;; Sparc VM definitions of various system hacking operations
2
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
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.
11
12 (in-package "SB!VM")
13 \f
14 ;;;; type frobbing VOPs
15
16 (define-vop (lowtag-of)
17   (:translate lowtag-of)
18   (:policy :fast-safe)
19   (:args (object :scs (any-reg descriptor-reg)))
20   (:results (result :scs (unsigned-reg)))
21   (:result-types positive-fixnum)
22   (:generator 1
23     (inst and result object lowtag-mask)))
24
25 (define-vop (widetag-of)
26   (:translate widetag-of)
27   (:policy :fast-safe)
28   (:args (object :scs (descriptor-reg) :to (:eval 1)))
29   (:results (result :scs (unsigned-reg) :from (:eval 0)))
30   (:result-types positive-fixnum)
31   (:generator 6
32     ;; Grab the lowtag.
33     (inst andcc result object lowtag-mask)
34     ;; Check for various pointer types.
35     (inst cmp result list-pointer-lowtag)
36     (inst b :eq done)
37     (inst cmp result other-pointer-lowtag)
38     (inst b :eq other-pointer)
39     (inst cmp result fun-pointer-lowtag)
40     (inst b :eq function-pointer)
41     (inst cmp result instance-pointer-lowtag)
42     (inst b :eq done)
43     ;; Okay, it is an immediate.  If fixnum, we want zero.  Otherwise,
44     ;; we want the low 8 bits.
45     (inst andcc zero-tn object fixnum-tag-mask)
46     (inst b :eq done)
47     (inst li result 0)
48     ;; It wasn't a fixnum, so get the low 8 bits.
49     (inst b done)
50     (inst and result object widetag-mask)
51
52     FUNCTION-POINTER
53     (inst b done)
54     (load-type result object (- fun-pointer-lowtag))
55
56     OTHER-POINTER
57     (load-type result object (- other-pointer-lowtag))
58
59     DONE))
60
61
62 (define-vop (fun-subtype)
63   (:translate fun-subtype)
64   (:policy :fast-safe)
65   (:args (function :scs (descriptor-reg)))
66   (:results (result :scs (unsigned-reg)))
67   (:result-types positive-fixnum)
68   (:generator 6
69     (load-type result function (- fun-pointer-lowtag))))
70
71 ;;; Is this VOP dead? I can't see anywhere that it is used... -- CSR,
72 ;;; 2002-06-21
73 (define-vop (set-fun-subtype)
74   (:translate (setf fun-subtype))
75   (:policy :fast-safe)
76   (:args (type :scs (unsigned-reg) :target result)
77          (function :scs (descriptor-reg)))
78   (:arg-types positive-fixnum *)
79   (:results (result :scs (unsigned-reg)))
80   (:result-types positive-fixnum)
81   (:generator 6
82     ;; FIXME: I don't understand what this hardcoded 3 is doing
83     ;; here. -- CSR, 2002-02-08
84     (inst stb type function (- 3 fun-pointer-lowtag))
85     (move result type)))
86
87 (define-vop (get-header-data)
88   (:translate get-header-data)
89   (:policy :fast-safe)
90   (:args (x :scs (descriptor-reg)))
91   (:results (res :scs (unsigned-reg)))
92   (:result-types positive-fixnum)
93   (:generator 6
94     (loadw res x 0 other-pointer-lowtag)
95     (inst srl res res n-widetag-bits)))
96
97 (define-vop (get-closure-length)
98   (:translate get-closure-length)
99   (:policy :fast-safe)
100   (:args (x :scs (descriptor-reg)))
101   (:results (res :scs (unsigned-reg)))
102   (:result-types positive-fixnum)
103   (:generator 6
104     (loadw res x 0 fun-pointer-lowtag)
105     (inst srl res res n-widetag-bits)))
106
107 (define-vop (set-header-data)
108   (:translate set-header-data)
109   (:policy :fast-safe)
110   (:args (x :scs (descriptor-reg) :target res)
111          (data :scs (any-reg immediate zero)))
112   (:arg-types * positive-fixnum)
113   (:results (res :scs (descriptor-reg)))
114   (:temporary (:scs (non-descriptor-reg)) t1 t2)
115   (:generator 6
116     (loadw t1 x 0 other-pointer-lowtag)
117     (inst and t1 widetag-mask)
118     (sc-case data
119       (any-reg
120        (inst sll t2 data (- n-widetag-bits n-fixnum-tag-bits))
121        (inst or t1 t2))
122       (immediate
123        (inst or t1 (ash (tn-value data) n-widetag-bits)))
124       (zero))
125     (storew t1 x 0 other-pointer-lowtag)
126     (move res x)))
127
128
129 (define-vop (pointer-hash)
130   (:translate pointer-hash)
131   (:args (ptr :scs (any-reg descriptor-reg)))
132   (:results (res :scs (any-reg descriptor-reg)))
133   (:policy :fast-safe)
134   (:generator 1
135     ;; FIXME: It would be better if this would mask the lowtag,
136     ;; and shift the result into a positive fixnum like on x86.
137     (inst sll res ptr 3)
138     (inst srl res res 1)))
139
140 (define-vop (make-other-immediate-type)
141   (:args (val :scs (any-reg descriptor-reg))
142          (type :scs (any-reg descriptor-reg immediate)
143                :target temp))
144   (:results (res :scs (any-reg descriptor-reg)))
145   (:temporary (:scs (non-descriptor-reg)) temp)
146   (:generator 2
147     (sc-case type
148       (immediate
149        (inst sll temp val n-widetag-bits)
150        (inst or res temp (tn-value type)))
151       (t
152        (inst sra temp type n-fixnum-tag-bits)
153        (inst sll res val (- n-widetag-bits n-fixnum-tag-bits))
154        (inst or res res temp)))))
155
156 \f
157 ;;;; allocation
158
159 (define-vop (dynamic-space-free-pointer)
160   (:results (int :scs (sap-reg)))
161   (:result-types system-area-pointer)
162   (:translate dynamic-space-free-pointer)
163   (:policy :fast-safe)
164   (:generator 1
165     (move int alloc-tn)))
166
167 (define-vop (binding-stack-pointer-sap)
168   (:results (int :scs (sap-reg)))
169   (:result-types system-area-pointer)
170   (:translate binding-stack-pointer-sap)
171   (:policy :fast-safe)
172   (:generator 1
173     (move int bsp-tn)))
174
175 (define-vop (control-stack-pointer-sap)
176   (:results (int :scs (sap-reg)))
177   (:result-types system-area-pointer)
178   (:translate control-stack-pointer-sap)
179   (:policy :fast-safe)
180   (:generator 1
181     (move int csp-tn)))
182
183 \f
184 ;;;; code object frobbing.
185
186 (define-vop (code-instructions)
187   (:translate code-instructions)
188   (:policy :fast-safe)
189   (:args (code :scs (descriptor-reg)))
190   (:temporary (:scs (non-descriptor-reg)) ndescr)
191   (:results (sap :scs (sap-reg)))
192   (:result-types system-area-pointer)
193   (:generator 10
194     (loadw ndescr code 0 other-pointer-lowtag)
195     (inst srl ndescr n-widetag-bits)
196     (inst sll ndescr word-shift)
197     (inst sub ndescr other-pointer-lowtag)
198     (inst add sap code ndescr)))
199
200 (define-vop (compute-fun)
201   (:args (code :scs (descriptor-reg))
202          (offset :scs (signed-reg unsigned-reg)))
203   (:arg-types * positive-fixnum)
204   (:results (func :scs (descriptor-reg)))
205   (:temporary (:scs (non-descriptor-reg)) ndescr)
206   (:generator 10
207     (loadw ndescr code 0 other-pointer-lowtag)
208     (inst srl ndescr n-widetag-bits)
209     (inst sll ndescr word-shift)
210     (inst add ndescr offset)
211     (inst add ndescr (- fun-pointer-lowtag other-pointer-lowtag))
212     (inst add func code ndescr)))
213
214
215 \f
216 ;;;; other random VOPs.
217
218
219 (defknown sb!unix::receive-pending-interrupt () (values))
220 (define-vop (sb!unix::receive-pending-interrupt)
221   (:policy :fast-safe)
222   (:translate sb!unix::receive-pending-interrupt)
223   (:generator 1
224     (inst unimp pending-interrupt-trap)))
225
226 #!+sb-thread
227 (error "write a VOP for CURRENT-THREAD-OFFSET-SAP")
228
229 (define-vop (halt)
230   (:generator 1
231     (inst unimp halt-trap)))
232
233
234 \f
235 ;;;; dynamic VOP count collection support
236
237 (define-vop (count-me)
238   (:args (count-vector :scs (descriptor-reg)))
239   (:info index)
240   (:temporary (:scs (non-descriptor-reg)) count)
241   (:generator 1
242     (let ((offset
243            (- (* (+ index vector-data-offset) n-word-bytes)
244               other-pointer-lowtag)))
245       (aver (typep offset '(signed-byte 13)))
246       (inst ld count count-vector offset)
247       (inst add count 1)
248       (inst st count count-vector offset))))
249
250 ;;;; Dummy definition for a spin-loop hint VOP
251 (define-vop (spin-loop-hint)
252   (:translate spin-loop-hint)
253   (:policy :fast-safe)
254   (:generator 0))