From 7acfca905d76140f4cc0b09c9a12de237de364cd Mon Sep 17 00:00:00 2001 From: Nick Barnes Date: Wed, 31 Oct 2001 14:40:56 +0000 Subject: Branch imports for masters. Copied from Perforce Change: 23678 ServerID: perforce.ravenbrook.com --- mps/code/ref.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 mps/code/ref.c (limited to 'mps/code/ref.c') diff --git a/mps/code/ref.c b/mps/code/ref.c new file mode 100644 index 00000000000..8614cd5b451 --- /dev/null +++ b/mps/code/ref.c @@ -0,0 +1,81 @@ +/* impl.c.ref: REFERENCES + * + * $HopeName: MMsrc!ref.c(trunk.12) $ + * Copyright (C) 1999 Harlequin Limited. All rights reserved. + * + * .purpose: Implement operations on Ref, RefSet, ZoneSet, and Rank. + * + * .design: See design.mps.ref and design.mps.refset. + */ + +#include "mpm.h" + +SRCID(ref, "$HopeName: MMsrc!ref.c(trunk.12) $"); + + +/* RankCheck -- check a rank value */ + +Bool RankCheck(Rank rank) +{ + CHECKL(rank < RankLIMIT); + UNUSED(rank); /* impl.c.mpm.check.unused */ + return TRUE; +} + + +/* RankSetCheck -- check a rank set */ + +Bool RankSetCheck(RankSet rankSet) +{ + CHECKL(rankSet < (1uL << RankLIMIT)); + UNUSED(rankSet); /* impl.c.mpm.check.unused */ + return TRUE; +} + + +/* ZoneSetOfRange -- calculate the zone set of a range of addresses */ + +RefSet ZoneSetOfRange(Arena arena, Addr base, Addr limit) +{ + Word zbase, zlimit; + + AVERT(Arena, arena); + AVER(limit > base); + + /* The base and limit zones of the range are calculated. The limit */ + /* zone is the zone after the last zone of the range, not the zone of */ + /* the limit address. */ + zbase = (Word)base >> arena->zoneShift; + zlimit = (((Word)limit-1) >> arena->zoneShift) + 1; + + + /* If the range is large enough to span all zones, its zone set is */ + /* universal. */ + if (zlimit - zbase >= MPS_WORD_WIDTH) + return ZoneSetUNIV; + + zbase &= MPS_WORD_WIDTH - 1; + zlimit &= MPS_WORD_WIDTH - 1; + + /* If the base zone is less than the limit zone, the zone set looks */ + /* like 000111100, otherwise it looks like 111000011. */ + if (zbase < zlimit) + return ((ZoneSet)1<