Constants.h 9.82 KB
Newer Older
1
/* ----------------------------------------------------------------------------
2
 * $Id: Constants.h,v 1.27 2004/11/18 09:56:19 tharris Exp $
3
 *
4
 * (c) The GHC Team, 1998-2002
5 6 7
 *
 * Constants
 *
8 9 10 11 12 13 14
 * NOTE: this information is used by both the compiler and the RTS.
 * Some of it is tweakable, and some of it must be kept up to date
 * with various other parts of the system.
 *
 * Constants which are derived automatically from other definitions in
 * the system (eg. structure sizes) are generated into the file
 * DerivedConstants.h by a C program (mkDerivedConstantsHdr).
15 16 17 18 19 20 21 22 23
 *
 * -------------------------------------------------------------------------- */

#ifndef CONSTANTS_H
#define CONSTANTS_H

/* -----------------------------------------------------------------------------
   Minimum closure sizes

sof's avatar
sof committed
24
   Here we define the minimum size for updatable closures. This must be at
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
   least 2, to allow for cons cells and linked indirections. All updates
   will be performed on closures of this size. For non-updatable closures
   the minimum size is 1 to allow for a forwarding pointer.

   Linked indirections are UPD_OLDGEN things: see Closures.h

   o MIN_UPD_SIZE doesn't apply to stack closures, static closures
     or non-updateable objects like PAPs or CONSTRs
   o MIN_UPD_SIZE is big enough to contain any of the following:
     o EVACUATED
     o BLACKHOLE
     o BLOCKING QUEUE
     o IND, IND_PERM, IND_OLDGEN and IND_OLDGEN_PERM
       (it need not be big enough for IND_STATIC - but it is)
   o MIN_NONUPD_SIZE doesn't apply to stack closures, static closures
     or updateable objects like APs, THUNKS or THUNK_SELECTORs
   o MIN_NONUPD_SIZE is big enough to contain any of the following:
     o EVACUATED
   -------------------------------------------------------------------------- */

#define MIN_UPD_SIZE	2
#define MIN_NONUPD_SIZE 1

/* -----------------------------------------------------------------------------
   Constants to do with specialised closure types.
   -------------------------------------------------------------------------- */

sof's avatar
sof committed
52 53 54
/* We have some pre-compiled selector thunks defined in rts/StgStdThunks.hc.
 * This constant defines the highest selectee index that we can replace with a 
 * reference to the pre-compiled code.
55 56 57 58 59 60 61 62 63 64
 */

#define MAX_SPEC_SELECTEE_SIZE 15

/* Vector-apply thunks.  These thunks just push their free variables
 * on the stack and enter the first one.  They're a bit like PAPs, but
 * don't have a dynamic size.  We've pre-compiled a few to save
 * space. 
 */

65
#define MAX_SPEC_AP_SIZE       7
66

67 68 69 70 71 72
/* Specialised FUN/THUNK/CONSTR closure types */

#define MAX_SPEC_THUNK_SIZE    2
#define MAX_SPEC_FUN_SIZE      2
#define MAX_SPEC_CONSTR_SIZE   2

73 74 75 76 77 78 79 80 81 82 83
/* Range of built-in table of static small int-like and char-like closures. 
 * 
 *   NB. This corresponds with the number of actual INTLIKE/CHARLIKE
 *   closures defined in rts/StgMiscClosures.cmm.
 */
#define MAX_INTLIKE 		16
#define MIN_INTLIKE 		(-16)

#define MAX_CHARLIKE		255
#define MIN_CHARLIKE		0

84 85 86 87 88 89 90 91 92 93 94 95
/* -----------------------------------------------------------------------------
   STG Registers.

   Note that in MachRegs.h we define how many of these registers are
   *real* machine registers, and not just offsets in the Register Table.
   -------------------------------------------------------------------------- */

#define MAX_VANILLA_REG 8
#define MAX_FLOAT_REG   4
#define MAX_DOUBLE_REG  2
#define MAX_LONG_REG    1

96 97 98 99 100 101 102
/* -----------------------------------------------------------------------------
 *  Maximum number of constructors in a data type for direct-returns. 
 *
 *   NB. There are various places that assume the value of this
 *   constant, such as the polymorphic return frames for updates
 *   (stg_upd_frame_info) and catch frames (stg_catch_frame_info).
 * -------------------------------------------------------------------------- */
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125

#define MAX_VECTORED_RTN 8

/* -----------------------------------------------------------------------------
   Semi-Tagging constants

   Old Comments about this stuff:

   Tags for indirection nodes and ``other'' (probably unevaluated) nodes;
   normal-form values of algebraic data types will have tags 0, 1, ...
   
   @INFO_IND_TAG@ is different from @INFO_OTHER_TAG@ just so we can count
   how often we bang into indirection nodes; that's all.  (WDP 95/11)

   ToDo: find out if we need any of this.
   -------------------------------------------------------------------------- */

#define INFO_OTHER_TAG		(-1)
#define INFO_IND_TAG		(-2)
#define INFO_FIRST_TAG		0

/* -----------------------------------------------------------------------------
   How much C stack to reserve for local temporaries when in the STG
sof's avatar
sof committed
126
   world.  Used in StgCRun.c.
127 128
   -------------------------------------------------------------------------- */

129
#define RESERVED_C_STACK_BYTES (2048 * SIZEOF_LONG)
130 131 132 133 134 135 136

