0fb39b3b12d647abd70310f40c2eb08371f64a8d
[ghc-hetmet.git] / rts / GCCompact.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team 1998-2005
4  *
5  * Compacting garbage collector
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #ifndef GCCOMPACT_H
10 #define GCCOMPACT_H
11
12 STATIC_INLINE void 
13 mark(StgPtr p, bdescr *bd)
14 {
15     nat offset_within_block = p - bd->start; // in words
16     StgPtr bitmap_word = (StgPtr)bd->u.bitmap + 
17         (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
18     StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
19     *bitmap_word |= bit_mask;
20 }
21
22 STATIC_INLINE void 
23 unmark(StgPtr p, bdescr *bd)
24 {
25     nat offset_within_block = p - bd->start; // in words
26     StgPtr bitmap_word = (StgPtr)bd->u.bitmap + 
27         (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
28     StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
29     *bitmap_word &= ~bit_mask;
30 }
31
32 STATIC_INLINE StgWord
33 is_marked(StgPtr p, bdescr *bd)
34 {
35     nat offset_within_block = p - bd->start; // in words
36     StgPtr bitmap_word = (StgPtr)bd->u.bitmap + 
37         (offset_within_block / (sizeof(W_)*BITS_PER_BYTE));
38     StgWord bit_mask = (StgWord)1 << (offset_within_block & (sizeof(W_)*BITS_PER_BYTE - 1));
39     return (*bitmap_word & bit_mask);
40 }
41
42 void compact( void (*get_roots)(evac_fn) );
43
44 #endif /* GCCOMPACT_H */