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