/* -----------------------------------------------------------------------------
   How much Haskell stack space to reserve for the saving of registers
   etc. in the case of a stack/heap overflow.
   
   This must be large enough to accomodate the largest stack frame
   pushed in one of the heap check fragments in HeapStackCheck.hc
137 138 139 140 141 142 143
   (ie. currently the generic heap checks - 3 words for StgRetDyn,
   18 words for the saved registers, see StgMacros.h).  

   In the event of an unboxed tuple or let-no-escape stack/heap check
   failure, there will be other words on the stack which are covered
   by the RET_DYN frame.  These will have been accounted for by stack
   checks however, so we don't need to allow for them here.
144 145
   -------------------------------------------------------------------------- */

146
#define RESERVED_STACK_WORDS 21
147 148 149 150 151

/* -----------------------------------------------------------------------------
   Storage manager constants
   -------------------------------------------------------------------------- */

152
/* The size of a block (2^BLOCK_SHIFT bytes) */
153
#define BLOCK_SHIFT  12
154

155
/* The size of a megablock (2^MBLOCK_SHIFT bytes) */
156 157
#define MBLOCK_SHIFT   20

158 159 160
/* -----------------------------------------------------------------------------
   Bitmap/size fields (used in info tables)
   -------------------------------------------------------------------------- */
161

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
/* In a 32-bit bitmap field, we use 5 bits for the size, and 27 bits
 * for the bitmap.  If the bitmap requires more than 27 bits, then we
 * store it in a separate array, and leave a pointer in the bitmap
 * field.  On a 64-bit machine, the sizes are extended accordingly.
 */
#if SIZEOF_VOID_P == 4
#define BITMAP_SIZE_MASK     0x1f
#define BITMAP_BITS_SHIFT    5
#elif SIZEOF_VOID_P == 8
#define BITMAP_SIZE_MASK     0x3f
#define BITMAP_BITS_SHIFT    6
#else
#error unknown SIZEOF_VOID_P
#endif

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
/* -----------------------------------------------------------------------------
   Lag/Drag/Void constants
   -------------------------------------------------------------------------- */

/*
  An LDV word is divided into 3 parts: state bits (LDV_STATE_MASK), creation 
  time bits (LDV_CREATE_MASK), and last use time bits (LDV_LAST_MASK). 
 */
#if SIZEOF_VOID_P == 8
#define LDV_SHIFT               30
#define LDV_STATE_MASK          0x1000000000000000
#define LDV_CREATE_MASK         0x0FFFFFFFC0000000
#define LDV_LAST_MASK           0x000000003FFFFFFF
#define LDV_STATE_CREATE        0x0000000000000000
#define LDV_STATE_USE           0x1000000000000000
#else
#define LDV_SHIFT               15
#define LDV_STATE_MASK          0x40000000 
#define LDV_CREATE_MASK         0x3FFF8000
#define LDV_LAST_MASK           0x00007FFF
#define LDV_STATE_CREATE        0x00000000
#define LDV_STATE_USE           0x40000000
#endif  // SIZEOF_VOID_P

/* -----------------------------------------------------------------------------
   TSO related constants
   -------------------------------------------------------------------------- */

/*
 * Constants for the what_next field of a TSO, which indicates how it
 * is to be run.
 */
#define ThreadRunGHC    1	/* return to address on top of stack */
#define ThreadInterpret 2	/* interpret this thread */
#define ThreadKilled	3	/* thread has died, don't run it */
#define ThreadRelocated	4	/* thread has moved, link points to new locn */
#define ThreadComplete	5	/* thread has finished */

/*
 * Constants for the why_blocked field of a TSO
 */
#define NotBlocked          0
#define BlockedOnMVar       1
#define BlockedOnBlackHole  2
#define BlockedOnException  3
#define BlockedOnRead       4
#define BlockedOnWrite      5
#define BlockedOnDelay      6
225
#define BlockedOnSTM        7
226 227

/* Win32 only: */
228
#define BlockedOnDoProc     8
229 230 231

/* Only relevant for PAR: */
  /* blocked on a remote closure represented by a Global Address: */
232
#define BlockedOnGA         9
233
  /* same as above but without sending a Fetch message */
234
#define BlockedOnGA_NoSend  10
235
/* Only relevant for RTS_SUPPORTS_THREADS: */
236 237
#define BlockedOnCCall      11
#define BlockedOnCCall_NoUnblockExc 12
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
   /* same as above but don't unblock async exceptions in resumeThread() */

/*
 * These constants are returned to the scheduler by a thread that has
 * stopped for one reason or another.  See typedef StgThreadReturnCode
 * in TSO.h.
 */
#define HeapOverflow   1		/* might also be StackOverflow */
#define StackOverflow  2
#define ThreadYielding 3
#define ThreadBlocked  4
#define ThreadFinished 5

/* -----------------------------------------------------------------------------
   RET_DYN stack frames
   -------------------------------------------------------------------------- */

/* VERY MAGIC CONSTANTS! 
 * must agree with code in HeapStackCheck.c, stg_gen_chk, and
 * RESERVED_STACK_WORDS in Constants.h.
 */
#define RET_DYN_BITMAP_SIZE 8
#define RET_DYN_NONPTR_REGS_SIZE 10

/* Sanity check that RESERVED_STACK_WORDS is reasonable.  We can't
 * just derive RESERVED_STACK_WORDS because it's used in Haskell code
 * too.
 */
#if RESERVED_STACK_WORDS != (3 + RET_DYN_BITMAP_SIZE + RET_DYN_NONPTR_REGS_SIZE)
#error RESERVED_STACK_WORDS may be wrong!
#endif

270
#endif /* CONSTANTS_H */