c99e7a8ed2ebf4b0f6f70eaa42a2c3d865652d5e
[sbcl.git] / src / compiler / generic / early-objdef.lisp
1 ;;;; type-based constants
2
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.
11
12 (in-package "SB!VM")
13
14 ;;; FIXME: It's clever using :SUFFIX -TYPE for these things, but it's
15 ;;; a pain for people just learning to find their way around the code
16 ;;; who want to use lexical search to figure out where things like
17 ;;; EVEN-FIXNUM-LOWTAG are defined. Remove the :SUFFIXes and just expand
18 ;;; out the full names. Or even define them in DEF EVEN-FIXNUM-LOWTAG
19 ;;; style so searches like 'def.*even-fixnum-lowtag' can find them.
20
21 ;;; Tags for the main low-level types are stored in the low n (usually three)
22 ;;; bits to identify the type of a machine word.  Certain constraints 
23 ;;; apply:
24 ;;;   * EVEN-FIXNUM-LOWTAG and ODD-FIXNUM-LOWTAG must be 0 and 4: code
25 ;;;     which shifts left two places to convert raw integers to tagged
26 ;;;     fixnums is ubiquitous.
27 ;;;   * LIST-POINTER-LOWTAG + N-WORD-BYTES = OTHER-POINTER-LOWTAG: NIL 
28 ;;;     is both a cons and a symbol (at the same address) and depends on this.
29 ;;;     See the definition of SYMBOL in objdef.lisp
30 ;;;   * OTHER-POINTER-LOWTAG > 4: Some code in the SPARC backend,
31 ;;;     which uses bit 2 of the ALLOC register to indicate that
32 ;;;     PSEUDO-ATOMIC is on, doesn't strip the low bits of reg_ALLOC
33 ;;;     before ORing in OTHER-POINTER-LOWTAG within a PSEUDO-ATOMIC
34 ;;;     section.
35 ;;;   * OTHER-IMMEDIATE-0-LOWTAG are spaced 4 apart: various code wants to 
36 ;;;     iterate through these
37 ;;; (These are just the ones we know about as of sbcl-0.7.1.22. There
38 ;;; might easily be more, since these values have stayed highly
39 ;;; constrained for more than a decade, an inviting target for
40 ;;; inventive abstraction-phobic maintainers.:-)
41 (eval-when (:compile-toplevel :load-toplevel :execute)
42   ;; The EVAL-WHEN is necessary (at least for Lispworks), because the
43   ;; second DEFENUM uses the value of OTHER-IMMEDIATE-0-LOWTAG, which is
44   ;; defined in the first DEFENUM. -- AL 20000216
45   #!+x86-64
46   (defenum (:suffix -lowtag)
47     even-fixnum
48     instance-pointer
49     other-immediate-0
50     pad0 pad1 pad2
51     other-immediate-1
52     list-pointer
53     odd-fixnum
54     fun-pointer
55     other-immediate-2
56     pad3 pad4 pad5
57     other-immediate-3
58     other-pointer)
59   #!-x86-64
60   (defenum (:suffix -lowtag)
61     even-fixnum
62     instance-pointer
63     other-immediate-0
64     list-pointer
65     odd-fixnum
66     fun-pointer
67     other-immediate-1
68     other-pointer))
69
70 (def!constant nil-value
71     (+ static-space-start n-word-bytes other-pointer-lowtag))
72
73 ;;; the heap types, stored in 8 bits of the header of an object on the
74 ;;; heap, to identify the type of the heap object (which'll be at
75 ;;; least two machine words, often more)
76 ;;;
77 ;;; Note: the order specified here is not critical for correctness,
78 ;;; but (FIXME) with %TEST-HEADERS as currently defined, BIGNUM must
79 ;;; be first, and COMPLEX-ARRAY must be last.
80 ;;;
81 ;;; However, for efficiency, we prefer contiguous sets of widetags for
82 ;;; "similar" objects, so that type checking can be done with a range
83 ;;; check, rather than several individual checks.
84 ;;;
85 ;;; * BIGNUM + RATIO (+ FIXNUM) = RATIONAL
86 ;;;
87 ;;; * SINGLE-FLOAT + DOUBLE-FLOAT + LONG-FLOAT = FLOAT
88 ;;;
89 ;;; * RATIONAL + FLOAT = REAL
90 ;;;
91 ;;; * (FIXME: COMPLEX example, which needs fixing anyway -- see
92 ;;;   UPGRADED-COMPLEX-PART-TYPE)
93 ;;;
94 ;;; * SIMPLE-ARRAY-* = (SIMPLE-ARRAY * (*))
95 ;;;
96 ;;; * SIMPLE-ARRAY-NIL + SIMPLE-BASE-STRING = SIMPLE-STRING
97 ;;;
98 ;;; * SIMPLE-ARRAY + COMPLEX-ARRAYOID = (SATISFIES ARRAY-HEADER-P)
99 ;;;
100 ;;; In addition, with
101 ;;; sufficient care we can cause extra combinations to appear with
102 ;;; differences in only one bit, permitting a more efficient type
103 ;;; test.  As an example, if SIMPLE-BASE-STRING = 0xA6 and
104 ;;; COMPLEX-BASE-STRING = 0xE6, then the type test for BASE-STRING is
105 ;;;
106 ;;;   AND   tag, ~0x40, tag
107 ;;;   ANDcc tag,  0xA6, tag
108 ;;;   JNE   tag, label
109 ;;;
110 ;;; rather than two separate tests and jumps 
111 (defenum (:suffix -widetag
112           :start (+ (ash 1 n-lowtag-bits) other-immediate-0-lowtag)
113           :step 4)
114   bignum
115   ratio
116   single-float
117   double-float
118   complex
119   complex-single-float
120   complex-double-float
121
122   code-header
123   simple-fun-header
124   closure-header
125   funcallable-instance-header
126
127   return-pc-header
128   value-cell-header
129   symbol-header
130   base-char
131   sap
132   unbound-marker
133   weak-pointer
134   instance-header
135   fdefn
136
137   unused00
138   unused01
139   unused02
140   unused03
141   unused04
142   unused05
143   unused06
144   unused07
145   unused08
146   unused09
147   
148   unused10
149   unused11
150
151   simple-array-unsigned-byte-2
152   simple-array-unsigned-byte-4
153   simple-array-unsigned-byte-7
154   simple-array-unsigned-byte-8
155   simple-array-unsigned-byte-15
156   simple-array-unsigned-byte-16
157   simple-array-nil
158   simple-base-string
159   simple-bit-vector
160   simple-vector
161   simple-array-unsigned-byte-29
162   simple-array-unsigned-byte-31
163   simple-array-unsigned-byte-32
164   simple-array-signed-byte-8
165   simple-array-signed-byte-16
166   simple-array-signed-byte-30
167   simple-array-signed-byte-32
168   simple-array-single-float
169   simple-array-double-float
170   simple-array-complex-single-float
171   simple-array-complex-double-float
172   simple-array
173   complex-vector-nil
174   complex-base-string
175   complex-bit-vector
176   complex-vector
177   complex-array
178 )
179
180 ;;; the different vector subtypes
181 (defenum (:prefix vector- :suffix -subtype)
182   normal
183   unused
184   valid-hashing
185   must-rehash)