1 /* -----------------------------------------------------------------------------
2 * $Id: Block.h,v 1.7 2000/04/05 14:26:31 panne Exp $
4 * (c) The GHC Team, 1998-1999
6 * Block structure for the storage manager
8 * ---------------------------------------------------------------------------*/
13 /* The actual block and megablock-size constants are defined in
14 * includes/Constants.h, all constants here are derived from these.
17 /* Block related constants (4k blocks) */
19 #define BLOCK_SIZE_W (BLOCK_SIZE/sizeof(W_))
20 #define BLOCK_MASK (BLOCK_SIZE-1)
22 #define BLOCK_ROUND_UP(p) ((void *) (((W_)(p)+BLOCK_SIZE-1) & ~BLOCK_MASK))
23 #define BLOCK_ROUND_DOWN(p) ((void *) ((W_)(p) & ~BLOCK_MASK))
25 /* Megablock related constants (1M megablocks) */
27 #define MBLOCK_SIZE_W (MBLOCK_SIZE/sizeof(W_))
28 #define MBLOCK_MASK (MBLOCK_SIZE-1)
30 #define MBLOCK_ROUND_UP(p) ((void *)(((W_)(p)+MBLOCK_SIZE-1) & ~MBLOCK_MASK))
31 #define MBLOCK_ROUND_DOWN(p) ((void *)((W_)(p) & ~MBLOCK_MASK ))
34 /* -----------------------------------------------------------------------------
35 * Block descriptor. This structure *must* be the right length, so we
36 * can do pointer arithmetic on pointers to it.
39 /* The block descriptor is 64 bytes on a 64-bit machine, and 32-bytes
40 * on a 32-bit machine.
43 typedef struct _bdescr {
44 StgPtr start; /* start addr of memory */
45 StgPtr free; /* first free byte of memory */
46 struct _bdescr *link; /* used for chaining blocks together */
47 struct _bdescr *back; /* used (occasionally) for doubly-linked lists*/
48 struct _generation *gen; /* generation */
49 struct _step *step; /* step */
50 StgWord32 blocks; /* no. of blocks (if grp head, 0 otherwise) */
51 StgWord32 evacuated; /* block is in to-space */
52 #if SIZEOF_VOID_P == 8
53 StgWord32 _padding[2];
55 StgWord32 _padding[0];
59 #if SIZEOF_VOID_P == 8
60 #define BDESCR_SIZE 0x40
61 #define BDESCR_MASK 0x3f
62 #define BDESCR_SHIFT 6
64 #define BDESCR_SIZE 0x20
65 #define BDESCR_MASK 0x1f
66 #define BDESCR_SHIFT 5
69 /* Finding the block descriptor for a given block -------------------------- */
71 static inline bdescr *Bdescr(StgPtr p)
74 ((((W_)p & MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT))
75 | ((W_)p & ~MBLOCK_MASK)
79 /* Useful Macros ------------------------------------------------------------ */
81 /* Offset of first real data block in a megablock */
83 #define FIRST_BLOCK_OFF \
84 ((W_)BLOCK_ROUND_UP(MBLOCK_SIZE / BLOCK_SIZE * BDESCR_SIZE))
86 /* First data block in a given megablock */
88 #define FIRST_BLOCK(m) ((void *)(FIRST_BLOCK_OFF + (W_)(m)))
90 /* Last data block in a given megablock */
92 #define LAST_BLOCK(m) ((void *)(MBLOCK_SIZE-BLOCK_SIZE + (W_)(m)))
94 /* First real block descriptor in a megablock */
96 #define FIRST_BDESCR(m) \
97 ((bdescr *)((FIRST_BLOCK_OFF>>(BLOCK_SHIFT-BDESCR_SHIFT)) + (W_)(m)))
99 /* Number of usable blocks in a megablock */
101 #define BLOCKS_PER_MBLOCK ((MBLOCK_SIZE - FIRST_BLOCK_OFF) / BLOCK_SIZE)
103 /* How many blocks in this megablock group */
105 #define MBLOCK_GROUP_BLOCKS(n) \
106 (BLOCKS_PER_MBLOCK + (n-1) * (MBLOCK_SIZE / BLOCK_SIZE))
108 /* Compute the required size of a megablock group */
110 #define BLOCKS_TO_MBLOCKS(n) \
111 (1 + (W_)MBLOCK_ROUND_UP((n-BLOCKS_PER_MBLOCK) * BLOCK_SIZE) / MBLOCK_SIZE)