1.0.20.8: ATOMIC-INCF implementation
[sbcl/pkhuong.git] / src / compiler / generic / vm-fndb.lisp
blob28b263b5f8d9ca6a511fca635c5bc73b7defc417
1 ;;;; signatures of machine-specific functions
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.
12 (in-package "SB!C")
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
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))
70 ;;;; miscellaneous "sub-primitives"
72 (defknown pointer-hash (t) hash (flushable))
74 (defknown %sp-string-compare
75 (simple-string index index simple-string index index)
76 (or index null)
77 (foldable flushable))
79 (defknown %sxhash-simple-string (simple-string) index
80 (foldable flushable))
82 (defknown %sxhash-simple-substring (simple-string index) index
83 (foldable flushable))
85 (defknown symbol-hash (symbol) (integer 0 #.sb!xc:most-positive-fixnum)
86 (flushable movable))
88 (defknown %set-symbol-hash (symbol (integer 0 #.sb!xc:most-positive-fixnum))
89 t (unsafe))
91 (defknown vector-length (vector) index (flushable))
93 (defknown vector-sap ((simple-unboxed-array (*))) system-area-pointer
94 (flushable))
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))
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))
106 (defknown %array-dimension (t index) index
107 (flushable))
108 (defknown %set-array-dimension (t index index) index
110 (defknown %array-rank (t) index
111 (flushable))
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)
129 #!-hppa
130 (progn
131 (defknown %raw-instance-ref/word (instance index) sb!vm:word
132 (flushable always-translatable))
133 (defknown %raw-instance-set/word (instance index sb!vm:word) sb!vm:word
134 (unsafe always-translatable))
135 (defknown %raw-instance-ref/single (instance index) single-float
136 (flushable always-translatable))
137 (defknown %raw-instance-set/single (instance index single-float) single-float
138 (unsafe always-translatable))
139 (defknown %raw-instance-ref/double (instance index) double-float
140 (flushable always-translatable))
141 (defknown %raw-instance-set/double (instance index double-float) double-float
142 (unsafe always-translatable))
143 (defknown %raw-instance-ref/complex-single (instance index)
144 (complex single-float)
145 (flushable always-translatable))
146 (defknown %raw-instance-set/complex-single
147 (instance index (complex single-float))
148 (complex single-float)
149 (unsafe always-translatable))
150 (defknown %raw-instance-ref/complex-double (instance index)
151 (complex double-float)
152 (flushable always-translatable))
153 (defknown %raw-instance-set/complex-double
154 (instance index (complex double-float))
155 (complex double-float)
156 (unsafe always-translatable)))
158 #!+(or x86 x86-64)
159 (defknown %raw-instance-atomic-incf/word (instance index sb!vm:signed-word) sb!vm:word
160 (unsafe always-translatable))
162 ;;; %RAW-{REF,SET}-FOO VOPs should be declared as taking a RAW-VECTOR
163 ;;; as their first argument (clarity and to match these DEFKNOWNs).
164 ;;; We declare RAW-VECTOR as a primitive type so the VOP machinery
165 ;;; will accept our VOPs as legitimate. --njf, 2004-08-10
167 ;;; These are only used on HPPA, since on HPPA implements raw slots in
168 ;;; structures with an indirection vector; all other ports implement
169 ;;; raw slots directly in the structure. --njf, 2006-06-02
170 #!+hppa
171 (progn
172 (sb!xc:deftype raw-vector () '(simple-array sb!vm:word (*)))
174 (sb!vm::!def-primitive-type-alias raw-vector
175 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
176 sb!vm::simple-array-unsigned-byte-32
177 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
178 sb!vm::simple-array-unsigned-byte-64)
180 (defknown %raw-ref-single (raw-vector index) single-float
181 (foldable flushable always-translatable))
182 (defknown %raw-ref-double (raw-vector index) double-float
183 (foldable flushable always-translatable))
184 #!+long-float
185 (defknown %raw-ref-long (raw-vector index) long-float
186 (foldable flushable always-translatable))
187 (defknown %raw-set-single (raw-vector index single-float) single-float
188 (unsafe always-translatable))
189 (defknown %raw-set-double (raw-vector index double-float) double-float
190 (unsafe always-translatable))
191 #!+long-float
192 (defknown %raw-set-long (raw-vector index long-float) long-float
193 (unsafe always-translatable))
195 (defknown %raw-ref-complex-single (raw-vector index) (complex single-float)
196 (foldable flushable always-translatable))
197 (defknown %raw-ref-complex-double (raw-vector index) (complex double-float)
198 (foldable flushable always-translatable))
200 (defknown %raw-set-complex-single (raw-vector index (complex single-float))
201 (complex single-float)
202 (unsafe always-translatable))
203 (defknown %raw-set-complex-double (raw-vector index (complex double-float))
204 (complex double-float)
205 (unsafe always-translatable))
208 (defknown %raw-bits (t fixnum) sb!vm:word
209 (foldable flushable))
210 #!+x86
211 (defknown %raw-bits-with-offset (t fixnum fixnum) sb!vm:word
212 (flushable always-translatable))
213 (defknown (%set-raw-bits) (t fixnum sb!vm:word) sb!vm:word
214 (unsafe))
215 #!+x86
216 (defknown (%set-raw-bits-with-offset) (t fixnum fixnum sb!vm:word) sb!vm:word
217 (unsafe always-translatable))
218 ;;; These two are mostly used for bit-bashing operations.
219 (defknown %vector-raw-bits (t fixnum) sb!vm:word
220 (flushable))
221 (defknown (%set-vector-raw-bits) (t fixnum sb!vm:word) sb!vm:word
222 (unsafe))
225 (defknown allocate-vector ((unsigned-byte 8) index index) (simple-array * (*))
226 (flushable movable))
228 (defknown make-array-header ((unsigned-byte 8) (unsigned-byte 24)) array
229 (flushable movable))
232 (defknown make-weak-pointer (t) weak-pointer
233 (flushable))
235 (defknown %make-complex (real real) complex
236 (flushable movable))
237 (defknown %make-ratio (rational rational) ratio
238 (flushable movable))
239 (defknown make-value-cell (t) t
240 (flushable movable))
242 ;;;; threading
244 #!+(and sb-lutex sb-thread)
245 (progn
246 (defknown sb!vm::%make-lutex () sb!vm::lutex ())
247 (defknown sb!vm::lutexp (t) boolean (foldable flushable)))
249 (defknown (dynamic-space-free-pointer binding-stack-pointer-sap
250 control-stack-pointer-sap) ()
251 system-area-pointer
252 (flushable))
254 ;;;; debugger support
256 (defknown current-sp () system-area-pointer (movable flushable))
257 (defknown current-fp () system-area-pointer (movable flushable))
258 (defknown stack-ref (system-area-pointer index) t (flushable))
259 (defknown %set-stack-ref (system-area-pointer index t) t (unsafe))
260 (defknown lra-code-header (t) t (movable flushable))
261 (defknown fun-code-header (t) t (movable flushable))
262 (defknown %make-lisp-obj (sb!vm:word) t (movable flushable))
263 (defknown get-lisp-obj-address (t) sb!vm:word (movable flushable))
264 (defknown fun-word-offset (function) index (movable flushable))
266 ;;;; 32-bit logical operations
268 (defknown merge-bits ((unsigned-byte 5) sb!vm:word sb!vm:word)
269 sb!vm:word
270 (foldable flushable movable))
272 (defknown word-logical-not (sb!vm:word) sb!vm:word
273 (foldable flushable movable))
275 (defknown (word-logical-and word-logical-nand
276 word-logical-or word-logical-nor
277 word-logical-xor word-logical-eqv
278 word-logical-andc1 word-logical-andc2
279 word-logical-orc1 word-logical-orc2)
280 (sb!vm:word sb!vm:word) sb!vm:word
281 (foldable flushable movable))
283 (defknown (shift-towards-start shift-towards-end) (sb!vm:word fixnum)
284 sb!vm:word
285 (foldable flushable movable))
287 ;;;; bignum operations
289 (defknown %allocate-bignum (bignum-index) bignum-type
290 (flushable))
292 (defknown %bignum-length (bignum-type) bignum-index
293 (foldable flushable movable))
295 (defknown %bignum-set-length (bignum-type bignum-index) bignum-type
296 (unsafe))
298 (defknown %bignum-ref (bignum-type bignum-index) bignum-element-type
299 (flushable))
300 #!+(or x86 x86-64)
301 (defknown %bignum-ref-with-offset (bignum-type bignum-index (signed-byte 24))
302 bignum-element-type (flushable always-translatable))
304 (defknown %bignum-set (bignum-type bignum-index bignum-element-type)
305 bignum-element-type
306 (unsafe))
307 #!+(or x86 x86-64)
308 (defknown %bignum-set-with-offset
309 (bignum-type bignum-index (signed-byte 24) bignum-element-type)
310 bignum-element-type (unsafe always-translatable))
312 (defknown %digit-0-or-plusp (bignum-element-type) boolean
313 (foldable flushable movable))
315 (defknown (%add-with-carry %subtract-with-borrow)
316 (bignum-element-type bignum-element-type (mod 2))
317 (values bignum-element-type (mod 2))
318 (foldable flushable movable))
320 (defknown %multiply-and-add
321 (bignum-element-type bignum-element-type bignum-element-type
322 &optional bignum-element-type)
323 (values bignum-element-type bignum-element-type)
324 (foldable flushable movable))
326 (defknown %multiply (bignum-element-type bignum-element-type)
327 (values bignum-element-type bignum-element-type)
328 (foldable flushable movable))
330 (defknown %lognot (bignum-element-type) bignum-element-type
331 (foldable flushable movable))
333 (defknown (%logand %logior %logxor) (bignum-element-type bignum-element-type)
334 bignum-element-type
335 (foldable flushable movable))
337 (defknown %fixnum-to-digit (fixnum) bignum-element-type
338 (foldable flushable movable))
340 (defknown %floor (bignum-element-type bignum-element-type bignum-element-type)
341 (values bignum-element-type bignum-element-type)
342 (foldable flushable movable))
344 (defknown %fixnum-digit-with-correct-sign (bignum-element-type)
345 (signed-byte #.sb!vm:n-word-bits)
346 (foldable flushable movable))
348 (defknown (%ashl %ashr %digit-logical-shift-right)
349 (bignum-element-type (mod #.sb!vm:n-word-bits)) bignum-element-type
350 (foldable flushable movable))
352 ;;;; bit-bashing routines
354 ;;; FIXME: there's some ugly duplication between the (INTERN (FORMAT ...))
355 ;;; magic here and the same magic in src/code/bit-bash.lisp. I don't know
356 ;;; of any good way to clean it up, but it's definitely violating OAOO.
357 (macrolet ((define-known-copiers ()
358 `(progn
359 ,@(loop for i = 1 then (* i 2)
360 collect `(defknown ,(intern (format nil "UB~D-BASH-COPY" i)
361 (find-package "SB!KERNEL"))
362 ((simple-unboxed-array (*)) index (simple-unboxed-array (*)) index index)
363 (values)
365 collect `(defknown ,(intern (format nil "SYSTEM-AREA-UB~D-COPY" i)
366 (find-package "SB!KERNEL"))
367 (system-area-pointer index system-area-pointer index index)
368 (values)
370 collect `(defknown ,(intern (format nil "COPY-UB~D-TO-SYSTEM-AREA" i)
371 (find-package "SB!KERNEL"))
372 ((simple-unboxed-array (*)) index system-area-pointer index index)
373 (values)
375 collect `(defknown ,(intern (format nil "COPY-UB~D-FROM-SYSTEM-AREA" i)
376 (find-package "SB!KERNEL"))
377 (system-area-pointer index (simple-unboxed-array (*)) index index)
378 (values)
380 until (= i sb!vm:n-word-bits)))))
381 (define-known-copiers))
383 ;;; (not really a bit-bashing routine, but starting to take over from
384 ;;; bit-bashing routines in byte-sized copies as of sbcl-0.6.12.29:)
385 (defknown %byte-blt
386 ((or (simple-unboxed-array (*)) system-area-pointer) index
387 (or (simple-unboxed-array (*)) system-area-pointer) index index)
388 (values)
391 ;;;; code/function/fdefn object manipulation routines
393 (defknown code-instructions (t) system-area-pointer (flushable movable))
394 (defknown code-header-ref (t index) t (flushable))
395 (defknown code-header-set (t index t) t ())
397 (defknown fun-subtype (function) (unsigned-byte #.sb!vm:n-widetag-bits)
398 (flushable))
399 (defknown ((setf fun-subtype))
400 ((unsigned-byte #.sb!vm:n-widetag-bits) function)
401 (unsigned-byte #.sb!vm:n-widetag-bits)
404 (defknown make-fdefn (t) fdefn (flushable movable))
405 (defknown fdefn-p (t) boolean (movable foldable flushable))
406 (defknown fdefn-name (fdefn) t (foldable flushable))
407 (defknown fdefn-fun (fdefn) (or function null) (flushable))
408 (defknown (setf fdefn-fun) (function fdefn) t (unsafe))
409 (defknown fdefn-makunbound (fdefn) t ())
411 (defknown %simple-fun-self (function) function
412 (flushable))
413 (defknown (setf %simple-fun-self) (function function) function
414 (unsafe))
416 (defknown %closure-fun (function) function
417 (flushable))
419 (defknown %closure-index-ref (function index) t
420 (flushable))
422 (defknown %make-funcallable-instance (index) function
423 (unsafe))
425 (defknown %funcallable-instance-info (function index) t (flushable))
426 (defknown %set-funcallable-instance-info (function index t) t (unsafe))
428 ;;;; mutator accessors
430 (defknown mutator-self () system-area-pointer (flushable movable))
432 (defknown %data-vector-and-index (array index)
433 (values (simple-array * (*)) index)
434 (foldable flushable))