Remove vops for LOWTAG-OF
[sbcl.git] / src / compiler / sparc / system.lisp
blob2969ca08eb6c4234cc27f13b914e5eeb294d94ba
1 ;;;; Sparc 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")
14 ;;;; type frobbing VOPs
16 (define-vop (widetag-of)
17 (:translate widetag-of)
18 (:policy :fast-safe)
19 (:args (object :scs (descriptor-reg) :to (:eval 1)))
20 (:results (result :scs (unsigned-reg) :from (:eval 0)))
21 (:result-types positive-fixnum)
22 (:generator 6
23 ;; Grab the lowtag.
24 (inst andcc result object lowtag-mask)
25 ;; Check for various pointer types.
26 (inst cmp result list-pointer-lowtag)
27 (inst b :eq done)
28 (inst cmp result other-pointer-lowtag)
29 (inst b :eq other-pointer)
30 (inst cmp result fun-pointer-lowtag)
31 (inst b :eq function-pointer)
32 (inst cmp result instance-pointer-lowtag)
33 (inst b :eq done)
34 ;; Okay, it is an immediate. If fixnum, we want zero. Otherwise,
35 ;; we want the low 8 bits.
36 (inst andcc zero-tn object fixnum-tag-mask)
37 (inst b :eq done)
38 (inst li result 0)
39 ;; It wasn't a fixnum, so get the low 8 bits.
40 (inst b done)
41 (inst and result object widetag-mask)
43 FUNCTION-POINTER
44 (inst b done)
45 (load-type result object (- fun-pointer-lowtag))
47 OTHER-POINTER
48 (load-type result object (- other-pointer-lowtag))
50 DONE))
52 (define-vop (%other-pointer-widetag)
53 (:translate %other-pointer-widetag)
54 (:policy :fast-safe)
55 (:args (object :scs (descriptor-reg)))
56 (:results (result :scs (unsigned-reg)))
57 (:result-types positive-fixnum)
58 (:generator 6
59 (load-type result object (- other-pointer-lowtag))))
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))))
70 (define-vop (get-header-data)
71 (:translate get-header-data)
72 (:policy :fast-safe)
73 (:args (x :scs (descriptor-reg)))
74 (:results (res :scs (unsigned-reg)))
75 (:result-types positive-fixnum)
76 (:generator 6
77 (loadw res x 0 other-pointer-lowtag)
78 (inst srl res res n-widetag-bits)))
80 (define-vop (get-closure-length)
81 (:translate get-closure-length)
82 (:policy :fast-safe)
83 (:args (x :scs (descriptor-reg)))
84 (:results (res :scs (unsigned-reg)))
85 (:result-types positive-fixnum)
86 (:generator 6
87 (loadw res x 0 fun-pointer-lowtag)
88 (let* ((n-size-bits (integer-length short-header-max-words))
89 (lshift (- n-word-bits (+ n-size-bits n-widetag-bits))))
90 ;; To avoid constructing a 15-bit mask which would require another
91 ;; instruction, (ldb (byte n-size-bits n-widetag-bits) ...)
92 ;; is done as "shift left, shift right" discarding bits out both ends.
93 (inst sll res res lshift)
94 (inst srl res res (+ lshift n-widetag-bits)))))
96 (define-vop (set-header-data)
97 (:translate set-header-data)
98 (:policy :fast-safe)
99 (:args (x :scs (descriptor-reg) :target res)
100 (data :scs (any-reg immediate zero)))
101 (:arg-types * positive-fixnum)
102 (:results (res :scs (descriptor-reg)))
103 (:temporary (:scs (non-descriptor-reg)) t1 t2)
104 (:generator 6
105 (loadw t1 x 0 other-pointer-lowtag)
106 (inst and t1 widetag-mask)
107 (sc-case data
108 (any-reg
109 (inst sll t2 data (- n-widetag-bits n-fixnum-tag-bits))
110 (inst or t1 t2))
111 (immediate
112 (let ((val (ash (tn-value data) n-widetag-bits)))
113 (cond ((typep val '(signed-byte 13))
114 (inst or t1 val))
116 (inst li t2 val)
117 (inst or t1 t2)))))
118 (zero))
119 (storew t1 x 0 other-pointer-lowtag)
120 (move res x)))
123 (define-vop (pointer-hash)
124 (:translate pointer-hash)
125 (:args (ptr :scs (any-reg descriptor-reg)))
126 (:results (res :scs (any-reg descriptor-reg)))
127 (:policy :fast-safe)
128 (:generator 1
129 ;; FIXME: It would be better if this would mask the lowtag,
130 ;; and shift the result into a positive fixnum like on x86.
131 (inst sll res ptr 3)
132 (inst srl res res 1)))
135 ;;;; allocation
137 (define-vop (dynamic-space-free-pointer)
138 (:results (int :scs (sap-reg)))
139 (:result-types system-area-pointer)
140 (:translate dynamic-space-free-pointer)
141 (:policy :fast-safe)
142 (:generator 1
143 (move int alloc-tn)))
145 (define-vop (binding-stack-pointer-sap)
146 (:results (int :scs (sap-reg)))
147 (:result-types system-area-pointer)
148 (:translate binding-stack-pointer-sap)
149 (:policy :fast-safe)
150 (:generator 1
151 (move int bsp-tn)))
153 (define-vop (control-stack-pointer-sap)
154 (:results (int :scs (sap-reg)))
155 (:result-types system-area-pointer)
156 (:translate control-stack-pointer-sap)
157 (:policy :fast-safe)
158 (:generator 1
159 (move int csp-tn)))
162 ;;;; code object frobbing.
164 (define-vop (code-instructions)
165 (:translate code-instructions)
166 (:policy :fast-safe)
167 (:args (code :scs (descriptor-reg)))
168 (:temporary (:scs (non-descriptor-reg)) ndescr)
169 (:results (sap :scs (sap-reg)))
170 (:result-types system-area-pointer)
171 (:generator 10
172 (loadw ndescr code 0 other-pointer-lowtag)
173 (inst srl ndescr n-widetag-bits)
174 (inst sll ndescr word-shift)
175 (inst sub ndescr other-pointer-lowtag)
176 (inst add sap code ndescr)))
178 (define-vop (compute-fun)
179 (:args (code :scs (descriptor-reg))
180 (offset :scs (signed-reg unsigned-reg)))
181 (:arg-types * positive-fixnum)
182 (:results (func :scs (descriptor-reg)))
183 (:temporary (:scs (non-descriptor-reg)) ndescr)
184 (:generator 10
185 (loadw ndescr code 0 other-pointer-lowtag)
186 (inst srl ndescr n-widetag-bits)
187 (inst sll ndescr word-shift)
188 (inst add ndescr offset)
189 (inst add ndescr (- fun-pointer-lowtag other-pointer-lowtag))
190 (inst add func code ndescr)))
194 ;;;; other random VOPs.
197 (defknown sb!unix::receive-pending-interrupt () (values))
198 (define-vop (sb!unix::receive-pending-interrupt)
199 (:policy :fast-safe)
200 (:translate sb!unix::receive-pending-interrupt)
201 (:generator 1
202 (inst unimp pending-interrupt-trap)))
204 #!+sb-thread
205 (error "write a VOP for CURRENT-THREAD-OFFSET-SAP")
207 (define-vop (halt)
208 (:generator 1
209 (inst unimp halt-trap)))
213 ;;;; dynamic VOP count collection support
215 (define-vop (count-me)
216 (:args (count-vector :scs (descriptor-reg)))
217 (:info index)
218 (:temporary (:scs (non-descriptor-reg)) count)
219 (:generator 1
220 (let ((offset
221 (- (* (+ index vector-data-offset) n-word-bytes)
222 other-pointer-lowtag)))
223 (aver (typep offset '(signed-byte 13)))
224 (inst ld count count-vector offset)
225 (inst add count 1)
226 (inst st count count-vector offset))))
228 ;;;; Dummy definition for a spin-loop hint VOP
229 (define-vop (spin-loop-hint)
230 (:translate spin-loop-hint)
231 (:policy :fast-safe)
232 (:generator 0))