19 #define LIKELY(x) __builtin_expect(!!(x), !0)
20 #define UNLIKELY(x) __builtin_expect(!!(x), 0)
22 #define LIKELY(x) (!!(x))
23 #define UNLIKELY(x) (!!(x))
27 void *al_malloc(size_t alignment
, size_t size
)
29 #if defined(HAVE_ALIGNED_ALLOC)
30 size
= (size
+(alignment
-1))&~(alignment
-1);
31 return aligned_alloc(alignment
, size
);
32 #elif defined(HAVE_POSIX_MEMALIGN)
34 if(posix_memalign(&ret
, alignment
, size
) == 0)
37 #elif defined(HAVE__ALIGNED_MALLOC)
38 return _aligned_malloc(size
, alignment
);
40 char *ret
= malloc(size
+alignment
);
44 while(((ptrdiff_t)ret
&(alignment
-1)) != 0)
51 void *al_calloc(size_t alignment
, size_t size
)
53 void *ret
= al_malloc(alignment
, size
);
54 if(ret
) memset(ret
, 0, size
);
58 void al_free(void *ptr
)
60 #if defined(HAVE_ALIGNED_ALLOC) || defined(HAVE_POSIX_MEMALIGN)
62 #elif defined(HAVE__ALIGNED_MALLOC)
70 } while(*finder
== 0x55);
76 size_t al_get_page_size(void)
78 static size_t psize
= 0;
82 #if defined(_SC_PAGESIZE)
83 if(!psize
) psize
= sysconf(_SC_PAGESIZE
);
84 #elif defined(_SC_PAGE_SIZE)
85 if(!psize
) psize
= sysconf(_SC_PAGE_SIZE
);
87 #endif /* HAVE_SYSCONF */
92 memset(&sysinfo
, 0, sizeof(sysinfo
));
94 GetSystemInfo(&sysinfo
);
95 psize
= sysinfo
.dwPageSize
;
98 if(!psize
) psize
= DEF_ALIGN
;
103 int al_is_sane_alignment_allocator(void)
105 #if defined(HAVE_ALIGNED_ALLOC) || defined(HAVE_POSIX_MEMALIGN) || defined(HAVE__ALIGNED_MALLOC)