diff --git a/mps/src/mpm.c b/mps/src/mpm.c index 0ca80e07c89..a8921302c8e 100644 --- a/mps/src/mpm.c +++ b/mps/src/mpm.c @@ -1,6 +1,6 @@ /* impl.c.mpm: GENERAL MPM SUPPORT * - * $HopeName: MMsrc!mpm.c(trunk.25) $ + * $HopeName: MMsrc!mpm.c(trunk.26) $ * Copyright (C) 1996. Harlequin Group plc. All rights reserved. * * .readership: MM developers. @@ -17,7 +17,7 @@ #include -SRCID(mpm, "$HopeName: MMsrc!mpm.c(trunk.25) $"); +SRCID(mpm, "$HopeName: MMsrc!mpm.c(trunk.26) $"); /* MPMCheck -- test MPM assumptions */ @@ -140,6 +140,25 @@ Word (WordAlignUp)(Word word, Align align) return WordAlignUp(word, align); } +/* WordRoundUp -- round word up to round. + * + * .wordroundup.arg.word: the quantity to be rounded. + * .wordroundup.arg.round: The modulus to round to. Not necessarily + * an alignment (ie not a power of two). + * + * .wordroundup.result: + * Let m be congruent to 0 mod r (m == 0(r)), + * and let m be the least m >= w. + * If w+r-1 (!) is representible in Word then result is m. + * Otherwise result is 0. Wittily. + * (NB result may be 0 even if m is representible) + */ +Word (WordRoundUp)(Word word, Size round) +{ + AVER(round > 0); + return WordRoundUp(word, round); +} + /* WordAlignUp -- round a word down to the nearest aligned value */ diff --git a/mps/src/mpm.h b/mps/src/mpm.h index 434c86521d2..122b52da946 100644 --- a/mps/src/mpm.h +++ b/mps/src/mpm.h @@ -1,6 +1,6 @@ /* impl.h.mpm: MEMORY POOL MANAGER DEFINITIONS * - * $HopeName: MMsrc!mpm.h(trunk.99) $ + * $HopeName: MMsrc!mpm.h(trunk.100) $ * Copyright (C) 1998. Harlequin Group plc. All rights reserved. */ @@ -50,6 +50,10 @@ extern Bool (WordIsAligned)(Word word, Align align); extern Word (WordAlignUp)(Word word, Align align); #define WordAlignUp(w, a) (((w) + (a) - 1) & ~((Word)(a) - 1)) +/* Rounds w up to a multiple of r, see impl.c.mpm for exact behaviour */ +extern Word (WordRoundUp)(Word word, Size round); +#define WordRoundUp(w, r) (((w)+(r)-1) - ((w)+(r)-1)%(r)) + extern Word (WordAlignDown)(Word word, Align align); #define WordAlignDown(w, a) ((w) & ~((Word)(a) - 1)) @@ -90,6 +94,10 @@ extern Addr (AddrAlignDown)(Addr addr, Align align); #define SizeAlignUp(s, a) ((Size)WordAlignUp(SizeWord(s), (a))) #define SizeAlignDown(s, a) ((Size)WordAlignDown(SizeWord(s), (a))) +/* r not required to be a power of 2 */ +#define SizeRoundUp(s, r) \ + ((Size)WordRoundUp(SizeWord(s), (Size)(r))) + extern Addr (AddrSet)(Addr target, Byte value, Size size); /* This is one of the places that implements Addr, so it's allowed to */ /* convert to void *, see design.mps.type.addr.ops.mem. */