ef6563c42057e7d11a7660a38833c5e560d8243a
[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 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 + 4 = OTHER-POINTER-LOWTAG: NIL is both a
28 ;;;     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 ;;; (These are just the ones we know about as of sbcl-0.7.1.22. There
36 ;;; might easily be more, since these values have stayed highly
37 ;;; constrained for more than a decade, an inviting target for
38 ;;; inventive abstraction-phobic maintainers.:-)
39 (eval-when (:compile-toplevel :load-toplevel :execute)
40   ;; The EVAL-WHEN is necessary (at least for Lispworks), because the
41   ;; second DEFENUM uses the value of OTHER-IMMEDIATE-0-LOWTAG, which is
42   ;; defined in the first DEFENUM. -- AL 20000216
43   (defenum (:suffix -lowtag)
44     even-fixnum
45     ;; Note: CMU CL, and SBCL < 0.pre7.39, had FUN-POINTER-LOWTAG
46     ;; here. We swapped FUN-POINTER-LOWTAG and
47     ;; INSTANCE-POINTER-LOWTAG in sbcl-0.pre7.39 in order to help with a
48     ;; low-level pun in the function call sequence on the PPC port.
49     ;; For more information, see the PPC port code. -- WHN 2001-10-03
50     instance-pointer
51     other-immediate-0
52     list-pointer
53     odd-fixnum
54     fun-pointer
55     other-immediate-1
56     other-pointer))
57
58 ;;; the heap types, stored in 8 bits of the header of an object on the
59 ;;; heap, to identify the type of the heap object (which'll be at
60 ;;; least two machine words, often more)
61 ;;;
62 ;;; Note: the order specified here is not critical for correctness,
63 ;;; but (FIXME) with %TEST-HEADERS as currently defined, BIGNUM must
64 ;;; be first, and COMPLEX-ARRAY must be last.
65 ;;;
66 ;;; However, for efficiency, we prefer contiguous sets of widetags for
67 ;;; "similar" objects, so that type checking can be done with a range
68 ;;; check, rather than several individual checks.
69 ;;;
70 ;;; * BIGNUM + RATIO (+ FIXNUM) = RATIONAL
71 ;;;
72 ;;; * SINGLE-FLOAT + DOUBLE-FLOAT + LONG-FLOAT = FLOAT
73 ;;;
74 ;;; * RATIONAL + FLOAT = REAL
75 ;;;
76 ;;; * (FIXME: COMPLEX example, which needs fixing anyway -- see
77 ;;;   UPGRADED-COMPLEX-PART-TYPE)
78 ;;;
79 ;;; * SIMPLE-ARRAY-* = (SIMPLE-ARRAY * (*))
80 ;;;
81 ;;; * SIMPLE-ARRAY-NIL + SIMPLE-BASE-STRING = SIMPLE-STRING
82 ;;;
83 ;;; * SIMPLE-ARRAY + COMPLEX-ARRAYOID = (SATISFIES ARRAY-HEADER-P)
84 ;;;
85 ;;; In addition, with
86 ;;; sufficient care we can cause extra combinations to appear with
87 ;;; differences in only one bit, permitting a more efficient type
88 ;;; test.  As an example, if SIMPLE-BASE-STRING = 0xA6 and
89 ;;; COMPLEX-BASE-STRING = 0xE6, then the type test for BASE-STRING is
90 ;;;
91 ;;;   AND   tag, ~0x40, tag
92 ;;;   ANDcc tag,  0xA6, tag
93 ;;;   JNE   tag, label
94 ;;;
95 ;;; rather than two separate tests and jumps 
96 (defenum (:suffix -widetag
97           :start (+ (ash 1 n-lowtag-bits) other-immediate-0-lowtag)
98           :step (ash 1 (1- n-lowtag-bits)))
99   bignum
100   ratio
101   single-float
102   double-float
103   #!+long-float long-float
104   complex
105   complex-single-float
106   complex-double-float
107   #!+long-float complex-long-float
108
109   code-header
110   simple-fun-header
111   closure-header
112   funcallable-instance-header
113
114   return-pc-header
115   value-cell-header
116   symbol-header
117   base-char
118   sap
119   unbound-marker
120   weak-pointer
121   instance-header
122   fdefn
123
124   unused00
125   unused01
126   unused02
127   unused03
128   unused04
129   unused05
130   unused06
131   unused07
132   #!-long-float unused08
133   #!-long-float unused09
134   
135   #!+long-float simple-array-long-float
136   #!+long-float simple-array-complex-long-float
137   #!-long-float unused10
138   #!-long-float unused11
139
140   simple-array-unsigned-byte-2
141   simple-array-unsigned-byte-4
142   simple-array-unsigned-byte-7
143   simple-array-unsigned-byte-8
144   simple-array-unsigned-byte-15
145   simple-array-unsigned-byte-16
146   simple-array-nil
147   simple-base-string
148   simple-bit-vector
149   simple-vector
150   simple-array-unsigned-byte-29
151   simple-array-unsigned-byte-31
152   simple-array-unsigned-byte-32
153   simple-array-signed-byte-8
154   simple-array-signed-byte-16
155   simple-array-signed-byte-30
156   simple-array-signed-byte-32
157   simple-array-single-float
158   simple-array-double-float
159   simple-array-complex-single-float
160   simple-array-complex-double-float
161   simple-array
162   complex-vector-nil
163   complex-base-string
164   complex-bit-vector
165   complex-vector
166   complex-array
167 )
168
169 ;;; the different vector subtypes
170 (defenum (:prefix vector- :suffix -subtype)
171   normal
172   unused
173   valid-hashing
174   must-rehash)