1 ;;;; signatures of machine-specific functions
3 ;;;; This software is part of the SBCL system. See the README file for
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.
14 ;;;; internal type predicates
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
23 base-char-p %standard-char-p %instancep
24 base-string-p simple-base-string-p
25 #!+sb-unicode character-string-p
26 #!+sb-unicode simple-character-string-p
28 simple-array-p simple-array-nil-p vector-nil-p
29 simple-array-unsigned-byte-2-p
30 simple-array-unsigned-byte-4-p simple-array-unsigned-byte-7-p
31 simple-array-unsigned-byte-8-p simple-array-unsigned-byte-15-p
32 simple-array-unsigned-byte-16-p
33 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
34 simple-array-unsigned-byte-29-p
35 simple-array-unsigned-byte-31-p
36 simple-array-unsigned-byte-32-p
37 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
38 simple-array-unsigned-byte-60-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 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
45 simple-array-signed-byte-30-p
46 simple-array-signed-byte-32-p
47 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
48 simple-array-signed-byte-61-p
49 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
50 simple-array-signed-byte-64-p
51 simple-array-single-float-p simple-array-double-float-p
52 #!+long-float simple-array-long-float-p
53 simple-array-complex-single-float-p
54 simple-array-complex-double-float-p
55 #!+long-float simple-array-complex-long-float-p
56 system-area-pointer-p realp
57 ;; #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
59 ;; #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
61 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
63 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
65 vector-t-p weak-pointer-p code-component-p lra-p
66 funcallable-instance-p)
67 (t) boolean (movable foldable flushable))
69 ;;;; miscellaneous "sub-primitives"
71 (defknown %sp-string-compare
72 (simple-string index index simple-string index index)
76 (defknown %sxhash-simple-string (simple-string) index
79 (defknown %sxhash-simple-substring (simple-string index) index
82 (defknown symbol-hash (symbol) (integer 0 #.sb!xc:most-positive-fixnum)
85 (defknown %set-symbol-hash (symbol (integer 0 #.sb!xc:most-positive-fixnum))
88 (defknown vector-length (vector) index (flushable))
90 (defknown vector-sap ((simple-unboxed-array (*))) system-area-pointer
93 (defknown lowtag-of (t) (unsigned-byte #.sb!vm:n-lowtag-bits)
95 (defknown widetag-of (t) (unsigned-byte #.sb!vm:n-widetag-bits)
98 (defknown (get-header-data get-closure-length) (t) (unsigned-byte 24)
100 (defknown set-header-data (t (unsigned-byte 24)) t
103 (defknown %array-dimension (t index) index
105 (defknown %set-array-dimension (t index index) index
107 (defknown %array-rank (t) index
110 (defknown %make-instance (index) instance
112 (defknown %instance-layout (instance) layout
113 (foldable flushable))
114 (defknown %set-instance-layout (instance layout) layout
116 (defknown %instance-length (instance) index
117 (foldable flushable))
118 (defknown %instance-ref (instance index) t
120 (defknown %instance-set (instance index t) t
122 (defknown %layout-invalid-error (t layout) nil)
125 (sb!xc:deftype raw-vector () '(simple-array sb!vm:word (*)))
127 ;;; %RAW-{REF,SET}-FOO VOPs should be declared as taking a RAW-VECTOR
128 ;;; as their first argument (clarity and to match these DEFKNOWNs).
129 ;;; We declare RAW-VECTOR as a primitive type so the VOP machinery
130 ;;; will accept our VOPs as legitimate. --njf, 2004-08-10
131 (sb!vm::!def-primitive-type-alias raw-vector
132 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
133 sb!vm::simple-array-unsigned-byte-32
134 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
135 sb!vm::simple-array-unsigned-byte-64)
137 (defknown %raw-ref-single (raw-vector index) single-float
138 (foldable flushable))
139 (defknown %raw-ref-double (raw-vector index) double-float
140 (foldable flushable))
142 (defknown %raw-ref-long (raw-vector index) long-float
143 (foldable flushable))
144 (defknown %raw-set-single (raw-vector index single-float) single-float
146 (defknown %raw-set-double (raw-vector index double-float) double-float
149 (defknown %raw-set-long (raw-vector index long-float) long-float
152 (defknown %raw-ref-complex-single (raw-vector index) (complex single-float)
153 (foldable flushable))
154 (defknown %raw-ref-complex-double (raw-vector index) (complex double-float)
155 (foldable flushable))
157 (defknown %raw-set-complex-single (raw-vector index (complex single-float))
158 (complex single-float)
160 (defknown %raw-set-complex-double (raw-vector index (complex double-float))
161 (complex double-float)
165 (defknown %raw-bits (t fixnum) sb!vm:word
166 (foldable flushable))
167 (defknown (%set-raw-bits) (t fixnum sb!vm:word) sb!vm:word
169 ;; These two are mostly used for bit-bashing operations.
170 (defknown %vector-raw-bits (t fixnum) sb!vm:word
171 (foldable flushable))
172 (defknown (%set-vector-raw-bits) (t fixnum sb!vm:word) sb!vm:word
176 (defknown allocate-vector ((unsigned-byte 8) index index) (simple-array * (*))
179 (defknown make-array-header ((unsigned-byte 8) (unsigned-byte 24)) array
183 (defknown make-weak-pointer (t) weak-pointer
186 (defknown %make-complex (real real) complex
188 (defknown %make-ratio (rational rational) ratio
190 (defknown make-value-cell (t) t
193 (defknown (dynamic-space-free-pointer binding-stack-pointer-sap
194 control-stack-pointer-sap) ()
198 ;;;; debugger support
200 (defknown current-sp () system-area-pointer (movable flushable))
201 (defknown current-fp () system-area-pointer (movable flushable))
202 (defknown stack-ref (system-area-pointer index) t (flushable))
203 (defknown %set-stack-ref (system-area-pointer index t) t (unsafe))
204 (defknown lra-code-header (t) t (movable flushable))
205 (defknown fun-code-header (t) t (movable flushable))
206 (defknown make-lisp-obj (sb!vm:word) t (movable flushable))
207 (defknown get-lisp-obj-address (t) sb!vm:word (movable flushable))
208 (defknown fun-word-offset (function) index (movable flushable))
210 ;;;; 32-bit logical operations
212 (defknown merge-bits ((unsigned-byte 5) sb!vm:word sb!vm:word)
214 (foldable flushable movable))
216 (defknown word-logical-not (sb!vm:word) sb!vm:word
217 (foldable flushable movable))
219 (defknown (word-logical-and word-logical-nand
220 word-logical-or word-logical-nor
221 word-logical-xor word-logical-eqv
222 word-logical-andc1 word-logical-andc2
223 word-logical-orc1 word-logical-orc2)
224 (sb!vm:word sb!vm:word) sb!vm:word
225 (foldable flushable movable))
227 (defknown (shift-towards-start shift-towards-end) (sb!vm:word fixnum)
229 (foldable flushable movable))
231 ;;;; bignum operations
233 (defknown %allocate-bignum (bignum-index) bignum-type
236 (defknown %bignum-length (bignum-type) bignum-index
237 (foldable flushable movable))
239 (defknown %bignum-set-length (bignum-type bignum-index) bignum-type
242 (defknown %bignum-ref (bignum-type bignum-index) bignum-element-type
245 (defknown %bignum-set (bignum-type bignum-index bignum-element-type)
249 (defknown %digit-0-or-plusp (bignum-element-type) boolean
250 (foldable flushable movable))
252 (defknown (%add-with-carry %subtract-with-borrow)
253 (bignum-element-type bignum-element-type (mod 2))
254 (values bignum-element-type (mod 2))
255 (foldable flushable movable))
257 (defknown %multiply-and-add
258 (bignum-element-type bignum-element-type bignum-element-type
259 &optional bignum-element-type)
260 (values bignum-element-type bignum-element-type)
261 (foldable flushable movable))
263 (defknown %multiply (bignum-element-type bignum-element-type)
264 (values bignum-element-type bignum-element-type)
265 (foldable flushable movable))
267 (defknown %lognot (bignum-element-type) bignum-element-type
268 (foldable flushable movable))
270 (defknown (%logand %logior %logxor) (bignum-element-type bignum-element-type)
272 (foldable flushable movable))
274 (defknown %fixnum-to-digit (fixnum) bignum-element-type
275 (foldable flushable movable))
277 (defknown %floor (bignum-element-type bignum-element-type bignum-element-type)
278 (values bignum-element-type bignum-element-type)
279 (foldable flushable movable))
281 (defknown %fixnum-digit-with-correct-sign (bignum-element-type)
282 (signed-byte #.sb!vm:n-word-bits)
283 (foldable flushable movable))
285 (defknown (%ashl %ashr %digit-logical-shift-right)
286 (bignum-element-type (mod #.sb!vm:n-word-bits)) bignum-element-type
287 (foldable flushable movable))
289 ;;;; bit-bashing routines
291 ;;; FIXME: there's some ugly duplication between the (INTERN (FORMAT ...))
292 ;;; magic here and the same magic in src/code/bit-bash.lisp. I don't know
293 ;;; of any good way to clean it up, but it's definitely violating OAOO.
294 (macrolet ((define-known-copiers ()
296 ,@(loop for i = 1 then (* i 2)
297 collect `(defknown ,(intern (format nil "UB~A-BASH-COPY" i)
298 (find-package "SB!KERNEL"))
299 ((simple-unboxed-array (*)) index (simple-unboxed-array (*)) index index)
302 collect `(defknown ,(intern (format nil "SYSTEM-AREA-UB~A-COPY" i)
303 (find-package "SB!KERNEL"))
304 (system-area-pointer index system-area-pointer index index)
307 collect `(defknown ,(intern (format nil "COPY-UB~A-TO-SYSTEM-AREA" i)
308 (find-package "SB!KERNEL"))
309 ((simple-unboxed-array (*)) index system-area-pointer index index)
312 collect `(defknown ,(intern (format nil "COPY-UB~A-FROM-SYSTEM-AREA" i)
313 (find-package "SB!KERNEL"))
314 (system-area-pointer index (simple-unboxed-array (*)) index index)
317 until (= i sb!vm:n-word-bits)))))
318 (define-known-copiers))
320 ;;; (not really a bit-bashing routine, but starting to take over from
321 ;;; bit-bashing routines in byte-sized copies as of sbcl-0.6.12.29:)
323 ((or (simple-unboxed-array (*)) system-area-pointer) index
324 (or (simple-unboxed-array (*)) system-area-pointer) index index)
328 ;;;; code/function/fdefn object manipulation routines
330 (defknown code-instructions (t) system-area-pointer (flushable movable))
331 (defknown code-header-ref (t index) t (flushable))
332 (defknown code-header-set (t index t) t ())
334 (defknown fun-subtype (function) (unsigned-byte #.sb!vm:n-widetag-bits)
336 (defknown ((setf fun-subtype))
337 ((unsigned-byte #.sb!vm:n-widetag-bits) function)
338 (unsigned-byte #.sb!vm:n-widetag-bits)
341 (defknown make-fdefn (t) fdefn (flushable movable))
342 (defknown fdefn-p (t) boolean (movable foldable flushable))
343 (defknown fdefn-name (fdefn) t (foldable flushable))
344 (defknown fdefn-fun (fdefn) (or function null) (flushable))
345 (defknown (setf fdefn-fun) (function fdefn) t (unsafe))
346 (defknown fdefn-makunbound (fdefn) t ())
348 (defknown %simple-fun-self (function) function
350 (defknown (setf %simple-fun-self) (function function) function
353 (defknown %closure-fun (function) function
356 (defknown %closure-index-ref (function index) t
359 (defknown %make-funcallable-instance (index layout) function
362 (defknown %funcallable-instance-info (function index) t (flushable))
363 (defknown %set-funcallable-instance-info (function index t) t (unsafe))
365 ;;;; mutator accessors
367 (defknown mutator-self () system-area-pointer (flushable movable))
369 (defknown %data-vector-and-index (array index)
370 (values (simple-array * (*)) index)
371 (foldable flushable))