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.:-)
37 ;;; Another way to look at lowtags is that there is no one lowtag
38 ;;; length. On 32-bit platforms, fixnums and other-immediates have a
39 ;;; lowtag length of two bits, and pointers have a lowtag length of
40 ;;; three bits. On 64-bit platforms, fixnums and pointers gain an
41 ;;; extra bit, and six "pad" lowtags waste the extra encoding space so
45 ;;; x10 -- other-immediate
46 ;;; 001 -- instance-pointer
47 ;;; 011 -- list-pointer
48 ;;; 101 -- fun-pointer
49 ;;; 111 -- other-pointer
51 ;;; If you change the tag layout, check the various functions in
52 ;;; src/runtime/runtime.h to see if they need to be updated, along
53 ;;; with print_obj() in src/runtime/print.c, possibly gc_init_tables()
54 ;;; in src/runtime/gc-common-c and possibly the code in src/code/room.
55 (eval-when (:compile-toplevel :load-toplevel :execute)
56 ;; The EVAL-WHEN is necessary (at least for Lispworks), because the
57 ;; second DEFENUM uses the value of OTHER-IMMEDIATE-0-LOWTAG, which is
58 ;; defined in the first DEFENUM. -- AL 20000216
59 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
62 other-immediate-0-lowtag
64 instance-pointer-lowtag
66 other-immediate-1-lowtag
70 other-immediate-2-lowtag
74 other-immediate-3-lowtag
77 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
80 instance-pointer-lowtag
81 other-immediate-0-lowtag
85 other-immediate-1-lowtag
86 other-pointer-lowtag))
88 (def!constant nil-value
89 (+ static-space-start n-word-bytes other-pointer-lowtag))
91 (defconstant-eqx fixnum-lowtags
92 #.(let ((fixtags nil))
93 (do-external-symbols (sym "SB!VM")
94 (let* ((name (symbol-name sym))
96 (when (and (boundp sym)
97 (integerp (symbol-value sym))
99 (string= name "-LOWTAG" :start1 (- len 7))
100 (zerop (logand (symbol-value sym) fixnum-tag-mask)))
101 (push sym fixtags))))
105 ;;; the heap types, stored in 8 bits of the header of an object on the
106 ;;; heap, to identify the type of the heap object (which'll be at
107 ;;; least two machine words, often more)
109 ;;; Note: the order specified here is not critical for correctness,
110 ;;; but (FIXME) with %TEST-HEADERS as currently defined, BIGNUM must
111 ;;; be first, and COMPLEX-ARRAY must be last.
113 ;;; However, for efficiency, we prefer contiguous sets of widetags for
114 ;;; "similar" objects, so that type checking can be done with a range
115 ;;; check, rather than several individual checks.
117 ;;; * BIGNUM + RATIO (+ FIXNUM) = RATIONAL
119 ;;; * SINGLE-FLOAT + DOUBLE-FLOAT + LONG-FLOAT = FLOAT
121 ;;; * RATIONAL + FLOAT = REAL
123 ;;; * (FIXME: COMPLEX example, which needs fixing anyway -- see
124 ;;; UPGRADED-COMPLEX-PART-TYPE)
126 ;;; * SIMPLE-ARRAY-* = (SIMPLE-ARRAY * (*))
128 ;;; * SIMPLE-ARRAY-NIL + SIMPLE-BASE-STRING = SIMPLE-STRING
130 ;;; * SIMPLE-ARRAY + COMPLEX-ARRAYOID = (SATISFIES ARRAY-HEADER-P)
132 ;;; In addition, with
133 ;;; sufficient care we can cause extra combinations to appear with
134 ;;; differences in only one bit, permitting a more efficient type
135 ;;; test. As an example, if SIMPLE-BASE-STRING = 0xA6 and
136 ;;; COMPLEX-BASE-STRING = 0xE6, then the type test for BASE-STRING is
138 ;;; AND tag, ~0x40, tag
139 ;;; ANDcc tag, 0xA6, tag
142 ;;; rather than two separate tests and jumps
143 (defenum (;; The first widetag must be greater than SB!VM:LOWTAG-LIMIT
144 ;; otherwise code in generic/early-type-vops will suffer
145 ;; a long, horrible death. --njf, 2004-08-09
146 :start (+ (ash 1 n-lowtag-bits) other-immediate-0-lowtag)
148 ;; NOTE: the binary numbers off to the side are only valid for 32-bit
149 ;; ports; add #b1000 if you want to know the values for 64-bit ports.
150 ;; And note that the numbers get a little scrambled further down.
152 bignum-widetag ; 00001010
153 ratio-widetag ; 00001110
154 single-float-widetag ; 00010010
155 double-float-widetag ; 00010110
156 complex-widetag ; 00011010
157 complex-single-float-widetag ; 00011110
158 complex-double-float-widetag ; 00100010
160 code-header-widetag ; 00100110
162 simple-fun-header-widetag ; 00101010
163 closure-header-widetag ; 00101110
164 funcallable-instance-header-widetag ; 00110010
166 return-pc-header-widetag ; 00110110
167 value-cell-header-widetag ; 00111010
168 symbol-header-widetag ; 00111110
169 character-widetag ; 01000010
170 sap-widetag ; 01000110
171 unbound-marker-widetag ; 01001010
172 weak-pointer-widetag ; 01001110
173 instance-header-widetag ; 01010010
174 fdefn-widetag ; 01010110
176 no-tls-value-marker-widetag ; 01011010
177 unused01-widetag ; 01011110
178 unused02-widetag ; 01100010
179 unused03-widetag ; 01100110
180 unused04-widetag ; 01101010
181 unused05-widetag ; 01101110
182 unused06-widetag ; 01110010
183 unused07-widetag ; 01110110
184 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
185 unused08-widetag ; 01111010
186 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
187 unused09-widetag ; 01111110
189 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
190 unused10-widetag ; 10000010
191 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
192 unused11-widetag ; 10000110
194 simple-array-unsigned-byte-2-widetag ; 10001010
195 simple-array-unsigned-byte-4-widetag ; 10001110
196 simple-array-unsigned-byte-7-widetag ; 10010010
197 simple-array-unsigned-byte-8-widetag ; 10010110
198 simple-array-unsigned-byte-15-widetag ; 10011010
199 simple-array-unsigned-byte-16-widetag ; 10011110
200 simple-array-nil-widetag ; 10100010
201 simple-base-string-widetag ; 10100110
202 #!+sb-unicode simple-character-string-widetag
203 simple-bit-vector-widetag ; 10101010
204 simple-vector-widetag ; 10101110
205 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
206 simple-array-unsigned-fixnum-widetag ; 10110010
207 simple-array-unsigned-byte-31-widetag ; 10110110
208 simple-array-unsigned-byte-32-widetag ; 10111010
209 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
210 simple-array-unsigned-fixnum-widetag
211 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
212 simple-array-unsigned-byte-63-widetag
213 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
214 simple-array-unsigned-byte-64-widetag
215 simple-array-signed-byte-8-widetag ; 10111110
216 simple-array-signed-byte-16-widetag ; 11000010
217 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
218 simple-array-fixnum-widetag ; 11000110
219 simple-array-signed-byte-32-widetag ; 11001010
220 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
221 simple-array-fixnum-widetag
222 #!+#.(cl:if (cl:= 64 sb!vm:n-word-bits) '(and) '(or))
223 simple-array-signed-byte-64-widetag
224 simple-array-single-float-widetag ; 11001110
225 simple-array-double-float-widetag ; 11010010
226 simple-array-complex-single-float-widetag ; 11010110
227 simple-array-complex-double-float-widetag ; 11011010
228 simple-array-widetag ; 11011110
229 complex-vector-nil-widetag ; 11100010
230 complex-base-string-widetag ; 11100110
231 #!+sb-unicode complex-character-string-widetag
232 complex-bit-vector-widetag ; 11101010
233 complex-vector-widetag ; 11101110
234 complex-array-widetag ; 11110010
236 #!+#.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
237 unused12-widetag ; 11110110
238 #!+(and #.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
240 unused13-widetag ; 11111010
241 #!+(and #.(cl:if (cl:= 32 sb!vm:n-word-bits) '(and) '(or))
243 unused14-widetag ; 11111110
246 ;;; the different vector subtypes
248 vector-normal-subtype
249 vector-unused-subtype
250 vector-valid-hashing-subtype)