0.8.13.54:
[sbcl.git] / src / compiler / generic / vm-fndb.lisp
1 ;;;; signatures of machine-specific functions
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!C")
13 \f
14 ;;;; internal type predicates
15
16 ;;; Simple TYPEP uses that don't have any standard predicate are
17 ;;; translated into non-standard unary predicates.
18 (defknown (fixnump bignump ratiop
19            short-float-p single-float-p double-float-p long-float-p
20            complex-rational-p complex-float-p complex-single-float-p
21            complex-double-float-p #!+long-float complex-long-float-p
22            complex-vector-p
23            base-char-p %standard-char-p %instancep
24            base-string-p simple-base-string-p
25            array-header-p
26            simple-array-p simple-array-nil-p vector-nil-p
27            simple-array-unsigned-byte-2-p
28            simple-array-unsigned-byte-4-p simple-array-unsigned-byte-7-p
29            simple-array-unsigned-byte-8-p simple-array-unsigned-byte-15-p
30            simple-array-unsigned-byte-16-p
31            #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
32            simple-array-unsigned-byte-29-p
33            simple-array-unsigned-byte-31-p
34            simple-array-unsigned-byte-32-p
35            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
36            simple-array-unsigned-byte-60-p
37            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
38            simple-array-unsigned-byte-63-p
39            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
40            simple-array-unsigned-byte-64-p
41            simple-array-signed-byte-8-p simple-array-signed-byte-16-p
42            #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
43            simple-array-signed-byte-30-p
44            simple-array-signed-byte-32-p
45            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
46            simple-array-signed-byte-61-p
47            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
48            simple-array-signed-byte-64-p
49            simple-array-single-float-p simple-array-double-float-p
50            #!+long-float simple-array-long-float-p
51            simple-array-complex-single-float-p
52            simple-array-complex-double-float-p
53            #!+long-float simple-array-complex-long-float-p
54            system-area-pointer-p realp
55            #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
56            unsigned-byte-32-p
57            #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
58            signed-byte-32-p
59            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
60            unsigned-byte-64-p
61            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
62            signed-byte-64-p
63            vector-t-p weak-pointer-p code-component-p lra-p
64            funcallable-instance-p)
65   (t) boolean (movable foldable flushable))
66 \f
67 ;;;; miscellaneous "sub-primitives"
68
69 (defknown %sp-string-compare
70   (simple-string index index simple-string index index)
71   (or index null)
72   (foldable flushable))
73
74 (defknown %sxhash-simple-string (simple-string) index
75   (foldable flushable))
76
77 (defknown %sxhash-simple-substring (simple-string index) index
78   (foldable flushable))
79
80 (defknown symbol-hash (symbol) (integer 0 #.sb!xc:most-positive-fixnum)
81   (flushable movable))
82
83 (defknown %set-symbol-hash (symbol (integer 0 #.sb!xc:most-positive-fixnum))
84   t (unsafe))
85
86 (defknown vector-length (vector) index (flushable))
87
88 (defknown vector-sap ((simple-unboxed-array (*))) system-area-pointer
89   (flushable))
90
91 (defknown lowtag-of (t) (unsigned-byte #.sb!vm:n-lowtag-bits)
92   (flushable movable))
93 (defknown widetag-of (t) (unsigned-byte #.sb!vm:n-widetag-bits)
94   (flushable movable))
95
96 (defknown (get-header-data get-closure-length) (t) (unsigned-byte 24)
97   (flushable))
98 (defknown set-header-data (t (unsigned-byte 24)) t
99   (unsafe))
100
101 (defknown %array-dimension (t index) index
102   (flushable))
103 (defknown %set-array-dimension (t index index) index
104   ())
105 (defknown %array-rank (t) index
106   (flushable))
107
108 (defknown %make-instance (index) instance
109   (unsafe))
110 (defknown %instance-layout (instance) layout
111   (foldable flushable))
112 (defknown %set-instance-layout (instance layout) layout
113   (unsafe))
114 (defknown %instance-length (instance) index
115   (foldable flushable))
116 (defknown %instance-ref (instance index) t
117   (flushable))
118 (defknown %instance-set (instance index t) t
119   (unsafe))
120 (defknown %layout-invalid-error (t layout) nil)
121
122
123 (sb!xc:deftype raw-vector () '(simple-array sb!vm:word (*)))
124
125 ;;; %RAW-{REF,SET}-FOO VOPs should be declared as taking a RAW-VECTOR
126 ;;; as their first argument (clarity and to match these DEFKNOWNs).
127 ;;; We declare RAW-VECTOR as a primitive type so the VOP machinery
128 ;;; will accept our VOPs as legitimate.  --njf, 2004-08-10
129 (sb!vm::!def-primitive-type-alias raw-vector
130                                   #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
131                                   sb!vm::simple-array-unsigned-byte-32
132                                   #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
133                                   sb!vm::simple-array-unsigned-byte-64)
134
135 (defknown %raw-ref-single (raw-vector index) single-float
136   (foldable flushable))
137 (defknown %raw-ref-double (raw-vector index) double-float
138   (foldable flushable))
139 #!+long-float
140 (defknown %raw-ref-long (raw-vector index) long-float
141   (foldable flushable))
142 (defknown %raw-set-single (raw-vector index single-float) single-float
143   (unsafe))
144 (defknown %raw-set-double (raw-vector index double-float) double-float
145   (unsafe))
146 #!+long-float
147 (defknown %raw-set-long (raw-vector index long-float) long-float
148   (unsafe))
149
150 (defknown %raw-ref-complex-single (raw-vector index) (complex single-float)
151   (foldable flushable))
152 (defknown %raw-ref-complex-double (raw-vector index) (complex double-float)
153   (foldable flushable))
154
155 (defknown %raw-set-complex-single (raw-vector index (complex single-float))
156   (complex single-float)
157   (unsafe))
158 (defknown %raw-set-complex-double (raw-vector index (complex double-float))
159   (complex double-float)
160   (unsafe))
161
162
163 (defknown %raw-bits (t fixnum) sb!vm:word
164   (foldable flushable))
165 (defknown (%set-raw-bits) (t fixnum sb!vm:word) sb!vm:word
166   (unsafe))
167
168
169 (defknown allocate-vector ((unsigned-byte 8) index index) (simple-array * (*))
170   (flushable movable))
171
172 (defknown make-array-header ((unsigned-byte 8) (unsigned-byte 24)) array
173   (flushable movable))
174
175
176 (defknown make-weak-pointer (t) weak-pointer
177   (flushable))
178
179 (defknown %make-complex (real real) complex
180   (flushable movable))
181 (defknown %make-ratio (rational rational) ratio
182   (flushable movable))
183 (defknown make-value-cell (t) t
184   (flushable movable))
185
186 (defknown (dynamic-space-free-pointer binding-stack-pointer-sap
187                                       control-stack-pointer-sap)  ()
188   system-area-pointer
189   (flushable))
190 \f
191 ;;;; debugger support
192
193 (defknown current-sp () system-area-pointer (movable flushable))
194 (defknown current-fp () system-area-pointer (movable flushable))
195 (defknown stack-ref (system-area-pointer index) t (flushable))
196 (defknown %set-stack-ref (system-area-pointer index t) t (unsafe))
197 (defknown lra-code-header (t) t (movable flushable))
198 (defknown fun-code-header (t) t (movable flushable))
199 (defknown make-lisp-obj (sb!vm:word) t (movable flushable))
200 (defknown get-lisp-obj-address (t) sb!vm:word (movable flushable))
201 (defknown fun-word-offset (function) index (movable flushable))
202 \f
203 ;;;; 32-bit logical operations
204
205 (defknown merge-bits ((unsigned-byte 5) sb!vm:word sb!vm:word)
206   sb!vm:word
207   (foldable flushable movable))
208
209 (defknown word-logical-not (sb!vm:word) sb!vm:word
210   (foldable flushable movable))
211
212 (defknown (word-logical-and word-logical-nand
213            word-logical-or word-logical-nor
214            word-logical-xor word-logical-eqv
215            word-logical-andc1 word-logical-andc2
216            word-logical-orc1 word-logical-orc2)
217           (sb!vm:word sb!vm:word) sb!vm:word
218   (foldable flushable movable))
219
220 (defknown (shift-towards-start shift-towards-end) (sb!vm:word fixnum)
221   sb!vm:word
222   (foldable flushable movable))
223 \f
224 ;;;; bignum operations
225
226 (defknown %allocate-bignum (bignum-index) bignum-type
227   (flushable))
228
229 (defknown %bignum-length (bignum-type) bignum-index
230   (foldable flushable movable))
231
232 (defknown %bignum-set-length (bignum-type bignum-index) bignum-type
233   (unsafe))
234
235 (defknown %bignum-ref (bignum-type bignum-index) bignum-element-type
236   (flushable))
237
238 (defknown %bignum-set (bignum-type bignum-index bignum-element-type)
239   bignum-element-type
240   (unsafe))
241
242 (defknown %digit-0-or-plusp (bignum-element-type) boolean
243   (foldable flushable movable))
244
245 (defknown (%add-with-carry %subtract-with-borrow)
246           (bignum-element-type bignum-element-type (mod 2))
247   (values bignum-element-type (mod 2))
248   (foldable flushable movable))
249
250 (defknown %multiply-and-add
251           (bignum-element-type bignum-element-type bignum-element-type
252                                &optional bignum-element-type)
253   (values bignum-element-type bignum-element-type)
254   (foldable flushable movable))
255
256 (defknown %multiply (bignum-element-type bignum-element-type)
257   (values bignum-element-type bignum-element-type)
258   (foldable flushable movable))
259
260 (defknown %lognot (bignum-element-type) bignum-element-type
261   (foldable flushable movable))
262
263 (defknown (%logand %logior %logxor) (bignum-element-type bignum-element-type)
264   bignum-element-type
265   (foldable flushable movable))
266
267 (defknown %fixnum-to-digit (fixnum) bignum-element-type
268   (foldable flushable movable))
269
270 (defknown %floor (bignum-element-type bignum-element-type bignum-element-type)
271   (values bignum-element-type bignum-element-type)
272   (foldable flushable movable))
273
274 (defknown %fixnum-digit-with-correct-sign (bignum-element-type)
275   (signed-byte #.sb!vm:n-word-bits)
276   (foldable flushable movable))
277
278 (defknown (%ashl %ashr %digit-logical-shift-right)
279           (bignum-element-type (mod #.sb!vm:n-word-bits)) bignum-element-type
280   (foldable flushable movable))
281 \f
282 ;;;; bit-bashing routines
283
284 (defknown copy-to-system-area
285           ((simple-unboxed-array (*)) index system-area-pointer index index)
286   (values)
287   ())
288
289 (defknown copy-from-system-area
290           (system-area-pointer index (simple-unboxed-array (*)) index index)
291   (values)
292   ())
293
294 (defknown system-area-copy
295           (system-area-pointer index system-area-pointer index index)
296   (values)
297   ())
298
299 (defknown bit-bash-copy
300           ((simple-unboxed-array (*)) index
301            (simple-unboxed-array (*)) index index)
302   (values)
303   ())
304
305 ;;; (not really a bit-bashing routine, but starting to take over from
306 ;;; bit-bashing routines in byte-sized copies as of sbcl-0.6.12.29:)
307 (defknown %byte-blt
308   ((or (simple-unboxed-array (*)) system-area-pointer) index
309    (or (simple-unboxed-array (*)) system-area-pointer) index index)
310   (values)
311   ())
312 \f
313 ;;;; code/function/fdefn object manipulation routines
314
315 (defknown code-instructions (t) system-area-pointer (flushable movable))
316 (defknown code-header-ref (t index) t (flushable))
317 (defknown code-header-set (t index t) t ())
318
319 (defknown fun-subtype (function) (unsigned-byte #.sb!vm:n-widetag-bits)
320   (flushable))
321 (defknown ((setf fun-subtype))
322           ((unsigned-byte #.sb!vm:n-widetag-bits) function)
323   (unsigned-byte #.sb!vm:n-widetag-bits)
324   ())
325
326 (defknown make-fdefn (t) fdefn (flushable movable))
327 (defknown fdefn-p (t) boolean (movable foldable flushable))
328 (defknown fdefn-name (fdefn) t (foldable flushable))
329 (defknown fdefn-fun (fdefn) (or function null) (flushable))
330 (defknown (setf fdefn-fun) (function fdefn) t (unsafe))
331 (defknown fdefn-makunbound (fdefn) t ())
332
333 (defknown %simple-fun-self (function) function
334   (flushable))
335 (defknown (setf %simple-fun-self) (function function) function
336   (unsafe))
337
338 (defknown %closure-fun (function) function
339   (flushable))
340
341 (defknown %closure-index-ref (function index) t
342   (flushable))
343
344 (defknown %make-funcallable-instance (index layout) function
345   (unsafe))
346
347 (defknown %funcallable-instance-info (function index) t (flushable))
348 (defknown %set-funcallable-instance-info (function index t) t (unsafe))
349 \f
350 ;;;; mutator accessors
351
352 (defknown mutator-self () system-area-pointer (flushable movable))
353
354 (defknown %data-vector-and-index (array index)
355                                  (values (simple-array * (*)) index)
356                                  (foldable flushable))