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