0.pre7.74:
[sbcl.git] / src / compiler / alpha / system.lisp
1 ;;;; Alpha 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 object lowtag-mask result)))
24
25 (define-vop (widetag-of)
26   (:translate widetag-of)
27   (:policy :fast-safe)
28   (:args (object :scs (descriptor-reg)))
29   (:temporary (:scs (non-descriptor-reg)) ndescr)
30   (:results (result :scs (unsigned-reg)))
31   (:result-types positive-fixnum)
32   (:generator 6
33     ;; Pick off objects with headers.
34     (inst and object lowtag-mask result)
35     (inst cmpeq result other-pointer-lowtag ndescr)
36     (inst bne ndescr other-ptr)
37     (inst cmpeq result fun-pointer-lowtag ndescr)
38     (inst bne ndescr function-ptr)
39
40     ;; Pick off structure and list pointers.
41     (inst blbs object done)
42
43     ;; Pick off fixnums.
44     (inst and object 3 result)
45     (inst beq result done)
46
47     ;; Must be an other immediate.
48     (inst and object widetag-mask result)
49     (inst br zero-tn done)
50
51     FUNCTION-PTR
52     (load-type result object (- fun-pointer-lowtag))
53     (inst br zero-tn done)
54
55     OTHER-PTR
56     (load-type result object (- other-pointer-lowtag))
57       
58     DONE))
59
60 (define-vop (function-subtype)
61   (:translate function-subtype)
62   (:policy :fast-safe)
63   (:args (function :scs (descriptor-reg)))
64   (:results (result :scs (unsigned-reg)))
65   (:result-types positive-fixnum)
66   (:generator 6
67     (load-type result function (- fun-pointer-lowtag))))
68
69 (define-vop (set-function-subtype)
70   (:translate (setf function-subtype))
71   (:policy :fast-safe)
72   (:args (type :scs (unsigned-reg) :target result)
73          (function :scs (descriptor-reg)))
74   (:arg-types positive-fixnum *)
75   (:temporary (:scs (non-descriptor-reg)) temp)
76   (:results (result :scs (unsigned-reg)))
77   (:result-types positive-fixnum)
78   (:generator 6
79     (inst ldl temp (- fun-pointer-lowtag) function)
80     (inst and temp #xff temp)
81     (inst bis type temp temp)
82     (inst stl temp (- fun-pointer-lowtag) function)
83     (move type result)))
84
85
86 (define-vop (get-header-data)
87   (:translate get-header-data)
88   (:policy :fast-safe)
89   (:args (x :scs (descriptor-reg)))
90   (:results (res :scs (unsigned-reg)))
91   (:result-types positive-fixnum)
92   (:generator 6
93     (loadw res x 0 other-pointer-lowtag)
94     (inst srl res n-widetag-bits res)))
95
96 (define-vop (get-closure-length)
97   (:translate get-closure-length)
98   (:policy :fast-safe)
99   (:args (x :scs (descriptor-reg)))
100   (:results (res :scs (unsigned-reg)))
101   (:result-types positive-fixnum)
102   (:generator 6
103     (loadw res x 0 fun-pointer-lowtag)
104     (inst srl res n-widetag-bits res)))
105
106 (define-vop (set-header-data)
107   (:translate set-header-data)
108   (:policy :fast-safe)
109   (:args (x :scs (descriptor-reg) :target res)
110          (data :scs (any-reg immediate zero)))
111   (:arg-types * positive-fixnum)
112   (:results (res :scs (descriptor-reg)))
113   (:temporary (:scs (non-descriptor-reg)) t1 t2)
114   (:generator 6
115     (loadw t1 x 0 other-pointer-lowtag)
116     (inst and t1 widetag-mask t1)
117     (sc-case data
118       (any-reg
119        (inst sll data (- n-widetag-bits 2) t2)
120        (inst bis t1 t2 t1))
121       (immediate
122        (let ((c (ash (tn-value data) n-widetag-bits)))
123          (cond ((<= 0 c (1- (ash 1 8)))
124                 (inst bis t1 c t1))
125                (t
126                 (inst li c t2)
127                 (inst bis t1 t2 t1)))))
128       (zero))
129     (storew t1 x 0 other-pointer-lowtag)
130     (move x res)))
131
132 (define-vop (make-fixnum)
133   (:args (ptr :scs (any-reg descriptor-reg)))
134   (:results (res :scs (any-reg descriptor-reg)))
135   (:generator 1
136     ;;
137     ;; Some code (the hash table code) depends on this returning a
138     ;; positive number so make sure it does.
139     (inst sll ptr 35 res)
140     (inst srl res 33 res)))
141
142 (define-vop (make-other-immediate-type)
143   (:args (val :scs (any-reg descriptor-reg))
144          (type :scs (any-reg descriptor-reg immediate)
145                :target temp))
146   (:results (res :scs (any-reg descriptor-reg)))
147   (:temporary (:scs (non-descriptor-reg)) temp)
148   (:generator 2
149     (sc-case type
150       ((immediate)
151        (inst sll val n-widetag-bits temp)
152        (inst bis temp (tn-value type) res))
153       (t
154        (inst sra type 2 temp)
155        (inst sll val (- n-widetag-bits 2) res)
156        (inst bis res temp res)))))
157
158 \f
159 ;;;; allocation
160
161 (define-vop (dynamic-space-free-pointer)
162   (:results (int :scs (sap-reg)))
163   (:result-types system-area-pointer)
164   (:translate dynamic-space-free-pointer)
165   (:policy :fast-safe)
166   (:generator 1
167     (move alloc-tn int)))
168
169 (define-vop (binding-stack-pointer-sap)
170   (:results (int :scs (sap-reg)))
171   (:result-types system-area-pointer)
172   (:translate binding-stack-pointer-sap)
173   (:policy :fast-safe)
174   (:generator 1
175     (move bsp-tn int)))
176
177 (define-vop (control-stack-pointer-sap)
178   (:results (int :scs (sap-reg)))
179   (:result-types system-area-pointer)
180   (:translate control-stack-pointer-sap)
181   (:policy :fast-safe)
182   (:generator 1
183     (move csp-tn int)))
184
185 \f
186 ;;;; code object frobbing
187
188 (define-vop (code-instructions)
189   (:translate code-instructions)
190   (:policy :fast-safe)
191   (:args (code :scs (descriptor-reg)))
192   (:temporary (:scs (non-descriptor-reg)) ndescr)
193   (:results (sap :scs (sap-reg)))
194   (:result-types system-area-pointer)
195   (:generator 10
196     (loadw ndescr code 0 other-pointer-lowtag)
197     (inst srl ndescr n-widetag-bits ndescr)
198     (inst sll ndescr word-shift ndescr)
199     (inst subq ndescr other-pointer-lowtag ndescr)
200     (inst addq code ndescr sap)))
201
202 (define-vop (compute-function)
203   (:args (code :scs (descriptor-reg))
204          (offset :scs (signed-reg unsigned-reg)))
205   (:arg-types * positive-fixnum)
206   (:results (func :scs (descriptor-reg)))
207   (:temporary (:scs (non-descriptor-reg)) ndescr)
208   (:generator 10
209     (loadw ndescr code 0 other-pointer-lowtag)
210     (inst srl ndescr n-widetag-bits ndescr)
211     (inst sll ndescr word-shift ndescr)
212     (inst addq ndescr offset ndescr)
213     (inst subq ndescr (- other-pointer-lowtag fun-pointer-lowtag) ndescr)
214     (inst addq code ndescr func)))
215 \f
216 ;;;; other random VOPs.
217
218 (defknown sb!unix::do-pending-interrupt () (values))
219 (define-vop (sb!unix::do-pending-interrupt)
220   (:policy :fast-safe)
221   (:translate sb!unix::do-pending-interrupt)
222   (:generator 1
223     (inst gentrap pending-interrupt-trap)))
224
225
226 (define-vop (halt)
227   (:generator 1
228     (inst gentrap halt-trap)))
229 \f
230 ;;;; dynamic vop count collection support
231
232 (define-vop (count-me)
233   (:args (count-vector :scs (descriptor-reg)))
234   (:info index)
235   (:temporary (:scs (non-descriptor-reg)) count)
236   (:generator 1
237     (let ((offset
238            (- (* (+ index vector-data-offset) n-word-bytes)
239               other-pointer-lowtag)))
240       (inst ldl count offset count-vector)
241       (inst addq count 1 count)
242       (inst stl count offset count-vector))))