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