dlvhex  2.5.0
vs10/bm/bmdef.h
Go to the documentation of this file.
00001 // Copyright(c) 2002-2009 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)
00002 //
00003 // BM library internal header
00004 //
00005 // Set all required preprocessor defines
00006 
00007 
00008 
00009 // macro to define/undefine unaligned memory access (x86, PowerPC)
00010 //
00011 #if defined(__i386) || defined(__x86_64) || defined(__ppc__) || \
00012     defined(__ppc64__) || defined(_M_IX86) || defined(_M_AMD64) || \
00013     defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || \
00014     (defined(_M_MPPC) && !defined(BM_FORBID_UNALIGNED_ACCESS))
00015 #define BM_UNALIGNED_ACCESS_OK 1
00016 #endif
00017 
00018 #if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64) || \
00019     defined(__i386) || defined(__x86_64) || defined(_M_AMD64) || \
00020     defined(BMSSE2OPT) || defined(BMSSE42OPT)
00021 #define BM_x86
00022 #endif
00023 
00024 
00025 // Enable MSVC 8.0 (2005) specific optimization options
00026 //
00027 #if(_MSC_VER >= 1400)
00028 
00029 #  define BM_HASFORCEINLINE
00030 #  ifndef BMRESTRICT
00031 #    define BMRESTRICT __restrict
00032 #  endif
00033 #endif 
00034 
00035 #ifdef __GNUG__
00036 
00037 #  ifndef BMRESTRICT
00038 #    define BMRESTRICT __restrict__
00039 #  endif
00040 
00041 #  ifdef __OPTIMIZE__
00042 #    define BM_NOASSERT
00043 #  endif
00044 #endif
00045 
00046 #ifndef BM_ASSERT
00047 
00048 # ifndef BM_NOASSERT
00049 #  include <cassert>
00050 #  define BM_ASSERT assert
00051 # else
00052 #  ifndef BM_ASSERT
00053 #    define BM_ASSERT(x)
00054 #  endif
00055 # endif
00056 
00057 #endif
00058 
00059 
00060 #define FULL_BLOCK_ADDR bm::all_set<true>::_block._p
00061 #define IS_VALID_ADDR(addr) (addr && (addr != FULL_BLOCK_ADDR))
00062 #define IS_FULL_BLOCK(addr) (addr == FULL_BLOCK_ADDR)
00063 #define IS_EMPTY_BLOCK(addr) (addr == 0)
00064 
00065 // Macro definitions to manipulate bits in pointers
00066 // This trick is based on the fact that pointers allocated by malloc are
00067 // aligned and bit 0 is never set. It means we are safe to use it.
00068 // BM library keeps GAP flag in pointer.
00069 
00070 
00071 
00072 # if ULONG_MAX != 0xffffffff || defined(_WIN64)  // 64-bit
00073 
00074 #  define BMPTR_SETBIT0(ptr)   ( ((bm::id64_t)ptr) | 1 )
00075 #  define BMPTR_CLEARBIT0(ptr) ( ((bm::id64_t)ptr) & ~(bm::id64_t)1 )
00076 #  define BMPTR_TESTBIT0(ptr)  ( ((bm::id64_t)ptr) & 1 )
00077 
00078 # else // 32-bit
00079 
00080 #  define BMPTR_SETBIT0(ptr)   ( ((bm::id_t)ptr) | 1 )
00081 #  define BMPTR_CLEARBIT0(ptr) ( ((bm::id_t)ptr) & ~(bm::id_t)1 )
00082 #  define BMPTR_TESTBIT0(ptr)  ( ((bm::id_t)ptr) & 1 )
00083 
00084 # endif
00085 
00086 # define BMGAP_PTR(ptr) ((bm::gap_word_t*)BMPTR_CLEARBIT0(ptr))
00087 # define BMSET_PTRGAP(ptr) ptr = (bm::word_t*)BMPTR_SETBIT0(ptr)
00088 # define BM_IS_GAP(ptr) ( BMPTR_TESTBIT0(ptr)!=0 )
00089 
00090 
00091 
00092 
00093 
00094 #ifdef BM_HASRESTRICT
00095 # ifndef BMRESTRICT
00096 #  define BMRESTRICT restrict
00097 # endif
00098 #else
00099 # ifndef BMRESTRICT
00100 #   define BMRESTRICT
00101 # endif
00102 #endif
00103 
00104 
00105 #ifdef BM_HASFORCEINLINE
00106 # ifndef BMFORCEINLINE
00107 #  define BMFORCEINLINE __forceinline
00108 # endif
00109 #else
00110 # define BMFORCEINLINE inline
00111 #endif
00112 
00113 
00114 // --------------------------------
00115 // SSE optmization
00116 //
00117 
00118 #if !(defined(BMSSE2OPT) || defined(BMSSE42OPT)) 
00119 
00120 # ifndef BM_SET_MMX_GUARD
00121 #  define BM_SET_MMX_GUARD
00122 # endif
00123 
00124 #define BM_ALIGN16 
00125 #define BM_ALIGN16ATTR
00126 
00127 #else  
00128 
00129 # ifndef BM_SET_MMX_GUARD
00130 #  define BM_SET_MMX_GUARD  sse_empty_guard  bm_mmx_guard_;
00131 # endif
00132 
00133 #ifdef _MSC_VER
00134 
00135 #ifndef BM_ALIGN16
00136 #  define BM_ALIGN16 __declspec(align(16))
00137 #  define BM_ALIGN16ATTR
00138 #endif
00139 
00140 # else // GCC
00141 
00142 #ifndef BM_ALIGN16
00143 #  define BM_ALIGN16
00144 #  define BM_ALIGN16ATTR __attribute__((aligned(16)))
00145 #endif
00146 
00147 #endif
00148 
00149 #endif
00150 
00155 #ifndef BM_INCWORD_BITCOUNT
00156 
00157 #ifdef BMSSE42OPT
00158 
00159 # define BM_INCWORD_BITCOUNT(cnt, w) cnt += _mm_popcnt_u32(w);
00160 
00161 #else
00162 
00163 # define BM_INCWORD_BITCOUNT(cnt, w) cnt += \
00164      bm::bit_count_table<true>::_count[(unsigned char)(w)] + \
00165      bm::bit_count_table<true>::_count[(unsigned char)((w) >> 8)] + \
00166      bm::bit_count_table<true>::_count[(unsigned char)((w) >> 16)] + \
00167      bm::bit_count_table<true>::_count[(unsigned char)((w) >> 24)];
00168 
00169 #endif
00170 
00171 #endif
00172 
00173