0.9.3.2:
[sbcl.git] / src / compiler / ppc / system.lisp
1 ;;;; PPC 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 andi. 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 andi. result object lowtag-mask)
34     ;; Check for various pointer types.
35     (inst cmpwi result list-pointer-lowtag)
36     (inst beq done)
37     (inst cmpwi result other-pointer-lowtag)
38     (inst beq other-pointer)
39     (inst cmpwi result fun-pointer-lowtag)
40     (inst beq function-pointer)
41     (inst cmpwi result instance-pointer-lowtag)
42     (inst beq done)
43     ;; Okay, it is an immediate.  If fixnum, we want zero.  Otherwise,
44     ;; we want the low 8 bits.
45     (inst andi. result object #b11)
46     (inst beq done)
47     ;; It wasn't a fixnum, so get the low 8 bits.
48     (inst andi. result object widetag-mask)
49     (inst b done)
50
51     FUNCTION-POINTER
52     (load-type result object (- fun-pointer-lowtag))
53     (inst b done)
54
55     OTHER-POINTER
56     (load-type result object (- other-pointer-lowtag))
57
58     DONE))
59
60
61 (define-vop (fun-subtype)
62   (:translate fun-subtype)
63   (:policy :fast-safe)
64   (:args (function :scs (descriptor-reg)))
65   (:results (result :scs (unsigned-reg)))
66   (:result-types positive-fixnum)
67   (:generator 6
68     (load-type result function (- fun-pointer-lowtag))))
69
70 (define-vop (set-fun-subtype)
71   (:translate (setf fun-subtype))
72   (:policy :fast-safe)
73   (:args (type :scs (unsigned-reg) :target result)
74          (function :scs (descriptor-reg)))
75   (:arg-types positive-fixnum *)
76   (:results (result :scs (unsigned-reg)))
77   (:result-types positive-fixnum)
78   (:generator 6
79     (inst stb type function (- 3 fun-pointer-lowtag))
80     (move result type)))
81
82 (define-vop (get-header-data)
83   (:translate get-header-data)
84   (:policy :fast-safe)
85   (:args (x :scs (descriptor-reg)))
86   (:results (res :scs (unsigned-reg)))
87   (:result-types positive-fixnum)
88   (:generator 6
89     (loadw res x 0 other-pointer-lowtag)
90     (inst srwi res res n-widetag-bits)))
91
92 (define-vop (get-closure-length)
93   (:translate get-closure-length)
94   (:policy :fast-safe)
95   (:args (x :scs (descriptor-reg)))
96   (:results (res :scs (unsigned-reg)))
97   (:result-types positive-fixnum)
98   (:generator 6
99     (loadw res x 0 fun-pointer-lowtag)
100     (inst srwi res res n-widetag-bits)))
101
102 (define-vop (set-header-data)
103   (:translate set-header-data)
104   (:policy :fast-safe)
105   (:args (x :scs (descriptor-reg) :target res)
106          (data :scs (any-reg immediate zero)))
107   (:arg-types * positive-fixnum)
108   (:results (res :scs (descriptor-reg)))
109   (:temporary (:scs (non-descriptor-reg)) t1 t2)
110   (:generator 6
111     (loadw t1 x 0 other-pointer-lowtag)
112     (inst andi. t1 t1 widetag-mask)
113     (sc-case data
114       (any-reg
115        (inst slwi t2 data (- n-widetag-bits 2))
116        (inst or t1 t1 t2))
117       (immediate
118        (inst ori t1 t1 (ash (tn-value data) n-widetag-bits)))
119       (zero))
120     (storew t1 x 0 other-pointer-lowtag)
121     (move res x)))
122
123
124 (define-vop (make-fixnum)
125   (:args (ptr :scs (any-reg descriptor-reg)))
126   (:results (res :scs (any-reg descriptor-reg)))
127   (:generator 1
128     ;;
129     ;; Some code (the hash table code) depends on this returning a
130     ;; positive number so make sure it does.
131     (inst rlwinm res ptr n-fixnum-tag-bits 1 n-positive-fixnum-bits)))
132
133 (define-vop (make-other-immediate-type)
134   (:args (val :scs (any-reg descriptor-reg))
135          (type :scs (any-reg descriptor-reg immediate)
136                :target temp))
137   (:results (res :scs (any-reg descriptor-reg)))
138   (:temporary (:scs (non-descriptor-reg)) temp)
139   (:generator 2
140     (sc-case type
141       (immediate
142        (inst slwi temp val n-widetag-bits)
143        (inst ori res temp (tn-value type)))
144       (t
145        (inst srawi temp type 2)
146        (inst slwi res val (- n-widetag-bits 2))
147        (inst or res res temp)))))
148
149 \f
150 ;;;; Allocation
151
152 (define-vop (dynamic-space-free-pointer)
153   (:results (int :scs (sap-reg)))
154   (:result-types system-area-pointer)
155   (:translate dynamic-space-free-pointer)
156   (:policy :fast-safe)
157   (:generator 1
158     (move int alloc-tn)))
159
160 (define-vop (binding-stack-pointer-sap)
161   (:results (int :scs (sap-reg)))
162   (:result-types system-area-pointer)
163   (:translate binding-stack-pointer-sap)
164   (:policy :fast-safe)
165   (:generator 1
166     (move int bsp-tn)))
167
168 (define-vop (control-stack-pointer-sap)
169   (:results (int :scs (sap-reg)))
170   (:result-types system-area-pointer)
171   (:translate control-stack-pointer-sap)
172   (:policy :fast-safe)
173   (:generator 1
174     (move int csp-tn)))
175
176 \f
177 ;;;; Code object frobbing.
178
179 (define-vop (code-instructions)
180   (:translate code-instructions)
181   (:policy :fast-safe)
182   (:args (code :scs (descriptor-reg)))
183   (:temporary (:scs (non-descriptor-reg)) ndescr)
184   (:results (sap :scs (sap-reg)))
185   (:result-types system-area-pointer)
186   (:generator 10
187     (loadw ndescr code 0 other-pointer-lowtag)
188     (inst srwi ndescr ndescr n-widetag-bits)
189     (inst slwi ndescr ndescr word-shift)
190     (inst subi ndescr ndescr other-pointer-lowtag)
191     (inst add sap code ndescr)))
192
193 (define-vop (compute-fun)
194   (:args (code :scs (descriptor-reg))
195          (offset :scs (signed-reg unsigned-reg)))
196   (:arg-types * positive-fixnum)
197   (:results (func :scs (descriptor-reg)))
198   (:temporary (:scs (non-descriptor-reg)) ndescr)
199   (:generator 10
200     (loadw ndescr code 0 other-pointer-lowtag)
201     (inst srwi ndescr ndescr n-widetag-bits)
202     (inst slwi ndescr ndescr word-shift)
203     (inst add ndescr ndescr offset)
204     (inst addi ndescr ndescr (- fun-pointer-lowtag other-pointer-lowtag))
205     (inst add func code ndescr)))
206
207
208 \f
209 ;;;; Other random VOPs.
210
211
212 (defknown sb!unix::receive-pending-interrupt () (values))
213 (define-vop (sb!unix::receive-pending-interrupt)
214   (:policy :fast-safe)
215   (:translate sb!unix::receive-pending-interrupt)
216   (:generator 1
217     (inst unimp pending-interrupt-trap)))
218
219 (define-vop (halt)
220   (:generator 1
221     (inst unimp halt-trap)))
222 \f
223 ;;;; Dynamic vop count collection support
224
225 (define-vop (count-me)
226   (:args (count-vector :scs (descriptor-reg)))
227   (:info index)
228   (:temporary (:scs (non-descriptor-reg)) count)
229   (:generator 1
230     (let ((offset
231            (- (* (+ index vector-data-offset) n-word-bytes) other-pointer-lowtag)))
232       (aver (typep offset '(signed-byte 16)))
233       (inst lwz count count-vector offset)
234       (inst addi count count 1)
235       (inst stw count count-vector offset))))