Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Bdescr
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Condoluci committed Mar 4, 2020
1 parent e2571ed commit 5539e8c
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions ghc-toolkit/ghc-libdir/include/rts/storage/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@
#define BLOCK_SIZE_W (BLOCK_SIZE/sizeof(W_))
#define BLOCK_MASK (BLOCK_SIZE-1)

#if defined(CMINUSMINUS)
#define BLOCK_ROUND_UP(p) ((p + BLOCK_SIZE - 1) & ~BLOCK_MASK)
#define BLOCK_ROUND_DOWN(p) ((p & ~BLOCK_MASK))
#else
#define BLOCK_ROUND_UP(p) (((W_)(p)+BLOCK_SIZE-1) & ~BLOCK_MASK)
#define BLOCK_ROUND_DOWN(p) ((void *) ((W_)(p) & ~BLOCK_MASK))
#endif

/* Megablock related constants (MBLOCK_SHIFT is defined in Constants.h) */

Expand Down Expand Up @@ -156,33 +161,17 @@ typedef struct bdescr_ {
/* Maximum flag value (do not define anything higher than this!) */
#define BF_FLAG_MAX (1 << 15)

/* Finding the block descriptor for a given block -------------------------- */

#if defined(CMINUSMINUS)

#define Bdescr(p) \
((((p) & MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT)) \
| ((p) & ~MBLOCK_MASK))

#else

EXTERN_INLINE bdescr *Bdescr(StgPtr p);
EXTERN_INLINE bdescr *Bdescr(StgPtr p)
{
return (bdescr *)
((((W_)p & MBLOCK_MASK & ~BLOCK_MASK) >> (BLOCK_SHIFT-BDESCR_SHIFT))
| ((W_)p & ~MBLOCK_MASK)
);
}

#endif

/* Useful Macros ------------------------------------------------------------ */

/* Offset of first real data block in a megablock */

#if defined(CMINUSMINUS)
#define FIRST_BLOCK_OFF \
(BLOCK_ROUND_UP(BDESCR_SIZE * (MBLOCK_SIZE / BLOCK_SIZE)))
#else
#define FIRST_BLOCK_OFF \
((W_)BLOCK_ROUND_UP(BDESCR_SIZE * (MBLOCK_SIZE / BLOCK_SIZE)))
#endif

/* First data block in a given megablock */

Expand All @@ -194,8 +183,13 @@ EXTERN_INLINE bdescr *Bdescr(StgPtr p)

/* First real block descriptor in a megablock */

#if defined(CMINUSMINUS)
#define FIRST_BDESCR(m) \
((FIRST_BLOCK_OFF>>(BLOCK_SHIFT-BDESCR_SHIFT)) + m)
#else
#define FIRST_BDESCR(m) \
((bdescr *)((FIRST_BLOCK_OFF>>(BLOCK_SHIFT-BDESCR_SHIFT)) + (W_)(m)))
#endif

/* Last real block descriptor in a megablock */

Expand All @@ -218,6 +212,19 @@ EXTERN_INLINE bdescr *Bdescr(StgPtr p)
#define BLOCKS_TO_MBLOCKS(n) \
(1 + (W_)MBLOCK_ROUND_UP((n-BLOCKS_PER_MBLOCK) * BLOCK_SIZE) / MBLOCK_SIZE)

/* Finding the block descriptor for a given block -------------------------- */

#if defined(CMINUSMINUS)

// Redefined
#define Bdescr(p) \
((p & ~MBLOCK_MASK) + FIRST_BDESCR(0))

#else

EXTERN_INLINE bdescr *Bdescr(StgPtr p);

#endif

#if !defined(CMINUSMINUS)
/* to the end... */
Expand Down

0 comments on commit 5539e8c

Please sign in to comment.