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 ;;; Tags for the main low-level types are stored in the low n (usually three)
15 ;;; bits to identify the type of a machine word. Certain constraints
17 ;;; * EVEN-FIXNUM-LOWTAG and ODD-FIXNUM-LOWTAG must be 0 and 4: code
18 ;;; which shifts left two places to convert raw integers to tagged
19 ;;; fixnums is ubiquitous.
20 ;;; * LIST-POINTER-LOWTAG + N-WORD-BYTES = OTHER-POINTER-LOWTAG: NIL
21 ;;; is both a cons and a symbol (at the same address) and depends on this.
22 ;;; See the definition of SYMBOL in objdef.lisp
23 ;;; * OTHER-POINTER-LOWTAG > 4: Some code in the SPARC backend,
24 ;;; which uses bit 2 of the ALLOC register to indicate that
25 ;;; PSEUDO-ATOMIC is on, doesn't strip the low bits of reg_ALLOC
26 ;;; before ORing in OTHER-POINTER-LOWTAG within a PSEUDO-ATOMIC
28 ;;; * OTHER-IMMEDIATE-0-LOWTAG are spaced 4 apart: various code wants to
29 ;;; iterate through these
30 ;;; * Allocation code on Alpha wants lowtags for heap-allocated
31 ;;; objects to be odd.
32 ;;; (These are just the ones we know about as of sbcl-0.7.1.22. There
33 ;;; might easily be more, since these values have stayed highly
34 ;;; constrained for more than a decade, an inviting target for
35 ;;; inventive abstraction-phobic maintainers.:-)
36 (eval-when (:compile-toplevel :load-toplevel :execute)
37 ;; The EVAL-WHEN is necessary (at least for Lispworks), because the
38 ;; second DEFENUM uses the value of OTHER-IMMEDIATE-0-LOWTAG, which is
39 ;; defined in the first DEFENUM. -- AL 20000216
40 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
43 instance-pointer-lowtag
44 other-immediate-0-lowtag
46 pad1-lowtag pad2-lowtag
47 other-immediate-1-lowtag
51 other-immediate-2-lowtag
55 other-immediate-3-lowtag
57 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
60 instance-pointer-lowtag
61 other-immediate-0-lowtag
65 other-immediate-1-lowtag
66 other-pointer-lowtag))
68 (def!constant nil-value
69 (+ static-space-start n-word-bytes other-pointer-lowtag))
71 (defconstant-eqx fixnum-lowtags
72 #.(let ((fixtags nil))
73 (do-external-symbols (sym "SB!VM")
74 (let* ((name (symbol-name sym))
76 (when (and (boundp sym)
77 (integerp (symbol-value sym))
79 (string= name "-LOWTAG" :start1 (- len 7))
80 (zerop (logand (symbol-value sym) fixnum-tag-mask)))
85 ;;; the heap types, stored in 8 bits of the header of an object on the
86 ;;; heap, to identify the type of the heap object (which'll be at
87 ;;; least two machine words, often more)
89 ;;; Note: the order specified here is not critical for correctness,
90 ;;; but (FIXME) with %TEST-HEADERS as currently defined, BIGNUM must
91 ;;; be first, and COMPLEX-ARRAY must be last.
93 ;;; However, for efficiency, we prefer contiguous sets of widetags for
94 ;;; "similar" objects, so that type checking can be done with a range
95 ;;; check, rather than several individual checks.
97 ;;; * BIGNUM + RATIO (+ FIXNUM) = RATIONAL
99 ;;; * SINGLE-FLOAT + DOUBLE-FLOAT + LONG-FLOAT = FLOAT
101 ;;; * RATIONAL + FLOAT = REAL
103 ;;; * (FIXME: COMPLEX example, which needs fixing anyway -- see
104 ;;; UPGRADED-COMPLEX-PART-TYPE)
106 ;;; * SIMPLE-ARRAY-* = (SIMPLE-ARRAY * (*))
108 ;;; * SIMPLE-ARRAY-NIL + SIMPLE-BASE-STRING = SIMPLE-STRING
110 ;;; * SIMPLE-ARRAY + COMPLEX-ARRAYOID = (SATISFIES ARRAY-HEADER-P)
112 ;;; In addition, with
113 ;;; sufficient care we can cause extra combinations to appear with
114 ;;; differences in only one bit, permitting a more efficient type
115 ;;; test. As an example, if SIMPLE-BASE-STRING = 0xA6 and
116 ;;; COMPLEX-BASE-STRING = 0xE6, then the type test for BASE-STRING is
118 ;;; AND tag, ~0x40, tag
119 ;;; ANDcc tag, 0xA6, tag
122 ;;; rather than two separate tests and jumps
123 (defenum (;; The first widetag must be greater than SB!VM:LOWTAG-LIMIT
124 ;; otherwise code in generic/early-type-vops will suffer
125 ;; a long, horrible death. --njf, 2004-08-09
126 :start (+ (ash 1 n-lowtag-bits) other-immediate-0-lowtag)
128 ;; NOTE: the binary numbers off to the side are only valid for 32-bit
129 ;; ports; add #b1000 if you want to know the values for 64-bit ports.
130 ;; And note that the numbers get a little scrambled further down.
132 bignum-widetag ; 00001010
133 ratio-widetag ; 00001110
134 single-float-widetag ; 00010010
135 double-float-widetag ; 00010110
136 complex-widetag ; 00011010
137 complex-single-float-widetag ; 00011110
138 complex-double-float-widetag ; 00100010
140 code-header-widetag ; 00100110
142 simple-fun-header-widetag ; 00101010
143 closure-header-widetag ; 00101110
144 funcallable-instance-header-widetag ; 00110010
146 return-pc-header-widetag ; 00110110
147 value-cell-header-widetag ; 00111010
148 symbol-header-widetag ; 00111110
149 character-widetag ; 01000010
150 sap-widetag ; 01000110
151 unbound-marker-widetag ; 01001010
152 weak-pointer-widetag ; 01001110
153 instance-header-widetag ; 01010010
154 fdefn-widetag ; 01010110
156 no-tls-value-marker-widetag ; 01011010
157 #!-(and sb-lutex sb-thread)
159 #!+(and sb-lutex sb-thread)
160 lutex-widetag ; 01011110
161 unused02-widetag ; 01100010
162 unused03-widetag ; 01100110
163 unused04-widetag ; 01101010
164 unused05-widetag ; 01101110
165 unused06-widetag ; 01110010
166 unused07-widetag ; 01110110
167 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
168 unused08-widetag ; 01111010
169 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
170 unused09-widetag ; 01111110
172 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
173 unused10-widetag ; 10000010
174 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
175 unused11-widetag ; 10000110
177 simple-array-unsigned-byte-2-widetag ; 10001010
178 simple-array-unsigned-byte-4-widetag ; 10001110
179 simple-array-unsigned-byte-7-widetag ; 10010010
180 simple-array-unsigned-byte-8-widetag ; 10010110
181 simple-array-unsigned-byte-15-widetag ; 10011010
182 simple-array-unsigned-byte-16-widetag ; 10011110
183 simple-array-nil-widetag ; 10100010
184 simple-base-string-widetag ; 10100110
185 #!+sb-unicode simple-character-string-widetag
186 simple-bit-vector-widetag ; 10101010
187 simple-vector-widetag ; 10101110
188 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
189 simple-array-unsigned-fixnum-widetag ; 10110010
190 simple-array-unsigned-byte-31-widetag ; 10110110
191 simple-array-unsigned-byte-32-widetag ; 10111010
192 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
193 simple-array-unsigned-fixnum-widetag
194 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
195 simple-array-unsigned-byte-63-widetag
196 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
197 simple-array-unsigned-byte-64-widetag
198 simple-array-signed-byte-8-widetag ; 10111110
199 simple-array-signed-byte-16-widetag ; 11000010
200 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
201 simple-array-fixnum-widetag ; 11000110
202 simple-array-signed-byte-32-widetag ; 11001010
203 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
204 simple-array-fixnum-widetag
205 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
206 simple-array-signed-byte-64-widetag
207 simple-array-single-float-widetag ; 11001110
208 simple-array-double-float-widetag ; 11010010
209 simple-array-complex-single-float-widetag ; 11010110
210 simple-array-complex-double-float-widetag ; 11011010
211 simple-array-widetag ; 11011110
212 complex-vector-nil-widetag ; 11100010
213 complex-base-string-widetag ; 11100110
214 #!+sb-unicode complex-character-string-widetag
215 complex-bit-vector-widetag ; 11101010
216 complex-vector-widetag ; 11101110
217 complex-array-widetag ; 11110010
219 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
220 unused12-widetag ; 11110110
221 #!+(and #.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
223 unused13-widetag ; 11111010
224 #!+(and #.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
226 unused14-widetag ; 11111110
229 ;;; the different vector subtypes
231 vector-normal-subtype
232 vector-unused-subtype
233 vector-valid-hashing-subtype)