[project @ 1999-01-13 17:25:37 by simonm]
[ghc-hetmet.git] / ghc / includes / Block.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Block.h,v 1.3 1999/01/13 17:25:51 simonm Exp $
3  *
4  * Block structure for the storage manager
5  *
6  * ---------------------------------------------------------------------------*/
7
8 #ifndef BLOCK_H
9 #define BLOCK_H
10
11 /* The actual block and megablock-size constants are defined in
12  * includes/Constants.h, all constants here are derived from these.
13  */
14
15 /* Block related constants (4k blocks) */
16
17 #define BLOCK_SIZE_W (BLOCK_SIZE/sizeof(W_))
18 #define BLOCK_MASK   (BLOCK_SIZE-1)
19
20 #define BLOCK_ROUND_UP(p)   ((void *) (((W_)(p)+BLOCK_SIZE-1) & ~BLOCK_MASK))
21 #define BLOCK_ROUND_DOWN(p) ((void *) ((W_)(p) & ~BLOCK_MASK))
22
23 /* Megablock related constants (1M megablocks) */
24
25 #define MBLOCK_SIZE_W  (MBLOCK_SIZE/sizeof(W_))
26 #define MBLOCK_MASK    (MBLOCK_SIZE-1)
27
28 #define MBLOCK_ROUND_UP(p)   ((void *)(((W_)(p)+MBLOCK_SIZE-1) & ~MBLOCK_MASK))
29 #define MBLOCK_ROUND_DOWN(p) ((void *)((W_)(p) & ~MBLOCK_MASK ))
30
31
32 /* -----------------------------------------------------------------------------
33  * Block descriptor.  This structure *must* be the right length, so we
34  * can do pointer arithmetic on pointers to it.
35  */
36
37 /* The block descriptor is 64 bytes on a 64-bit machine, and 32-bytes
38  * on a 32-bit machine.
39  */
40
41 typedef struct _bdescr {
42   StgPtr start;                 /* start addr of memory */
43   StgPtr free;                  /* first free byte of memory */
44   struct _bdescr *link;         /* used for chaining blocks together */
45   struct _bdescr *back;         /* used (occasionally) for doubly-linked lists*/
46   struct _generation *gen;      /* generation */
47   struct _step *step;           /* step */
48   StgNat32 blocks;              /* no. of blocks (if grp head, 0 otherwise) */
49   StgNat32 evacuated;           /* block is in to-space */
50 #if SIZEOF_VOID_P == 8
51   StgNat32 _padding[2];
52 #else
53   StgNat32 _padding[0];
54 #endif
55 } bdescr;
56
57 #if SIZEOF_VOID_P == 8
58 #define BDESCR_SIZE  0x40
59 #define BDESCR_MASK  0x3f
60 #define BDESCR_SHIFT 6
61 #else
62 #define BDESCR_SIZE  0x20
63 #define BDESCR_MASK  0x1f
64 #define BDESCR_SHIFT 5
65 #endif
66
67 /* Useful Macros ------------------------------------------------------------ */
68
69 /* Offset of first real data block in a megablock */
70
71 #define FIRST_BLOCK_OFF \
72    ((W_)BLOCK_ROUND_UP(MBLOCK_SIZE / BLOCK_SIZE * BDESCR_SIZE))
73
74 /* First data block in a given megablock */
75
76 #define FIRST_BLOCK(m) ((void *)(FIRST_BLOCK_OFF + (W_)(m)))
77    
78 /* Last data block in a given megablock */
79
80 #define LAST_BLOCK(m)  ((void *)(MBLOCK_SIZE-BLOCK_SIZE + (W_)(m)))
81
82 /* First real block descriptor in a megablock */
83
84 #define FIRST_BDESCR(m) \
85    ((bdescr *)((FIRST_BLOCK_OFF>>(BLOCK_SHIFT-BDESCR_SHIFT)) + (W_)(m)))
86
87 /* Number of usable blocks in a megablock */
88
89 #define BLOCKS_PER_MBLOCK ((MBLOCK_SIZE - FIRST_BLOCK_OFF) / BLOCK_SIZE)
90
91 /* How many blocks in this megablock group */
92
93 #define MBLOCK_GROUP_BLOCKS(n) \
94    (BLOCKS_PER_MBLOCK + (n-1) * (MBLOCK_SIZE / BLOCK_SIZE))
95
96 /* Compute the required size of a megablock group */
97
98 #define BLOCKS_TO_MBLOCKS(n) \
99    (1 + (W_)MBLOCK_ROUND_UP((n-BLOCKS_PER_MBLOCK) * BLOCK_SIZE) / MBLOCK_SIZE)
100
101 #endif BLOCK_H