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
))))
102 `',(sort fixtags
#'string
< :key
#'symbol-name
))
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
180 simd-pack-widetag
; 01011110
181 unused02-widetag
; 01100010
182 unused03-widetag
; 01100110
183 unused04-widetag
; 01101010
184 unused05-widetag
; 01101110
185 unused06-widetag
; 01110010
186 unused07-widetag
; 01110110
187 #!+#.
(cl:if
(cl:= 32 sb
!vm
:n-word-bits
) '(and) '(or))
188 unused08-widetag
; 01111010
189 #!+#.
(cl:if
(cl:= 32 sb
!vm
:n-word-bits
) '(and) '(or))
190 unused09-widetag
; 01111110
192 #!+#.
(cl:if
(cl:= 32 sb
!vm
:n-word-bits
) '(and) '(or))
193 unused10-widetag
; 10000010
194 #!+#.
(cl:if
(cl:= 32 sb
!vm
:n-word-bits
) '(and) '(or))
195 unused11-widetag
; 10000110
197 simple-array-unsigned-byte-2-widetag
; 10001010
198 simple-array-unsigned-byte-4-widetag
; 10001110
199 simple-array-unsigned-byte-7-widetag
; 10010010
200 simple-array-unsigned-byte-8-widetag
; 10010110
201 simple-array-unsigned-byte-15-widetag
; 10011010
202 simple-array-unsigned-byte-16-widetag
; 10011110
203 simple-array-nil-widetag
; 10100010
204 simple-base-string-widetag
; 10100110
205 #!+sb-unicode simple-character-string-widetag
206 simple-bit-vector-widetag
; 10101010
207 simple-vector-widetag
; 10101110
208 #!+#.
(cl:if
(cl:= 32 sb
!vm
:n-word-bits
) '(and) '(or))
209 simple-array-unsigned-fixnum-widetag
; 10110010
210 simple-array-unsigned-byte-31-widetag
; 10110110
211 simple-array-unsigned-byte-32-widetag
; 10111010
212 #!+#.
(cl:if
(cl:= 64 sb
!vm
:n-word-bits
) '(and) '(or))
213 simple-array-unsigned-fixnum-widetag
214 #!+#.
(cl:if
(cl:= 64 sb
!vm
:n-word-bits
) '(and) '(or))
215 simple-array-unsigned-byte-63-widetag
216 #!+#.
(cl:if
(cl:= 64 sb
!vm
:n-word-bits
) '(and) '(or))
217 simple-array-unsigned-byte-64-widetag
218 simple-array-signed-byte-8-widetag
; 10111110
219 simple-array-signed-byte-16-widetag
; 11000010
220 #!+#.
(cl:if
(cl:= 32 sb
!vm
:n-word-bits
) '(and) '(or))
221 simple-array-fixnum-widetag
; 11000110
222 simple-array-signed-byte-32-widetag
; 11001010
223 #!+#.
(cl:if
(cl:= 64 sb
!vm
:n-word-bits
) '(and) '(or))
224 simple-array-fixnum-widetag
225 #!+#.
(cl:if
(cl:= 64 sb
!vm
:n-word-bits
) '(and) '(or))
226 simple-array-signed-byte-64-widetag
227 simple-array-single-float-widetag
; 11001110
228 simple-array-double-float-widetag
; 11010010
229 simple-array-complex-single-float-widetag
; 11010110
230 simple-array-complex-double-float-widetag
; 11011010
231 simple-array-widetag
; 11011110
232 complex-vector-nil-widetag
; 11100010
233 complex-base-string-widetag
; 11100110
234 #!+sb-unicode complex-character-string-widetag
235 complex-bit-vector-widetag
; 11101010
236 complex-vector-widetag
; 11101110
237 complex-array-widetag
; 11110010
239 #!+#.
(cl:if
(cl:= 32 sb
!vm
:n-word-bits
) '(and) '(or))
240 unused12-widetag
; 11110110
241 #!+(and #.
(cl:if
(cl:= 32 sb
!vm
:n-word-bits
) '(and) '(or))
243 unused13-widetag
; 11111010
244 #!+(and #.
(cl:if
(cl:= 32 sb
!vm
:n-word-bits
) '(and) '(or))
246 unused14-widetag
; 11111110
249 ;;; the different vector subtypes
251 vector-normal-subtype
252 vector-unused-subtype
253 vector-valid-hashing-subtype
)