From 59d59bad72ade2c85c5d97941694f25a11a6a317 Mon Sep 17 00:00:00 2001 From: sezero Date: Wed, 8 Aug 2018 11:06:51 +0300 Subject: [PATCH] h5, minihwc.c: VC6 doesn't have _aligned_malloc(). locally implemented. --- glide3x/h5/minihwc/minihwc.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/glide3x/h5/minihwc/minihwc.c b/glide3x/h5/minihwc/minihwc.c index ef1edf1..8595bc4 100644 --- a/glide3x/h5/minihwc/minihwc.c +++ b/glide3x/h5/minihwc/minihwc.c @@ -865,13 +865,30 @@ typedef struct sli_aa_request { #define _aligned_free free /* don't like macros, because of side-effects */ #ifndef __WATCOMC__ -static __inline int min (int x, int y) -{ +static __inline int min(int x, int y) { return (x > y) ? y : x; } #endif #endif +#if defined(_MSC_VER) && (_MSC_VER < 1300) +/* code here only uses 8 byte alignment */ +#define _aligned_malloc(a,b) _aligned_malloc8(a) +#define _aligned_free _aligned_free8 +static void *_aligned_malloc8(size_t sz) { + const size_t align = 7; + void *got, **ret; + if (!(got = malloc(sizeof(void*) + align + sz))) return NULL; + ret = (void **) (((long)got + sizeof(void*) + align) & ~align); + ret[-1] = got; + return ret; +} +static void _aligned_free8(void *ptr) { + if (!ptr) return; + free (((void**)ptr) [-1]); +} +#endif + #ifdef __GNUC__ #define MMX_RESET() __asm __volatile ("emms")