1 /* ----------------------------------------------------------------------------
2 * $Id: Constants.h,v 1.27 2004/11/18 09:56:19 tharris Exp $
4 * (c) The GHC Team, 1998-2002
8 * NOTE: this information is used by both the compiler and the RTS.
9 * Some of it is tweakable, and some of it must be kept up to date
10 * with various other parts of the system.
12 * Constants which are derived automatically from other definitions in
13 * the system (eg. structure sizes) are generated into the file
14 * DerivedConstants.h by a C program (mkDerivedConstantsHdr).
16 * -------------------------------------------------------------------------- */
21 /* -----------------------------------------------------------------------------
24 Here we define the minimum size for updatable closures. This must be at
25 least 2, to allow for cons cells and linked indirections. All updates
26 will be performed on closures of this size. For non-updatable closures
27 the minimum size is 1 to allow for a forwarding pointer.
29 Linked indirections are UPD_OLDGEN things: see Closures.h
31 o MIN_UPD_SIZE doesn't apply to stack closures, static closures
32 or non-updateable objects like PAPs or CONSTRs
33 o MIN_UPD_SIZE is big enough to contain any of the following:
37 o IND, IND_PERM, IND_OLDGEN and IND_OLDGEN_PERM
38 (it need not be big enough for IND_STATIC - but it is)
39 o MIN_NONUPD_SIZE doesn't apply to stack closures, static closures
40 or updateable objects like APs, THUNKS or THUNK_SELECTORs
41 o MIN_NONUPD_SIZE is big enough to contain any of the following:
43 -------------------------------------------------------------------------- */
45 #define MIN_UPD_SIZE 2
46 #define MIN_NONUPD_SIZE 1
48 /* -----------------------------------------------------------------------------
49 Constants to do with specialised closure types.
50 -------------------------------------------------------------------------- */
52 /* We have some pre-compiled selector thunks defined in rts/StgStdThunks.hc.
53 * This constant defines the highest selectee index that we can replace with a
54 * reference to the pre-compiled code.
57 #define MAX_SPEC_SELECTEE_SIZE 15
59 /* Vector-apply thunks. These thunks just push their free variables
60 * on the stack and enter the first one. They're a bit like PAPs, but
61 * don't have a dynamic size. We've pre-compiled a few to save
65 #define MAX_SPEC_AP_SIZE 7
67 /* Specialised FUN/THUNK/CONSTR closure types */
69 #define MAX_SPEC_THUNK_SIZE 2
70 #define MAX_SPEC_FUN_SIZE 2
71 #define MAX_SPEC_CONSTR_SIZE 2
73 /* Range of built-in table of static small int-like and char-like closures.
75 * NB. This corresponds with the number of actual INTLIKE/CHARLIKE
76 * closures defined in rts/StgMiscClosures.cmm.
78 #define MAX_INTLIKE 16
79 #define MIN_INTLIKE (-16)
81 #define MAX_CHARLIKE 255
82 #define MIN_CHARLIKE 0
84 /* -----------------------------------------------------------------------------
87 Note that in MachRegs.h we define how many of these registers are
88 *real* machine registers, and not just offsets in the Register Table.
89 -------------------------------------------------------------------------- */
91 #define MAX_VANILLA_REG 8
92 #define MAX_FLOAT_REG 4
93 #define MAX_DOUBLE_REG 2
94 #define MAX_LONG_REG 1
96 /* -----------------------------------------------------------------------------
97 * Maximum number of constructors in a data type for direct-returns.
99 * NB. There are various places that assume the value of this
100 * constant, such as the polymorphic return frames for updates
101 * (stg_upd_frame_info) and catch frames (stg_catch_frame_info).
102 * -------------------------------------------------------------------------- */
104 #define MAX_VECTORED_RTN 8
106 /* -----------------------------------------------------------------------------
107 Semi-Tagging constants
109 Old Comments about this stuff:
111 Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
112 normal-form values of algebraic data types will have tags 0, 1, ...
114 @INFO_IND_TAG@ is different from @INFO_OTHER_TAG@ just so we can count
115 how often we bang into indirection nodes; that's all. (WDP 95/11)
117 ToDo: find out if we need any of this.
118 -------------------------------------------------------------------------- */
120 #define INFO_OTHER_TAG (-1)
121 #define INFO_IND_TAG (-2)
122 #define INFO_FIRST_TAG 0
124 /* -----------------------------------------------------------------------------
125 How much C stack to reserve for local temporaries when in the STG
126 world. Used in StgCRun.c.
127 -------------------------------------------------------------------------- */
129 #define RESERVED_C_STACK_BYTES (2048 * SIZEOF_LONG)
131 /* -----------------------------------------------------------------------------
132 How much Haskell stack space to reserve for the saving of registers
133 etc. in the case of a stack/heap overflow.
135 This must be large enough to accomodate the largest stack frame
136 pushed in one of the heap check fragments in HeapStackCheck.hc
137 (ie. currently the generic heap checks - 3 words for StgRetDyn,
138 18 words for the saved registers, see StgMacros.h).
140 In the event of an unboxed tuple or let-no-escape stack/heap check
141 failure, there will be other words on the stack which are covered
142 by the RET_DYN frame. These will have been accounted for by stack
143 checks however, so we don't need to allow for them here.
144 -------------------------------------------------------------------------- */
146 #define RESERVED_STACK_WORDS 21
148 /* -----------------------------------------------------------------------------
149 Storage manager constants
150 -------------------------------------------------------------------------- */
152 /* The size of a block (2^BLOCK_SHIFT bytes) */
153 #define BLOCK_SHIFT 12
155 /* The size of a megablock (2^MBLOCK_SHIFT bytes) */
156 #define MBLOCK_SHIFT 20
158 /* -----------------------------------------------------------------------------
159 Bitmap/size fields (used in info tables)
160 -------------------------------------------------------------------------- */
162 /* In a 32-bit bitmap field, we use 5 bits for the size, and 27 bits
163 * for the bitmap. If the bitmap requires more than 27 bits, then we
164 * store it in a separate array, and leave a pointer in the bitmap
165 * field. On a 64-bit machine, the sizes are extended accordingly.
167 #if SIZEOF_VOID_P == 4
168 #define BITMAP_SIZE_MASK 0x1f
169 #define BITMAP_BITS_SHIFT 5
170 #elif SIZEOF_VOID_P == 8
171 #define BITMAP_SIZE_MASK 0x3f
172 #define BITMAP_BITS_SHIFT 6
174 #error unknown SIZEOF_VOID_P
177 /* -----------------------------------------------------------------------------
178 Lag/Drag/Void constants
179 -------------------------------------------------------------------------- */
182 An LDV word is divided into 3 parts: state bits (LDV_STATE_MASK), creation
183 time bits (LDV_CREATE_MASK), and last use time bits (LDV_LAST_MASK).
185 #if SIZEOF_VOID_P == 8
187 #define LDV_STATE_MASK 0x1000000000000000
188 #define LDV_CREATE_MASK 0x0FFFFFFFC0000000
189 #define LDV_LAST_MASK 0x000000003FFFFFFF
190 #define LDV_STATE_CREATE 0x0000000000000000
191 #define LDV_STATE_USE 0x1000000000000000
194 #define LDV_STATE_MASK 0x40000000
195 #define LDV_CREATE_MASK 0x3FFF8000
196 #define LDV_LAST_MASK 0x00007FFF
197 #define LDV_STATE_CREATE 0x00000000
198 #define LDV_STATE_USE 0x40000000
199 #endif // SIZEOF_VOID_P
201 /* -----------------------------------------------------------------------------
202 TSO related constants
203 -------------------------------------------------------------------------- */
206 * Constants for the what_next field of a TSO, which indicates how it
209 #define ThreadRunGHC 1 /* return to address on top of stack */
210 #define ThreadInterpret 2 /* interpret this thread */
211 #define ThreadKilled 3 /* thread has died, don't run it */
212 #define ThreadRelocated 4 /* thread has moved, link points to new locn */
213 #define ThreadComplete 5 /* thread has finished */
216 * Constants for the why_blocked field of a TSO
219 #define BlockedOnMVar 1
220 #define BlockedOnBlackHole 2
221 #define BlockedOnException 3
222 #define BlockedOnRead 4
223 #define BlockedOnWrite 5
224 #define BlockedOnDelay 6
225 #define BlockedOnSTM 7
228 #define BlockedOnDoProc 8
230 /* Only relevant for PAR: */
231 /* blocked on a remote closure represented by a Global Address: */
232 #define BlockedOnGA 9
233 /* same as above but without sending a Fetch message */
234 #define BlockedOnGA_NoSend 10
235 /* Only relevant for RTS_SUPPORTS_THREADS: */
236 #define BlockedOnCCall 11
237 #define BlockedOnCCall_NoUnblockExc 12
238 /* same as above but don't unblock async exceptions in resumeThread() */
241 * These constants are returned to the scheduler by a thread that has
242 * stopped for one reason or another. See typedef StgThreadReturnCode
245 #define HeapOverflow 1 /* might also be StackOverflow */
246 #define StackOverflow 2
247 #define ThreadYielding 3
248 #define ThreadBlocked 4
249 #define ThreadFinished 5
251 /* -----------------------------------------------------------------------------
253 -------------------------------------------------------------------------- */
255 /* VERY MAGIC CONSTANTS!
256 * must agree with code in HeapStackCheck.c, stg_gen_chk, and
257 * RESERVED_STACK_WORDS in Constants.h.
259 #define RET_DYN_BITMAP_SIZE 8
260 #define RET_DYN_NONPTR_REGS_SIZE 10
262 /* Sanity check that RESERVED_STACK_WORDS is reasonable. We can't
263 * just derive RESERVED_STACK_WORDS because it's used in Haskell code
266 #if RESERVED_STACK_WORDS != (3 + RET_DYN_BITMAP_SIZE + RET_DYN_NONPTR_REGS_SIZE)
267 #error RESERVED_STACK_WORDS may be wrong!
270 #endif /* CONSTANTS_H */