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