1 /* ----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2002
7 * NOTE: this information is used by both the compiler and the RTS.
8 * Some of it is tweakable, and some of it must be kept up to date
9 * with various other parts of the system.
11 * Constants which are derived automatically from other definitions in
12 * the system (eg. structure sizes) are generated into the file
13 * DerivedConstants.h by a C program (mkDerivedConstantsHdr).
15 * -------------------------------------------------------------------------- */
20 /* -----------------------------------------------------------------------------
23 Here we define the minimum size for updatable closures. All updates
24 will be performed on closures of this size. For non-updatable closures
25 the minimum size is 1 to allow for a forwarding pointer.
27 When we used to keep the mutable list threaded through closures on
28 the heap, MIN_UPD_SIZE used to be 2. Now it's 1.
30 o MIN_UPD_SIZE doesn't apply to stack closures, static closures
31 or non-updateable objects like PAPs or CONSTRs
32 o MIN_UPD_SIZE is big enough to contain any of the following:
36 o IND, IND_PERM, IND_OLDGEN and IND_OLDGEN_PERM
37 (it need not be big enough for IND_STATIC - but it is)
38 o MIN_NONUPD_SIZE doesn't apply to stack closures, static closures
39 or updateable objects like APs, THUNKS or THUNK_SELECTORs
40 o MIN_NONUPD_SIZE is big enough to contain any of the following:
42 -------------------------------------------------------------------------- */
44 #define MIN_UPD_SIZE 1
45 #define MIN_NONUPD_SIZE 1
47 /* -----------------------------------------------------------------------------
48 Constants to do with specialised closure types.
49 -------------------------------------------------------------------------- */
51 /* We have some pre-compiled selector thunks defined in rts/StgStdThunks.hc.
52 * This constant defines the highest selectee index that we can replace with a
53 * reference to the pre-compiled code.
56 #define MAX_SPEC_SELECTEE_SIZE 15
58 /* Vector-apply thunks. These thunks just push their free variables
59 * on the stack and enter the first one. They're a bit like PAPs, but
60 * don't have a dynamic size. We've pre-compiled a few to save
64 #define MAX_SPEC_AP_SIZE 7
66 /* Specialised FUN/THUNK/CONSTR closure types */
68 #define MAX_SPEC_THUNK_SIZE 2
69 #define MAX_SPEC_FUN_SIZE 2
70 #define MAX_SPEC_CONSTR_SIZE 2
72 /* Range of built-in table of static small int-like and char-like closures.
74 * NB. This corresponds with the number of actual INTLIKE/CHARLIKE
75 * closures defined in rts/StgMiscClosures.cmm.
77 #define MAX_INTLIKE 16
78 #define MIN_INTLIKE (-16)
80 #define MAX_CHARLIKE 255
81 #define MIN_CHARLIKE 0
83 /* -----------------------------------------------------------------------------
86 Note that in MachRegs.h we define how many of these registers are
87 *real* machine registers, and not just offsets in the Register Table.
88 -------------------------------------------------------------------------- */
90 #define MAX_VANILLA_REG 8
91 #define MAX_FLOAT_REG 4
92 #define MAX_DOUBLE_REG 2
93 #define MAX_LONG_REG 1
95 /* -----------------------------------------------------------------------------
96 * Maximum number of constructors in a data type for direct-returns.
98 * NB. There are various places that assume the value of this
99 * constant, such as the polymorphic return frames for updates
100 * (stg_upd_frame_info) and catch frames (stg_catch_frame_info).
101 * -------------------------------------------------------------------------- */
103 #define MAX_VECTORED_RTN 8
105 /* -----------------------------------------------------------------------------
106 Semi-Tagging constants
108 Old Comments about this stuff:
110 Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
111 normal-form values of algebraic data types will have tags 0, 1, ...
113 @INFO_IND_TAG@ is different from @INFO_OTHER_TAG@ just so we can count
114 how often we bang into indirection nodes; that's all. (WDP 95/11)
116 ToDo: find out if we need any of this.
117 -------------------------------------------------------------------------- */
119 #define INFO_OTHER_TAG (-1)
120 #define INFO_IND_TAG (-2)
121 #define INFO_FIRST_TAG 0
123 /* -----------------------------------------------------------------------------
124 How much C stack to reserve for local temporaries when in the STG
125 world. Used in StgCRun.c.
126 -------------------------------------------------------------------------- */
128 #define RESERVED_C_STACK_BYTES (2048 * SIZEOF_LONG)
130 /* -----------------------------------------------------------------------------
131 How much Haskell stack space to reserve for the saving of registers
132 etc. in the case of a stack/heap overflow.
134 This must be large enough to accomodate the largest stack frame
135 pushed in one of the heap check fragments in HeapStackCheck.hc
136 (ie. currently the generic heap checks - 3 words for StgRetDyn,
137 18 words for the saved registers, see StgMacros.h).
139 In the event of an unboxed tuple or let-no-escape stack/heap check
140 failure, there will be other words on the stack which are covered
141 by the RET_DYN frame. These will have been accounted for by stack
142 checks however, so we don't need to allow for them here.
143 -------------------------------------------------------------------------- */
145 #define RESERVED_STACK_WORDS 21
147 /* -----------------------------------------------------------------------------
148 Storage manager constants
149 -------------------------------------------------------------------------- */
151 /* The size of a block (2^BLOCK_SHIFT bytes) */
152 #define BLOCK_SHIFT 12
154 /* The size of a megablock (2^MBLOCK_SHIFT bytes) */
155 #define MBLOCK_SHIFT 20
157 /* -----------------------------------------------------------------------------
158 Bitmap/size fields (used in info tables)
159 -------------------------------------------------------------------------- */
161 /* In a 32-bit bitmap field, we use 5 bits for the size, and 27 bits
162 * for the bitmap. If the bitmap requires more than 27 bits, then we
163 * store it in a separate array, and leave a pointer in the bitmap
164 * field. On a 64-bit machine, the sizes are extended accordingly.
166 #if SIZEOF_VOID_P == 4
167 #define BITMAP_SIZE_MASK 0x1f
168 #define BITMAP_BITS_SHIFT 5
169 #elif SIZEOF_VOID_P == 8
170 #define BITMAP_SIZE_MASK 0x3f
171 #define BITMAP_BITS_SHIFT 6
173 #error unknown SIZEOF_VOID_P
176 /* -----------------------------------------------------------------------------
177 Lag/Drag/Void constants
178 -------------------------------------------------------------------------- */
181 An LDV word is divided into 3 parts: state bits (LDV_STATE_MASK), creation
182 time bits (LDV_CREATE_MASK), and last use time bits (LDV_LAST_MASK).
184 #if SIZEOF_VOID_P == 8
186 #define LDV_STATE_MASK 0x1000000000000000
187 #define LDV_CREATE_MASK 0x0FFFFFFFC0000000
188 #define LDV_LAST_MASK 0x000000003FFFFFFF
189 #define LDV_STATE_CREATE 0x0000000000000000
190 #define LDV_STATE_USE 0x1000000000000000
193 #define LDV_STATE_MASK 0x40000000
194 #define LDV_CREATE_MASK 0x3FFF8000
195 #define LDV_LAST_MASK 0x00007FFF
196 #define LDV_STATE_CREATE 0x00000000
197 #define LDV_STATE_USE 0x40000000
198 #endif /* SIZEOF_VOID_P */
200 /* -----------------------------------------------------------------------------
201 TSO related constants
202 -------------------------------------------------------------------------- */
205 * Constants for the what_next field of a TSO, which indicates how it
208 #define ThreadRunGHC 1 /* return to address on top of stack */
209 #define ThreadInterpret 2 /* interpret this thread */
210 #define ThreadKilled 3 /* thread has died, don't run it */
211 #define ThreadRelocated 4 /* thread has moved, link points to new locn */
212 #define ThreadComplete 5 /* thread has finished */
215 * Constants for the why_blocked field of a TSO
218 #define BlockedOnMVar 1
219 #define BlockedOnBlackHole 2
220 #define BlockedOnException 3
221 #define BlockedOnRead 4
222 #define BlockedOnWrite 5
223 #define BlockedOnDelay 6
224 #define BlockedOnSTM 7
227 #define BlockedOnDoProc 8
229 /* Only relevant for PAR: */
230 /* blocked on a remote closure represented by a Global Address: */
231 #define BlockedOnGA 9
232 /* same as above but without sending a Fetch message */
233 #define BlockedOnGA_NoSend 10
234 /* Only relevant for THREADED_RTS: */
235 #define BlockedOnCCall 11
236 #define BlockedOnCCall_NoUnblockExc 12
237 /* same as above but don't unblock async exceptions in resumeThread() */
240 * These constants are returned to the scheduler by a thread that has
241 * stopped for one reason or another. See typedef StgThreadReturnCode
244 #define HeapOverflow 1 /* might also be StackOverflow */
245 #define StackOverflow 2
246 #define ThreadYielding 3
247 #define ThreadBlocked 4
248 #define ThreadFinished 5
250 /* -----------------------------------------------------------------------------
252 -------------------------------------------------------------------------- */
254 /* VERY MAGIC CONSTANTS!
255 * must agree with code in HeapStackCheck.c, stg_gen_chk, and
256 * RESERVED_STACK_WORDS in Constants.h.
258 #define RET_DYN_BITMAP_SIZE 8
259 #define RET_DYN_NONPTR_REGS_SIZE 10
261 /* Sanity check that RESERVED_STACK_WORDS is reasonable. We can't
262 * just derive RESERVED_STACK_WORDS because it's used in Haskell code
265 #if RESERVED_STACK_WORDS != (3 + RET_DYN_BITMAP_SIZE + RET_DYN_NONPTR_REGS_SIZE)
266 #error RESERVED_STACK_WORDS may be wrong!
269 /* -----------------------------------------------------------------------------
270 How often our context-switch timer ticks
271 -------------------------------------------------------------------------- */
273 #define TICK_FREQUENCY 50 /* ticks per second */
275 #endif /* CONSTANTS_H */