1 // Replacement for malloc.h which factors out platform differences.
5 #if defined(VGO_darwin)
6 # include <malloc/malloc.h>
7 #elif defined(VGO_freebsd)
9 # include <malloc_np.h>
16 // Allocates a 16-aligned block. Asserts if the allocation fails.
17 __attribute__((unused
))
18 static void* memalign16(size_t szB
)
21 #if defined(VGO_darwin) || defined(VGO_freebsd)
22 // Darwin lacks memalign, but its malloc is always 16-aligned anyway.
23 posix_memalign((void **)&x
, 16, szB
);
25 x
= memalign(16, szB
);
28 assert(0 == ((16-1) & (unsigned long)x
));
32 // Allocates a 32-aligned block. Asserts if the allocation fails.
33 __attribute__((unused
))
34 static void* memalign32(size_t szB
)
37 #if defined(VGO_darwin) || defined(VGO_freebsd)
38 // Darwin lacks memalign
39 posix_memalign((void **)&x
, 32, szB
);
41 x
= memalign(32, szB
);
44 assert(0 == ((32-1) & (unsigned long)x
));
48 // Allocates a 64-aligned block. Asserts if the allocation fails.
49 __attribute__((unused
))
50 static void* memalign64(size_t szB
)
53 #if defined(VGO_darwin) || defined(VGO_freebsd)
54 // Darwin lacks memalign
55 posix_memalign((void **)&x
, 64, szB
);
57 x
= memalign(64, szB
);
60 assert(0 == ((64-1) & (unsigned long)x
));