8974052821e63c78d73aa747f26dd9147e3e2698
[ghc-hetmet.git] / ghc / includes / Constants.h
1 /* ----------------------------------------------------------------------------
2  * $Id: Constants.h,v 1.25 2003/04/28 09:55:20 simonmar Exp $
3  *
4  * (c) The GHC Team, 1998-2002
5  *
6  * Constants
7  *
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.
11  *
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).
15  *
16  * -------------------------------------------------------------------------- */
17
18 #ifndef CONSTANTS_H
19 #define CONSTANTS_H
20
21 /* -----------------------------------------------------------------------------
22    Minimum closure sizes
23
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.
28
29    Linked indirections are UPD_OLDGEN things: see Closures.h
30
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:
34      o EVACUATED
35      o BLACKHOLE
36      o BLOCKING QUEUE
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:
42      o EVACUATED
43    -------------------------------------------------------------------------- */
44
45 #define MIN_UPD_SIZE    2
46 #define MIN_NONUPD_SIZE 1
47
48 /* -----------------------------------------------------------------------------
49    Constants to do with specialised closure types.
50    -------------------------------------------------------------------------- */
51
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.
55  */
56
57 #define MAX_SPEC_SELECTEE_SIZE 15
58
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
62  * space. 
63  */
64
65 #define MAX_SPEC_AP_SIZE       8
66 /* ToDo: make it 8 again */
67
68 /* Specialised FUN/THUNK/CONSTR closure types */
69
70 #define MAX_SPEC_THUNK_SIZE    2
71 #define MAX_SPEC_FUN_SIZE      2
72 #define MAX_SPEC_CONSTR_SIZE   2
73
74 /* -----------------------------------------------------------------------------
75    STG Registers.
76
77    Note that in MachRegs.h we define how many of these registers are
78    *real* machine registers, and not just offsets in the Register Table.
79    -------------------------------------------------------------------------- */
80
81 #define MAX_VANILLA_REG 8
82 #define MAX_FLOAT_REG   4
83 #define MAX_DOUBLE_REG  2
84 /* register is only used for returning (unboxed) 64-bit vals */
85 #define MAX_LONG_REG    1
86
87 /*---- Maximum number of constructors in a data type for direct-returns.  */
88
89 #define MAX_VECTORED_RTN 8
90
91 /*---- Range of built-in table of static small int-like and char-like closures. */
92
93 #define MAX_INTLIKE             16
94 #define MIN_INTLIKE             (-16)
95
96 #define MAX_CHARLIKE            255
97 #define MIN_CHARLIKE            0
98
99 /* You can change these constants (I hope) but be sure to modify
100    rts/StgMiscClosures.hs accordingly. */
101
102 /* -----------------------------------------------------------------------------
103    Semi-Tagging constants
104
105    Old Comments about this stuff:
106
107    Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
108    normal-form values of algebraic data types will have tags 0, 1, ...
109    
110    @INFO_IND_TAG@ is different from @INFO_OTHER_TAG@ just so we can count
111    how often we bang into indirection nodes; that's all.  (WDP 95/11)
112
113    ToDo: find out if we need any of this.
114    -------------------------------------------------------------------------- */
115
116 #define INFO_OTHER_TAG          (-1)
117 #define INFO_IND_TAG            (-2)
118 #define INFO_FIRST_TAG          0
119
120 /* -----------------------------------------------------------------------------
121    How much C stack to reserve for local temporaries when in the STG
122    world.  Used in StgCRun.c.
123    -------------------------------------------------------------------------- */
124
125 #define RESERVED_C_STACK_BYTES (2048 * SIZEOF_LONG)
126
127 /* -----------------------------------------------------------------------------
128    How much Haskell stack space to reserve for the saving of registers
129    etc. in the case of a stack/heap overflow.
130    
131    This must be large enough to accomodate the largest stack frame
132    pushed in one of the heap check fragments in HeapStackCheck.hc
133    (ie. currently the generic heap checks - 3 words for StgRetDyn,
134    18 words for the saved registers, see StgMacros.h).  
135
136    In the event of an unboxed tuple or let-no-escape stack/heap check
137    failure, there will be other words on the stack which are covered
138    by the RET_DYN frame.  These will have been accounted for by stack
139    checks however, so we don't need to allow for them here.
140    -------------------------------------------------------------------------- */
141
142 #define RESERVED_STACK_WORDS 21
143
144 /* -----------------------------------------------------------------------------
145    Storage manager constants
146    -------------------------------------------------------------------------- */
147
148 /* The size of a block (2^BLOCK_SHIFT bytes) */
149 #define BLOCK_SHIFT  12
150
151 /* The size of a megablock (2^MBLOCK_SHIFT bytes) */
152 #define MBLOCK_SHIFT   20
153
154 /* -----------------------------------------------------------------------------
155    Bitmap/size fields (used in info tables)
156    -------------------------------------------------------------------------- */
157
158 /* In a 32-bit bitmap field, we use 5 bits for the size, and 27 bits
159  * for the bitmap.  If the bitmap requires more than 27 bits, then we
160  * store it in a separate array, and leave a pointer in the bitmap
161  * field.  On a 64-bit machine, the sizes are extended accordingly.
162  */
163 #if SIZEOF_VOID_P == 4
164 #define BITMAP_SIZE_MASK     0x1f
165 #define BITMAP_BITS_SHIFT    5
166 #elif SIZEOF_VOID_P == 8
167 #define BITMAP_SIZE_MASK     0x3f
168 #define BITMAP_BITS_SHIFT    6
169 #else
170 #error unknown SIZEOF_VOID_P
171 #endif
172
173 #endif /* CONSTANTS_H */