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