Commit 9c9ce2a6 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make the power-of-two rounding functions generally available and

use them for VSM allocation
parent b530ed43
......@@ -93,3 +93,11 @@ void vsm_iter_n(struct vsm_chunk **pp);
/* cache_lck.c */
struct lock { void *priv; }; // Opaque
/*---------------------------------------------------------------------
* Generic power-2 rounding macros
*/
#define PWR2(x) ((((x)-1)&(x))==0) /* Is a power of two */
#define RDN2(x, y) ((x)&(~((y)-1))) /* if y is powers of two */
#define RUP2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
......@@ -148,11 +148,6 @@ struct smp_sc {
/*--------------------------------------------------------------------*/
/* Generic power-2 rounding */
#define PWR2(x) ((((x)-1)&(x))==0) /* Is a power of two */
#define RDN2(x, y) ((x)&(~((y)-1))) /* if y is powers of two */
#define RUP2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
/* Pointer round up/down & assert */
#define PRNDN(sc, x) ((void*)RDN2((uintptr_t)(x), sc->align))
#define PRNUP(sc, x) ((void*)RUP2((uintptr_t)(x), sc->align))
......
......@@ -165,8 +165,7 @@ VSM_Alloc(unsigned size, const char *class, const char *type, const char *ident)
vsm_cleanup();
/* Round up to pointersize */
size += sizeof(void *) - 1;
size &= ~(sizeof(void *) - 1);
size = RUP2(size, sizeof(void*));
size += sizeof *sha; /* Make space for the header */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment