1.0.24.11: stack allocation support for HPPA
[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) index
80   (foldable flushable))
81
82 (defknown %sxhash-simple-substring (simple-string index) index
83   (foldable flushable))
84
85 (defknown symbol-hash (symbol) (integer 0 #.sb!xc:most-positive-fixnum)
86   (flushable movable))
87
88 (defknown %set-symbol-hash (symbol (integer 0 #.sb!xc:most-positive-fixnum))
89   t (unsafe))
90
91 (defknown vector-length (vector) index (flushable))
92
93 (defknown vector-sap ((simple-unboxed-array (*))) system-area-pointer
94   (flushable))
95
96 (defknown lowtag-of (t) (unsigned-byte #.sb!vm:n-lowtag-bits)
97   (flushable movable))
98 (defknown widetag-of (t) (unsigned-byte #.sb!vm:n-widetag-bits)
99   (flushable movable))
100
101 (defknown (get-header-data get-closure-length) (t) (unsigned-byte 24)
102   (flushable))
103 (defknown set-header-data (t (unsigned-byte 24)) t
104   (unsafe))
105
106 (defknown %array-dimension (t index) index
107   (flushable))
108 (defknown %set-array-dimension (t index index) index
109   ())
110 (defknown %array-rank (t) index
111   (flushable))
112
113 (defknown %make-instance (index) instance
114   (flushable))
115 (defknown %make-structure-instance (defstruct-description list &rest t) instance
116   (flushable always-translatable))
117 (defknown %instance-layout (instance) layout
118   (foldable flushable))
119 (defknown %set-instance-layout (instance layout) layout
120   (unsafe))
121 (defknown %instance-length (instance) index
122   (foldable flushable))
123 (defknown %instance-ref (instance index) t
124   (flushable always-translatable))
125 (defknown %instance-set (instance index t) t
126   (unsafe always-translatable))
127 (defknown %layout-invalid-error (t layout) nil)
128
129 (defknown %raw-instance-ref/word (instance index) sb!vm:word
130   (flushable always-translatable))
131 (defknown %raw-instance-set/word (instance index sb!vm:word) sb!vm:word
132   (unsafe always-translatable))
133 (defknown %raw-instance-ref/single (instance index) single-float
134   (flushable always-translatable))
135 (defknown %raw-instance-set/single (instance index single-float) single-float
136   (unsafe always-translatable))
137 (defknown %raw-instance-ref/double (instance index) double-float
138   (flushable always-translatable))
139 (defknown %raw-instance-set/double (instance index double-float) double-float
140   (unsafe always-translatable))
141 (defknown %raw-instance-ref/complex-single (instance index)
142   (complex single-float)
143   (flushable always-translatable))
144 (defknown %raw-instance-set/complex-single
145     (instance index (complex single-float))
146   (complex single-float)
147   (unsafe always-translatable))
148 (defknown %raw-instance-ref/complex-double (instance index)
149   (complex double-float)
150   (flushable always-translatable))
151 (defknown %raw-instance-set/complex-double
152     (instance index (complex double-float))
153   (complex double-float)
154   (unsafe always-translatable))
155
156 #!+(or x86 x86-64)
157 (defknown %raw-instance-atomic-incf/word (instance index sb!vm:signed-word) sb!vm:word
158     (unsafe always-translatable))
159
160 ;;; %RAW-{REF,SET}-FOO VOPs should be declared as taking a RAW-VECTOR
161 ;;; as their first argument (clarity and to match these DEFKNOWNs).
162 ;;; We declare RAW-VECTOR as a primitive type so the VOP machinery
163 ;;; will accept our VOPs as legitimate.  --njf, 2004-08-10
164
165 (defknown %raw-bits (t fixnum) sb!vm:word
166   (foldable flushable))
167 #!+x86
168 (defknown %raw-bits-with-offset (t fixnum fixnum) sb!vm:word
169   (flushable always-translatable))
170 (defknown (%set-raw-bits) (t fixnum sb!vm:word) sb!vm:word
171   (unsafe))
172 #!+x86
173 (defknown (%set-raw-bits-with-offset) (t fixnum fixnum sb!vm:word) sb!vm:word
174   (unsafe always-translatable))
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 merge-bits ((unsigned-byte 5) sb!vm:word sb!vm:word)
226   sb!vm:word
227   (foldable flushable movable))
228
229 (defknown word-logical-not (sb!vm:word) sb!vm:word
230   (foldable flushable movable))
231
232 (defknown (word-logical-and word-logical-nand
233            word-logical-or word-logical-nor
234            word-logical-xor word-logical-eqv
235            word-logical-andc1 word-logical-andc2
236            word-logical-orc1 word-logical-orc2)
237           (sb!vm:word sb!vm:word) sb!vm:word
238   (foldable flushable movable))
239
240 (defknown (shift-towards-start shift-towards-end) (sb!vm:word fixnum)
241   sb!vm:word
242   (foldable flushable movable))
243 \f
244 ;;;; bignum operations
245
246 (defknown %allocate-bignum (bignum-index) bignum-type
247   (flushable))
248
249 (defknown %bignum-length (bignum-type) bignum-index
250   (foldable flushable movable))
251
252 (defknown %bignum-set-length (bignum-type bignum-index) bignum-type
253   (unsafe))
254
255 (defknown %bignum-ref (bignum-type bignum-index) bignum-element-type
256   (flushable))
257 #!+(or x86 x86-64)
258 (defknown %bignum-ref-with-offset (bignum-type bignum-index (signed-byte 24))
259   bignum-element-type (flushable always-translatable))
260
261 (defknown %bignum-set (bignum-type bignum-index bignum-element-type)
262   bignum-element-type
263   (unsafe))
264 #!+(or x86 x86-64)
265 (defknown %bignum-set-with-offset
266   (bignum-type bignum-index (signed-byte 24) bignum-element-type)
267   bignum-element-type (unsafe always-translatable))
268
269 (defknown %digit-0-or-plusp (bignum-element-type) boolean
270   (foldable flushable movable))
271
272 (defknown (%add-with-carry %subtract-with-borrow)
273           (bignum-element-type bignum-element-type (mod 2))
274   (values bignum-element-type (mod 2))
275   (foldable flushable movable))
276
277 (defknown %multiply-and-add
278           (bignum-element-type bignum-element-type bignum-element-type
279                                &optional bignum-element-type)
280   (values bignum-element-type bignum-element-type)
281   (foldable flushable movable))
282
283 (defknown %multiply (bignum-element-type bignum-element-type)
284   (values bignum-element-type bignum-element-type)
285   (foldable flushable movable))
286
287 (defknown %lognot (bignum-element-type) bignum-element-type
288   (foldable flushable movable))
289
290 (defknown (%logand %logior %logxor) (bignum-element-type bignum-element-type)
291   bignum-element-type
292   (foldable flushable movable))
293
294 (defknown %fixnum-to-digit (fixnum) bignum-element-type
295   (foldable flushable movable))
296
297 (defknown %floor (bignum-element-type bignum-element-type bignum-element-type)
298   (values bignum-element-type bignum-element-type)
299   (foldable flushable movable))
300
301 (defknown %fixnum-digit-with-correct-sign (bignum-element-type)
302   (signed-byte #.sb!vm:n-word-bits)
303   (foldable flushable movable))
304
305 (defknown (%ashl %ashr %digit-logical-shift-right)
306           (bignum-element-type (mod #.sb!vm:n-word-bits)) bignum-element-type
307   (foldable flushable movable))
308 \f
309 ;;;; bit-bashing routines
310
311 ;;; FIXME: there's some ugly duplication between the (INTERN (FORMAT ...))
312 ;;; magic here and the same magic in src/code/bit-bash.lisp.  I don't know
313 ;;; of any good way to clean it up, but it's definitely violating OAOO.
314 (macrolet ((define-known-copiers ()
315             `(progn
316               ,@(loop for i = 1 then (* i 2)
317                       collect `(defknown ,(intern (format nil "UB~D-BASH-COPY" i)
318                                                   (find-package "SB!KERNEL"))
319                                 ((simple-unboxed-array (*)) index (simple-unboxed-array (*)) index index)
320                                 (values)
321                                 ())
322                       collect `(defknown ,(intern (format nil "SYSTEM-AREA-UB~D-COPY" i)
323                                                   (find-package "SB!KERNEL"))
324                                 (system-area-pointer index system-area-pointer index index)
325                                 (values)
326                                 ())
327                       collect `(defknown ,(intern (format nil "COPY-UB~D-TO-SYSTEM-AREA" i)
328                                                   (find-package "SB!KERNEL"))
329                                 ((simple-unboxed-array (*)) index system-area-pointer index index)
330                                 (values)
331                                 ())
332                       collect `(defknown ,(intern (format nil "COPY-UB~D-FROM-SYSTEM-AREA" i)
333                                                   (find-package "SB!KERNEL"))
334                                 (system-area-pointer index (simple-unboxed-array (*)) index index)
335                                 (values)
336                                 ())
337                       until (= i sb!vm:n-word-bits)))))
338   (define-known-copiers))
339
340 ;;; (not really a bit-bashing routine, but starting to take over from
341 ;;; bit-bashing routines in byte-sized copies as of sbcl-0.6.12.29:)
342 (defknown %byte-blt
343   ((or (simple-unboxed-array (*)) system-area-pointer) index
344    (or (simple-unboxed-array (*)) system-area-pointer) index index)
345   (values)
346   ())
347 \f
348 ;;;; code/function/fdefn object manipulation routines
349
350 (defknown code-instructions (t) system-area-pointer (flushable movable))
351 (defknown code-header-ref (t index) t (flushable))
352 (defknown code-header-set (t index t) t ())
353
354 (defknown fun-subtype (function) (unsigned-byte #.sb!vm:n-widetag-bits)
355   (flushable))
356 (defknown ((setf fun-subtype))
357           ((unsigned-byte #.sb!vm:n-widetag-bits) function)
358   (unsigned-byte #.sb!vm:n-widetag-bits)
359   ())
360
361 (defknown make-fdefn (t) fdefn (flushable movable))
362 (defknown fdefn-p (t) boolean (movable foldable flushable))
363 (defknown fdefn-name (fdefn) t (foldable flushable))
364 (defknown fdefn-fun (fdefn) (or function null) (flushable))
365 (defknown (setf fdefn-fun) (function fdefn) t (unsafe))
366 (defknown fdefn-makunbound (fdefn) t ())
367
368 (defknown %simple-fun-self (function) function
369   (flushable))
370 (defknown (setf %simple-fun-self) (function function) function
371   (unsafe))
372
373 (defknown %closure-fun (function) function
374   (flushable))
375
376 (defknown %closure-index-ref (function index) t
377   (flushable))
378
379 (defknown %make-funcallable-instance (index) function
380   (unsafe))
381
382 (defknown %funcallable-instance-info (function index) t (flushable))
383 (defknown %set-funcallable-instance-info (function index t) t (unsafe))
384 \f
385 ;;;; mutator accessors
386
387 (defknown mutator-self () system-area-pointer (flushable movable))
388
389 (defknown %data-vector-and-index (array index)
390                                  (values (simple-array * (*)) index)
391                                  (foldable flushable))