Thou shalt not MAKE-OTHER-IMMEDIATE-TYPE.
[sbcl.git] / src / compiler / mips / system.lisp
1 ;;;; MIPS 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
14 \f
15 ;;;; Type frobbing VOPs
16
17 (define-vop (lowtag-of)
18   (:translate lowtag-of)
19   (:policy :fast-safe)
20   (:args (object :scs (any-reg descriptor-reg)))
21   (:results (result :scs (unsigned-reg)))
22   (:result-types positive-fixnum)
23   (:generator 1
24     (inst and result object lowtag-mask)))
25
26 (define-vop (widetag-of)
27   (:translate widetag-of)
28   (:policy :fast-safe)
29   (:args (object :scs (descriptor-reg)))
30   (:temporary (:scs (non-descriptor-reg)) ndescr)
31   (:results (result :scs (unsigned-reg)))
32   (:result-types positive-fixnum)
33   (:generator 6
34     ;; Pick off objects with headers.
35     (inst and ndescr object lowtag-mask)
36     (inst xor ndescr other-pointer-lowtag)
37     (inst beq ndescr other-ptr)
38     (inst xor ndescr (logxor other-pointer-lowtag fun-pointer-lowtag))
39     (inst beq ndescr function-ptr)
40
41     ;; Pick off fixnums.
42     (inst and result object fixnum-tag-mask)
43     (inst beq result done)
44
45     ;; Pick off structure and list pointers.
46     (inst and result object 1)
47     (inst bne result lowtag-only)
48     (inst nop)
49
50       ;; Must be an other immediate.
51     (inst b done)
52     (inst and result object widetag-mask)
53
54     FUNCTION-PTR
55     (load-type result object (- fun-pointer-lowtag))
56     (inst b done)
57     (inst nop)
58
59     LOWTAG-ONLY
60     (inst b done)
61     (inst and result object lowtag-mask)
62
63     OTHER-PTR
64     (load-type result object (- other-pointer-lowtag))
65     (inst nop)
66
67     DONE))
68
69 (define-vop (fun-subtype)
70   (:translate fun-subtype)
71   (:policy :fast-safe)
72   (:args (function :scs (descriptor-reg)))
73   (:results (result :scs (unsigned-reg)))
74   (:result-types positive-fixnum)
75   (:generator 6
76     (load-type result function (- fun-pointer-lowtag))
77     (inst nop)))
78
79 (define-vop (set-fun-subtype)
80   (:translate (setf fun-subtype))
81   (:policy :fast-safe)
82   (:args (type :scs (unsigned-reg) :target result)
83          (function :scs (descriptor-reg)))
84   (:arg-types positive-fixnum *)
85   (:results (result :scs (unsigned-reg)))
86   (:result-types positive-fixnum)
87   (:generator 6
88     (inst sb type function (- fun-pointer-lowtag))
89     (move result type)))
90
91
92 (define-vop (get-header-data)
93   (:translate get-header-data)
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 other-pointer-lowtag)
100     (inst srl res res n-widetag-bits)))
101
102 (define-vop (get-closure-length)
103   (:translate get-closure-length)
104   (:policy :fast-safe)
105   (:args (x :scs (descriptor-reg)))
106   (:results (res :scs (unsigned-reg)))
107   (:result-types positive-fixnum)
108   (:generator 6
109     (loadw res x 0 fun-pointer-lowtag)
110     (inst srl res res n-widetag-bits)))
111
112 (define-vop (set-header-data)
113   (:translate set-header-data)
114   (:policy :fast-safe)
115   (:args (x :scs (descriptor-reg) :target res)
116          (data :scs (any-reg immediate zero)))
117   (:arg-types * positive-fixnum)
118   (:results (res :scs (descriptor-reg)))
119   (:temporary (:scs (non-descriptor-reg)) t1 t2)
120   (:generator 6
121     (loadw t1 x 0 other-pointer-lowtag)
122     (inst and t1 widetag-mask)
123     (sc-case data
124       (any-reg
125        (inst sll t2 data (- n-widetag-bits n-fixnum-tag-bits))
126        (inst or t1 t2))
127       (immediate
128        (inst or t1 (ash (tn-value data) n-widetag-bits)))
129       (zero))
130     (storew t1 x 0 other-pointer-lowtag)
131     (move res x)))
132
133 (define-vop (pointer-hash)
134   (:translate pointer-hash)
135   (:args (ptr :scs (any-reg descriptor-reg)))
136   (:results (res :scs (any-reg descriptor-reg)))
137   (:policy :fast-safe)
138   (:generator 1
139     ;; FIXME: It would be better if this would mask the lowtag,
140     ;; and shift the result into a positive fixnum like on x86.
141     (inst sll res ptr 3)
142     (inst srl res res 1)))
143
144 \f
145 ;;;; Allocation
146
147 (define-vop (dynamic-space-free-pointer)
148   (:results (int :scs (sap-reg)))
149   (:result-types system-area-pointer)
150   (:translate dynamic-space-free-pointer)
151   (:policy :fast-safe)
152   (:generator 1
153     (move int alloc-tn)))
154
155 (define-vop (binding-stack-pointer-sap)
156   (:results (int :scs (sap-reg)))
157   (:result-types system-area-pointer)
158   (:translate binding-stack-pointer-sap)
159   (:policy :fast-safe)
160   (:generator 1
161     (move int bsp-tn)))
162
163 (define-vop (control-stack-pointer-sap)
164   (:results (int :scs (sap-reg)))
165   (:result-types system-area-pointer)
166   (:translate control-stack-pointer-sap)
167   (:policy :fast-safe)
168   (:generator 1
169     (move int csp-tn)))
170
171 \f
172 ;;;; Code object frobbing.
173
174 (define-vop (code-instructions)
175   (:translate code-instructions)
176   (:policy :fast-safe)
177   (:args (code :scs (descriptor-reg)))
178   (:temporary (:scs (non-descriptor-reg)) ndescr)
179   (:results (sap :scs (sap-reg)))
180   (:result-types system-area-pointer)
181   (:generator 10
182     (loadw ndescr code 0 other-pointer-lowtag)
183     (inst srl ndescr n-widetag-bits)
184     (inst sll ndescr word-shift)
185     (inst subu ndescr other-pointer-lowtag)
186     (inst addu sap code ndescr)))
187
188 (define-vop (compute-fun)
189   (:args (code :scs (descriptor-reg))
190          (offset :scs (signed-reg unsigned-reg)))
191   (:arg-types * positive-fixnum)
192   (:results (func :scs (descriptor-reg)))
193   (:temporary (:scs (non-descriptor-reg)) ndescr)
194   (:generator 10
195     (loadw ndescr code 0 other-pointer-lowtag)
196     (inst srl ndescr n-widetag-bits)
197     (inst sll ndescr word-shift)
198     (inst addu ndescr offset)
199     (inst addu ndescr (- fun-pointer-lowtag other-pointer-lowtag))
200     (inst addu func code ndescr)))
201
202 \f
203 ;;;; Other random VOPs.
204
205
206 (defknown sb!unix::receive-pending-interrupt () (values))
207 (define-vop (sb!unix::receive-pending-interrupt)
208   (:policy :fast-safe)
209   (:translate sb!unix::receive-pending-interrupt)
210   (:generator 1
211     (inst break 0 pending-interrupt-trap)))
212
213
214 (define-vop (halt)
215   (:generator 1
216     (inst break 0 halt-trap)))
217
218 \f
219 ;;;; Dynamic vop count collection support
220
221 (define-vop (count-me)
222   (:args (count-vector :scs (descriptor-reg)))
223   (:info index)
224   (:temporary (:scs (non-descriptor-reg)) count)
225   (:generator 1
226     (let ((offset
227            (- (* (+ index vector-data-offset) n-word-bytes) other-pointer-lowtag)))
228       (inst lw count count-vector offset)
229       (inst nop)
230       (inst addu count 1)
231       (inst sw count count-vector offset))))
232
233 ;;;; Dummy definition for a spin-loop hint VOP
234 (define-vop (spin-loop-hint)
235   (:translate spin-loop-hint)
236   (:policy :fast-safe)
237   (:generator 0))