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 #!+sb-unicode base-char-p
24 %standard-char-p %instancep
25 base-string-p simple-base-string-p
26 #!+sb-unicode character-string-p
27 #!+sb-unicode simple-character-string-p
29 sequencep extended-sequence-p
30 simple-array-p simple-array-nil-p vector-nil-p
31 simple-array-unsigned-byte-2-p
32 simple-array-unsigned-byte-4-p simple-array-unsigned-byte-7-p
33 simple-array-unsigned-byte-8-p simple-array-unsigned-byte-15-p
34 simple-array-unsigned-byte-16-p
36 simple-array-unsigned-fixnum-p
38 simple-array-unsigned-byte-31-p
39 simple-array-unsigned-byte-32-p
41 simple-array-unsigned-byte-63-p
43 simple-array-unsigned-byte-64-p
44 simple-array-signed-byte-8-p simple-array-signed-byte-16-p
48 simple-array-signed-byte-32-p
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 simple-rank-1-array-
*-p
57 system-area-pointer-p realp
66 weak-pointer-p code-component-p lra-p
69 funcallable-instance-p
)
70 (t) boolean
(movable foldable flushable
))
72 (defknown #.
(loop for
(name) in
*vector-without-complex-typecode-infos
*
74 (t) boolean
(movable foldable flushable
))
76 (defknown %other-pointer-p
(t) boolean
77 (movable foldable flushable always-translatable
))
79 ;; Return T if the first arg is an other-pointer and its widetag
80 ;; is in the collection specified by the second arg.
81 (defknown %other-pointer-subtype-p
(t list
) boolean
82 (movable foldable flushable always-translatable
))
84 ;;;; miscellaneous "sub-primitives"
86 (defknown pointer-hash
(t) hash
(flushable))
88 (defknown %sp-string-compare
89 (simple-string index index simple-string index index
)
93 (defknown %sxhash-simple-string
(simple-string) hash
96 (defknown (%sxhash-simple-substring compute-symbol-hash
)
97 (simple-string index
) hash
100 (defknown symbol-hash
(symbol) hash
103 (defknown %set-symbol-hash
(symbol hash
)
106 (defknown symbol-info-vector
(symbol) (or null simple-vector
))
108 (defknown initialize-vector
((simple-array * (*)) &rest t
)
110 (always-translatable flushable
)
113 (defknown vector-fill
* (t t t t
) vector
117 (defknown vector-length
(vector) index
(flushable dx-safe
))
119 (defknown vector-sap
((simple-unboxed-array (*))) system-area-pointer
122 (defknown lowtag-of
(t) (unsigned-byte #.sb
!vm
:n-lowtag-bits
)
124 (defknown (widetag-of %other-pointer-widetag
) (t)
125 (unsigned-byte #.sb
!vm
:n-widetag-bits
)
128 (defknown (get-header-data get-closure-length
) (t)
129 (unsigned-byte #.
(- sb
!vm
:n-word-bits sb
!vm
:n-widetag-bits
))
131 ;;; This unconventional setter returns its first arg, not the newval.
132 (defknown set-header-data
133 (t (unsigned-byte #.
(- sb
!vm
:n-word-bits sb
!vm
:n-widetag-bits
))) t
)
136 (defknown sb
!vm
::get-header-data-high
(t) (unsigned-byte 32) (flushable))
137 (defknown sb
!vm
::cas-header-data-high
138 (t (unsigned-byte 32) (unsigned-byte 32)) (unsigned-byte 32)))
140 (defknown %array-dimension
(t index
) index
142 (defknown %set-array-dimension
(t index index
) index
144 (defknown %array-rank
(t) array-rank
147 (defknown sb
!kernel
::check-array-shape
(simple-array list
)
152 (defknown %make-instance
(index) instance
154 (defknown %make-structure-instance
(defstruct-description list
&rest t
) instance
155 (flushable always-translatable
))
156 (defknown %instance-layout
(instance) layout
157 (foldable flushable
))
158 (defknown %funcallable-instance-layout
(funcallable-instance) layout
159 (foldable flushable
))
160 (defknown %set-instance-layout
(instance layout
) layout
162 (defknown %set-funcallable-instance-layout
(funcallable-instance layout
) layout
164 (defknown %instance-length
(instance) index
165 (foldable flushable
))
166 (defknown %instance-cas
(instance index t t
) t
())
167 (defknown %instance-ref
(instance index
) t
168 (flushable always-translatable
))
169 (defknown %instance-set
(instance index t
) t
170 (always-translatable)
171 :derive-type
#'result-type-last-arg
)
172 (defknown %layout-invalid-error
(t layout
) nil
)
175 (defknown %raw-instance-cas
/word
(instance index sb
!vm
:word sb
!vm
:word
)
180 (let* ((reader (sb!kernel
::raw-slot-data-accessor-name rsd
))
181 (name (copy-seq (string reader
)))
182 (writer (intern (replace name
"-SET/"
183 :start1
(search "-REF/" name
))))
184 (type (sb!kernel
::raw-slot-data-raw-type rsd
)))
186 (defknown ,reader
(instance index
) ,type
187 (flushable always-translatable
))
188 (defknown ,writer
(instance index
,type
) ,type
189 (always-translatable) :derive-type
#'result-type-last-arg
)
190 ;; Interpreter stubs, harmless but unnecessary on host
192 (progn (defun ,reader
(instance index
)
193 (,reader instance index
))
194 (defun ,writer
(instance index new-value
)
195 (,writer instance index new-value
))))))
196 sb
!kernel
::*raw-slot-data
*))
198 #!+compare-and-swap-vops
199 (defknown %raw-instance-atomic-incf
/word
(instance index sb
!vm
:word
) sb
!vm
:word
200 (always-translatable))
201 #!+compare-and-swap-vops
202 (defknown %array-atomic-incf
/word
(t index sb
!vm
:word
) sb
!vm
:word
203 (always-translatable))
205 ;;; These two are mostly used for bit-bashing operations.
206 (defknown %vector-raw-bits
(t fixnum
) sb
!vm
:word
208 (defknown (%set-vector-raw-bits
) (t fixnum sb
!vm
:word
) sb
!vm
:word
212 (defknown allocate-vector
((unsigned-byte 8) index
213 ;; The number of words is later converted
214 ;; to bytes, make sure it fits.
219 ;; all the allocation routines expect a signed word
221 ;; The size is double-word aligned, which is done by adding
222 ;; (1- (/ sb-vm:n-word-bits 2)) and then masking.
223 ;; Make sure addition doesn't overflow.
228 (defknown make-array-header
((unsigned-byte 8) (unsigned-byte 24)) array
231 (defknown make-array-header
* (&rest t
) array
(flushable movable
))
233 (defknown make-weak-pointer
(t) weak-pointer
236 (defknown %make-complex
(real real
) complex
238 (defknown %make-ratio
(rational rational
) ratio
240 (defknown make-value-cell
(t) t
245 (defknown simd-pack-p
(t) boolean
(foldable movable flushable
))
246 (defknown %simd-pack-tag
(simd-pack) fixnum
(movable flushable
))
247 (defknown %make-simd-pack
(fixnum (unsigned-byte 64) (unsigned-byte 64))
249 (flushable movable foldable
))
250 (defknown %make-simd-pack-double
(double-float double-float
)
251 (simd-pack double-float
)
252 (flushable movable foldable
))
253 (defknown %make-simd-pack-single
(single-float single-float
254 single-float single-float
)
255 (simd-pack single-float
)
256 (flushable movable foldable
))
257 (defknown %make-simd-pack-ub32
((unsigned-byte 32) (unsigned-byte 32)
258 (unsigned-byte 32) (unsigned-byte 32))
260 (flushable movable foldable
))
261 (defknown %make-simd-pack-ub64
((unsigned-byte 64) (unsigned-byte 64))
263 (flushable movable foldable
))
264 (defknown (%simd-pack-low %simd-pack-high
) (simd-pack)
266 (flushable movable foldable
))
267 (defknown %simd-pack-ub32s
(simd-pack)
268 (values (unsigned-byte 32) (unsigned-byte 32)
269 (unsigned-byte 32) (unsigned-byte 32))
270 (flushable movable foldable
))
271 (defknown %simd-pack-ub64s
(simd-pack)
272 (values (unsigned-byte 64) (unsigned-byte 64))
273 (flushable movable foldable
))
274 (defknown %simd-pack-singles
(simd-pack)
275 (values single-float single-float single-float single-float
)
276 (flushable movable foldable
))
277 (defknown %simd-pack-doubles
(simd-pack)
278 (values double-float double-float
)
279 (flushable movable foldable
)))
283 (defknown (dynamic-space-free-pointer binding-stack-pointer-sap
284 control-stack-pointer-sap
) ()
288 (defknown ensure-symbol-tls-index
(symbol) (and fixnum unsigned-byte
))
291 ;;;; debugger support
293 (defknown current-sp
() system-area-pointer
(movable flushable
))
294 (defknown current-fp
() system-area-pointer
(movable flushable
))
295 (defknown stack-ref
(system-area-pointer index
) t
(flushable))
296 (defknown %set-stack-ref
(system-area-pointer index t
) t
())
297 (defknown lra-code-header
(t) t
(movable flushable
))
298 (defknown fun-code-header
(t) t
(movable flushable
))
299 (defknown %make-lisp-obj
(sb!vm
:word
) t
(movable flushable
))
300 (defknown get-lisp-obj-address
(t) sb
!vm
:word
(movable flushable
))
301 (defknown fun-word-offset
(function) index
(movable flushable
))
303 ;;;; 32-bit logical operations
305 (defknown word-logical-not
(sb!vm
:word
) sb
!vm
:word
306 (foldable flushable movable
))
308 (defknown (word-logical-and word-logical-nand
309 word-logical-or word-logical-nor
310 word-logical-xor word-logical-eqv
311 word-logical-andc1 word-logical-andc2
312 word-logical-orc1 word-logical-orc2
)
313 (sb!vm
:word sb
!vm
:word
) sb
!vm
:word
314 (foldable flushable movable
))
316 (defknown (shift-towards-start shift-towards-end
) (sb!vm
:word fixnum
)
318 (foldable flushable movable
))
320 ;;;; bignum operations
322 (defknown %allocate-bignum
(bignum-length) bignum
325 (defknown %bignum-length
(bignum) bignum-length
326 (foldable flushable movable
))
328 (defknown %bignum-set-length
(bignum bignum-length
) bignum
331 (defknown %bignum-ref
(bignum bignum-index
) bignum-element-type
334 (defknown %bignum-ref-with-offset
(bignum fixnum
(signed-byte 24))
335 bignum-element-type
(flushable always-translatable
))
337 (defknown %bignum-set
(bignum bignum-index bignum-element-type
)
341 (defknown %digit-0-or-plusp
(bignum-element-type) boolean
342 (foldable flushable movable
))
344 (defknown (%add-with-carry %subtract-with-borrow
)
345 (bignum-element-type bignum-element-type
(mod 2))
346 (values bignum-element-type
(mod 2))
347 (foldable flushable movable
))
349 (defknown %multiply-and-add
350 (bignum-element-type bignum-element-type bignum-element-type
351 &optional bignum-element-type
)
352 (values bignum-element-type bignum-element-type
)
353 (foldable flushable movable
))
355 (defknown %multiply
(bignum-element-type bignum-element-type
)
356 (values bignum-element-type bignum-element-type
)
357 (foldable flushable movable
))
359 (defknown %lognot
(bignum-element-type) bignum-element-type
360 (foldable flushable movable
))
362 (defknown (%logand %logior %logxor
) (bignum-element-type bignum-element-type
)
364 (foldable flushable movable
))
366 (defknown %fixnum-to-digit
(fixnum) bignum-element-type
367 (foldable flushable movable
))
369 (defknown %bigfloor
(bignum-element-type bignum-element-type bignum-element-type
)
370 (values bignum-element-type bignum-element-type
)
371 (foldable flushable movable
))
373 (defknown %fixnum-digit-with-correct-sign
(bignum-element-type)
374 (signed-byte #.sb
!vm
:n-word-bits
)
375 (foldable flushable movable
))
377 (defknown (%ashl %ashr %digit-logical-shift-right
)
378 (bignum-element-type (mod #.sb
!vm
:n-word-bits
)) bignum-element-type
379 (foldable flushable movable
))
381 ;;;; bit-bashing routines
383 ;;; FIXME: there's some ugly duplication between the (INTERN (FORMAT ...))
384 ;;; magic here and the same magic in src/code/bit-bash.lisp. I don't know
385 ;;; of any good way to clean it up, but it's definitely violating OAOO.
386 (macrolet ((define-known-copiers ()
388 ,@(loop for i
= 1 then
(* i
2)
389 collect
`(defknown ,(intern (format nil
"UB~D-BASH-COPY" i
)
390 (find-package "SB!KERNEL"))
391 ((simple-unboxed-array (*)) index
(simple-unboxed-array (*)) index index
)
394 collect
`(defknown ,(intern (format nil
"SYSTEM-AREA-UB~D-COPY" i
)
395 (find-package "SB!KERNEL"))
396 (system-area-pointer index system-area-pointer index index
)
399 collect
`(defknown ,(intern (format nil
"COPY-UB~D-TO-SYSTEM-AREA" i
)
400 (find-package "SB!KERNEL"))
401 ((simple-unboxed-array (*)) index system-area-pointer index index
)
404 collect
`(defknown ,(intern (format nil
"COPY-UB~D-FROM-SYSTEM-AREA" i
)
405 (find-package "SB!KERNEL"))
406 (system-area-pointer index
(simple-unboxed-array (*)) index index
)
409 until
(= i sb
!vm
:n-word-bits
)))))
410 (define-known-copiers))
412 ;;; (not really a bit-bashing routine, but starting to take over from
413 ;;; bit-bashing routines in byte-sized copies as of sbcl-0.6.12.29:)
415 ((or (simple-unboxed-array (*)) system-area-pointer
) index
416 (or (simple-unboxed-array (*)) system-area-pointer
) index index
)
420 ;;;; code/function/fdefn object manipulation routines
422 (defknown code-instructions
(t) system-area-pointer
(flushable movable
))
423 (defknown code-header-ref
(t index
) t
(flushable))
424 (defknown code-header-set
(t index t
) t
())
426 (defknown fun-subtype
(function)
427 (member #.sb
!vm
:simple-fun-header-widetag
428 #.sb
!vm
:closure-header-widetag
429 #.sb
!vm
:funcallable-instance-header-widetag
)
432 (defknown make-fdefn
(t) fdefn
(flushable movable
))
433 (defknown fdefn-p
(t) boolean
(movable foldable flushable
))
434 (defknown fdefn-name
(fdefn) t
(foldable flushable
))
435 (defknown fdefn-fun
(fdefn) (or function null
) (flushable))
436 (defknown (setf fdefn-fun
) (function fdefn
) t
())
437 (defknown fdefn-makunbound
(fdefn) t
())
438 (defknown safe-fdefn-fun
(fdefn) function
())
440 (defknown %simple-fun-self
(function) function
442 (defknown (setf %simple-fun-self
) (function function
) function
444 (defknown %simple-fun-type
(function) t
(flushable))
446 (defknown %closure-fun
(function) function
449 (defknown %closure-index-ref
(function index
) t
452 (defknown %fun-fun
(function) function
(flushable recursive
))
454 (defknown %make-funcallable-instance
(index) function
457 (defknown %funcallable-instance-info
(function index
) t
(flushable))
458 (defknown %set-funcallable-instance-info
(function index t
) t
())
461 (defknown sb
!interpreter
:fun-proto-fn
(sb!interpreter
:interpreted-function
)
462 sb
!interpreter
::interpreted-fun-prototype
(flushable))
465 (defknown %data-vector-and-index
(array index
)
466 (values (simple-array * (*)) index
)
467 (foldable flushable
))