d02ae4d699dbf404e522451830bf9975cf0061dc
[ghc-hetmet.git] / ghc / includes / Constants.h
1 /* ----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2002
4  *
5  * Constants
6  *
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.
10  *
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).
14  *
15  * -------------------------------------------------------------------------- */
16
17 #ifndef CONSTANTS_H
18 #define CONSTANTS_H
19
20 /* -----------------------------------------------------------------------------
21    Minimum closure sizes
22
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.
26
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.
29
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:
33      o EVACUATED
34      o BLACKHOLE
35      o BLOCKING QUEUE
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:
41      o EVACUATED
42    -------------------------------------------------------------------------- */
43
44 #define MIN_UPD_SIZE    1
45 #define MIN_NONUPD_SIZE 1
46
47 /* -----------------------------------------------------------------------------
48    Constants to do with specialised closure types.
49    -------------------------------------------------------------------------- */
50
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.
54  */
55
56 #define MAX_SPEC_SELECTEE_SIZE 15
57
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
61  * space. 
62  */
63
64 #define MAX_SPEC_AP_SIZE       7
65
66 /* Specialised FUN/THUNK/CONSTR closure types */
67
68 #define MAX_SPEC_THUNK_SIZE    2
69 #define MAX_SPEC_FUN_SIZE      2
70 #define MAX_SPEC_CONSTR_SIZE   2
71
72 /* Range of built-in table of static small int-like and char-like closures. 
73  * 
74  *   NB. This corresponds with the number of actual INTLIKE/CHARLIKE
75  *   closures defined in rts/StgMiscClosures.cmm.
76  */
77 #define MAX_INTLIKE             16
78 #define MIN_INTLIKE             (-16)
79
80 #define MAX_CHARLIKE            255
81 #define MIN_CHARLIKE            0
82
83 /* -----------------------------------------------------------------------------
84    STG Registers.
85
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    -------------------------------------------------------------------------- */
89
90 #define MAX_VANILLA_REG 8
91 #define MAX_FLOAT_REG   4
92 #define MAX_DOUBLE_REG  2
93 #define MAX_LONG_REG    1
94
95 /* -----------------------------------------------------------------------------
96  *  Maximum number of constructors in a data type for direct-returns. 
97  *
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  * -------------------------------------------------------------------------- */
102
103 #define MAX_VECTORED_RTN 8
104
105 /* -----------------------------------------------------------------------------
106    Semi-Tagging constants
107
108    Old Comments about this stuff:
109
110    Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
111    normal-form values of algebraic data types will have tags 0, 1, ...
112    
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)
115
116    ToDo: find out if we need any of this.
117    -------------------------------------------------------------------------- */
118
119 #define INFO_OTHER_TAG          (-1)
120 #define INFO_IND_TAG            (-2)
121 #define INFO_FIRST_TAG          0
122
123 /* -----------------------------------------------------------------------------
124    How much C stack to reserve for local temporaries when in the STG
125    world.  Used in StgCRun.c.
126    -------------------------------------------------------------------------- */
127
128 #define RESERVED_C_STACK_BYTES (2048 * SIZEOF_LONG)
129
130 /* -----------------------------------------------------------------------------
131    How much Haskell stack space to reserve for the saving of registers
132    etc. in the case of a stack/heap overflow.
133    
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).  
138
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    -------------------------------------------------------------------------- */
144
145 #define RESERVED_STACK_WORDS 21
146
147 /* -----------------------------------------------------------------------------
148    Storage manager constants
149    -------------------------------------------------------------------------- */
150
151 /* The size of a block (2^BLOCK_SHIFT bytes) */
152 #define BLOCK_SHIFT  12
153
154 /* The size of a megablock (2^MBLOCK_SHIFT bytes) */
155 #define MBLOCK_SHIFT   20
156
157 /* -----------------------------------------------------------------------------
158    Bitmap/size fields (used in info tables)
159    -------------------------------------------------------------------------- */
160
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.
165  */
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
172 #else
173 #error unknown SIZEOF_VOID_P
174 #endif
175
176 /* -----------------------------------------------------------------------------
177    Lag/Drag/Void constants
178    -------------------------------------------------------------------------- */
179
180 /*
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). 
183  */
184 #if SIZEOF_VOID_P == 8
185 #define LDV_SHIFT               30
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
191 #else
192 #define LDV_SHIFT               15
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 */
199
200 /* -----------------------------------------------------------------------------
201    TSO related constants
202    -------------------------------------------------------------------------- */
203
204 /*
205  * Constants for the what_next field of a TSO, which indicates how it
206  * is to be run.
207  */
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 */
213
214 /*
215  * Constants for the why_blocked field of a TSO
216  */
217 #define NotBlocked          0
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
225
226 /* Win32 only: */
227 #define BlockedOnDoProc     8
228
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() */
238
239 /*
240  * These constants are returned to the scheduler by a thread that has
241  * stopped for one reason or another.  See typedef StgThreadReturnCode
242  * in TSO.h.
243  */
244 #define HeapOverflow   1                /* might also be StackOverflow */
245 #define StackOverflow  2
246 #define ThreadYielding 3
247 #define ThreadBlocked  4
248 #define ThreadFinished 5
249
250 /* -----------------------------------------------------------------------------
251    RET_DYN stack frames
252    -------------------------------------------------------------------------- */
253
254 /* VERY MAGIC CONSTANTS! 
255  * must agree with code in HeapStackCheck.c, stg_gen_chk, and
256  * RESERVED_STACK_WORDS in Constants.h.
257  */
258 #define RET_DYN_BITMAP_SIZE 8
259 #define RET_DYN_NONPTR_REGS_SIZE 10
260
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
263  * too.
264  */
265 #if RESERVED_STACK_WORDS != (3 + RET_DYN_BITMAP_SIZE + RET_DYN_NONPTR_REGS_SIZE)
266 #error RESERVED_STACK_WORDS may be wrong!
267 #endif
268
269 /* -----------------------------------------------------------------------------
270    How often our context-switch timer ticks
271    -------------------------------------------------------------------------- */
272
273 #define TICK_FREQUENCY   50                      /* ticks per second */
274
275 #endif /* CONSTANTS_H */