1 ;;;; type-based constants
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 ;;; FIXME: It's clever using :SUFFIX -LOWTAG for these things, but
15 ;;; it's a pain for people just learning to find their way around the
16 ;;; code who want to use lexical search to figure out where things
17 ;;; like EVEN-FIXNUM-LOWTAG are defined. Remove the :SUFFIXes and just
18 ;;; expand out the full names. Or even define them in DEF
19 ;;; EVEN-FIXNUM-LOWTAG style so searches like
20 ;;; 'def.*even-fixnum-lowtag' can find them.
22 ;;; Tags for the main low-level types are stored in the low n (usually three)
23 ;;; bits to identify the type of a machine word. Certain constraints
25 ;;; * EVEN-FIXNUM-LOWTAG and ODD-FIXNUM-LOWTAG must be 0 and 4: code
26 ;;; which shifts left two places to convert raw integers to tagged
27 ;;; fixnums is ubiquitous.
28 ;;; * LIST-POINTER-LOWTAG + N-WORD-BYTES = OTHER-POINTER-LOWTAG: NIL
29 ;;; is both a cons and a symbol (at the same address) and depends on this.
30 ;;; See the definition of SYMBOL in objdef.lisp
31 ;;; * OTHER-POINTER-LOWTAG > 4: Some code in the SPARC backend,
32 ;;; which uses bit 2 of the ALLOC register to indicate that
33 ;;; PSEUDO-ATOMIC is on, doesn't strip the low bits of reg_ALLOC
34 ;;; before ORing in OTHER-POINTER-LOWTAG within a PSEUDO-ATOMIC
36 ;;; * OTHER-IMMEDIATE-0-LOWTAG are spaced 4 apart: various code wants to
37 ;;; iterate through these
38 ;;; (These are just the ones we know about as of sbcl-0.7.1.22. There
39 ;;; might easily be more, since these values have stayed highly
40 ;;; constrained for more than a decade, an inviting target for
41 ;;; inventive abstraction-phobic maintainers.:-)
42 (eval-when (:compile-toplevel :load-toplevel :execute)
43 ;; The EVAL-WHEN is necessary (at least for Lispworks), because the
44 ;; second DEFENUM uses the value of OTHER-IMMEDIATE-0-LOWTAG, which is
45 ;; defined in the first DEFENUM. -- AL 20000216
46 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
47 (defenum (:suffix -lowtag)
60 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
61 (defenum (:suffix -lowtag)
71 (def!constant nil-value
72 (+ static-space-start n-word-bytes other-pointer-lowtag))
74 ;;; the heap types, stored in 8 bits of the header of an object on the
75 ;;; heap, to identify the type of the heap object (which'll be at
76 ;;; least two machine words, often more)
78 ;;; Note: the order specified here is not critical for correctness,
79 ;;; but (FIXME) with %TEST-HEADERS as currently defined, BIGNUM must
80 ;;; be first, and COMPLEX-ARRAY must be last.
82 ;;; However, for efficiency, we prefer contiguous sets of widetags for
83 ;;; "similar" objects, so that type checking can be done with a range
84 ;;; check, rather than several individual checks.
86 ;;; * BIGNUM + RATIO (+ FIXNUM) = RATIONAL
88 ;;; * SINGLE-FLOAT + DOUBLE-FLOAT + LONG-FLOAT = FLOAT
90 ;;; * RATIONAL + FLOAT = REAL
92 ;;; * (FIXME: COMPLEX example, which needs fixing anyway -- see
93 ;;; UPGRADED-COMPLEX-PART-TYPE)
95 ;;; * SIMPLE-ARRAY-* = (SIMPLE-ARRAY * (*))
97 ;;; * SIMPLE-ARRAY-NIL + SIMPLE-BASE-STRING = SIMPLE-STRING
99 ;;; * SIMPLE-ARRAY + COMPLEX-ARRAYOID = (SATISFIES ARRAY-HEADER-P)
101 ;;; In addition, with
102 ;;; sufficient care we can cause extra combinations to appear with
103 ;;; differences in only one bit, permitting a more efficient type
104 ;;; test. As an example, if SIMPLE-BASE-STRING = 0xA6 and
105 ;;; COMPLEX-BASE-STRING = 0xE6, then the type test for BASE-STRING is
107 ;;; AND tag, ~0x40, tag
108 ;;; ANDcc tag, 0xA6, tag
111 ;;; rather than two separate tests and jumps
112 (defenum (:suffix -widetag
113 ;; The first widetag must be greater than SB!VM:LOWTAG-LIMIT
114 ;; otherwise code in generic/early-type-vops will suffer
115 ;; a long, horrible death. --njf, 2004-08-09
116 :start (+ (ash 1 n-lowtag-bits) other-immediate-0-lowtag)
118 ;; NOTE: the binary numbers off to the side are only valid for 32-bit
119 ;; ports; add #x1000 if you want to know the values for 64-bit ports.
120 ;; And note that the numbers get a little scrambled further down.
124 single-float ; 00010010
125 double-float ; 00010110
127 complex-single-float ; 00011110
128 complex-double-float ; 00100010
130 code-header ; 00100110
132 simple-fun-header ; 00101010
133 closure-header ; 00101110
134 funcallable-instance-header ; 00110010
136 return-pc-header ; 00110110
137 value-cell-header ; 00111010
138 symbol-header ; 00111110
141 unbound-marker ; 01001010
142 weak-pointer ; 01001110
143 instance-header ; 01010010
157 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
159 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
162 simple-array-unsigned-byte-2 ; 10001010
163 simple-array-unsigned-byte-4 ; 10001110
164 simple-array-unsigned-byte-7 ; 10010010
165 simple-array-unsigned-byte-8 ; 10010110
166 simple-array-unsigned-byte-15 ; 10011010
167 simple-array-unsigned-byte-16 ; 10011110
168 simple-array-nil ; 10100010
169 simple-base-string ; 10100110
170 #!+sb-unicode simple-character-string
171 simple-bit-vector ; 10101010
172 simple-vector ; 10101110
173 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
174 simple-array-unsigned-byte-29 ; 10110010
175 simple-array-unsigned-byte-31 ; 10110110
176 simple-array-unsigned-byte-32 ; 10111010
177 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
178 simple-array-unsigned-byte-60
179 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
180 simple-array-unsigned-byte-63
181 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
182 simple-array-unsigned-byte-64
183 simple-array-signed-byte-8 ; 10111110
184 simple-array-signed-byte-16 ; 11000010
185 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
186 simple-array-signed-byte-30 ; 11000110
187 simple-array-signed-byte-32 ; 11001010
188 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
189 simple-array-signed-byte-61
190 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
191 simple-array-signed-byte-64
192 simple-array-single-float ; 11001110
193 simple-array-double-float ; 11010010
194 simple-array-complex-single-float ; 11010110
195 simple-array-complex-double-float ; 11011010
196 simple-array ; 11011110
197 complex-vector-nil ; 11100010
198 complex-base-string ; 11100110
199 #!+sb-unicode complex-character-string
200 complex-bit-vector ; 11101010
201 complex-vector ; 11101110
202 complex-array ; 11110010
204 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
206 #!+(and #.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
209 #!+(and #.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
214 ;;; the different vector subtypes
215 (defenum (:prefix vector- :suffix -subtype)