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