DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
include/util_pointer.h
00001 /* (C) 2014 Castus all rights reserved.
00002  * Written by Jonathan Campbell
00003  *
00004  * Intended language: C (also compatible with C++) */
00005 
00006 #ifndef __UTIL_POINTER_H
00007 #define __UTIL_POINTER_H
00008 
00009 #include <stdint.h>                     /* need standard C library integer types */
00010 #include <stddef.h>
00011 #include <alloca.h>
00012 
00013 #define min_uintptr_t                   ((uintptr_t)0)
00014 #define max_uintptr_t                   ( ~((uintptr_t)0) )
00015 
00016 #define min_size_t                      ((size_t)0)
00017 #define max_size_t                      ( ~((size_t)0) )
00018 
00019 #define ptr2int(x)                      ((uintptr_t)((void*)(x)))
00020 #define int2ptr(x)                      ((void*)(x))
00021 
00022 #define ptr_misaligned(x,a)             (ptr2int(x) & (((uintptr_t)(a)) - (uintptr_t)1))
00023 #define ptr_aligned(x,a)                (ptr_misaligned(x,a) == (uintptr_t)0)
00024 
00025 #define ptr_align_down(x,a)             (ptr2int(x) & (~(((uintptr_t)(a)) - (uintptr_t)1)))
00026 #define ptr_align_up(x,a)               ((ptr2int(x) + ((uintptr_t)(a) - (uintptr_t)1)) & (~(((uintptr_t)(a)) - (uintptr_t)1)))
00027 #define ptr_align_nearest(x,a)          ((ptr2int(x) + ((uintptr_t)(a) >> (uintptr_t)1)) & (~(((uintptr_t)(a)) - (uintptr_t)1)))
00028 #define ptr_align_next(x,a)             ((ptr2int(x) + (uintptr_t)(a)) & (~(((uintptr_t)(a)) - (uintptr_t)1)))
00029 
00030 #define alloca_aligned(s,a)             ( (void*)ptr_align_up((void*)alloca((size_t)(s) + (size_t)(a) - (size_t)1),a) )
00031 
00032 #define alignment_word                  (2)
00033 #define alignment_dword                 (4)
00034 #define alignment_qword                 (8)
00035 #define alignment_mmx                   (8)
00036 #define alignment_sse                   (16)
00037 #define alignment_avx                   (32)
00038 
00039 #endif /* __UTIL_POINTER_H */
00040