Handle :ALLOCATION of condition slots correctly
[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 %other-pointer-p
24            base-string-p simple-base-string-p
25            #!+sb-unicode character-string-p
26            #!+sb-unicode simple-character-string-p
27            array-header-p
28            sequencep extended-sequence-p
29            simple-array-p simple-array-nil-p vector-nil-p
30            simple-array-unsigned-byte-2-p
31            simple-array-unsigned-byte-4-p simple-array-unsigned-byte-7-p
32            simple-array-unsigned-byte-8-p simple-array-unsigned-byte-15-p
33            simple-array-unsigned-byte-16-p
34
35            simple-array-unsigned-fixnum-p
36
37            simple-array-unsigned-byte-31-p
38            simple-array-unsigned-byte-32-p
39            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
40            simple-array-unsigned-byte-63-p
41            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
42            simple-array-unsigned-byte-64-p
43            simple-array-signed-byte-8-p simple-array-signed-byte-16-p
44
45            simple-array-fixnum-p
46
47            simple-array-signed-byte-32-p
48            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
49            simple-array-signed-byte-64-p
50            simple-array-single-float-p simple-array-double-float-p
51            #!+long-float simple-array-long-float-p
52            simple-array-complex-single-float-p
53            simple-array-complex-double-float-p
54            #!+long-float simple-array-complex-long-float-p
55            system-area-pointer-p realp
56            ;; #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
57            unsigned-byte-32-p
58            ;; #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
59            signed-byte-32-p
60            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
61            unsigned-byte-64-p
62            #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
63            signed-byte-64-p
64            weak-pointer-p code-component-p lra-p
65            funcallable-instance-p)
66   (t) boolean (movable foldable flushable))
67 (defknown #.(loop for (name) in *vector-without-complex-typecode-infos*
68                   collect name)
69   (t) boolean (movable foldable flushable))
70 \f
71 ;;;; miscellaneous "sub-primitives"
72
73 (defknown pointer-hash (t) hash (flushable))
74
75 (defknown %sp-string-compare
76   (simple-string index index simple-string index index)
77   (or index null)
78   (foldable flushable))
79
80 (defknown %sxhash-simple-string (simple-string) hash
81   (foldable flushable))
82
83 (defknown %sxhash-simple-substring (simple-string index) hash
84   (foldable flushable))
85
86 (defknown symbol-hash (symbol) hash
87   (flushable movable))
88
89 (defknown %set-symbol-hash (symbol hash)
90   t ())
91
92 (defknown initialize-vector ((simple-array * (*)) &rest t)
93   (simple-array * (*))
94   (always-translatable flushable)
95   :result-arg 0)
96
97 (defknown vector-fill* (t t t t) vector
98   ()
99   :result-arg 0)
100
101 (defknown vector-length (vector) index (flushable dx-safe))
102
103 (defknown vector-sap ((simple-unboxed-array (*))) system-area-pointer
104   (flushable))
105
106 (defknown lowtag-of (t) (unsigned-byte #.sb!vm:n-lowtag-bits)
107   (flushable movable))
108 (defknown widetag-of (t) (unsigned-byte #.sb!vm:n-widetag-bits)
109   (flushable movable))
110
111 (defknown (get-header-data get-closure-length) (t) (unsigned-byte 24)
112   (flushable))
113 (defknown set-header-data (t (unsigned-byte 24)) t
114   ())
115
116 (defknown %array-dimension (t index) index
117   (flushable))
118 (defknown %set-array-dimension (t index index) index
119   ())
120 (defknown %array-rank (t) index
121   (flushable))
122
123 (defknown %make-instance (index) instance
124   (flushable))
125 (defknown %make-structure-instance (defstruct-description list &rest t) instance
126   (flushable always-translatable))
127 (defknown %instance-layout (instance) layout
128   (foldable flushable))
129 (defknown %set-instance-layout (instance layout) layout
130   ())
131 (defknown %instance-length (instance) index
132   (foldable flushable))
133 (defknown %instance-ref (instance index) t
134   (flushable always-translatable))
135 (defknown %instance-set (instance index t) t
136   (always-translatable))
137 (defknown %layout-invalid-error (t layout) nil)
138
139 (defknown %raw-instance-ref/word (instance index) sb!vm:word
140   (flushable always-translatable))
141 (defknown %raw-instance-set/word (instance index sb!vm:word) sb!vm:word
142   (always-translatable))
143 (defknown %raw-instance-ref/single (instance index) single-float
144   (flushable always-translatable))
145 (defknown %raw-instance-set/single (instance index single-float) single-float
146   (always-translatable))
147 (defknown %raw-instance-ref/double (instance index) double-float
148   (flushable always-translatable))
149 (defknown %raw-instance-set/double (instance index double-float) double-float
150   (always-translatable))
151 (defknown %raw-instance-ref/complex-single (instance index)
152   (complex single-float)
153   (flushable always-translatable))
154 (defknown %raw-instance-set/complex-single
155     (instance index (complex single-float))
156   (complex single-float)
157   (always-translatable))
158 (defknown %raw-instance-ref/complex-double (instance index)
159   (complex double-float)
160   (flushable always-translatable))
161 (defknown %raw-instance-set/complex-double
162     (instance index (complex double-float))
163   (complex double-float)
164   (always-translatable))
165
166 #!+(or x86 x86-64 ppc)
167 (defknown %raw-instance-atomic-incf/word (instance index sb!vm:word) sb!vm:word
168     (always-translatable))
169 #!+(or x86 x86-64 ppc)
170 (defknown %array-atomic-incf/word (t index sb!vm:word) sb!vm:word
171   (always-translatable))
172
173 ;;; These two are mostly used for bit-bashing operations.
174 (defknown %vector-raw-bits (t fixnum) sb!vm:word
175   (flushable))
176 (defknown (%set-vector-raw-bits) (t fixnum sb!vm:word) sb!vm:word
177   ())
178
179
180 (defknown allocate-vector ((unsigned-byte 8) index index) (simple-array * (*))
181   (flushable movable))
182
183 (defknown make-array-header ((unsigned-byte 8) (unsigned-byte 24)) array
184   (flushable movable))
185
186
187 (defknown make-weak-pointer (t) weak-pointer
188   (flushable))
189
190 (defknown %make-complex (real real) complex
191   (flushable movable))
192 (defknown %make-ratio (rational rational) ratio
193   (flushable movable))
194 (defknown make-value-cell (t) t
195   (flushable movable))
196
197 ;;;; threading
198
199 (defknown (dynamic-space-free-pointer binding-stack-pointer-sap
200                                       control-stack-pointer-sap)  ()
201   system-area-pointer
202   (flushable))
203 \f
204 ;;;; debugger support
205
206 (defknown current-sp () system-area-pointer (movable flushable))
207 (defknown current-fp () system-area-pointer (movable flushable))
208 (defknown stack-ref (system-area-pointer index) t (flushable))
209 (defknown %set-stack-ref (system-area-pointer index t) t ())
210 (defknown lra-code-header (t) t (movable flushable))
211 (defknown fun-code-header (t) t (movable flushable))
212 (defknown %make-lisp-obj (sb!vm:word) t (movable flushable))
213 (defknown get-lisp-obj-address (t) sb!vm:word (movable flushable))
214 (defknown fun-word-offset (function) index (movable flushable))
215 \f
216 ;;;; 32-bit logical operations
217
218 (defknown word-logical-not (sb!vm:word) sb!vm:word
219   (foldable flushable movable))
220
221 (defknown (word-logical-and word-logical-nand
222            word-logical-or word-logical-nor
223            word-logical-xor word-logical-eqv
224            word-logical-andc1 word-logical-andc2
225            word-logical-orc1 word-logical-orc2)
226           (sb!vm:word sb!vm:word) sb!vm:word
227   (foldable flushable movable))
228
229 (defknown (shift-towards-start shift-towards-end) (sb!vm:word fixnum)
230   sb!vm:word
231   (foldable flushable movable))
232 \f
233 ;;;; bignum operations
234
235 (defknown %allocate-bignum (bignum-index) bignum-type
236   (flushable))
237
238 (defknown %bignum-length (bignum-type) bignum-index
239   (foldable flushable movable))
240
241 (defknown %bignum-set-length (bignum-type bignum-index) bignum-type
242   ())
243
244 (defknown %bignum-ref (bignum-type bignum-index) bignum-element-type
245   (flushable))
246 #!+(or x86 x86-64)
247 (defknown %bignum-ref-with-offset (bignum-type bignum-index (signed-byte 24))
248   bignum-element-type (flushable always-translatable))
249
250 (defknown %bignum-set (bignum-type bignum-index bignum-element-type)
251   bignum-element-type
252   ())
253 #!+(or x86 x86-64)
254 (defknown %bignum-set-with-offset
255   (bignum-type bignum-index (signed-byte 24) bignum-element-type)
256   bignum-element-type (always-translatable))
257
258 (defknown %digit-0-or-plusp (bignum-element-type) boolean
259   (foldable flushable movable))
260
261 (defknown (%add-with-carry %subtract-with-borrow)
262           (bignum-element-type bignum-element-type (mod 2))
263   (values bignum-element-type (mod 2))
264   (foldable flushable movable))
265
266 (defknown %multiply-and-add
267           (bignum-element-type bignum-element-type bignum-element-type
268                                &optional bignum-element-type)
269   (values bignum-element-type bignum-element-type)
270   (foldable flushable movable))
271
272 (defknown %multiply (bignum-element-type bignum-element-type)
273   (values bignum-element-type bignum-element-type)
274   (foldable flushable movable))
275
276 (defknown %lognot (bignum-element-type) bignum-element-type
277   (foldable flushable movable))
278
279 (defknown (%logand %logior %logxor) (bignum-element-type bignum-element-type)
280   bignum-element-type
281   (foldable flushable movable))
282
283 (defknown %fixnum-to-digit (fixnum) bignum-element-type
284   (foldable flushable movable))
285
286 (defknown %bigfloor (bignum-element-type bignum-element-type bignum-element-type)
287   (values bignum-element-type bignum-element-type)
288   (foldable flushable movable))
289
290 (defknown %fixnum-digit-with-correct-sign (bignum-element-type)
291   (signed-byte #.sb!vm:n-word-bits)
292   (foldable flushable movable))
293
294 (defknown (%ashl %ashr %digit-logical-shift-right)
295           (bignum-element-type (mod #.sb!vm:n-word-bits)) bignum-element-type
296   (foldable flushable movable))
297 \f
298 ;;;; bit-bashing routines
299
300 ;;; FIXME: there's some ugly duplication between the (INTERN (FORMAT ...))
301 ;;; magic here and the same magic in src/code/bit-bash.lisp.  I don't know
302 ;;; of any good way to clean it up, but it's definitely violating OAOO.
303 (macrolet ((define-known-copiers ()
304             `(progn
305               ,@(loop for i = 1 then (* i 2)
306                       collect `(defknown ,(intern (format nil "UB~D-BASH-COPY" i)
307                                                   (find-package "SB!KERNEL"))
308                                 ((simple-unboxed-array (*)) index (simple-unboxed-array (*)) index index)
309                                 (values)
310                                 ())
311                       collect `(defknown ,(intern (format nil "SYSTEM-AREA-UB~D-COPY" i)
312                                                   (find-package "SB!KERNEL"))
313                                 (system-area-pointer index system-area-pointer index index)
314                                 (values)
315                                 ())
316                       collect `(defknown ,(intern (format nil "COPY-UB~D-TO-SYSTEM-AREA" i)
317                                                   (find-package "SB!KERNEL"))
318                                 ((simple-unboxed-array (*)) index system-area-pointer index index)
319                                 (values)
320                                 ())
321                       collect `(defknown ,(intern (format nil "COPY-UB~D-FROM-SYSTEM-AREA" i)
322                                                   (find-package "SB!KERNEL"))
323                                 (system-area-pointer index (simple-unboxed-array (*)) index index)
324                                 (values)
325                                 ())
326                       until (= i sb!vm:n-word-bits)))))
327   (define-known-copiers))
328
329 ;;; (not really a bit-bashing routine, but starting to take over from
330 ;;; bit-bashing routines in byte-sized copies as of sbcl-0.6.12.29:)
331 (defknown %byte-blt
332   ((or (simple-unboxed-array (*)) system-area-pointer) index
333    (or (simple-unboxed-array (*)) system-area-pointer) index index)
334   (values)
335   ())
336 \f
337 ;;;; code/function/fdefn object manipulation routines
338
339 (defknown code-instructions (t) system-area-pointer (flushable movable))
340 (defknown code-header-ref (t index) t (flushable))
341 (defknown code-header-set (t index t) t ())
342
343 (defknown fun-subtype (function) (unsigned-byte #.sb!vm:n-widetag-bits)
344   (flushable))
345 (defknown ((setf fun-subtype))
346           ((unsigned-byte #.sb!vm:n-widetag-bits) function)
347   (unsigned-byte #.sb!vm:n-widetag-bits)
348   ())
349
350 (defknown make-fdefn (t) fdefn (flushable movable))
351 (defknown fdefn-p (t) boolean (movable foldable flushable))
352 (defknown fdefn-name (fdefn) t (foldable flushable))
353 (defknown fdefn-fun (fdefn) (or function null) (flushable))
354 (defknown (setf fdefn-fun) (function fdefn) t ())
355 (defknown fdefn-makunbound (fdefn) t ())
356
357 (defknown %simple-fun-self (function) function
358   (flushable))
359 (defknown (setf %simple-fun-self) (function function) function
360   ())
361
362 (defknown %closure-fun (function) function
363   (flushable))
364
365 (defknown %closure-index-ref (function index) t
366   (flushable))
367
368 (defknown %make-funcallable-instance (index) function
369   ())
370
371 (defknown %funcallable-instance-info (function index) t (flushable))
372 (defknown %set-funcallable-instance-info (function index t) t ())
373 \f
374 ;;;; mutator accessors
375
376 (defknown mutator-self () system-area-pointer (flushable movable))
377
378 (defknown %data-vector-and-index (array index)
379                                  (values (simple-array * (*)) index)
380                                  (foldable flushable))