1.0.23.29: Specify the required double-stack alignment for MIPS.
[sbcl/tcr.git] / src / compiler / mips / system.lisp
blob4ac025c6df297700978b7834a9bfd74de63f0507
1 ;;;; MIPS VM definitions of various system hacking operations
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.
12 (in-package "SB!VM")
15 ;;;; Type frobbing VOPs
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)))
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)
41 ;; Pick off fixnums.
42 (inst and result object 3)
43 (inst beq result done)
45 ;; Pick off structure and list pointers.
46 (inst and result object 1)
47 (inst bne result lowtag-only)
48 (inst nop)
50 ;; Must be an other immediate.
51 (inst b done)
52 (inst and result object widetag-mask)
54 FUNCTION-PTR
55 (load-type result object (- fun-pointer-lowtag))
56 (inst b done)
57 (inst nop)
59 LOWTAG-ONLY
60 (inst b done)
61 (inst and result object lowtag-mask)
63 OTHER-PTR
64 (load-type result object (- other-pointer-lowtag))
65 (inst nop)
67 DONE))
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)))
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)))
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)))
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)))
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 2))
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)))
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)))
144 (define-vop (make-other-immediate-type)
145 (:args (val :scs (any-reg descriptor-reg))
146 (type :scs (any-reg descriptor-reg immediate)
147 :target temp))
148 (:results (res :scs (any-reg descriptor-reg)))
149 (:temporary (:scs (non-descriptor-reg)) temp)
150 (:generator 2
151 (sc-case type
152 ((immediate)
153 (inst sll temp val n-widetag-bits)
154 (inst or res temp (tn-value type)))
156 (inst sra temp type 2)
157 (inst sll res val (- n-widetag-bits 2))
158 (inst or res res temp)))))
161 ;;;; Allocation
163 (define-vop (dynamic-space-free-pointer)
164 (:results (int :scs (sap-reg)))
165 (:result-types system-area-pointer)
166 (:translate dynamic-space-free-pointer)
167 (:policy :fast-safe)
168 (:generator 1
169 (move int alloc-tn)))
171 (define-vop (binding-stack-pointer-sap)
172 (:results (int :scs (sap-reg)))
173 (:result-types system-area-pointer)
174 (:translate binding-stack-pointer-sap)
175 (:policy :fast-safe)
176 (:generator 1
177 (move int bsp-tn)))
179 (define-vop (control-stack-pointer-sap)
180 (:results (int :scs (sap-reg)))
181 (:result-types system-area-pointer)
182 (:translate control-stack-pointer-sap)
183 (:policy :fast-safe)
184 (:generator 1
185 (move int csp-tn)))
188 ;;;; Code object frobbing.
190 (define-vop (code-instructions)
191 (:translate code-instructions)
192 (:policy :fast-safe)
193 (:args (code :scs (descriptor-reg)))
194 (:temporary (:scs (non-descriptor-reg)) ndescr)
195 (:results (sap :scs (sap-reg)))
196 (:result-types system-area-pointer)
197 (:generator 10
198 (loadw ndescr code 0 other-pointer-lowtag)
199 (inst srl ndescr n-widetag-bits)
200 (inst sll ndescr word-shift)
201 (inst subu ndescr other-pointer-lowtag)
202 (inst addu sap code ndescr)))
204 (define-vop (compute-fun)
205 (:args (code :scs (descriptor-reg))
206 (offset :scs (signed-reg unsigned-reg)))
207 (:arg-types * positive-fixnum)
208 (:results (func :scs (descriptor-reg)))
209 (:temporary (:scs (non-descriptor-reg)) ndescr)
210 (:generator 10
211 (loadw ndescr code 0 other-pointer-lowtag)
212 (inst srl ndescr n-widetag-bits)
213 (inst sll ndescr word-shift)
214 (inst addu ndescr offset)
215 (inst addu ndescr (- fun-pointer-lowtag other-pointer-lowtag))
216 (inst addu func code ndescr)))
219 ;;;; Other random VOPs.
222 (defknown sb!unix::receive-pending-interrupt () (values))
223 (define-vop (sb!unix::receive-pending-interrupt)
224 (:policy :fast-safe)
225 (:translate sb!unix::receive-pending-interrupt)
226 (:generator 1
227 (inst break 0 pending-interrupt-trap)))
230 (define-vop (halt)
231 (:generator 1
232 (inst break 0 halt-trap)))
235 ;;;; Dynamic vop count collection support
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) other-pointer-lowtag)))
244 (inst lw count count-vector offset)
245 (inst nop)
246 (inst addu count 1)
247 (inst sw count count-vector offset))))