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