Allow the use of R9 and R10 in primops; fixes trac #5423
[ghc.git] / includes / rts / Constants.h
1 /* ----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2009
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 * To understand the structure of the RTS headers, see the wiki:
16 * http://hackage.haskell.org/trac/ghc/wiki/Commentary/SourceTree/Includes
17 *
18 * -------------------------------------------------------------------------- */
19
20 #ifndef RTS_CONSTANTS_H
21 #define RTS_CONSTANTS_H
22
23 /* -----------------------------------------------------------------------------
24 Minimum closure sizes
25
26 This is the minimum number of words in the payload of a
27 heap-allocated closure, so that the closure has enough room to be
28 overwritten with a forwarding pointer during garbage collection.
29 -------------------------------------------------------------------------- */
30
31 #define MIN_PAYLOAD_SIZE 1
32
33 /* -----------------------------------------------------------------------------
34 Constants to do with specialised closure types.
35 -------------------------------------------------------------------------- */
36
37 /* We have some pre-compiled selector thunks defined in rts/StgStdThunks.hc.
38 * This constant defines the highest selectee index that we can replace with a
39 * reference to the pre-compiled code.
40 */
41
42 #define MAX_SPEC_SELECTEE_SIZE 15
43
44 /* Vector-apply thunks. These thunks just push their free variables
45 * on the stack and enter the first one. They're a bit like PAPs, but
46 * don't have a dynamic size. We've pre-compiled a few to save
47 * space.
48 */
49
50 #define MAX_SPEC_AP_SIZE 7
51
52 /* Specialised FUN/THUNK/CONSTR closure types */
53
54 #define MAX_SPEC_THUNK_SIZE 2
55 #define MAX_SPEC_FUN_SIZE 2
56 #define MAX_SPEC_CONSTR_SIZE 2
57
58 /* Range of built-in table of static small int-like and char-like closures.
59 *
60 * NB. This corresponds with the number of actual INTLIKE/CHARLIKE
61 * closures defined in rts/StgMiscClosures.cmm.
62 */
63 #define MAX_INTLIKE 16
64 #define MIN_INTLIKE (-16)
65
66 #define MAX_CHARLIKE 255
67 #define MIN_CHARLIKE 0
68
69 /* Each byte in the card table for an StgMutaArrPtrs covers
70 * (1<<MUT_ARR_PTRS_CARD_BITS) elements in the array. To find a good
71 * value for this, I used the benchmarks nofib/gc/hash,
72 * nofib/gc/graph, and nofib/gc/gc_bench.
73 */
74 #define MUT_ARR_PTRS_CARD_BITS 7
75
76 /* -----------------------------------------------------------------------------
77 STG Registers.
78
79 Note that in MachRegs.h we define how many of these registers are
80 *real* machine registers, and not just offsets in the Register Table.
81 -------------------------------------------------------------------------- */
82
83 #define MAX_VANILLA_REG 10
84 #define MAX_FLOAT_REG 4
85 #define MAX_DOUBLE_REG 2
86 #define MAX_LONG_REG 1
87
88 /* -----------------------------------------------------------------------------
89 Semi-Tagging constants
90
91 Old Comments about this stuff:
92
93 Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
94 normal-form values of algebraic data types will have tags 0, 1, ...
95
96 @INFO_IND_TAG@ is different from @INFO_OTHER_TAG@ just so we can count
97 how often we bang into indirection nodes; that's all. (WDP 95/11)
98
99 ToDo: find out if we need any of this.
100 -------------------------------------------------------------------------- */
101
102 #define INFO_OTHER_TAG (-1)
103 #define INFO_IND_TAG (-2)
104 #define INFO_FIRST_TAG 0
105
106 /* -----------------------------------------------------------------------------
107 How much C stack to reserve for local temporaries when in the STG
108 world. Used in StgCRun.c.
109 -------------------------------------------------------------------------- */
110
111 #define RESERVED_C_STACK_BYTES (2048 * SIZEOF_LONG)
112
113 /* -----------------------------------------------------------------------------
114 How much Haskell stack space to reserve for the saving of registers
115 etc. in the case of a stack/heap overflow.
116
117 This must be large enough to accomodate the largest stack frame
118 pushed in one of the heap check fragments in HeapStackCheck.hc
119 (ie. currently the generic heap checks - 3 words for StgRetDyn,
120 18 words for the saved registers, see StgMacros.h).
121
122 In the event of an unboxed tuple or let-no-escape stack/heap check
123 failure, there will be other words on the stack which are covered
124 by the RET_DYN frame. These will have been accounted for by stack
125 checks however, so we don't need to allow for them here.
126 -------------------------------------------------------------------------- */
127
128 #define RESERVED_STACK_WORDS 21
129
130 /* -----------------------------------------------------------------------------
131 The limit on the size of the stack check performed when we enter an
132 AP_STACK, in words. See raiseAsync() and bug #1466.
133 -------------------------------------------------------------------------- */
134
135 #define AP_STACK_SPLIM 1024
136
137 /* -----------------------------------------------------------------------------
138 Storage manager constants
139 -------------------------------------------------------------------------- */
140
141 /* The size of a block (2^BLOCK_SHIFT bytes) */
142 #define BLOCK_SHIFT 12
143
144 /* The size of a megablock (2^MBLOCK_SHIFT bytes) */
145 #define MBLOCK_SHIFT 20
146
147 /* -----------------------------------------------------------------------------
148 Bitmap/size fields (used in info tables)
149 -------------------------------------------------------------------------- */
150
151 /* In a 32-bit bitmap field, we use 5 bits for the size, and 27 bits
152 * for the bitmap. If the bitmap requires more than 27 bits, then we
153 * store it in a separate array, and leave a pointer in the bitmap
154 * field. On a 64-bit machine, the sizes are extended accordingly.
155 */
156 #if SIZEOF_VOID_P == 4
157 #define BITMAP_SIZE_MASK 0x1f
158 #define BITMAP_BITS_SHIFT 5
159 #elif SIZEOF_VOID_P == 8
160 #define BITMAP_SIZE_MASK 0x3f
161 #define BITMAP_BITS_SHIFT 6
162 #else
163 #error unknown SIZEOF_VOID_P
164 #endif
165
166 /* -----------------------------------------------------------------------------
167 Lag/Drag/Void constants
168 -------------------------------------------------------------------------- */
169
170 /*
171 An LDV word is divided into 3 parts: state bits (LDV_STATE_MASK), creation
172 time bits (LDV_CREATE_MASK), and last use time bits (LDV_LAST_MASK).
173 */
174 #if SIZEOF_VOID_P == 8
175 #define LDV_SHIFT 30
176 #define LDV_STATE_MASK 0x1000000000000000
177 #define LDV_CREATE_MASK 0x0FFFFFFFC0000000
178 #define LDV_LAST_MASK 0x000000003FFFFFFF
179 #define LDV_STATE_CREATE 0x0000000000000000
180 #define LDV_STATE_USE 0x1000000000000000
181 #else
182 #define LDV_SHIFT 15
183 #define LDV_STATE_MASK 0x40000000
184 #define LDV_CREATE_MASK 0x3FFF8000
185 #define LDV_LAST_MASK 0x00007FFF
186 #define LDV_STATE_CREATE 0x00000000
187 #define LDV_STATE_USE 0x40000000
188 #endif /* SIZEOF_VOID_P */
189
190 /* -----------------------------------------------------------------------------
191 TSO related constants
192 -------------------------------------------------------------------------- */
193
194 /*
195 * Constants for the what_next field of a TSO, which indicates how it
196 * is to be run.
197 */
198 #define ThreadRunGHC 1 /* return to address on top of stack */
199 #define ThreadInterpret 2 /* interpret this thread */
200 #define ThreadKilled 3 /* thread has died, don't run it */
201 #define ThreadComplete 4 /* thread has finished */
202
203 /*
204 * Constants for the why_blocked field of a TSO
205 * NB. keep these in sync with GHC/Conc.lhs: threadStatus
206 */
207 #define NotBlocked 0
208 #define BlockedOnMVar 1
209 #define BlockedOnBlackHole 2
210 #define BlockedOnRead 3
211 #define BlockedOnWrite 4
212 #define BlockedOnDelay 5
213 #define BlockedOnSTM 6
214
215 /* Win32 only: */
216 #define BlockedOnDoProc 7
217
218 /* Only relevant for PAR: */
219 /* blocked on a remote closure represented by a Global Address: */
220 #define BlockedOnGA 8
221 /* same as above but without sending a Fetch message */
222 #define BlockedOnGA_NoSend 9
223 /* Only relevant for THREADED_RTS: */
224 #define BlockedOnCCall 10
225 #define BlockedOnCCall_Interruptible 11
226 /* same as above but permit killing the worker thread */
227
228 /* Involved in a message sent to tso->msg_cap */
229 #define BlockedOnMsgThrowTo 12
230
231 /* The thread is not on any run queues, but can be woken up
232 by tryWakeupThread() */
233 #define ThreadMigrating 13
234
235 /*
236 * These constants are returned to the scheduler by a thread that has
237 * stopped for one reason or another. See typedef StgThreadReturnCode
238 * in TSO.h.
239 */
240 #define HeapOverflow 1 /* might also be StackOverflow */
241 #define StackOverflow 2
242 #define ThreadYielding 3
243 #define ThreadBlocked 4
244 #define ThreadFinished 5
245
246 /*
247 * Flags for the tso->flags field.
248 */
249
250 /*
251 * TSO_LOCKED is set when a TSO is locked to a particular Capability.
252 */
253 #define TSO_LOCKED 2
254
255 /*
256 * TSO_BLOCKEX: the TSO is blocking exceptions
257 *
258 * TSO_INTERRUPTIBLE: the TSO can be interrupted if it blocks
259 * interruptibly (eg. with BlockedOnMVar).
260 *
261 * TSO_STOPPED_ON_BREAKPOINT: the thread is currently stopped in a breakpoint
262 */
263 #define TSO_BLOCKEX 4
264 #define TSO_INTERRUPTIBLE 8
265 #define TSO_STOPPED_ON_BREAKPOINT 16
266
267 /*
268 * Used by the sanity checker to check whether TSOs are on the correct
269 * mutable list.
270 */
271 #define TSO_MARKED 64
272
273 /*
274 * Used to communicate between stackSqueeze() and
275 * threadStackOverflow() that a thread's stack was squeezed and the
276 * stack may not need to be expanded.
277 */
278 #define TSO_SQUEEZED 128
279
280 /* -----------------------------------------------------------------------------
281 RET_DYN stack frames
282 -------------------------------------------------------------------------- */
283
284 /* VERY MAGIC CONSTANTS!
285 * must agree with code in HeapStackCheck.c, stg_gen_chk, and
286 * RESERVED_STACK_WORDS in Constants.h.
287 */
288 #define RET_DYN_BITMAP_SIZE 8
289 #define RET_DYN_NONPTR_REGS_SIZE 10
290
291 /* Sanity check that RESERVED_STACK_WORDS is reasonable. We can't
292 * just derive RESERVED_STACK_WORDS because it's used in Haskell code
293 * too.
294 */
295 #if RESERVED_STACK_WORDS != (3 + RET_DYN_BITMAP_SIZE + RET_DYN_NONPTR_REGS_SIZE)
296 #error RESERVED_STACK_WORDS may be wrong!
297 #endif
298
299 /*
300 * The number of times we spin in a spin lock before yielding (see
301 * #3758). To tune this value, use the benchmark in #3758: run the
302 * server with -N2 and the client both on a dual-core. Also make sure
303 * that the chosen value doesn't slow down any of the parallel
304 * benchmarks in nofib/parallel.
305 */
306 #define SPIN_COUNT 1000
307
308 /* -----------------------------------------------------------------------------
309 Spare workers per Capability in the threaded RTS
310
311 No more than MAX_SPARE_WORKERS will be kept in the thread pool
312 associated with each Capability.
313 -------------------------------------------------------------------------- */
314
315 #define MAX_SPARE_WORKERS 6
316
317 #endif /* RTS_CONSTANTS_H */