[project @ 2002-12-19 14:25:04 by simonmar]
[ghc-hetmet.git] / ghc / includes / Constants.h
1 /* ----------------------------------------------------------------------------
2  * $Id: Constants.h,v 1.22 2002/12/11 15:36:37 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
53  * StgSelectors.hc in the runtime system.  This constant defines the
54  * highest selectee index that we can replace with a reference to the
55  * pre-compiled code.
56  */
57
58 #define MAX_SPEC_SELECTEE_SIZE 15
59
60 /* Vector-apply thunks.  These thunks just push their free variables
61  * on the stack and enter the first one.  They're a bit like PAPs, but
62  * don't have a dynamic size.  We've pre-compiled a few to save
63  * space. 
64  */
65
66 #define MAX_SPEC_AP_SIZE       8
67 /* ToDo: make it 8 again */
68
69 /* Specialised FUN/THUNK/CONSTR closure types */
70
71 #define MAX_SPEC_THUNK_SIZE    2
72 #define MAX_SPEC_FUN_SIZE      2
73 #define MAX_SPEC_CONSTR_SIZE   2
74
75 /* -----------------------------------------------------------------------------
76    STG Registers.
77
78    Note that in MachRegs.h we define how many of these registers are
79    *real* machine registers, and not just offsets in the Register Table.
80    -------------------------------------------------------------------------- */
81
82 #define MAX_VANILLA_REG 8
83 #define MAX_FLOAT_REG   4
84 #define MAX_DOUBLE_REG  2
85 /* register is only used for returning (unboxed) 64-bit vals */
86 #define MAX_LONG_REG    1
87
88 /*---- Maximum number of constructors in a data type for direct-returns.  */
89
90 #define MAX_VECTORED_RTN 8
91
92 /*---- Range of built-in table of static small int-like and char-like closures. */
93
94 #define MAX_INTLIKE             16
95 #define MIN_INTLIKE             (-16)
96
97 #define MAX_CHARLIKE            255
98 #define MIN_CHARLIKE            0
99
100 /* You can change these constants (I hope) but be sure to modify
101    rts/StgMiscClosures.hs accordingly. */
102
103 /* -----------------------------------------------------------------------------
104    Semi-Tagging constants
105
106    Old Comments about this stuff:
107
108    Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
109    normal-form values of algebraic data types will have tags 0, 1, ...
110    
111    @INFO_IND_TAG@ is different from @INFO_OTHER_TAG@ just so we can count
112    how often we bang into indirection nodes; that's all.  (WDP 95/11)
113
114    ToDo: find out if we need any of this.
115    -------------------------------------------------------------------------- */
116
117 #define INFO_OTHER_TAG          (-1)
118 #define INFO_IND_TAG            (-2)
119 #define INFO_FIRST_TAG          0
120
121 /* -----------------------------------------------------------------------------
122    How much C stack to reserve for local temporaries when in the STG
123    world.  Used in StgRun.S and StgCRun.c.
124    -------------------------------------------------------------------------- */
125
126 #define RESERVED_C_STACK_BYTES (2048 * SIZEOF_LONG)
127
128 /* -----------------------------------------------------------------------------
129    How much Haskell stack space to reserve for the saving of registers
130    etc. in the case of a stack/heap overflow.
131    
132    This must be large enough to accomodate the largest stack frame
133    pushed in one of the heap check fragments in HeapStackCheck.hc
134    (ie. currently the generic heap checks - 19 words).
135    -------------------------------------------------------------------------- */
136
137 #define RESERVED_STACK_WORDS 19
138
139 /* -----------------------------------------------------------------------------
140    Storage manager constants
141    -------------------------------------------------------------------------- */
142
143 /* The size of a block (2^BLOCK_SHIFT bytes) */
144 #define BLOCK_SHIFT  12
145
146 /* The size of a megablock (2^MBLOCK_SHIFT bytes) */
147 #define MBLOCK_SHIFT   20
148
149 /* the largest size an object can be before we give it a block of its
150  * own and treat it as an immovable object during GC, expressed as a
151  * fraction of BLOCK_SIZE.
152  */
153 #define LARGE_OBJECT_THRESHOLD ((nat)(BLOCK_SIZE * 8 / 10))
154
155 /* -----------------------------------------------------------------------------
156    Bitmap/size fields (used in info tables)
157    -------------------------------------------------------------------------- */
158
159 /* In a 32-bit bitmap field, we use 5 bits for the size, and 27 bits
160  * for the bitmap.  If the bitmap requires more than 27 bits, then we
161  * store it in a separate array, and leave a pointer in the bitmap
162  * field.  On a 64-bit machine, the sizes are extended accordingly.
163  */
164 #if SIZEOF_VOID_P == 4
165 #define BITMAP_SIZE_MASK     0x1f
166 #define BITMAP_BITS_SHIFT    5
167 #elif SIZEOF_VOID_P == 8
168 #define BITMAP_SIZE_MASK     0x3f
169 #define BITMAP_BITS_SHIFT    6
170 #else
171 #error unknown SIZEOF_VOID_P
172 #endif
173
174 #endif /* CONSTANTS_H */