1 /* basicdefs.h: header with core definitions that are globally usable 2 3 Copyright 2001, 2002, 2003, 2004, 2005 Paul Zimmermann and Alexander Kruppa. 4 5 This program is free software; you can redistribute it and/or modify it 6 under the terms of the GNU General Public License as published by the 7 Free Software Foundation; either version 2 of the License, or (at your 8 option) any later version. 9 10 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 more details. 14 15 You should have received a copy of the GNU General Public License along 16 with this program; see the file COPYING. If not, write to the Free 17 Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 18 02111-1307, USA. 19 */ 20 21 #ifndef _BASICDEFS_H 22 #define _BASICDEFS_H 1 23 24 #include "config.h" 25 26 #ifdef HAVE_SYS_TYPES_H 27 #include <sys/types.h> /* needed for size_t */ 28 #endif 29 30 /* name some types whose bit widths are unambiguous */ 31 32 #if defined(HAVE_INTTYPES_H) 33 #include <inttypes.h> 34 #elif defined(_MSC_VER) 35 typedef signed __int32 int32_t; 36 typedef unsigned __int32 uint32_t; 37 typedef signed __int64 int64_t; 38 typedef unsigned __int64 uint64_t; 39 40 /* portable formatting of wide types */ 41 #define PRId64 "I64d" 42 #define PRIu64 "I64u" 43 #define PRIx64 "I64x" 44 45 #endif 46 47 #include <stdio.h> /* needed for "FILE *" */ 48 #include <limits.h> 49 50 /* Warnings about unused parameters by gcc can be suppressed by prefixing 51 parameter with ATTRIBUTE_UNUSED when parameter can't be removed, i.e. 52 for interface consistency reasons */ 53 #ifdef __GNUC__ 54 #if __GNUC__ >= 3 55 #define ATTRIBUTE_UNUSED __attribute__ ((unused)) 56 #else 57 #define ATTRIBUTE_UNUSED 58 #endif 59 #define ATTRIBUTE_CONST __attribute__ ((const)) 60 #else 61 #define ATTRIBUTE_UNUSED 62 #define ATTRIBUTE_CONST 63 #endif 64 65 #ifndef LIKELY 66 #if defined(__GNUC__) 67 #define LIKELY(x) __builtin_expect ((x) != 0, 1) 68 #else 69 #define LIKELY(x) x 70 #endif 71 #endif 72 73 #ifndef UNLIKELY 74 #if defined(__GNUC__) 75 #define UNLIKELY(x) __builtin_expect ((x) != 0, 0) 76 #else 77 #define UNLIKELY(x) x 78 #endif 79 #endif 80 81 #include <assert.h> 82 #define ASSERT_ALWAYS(expr) assert (expr) 83 #ifdef WANT_ASSERT 84 #define ASSERT(expr) assert (expr) 85 #else 86 #define ASSERT(expr) do {} while (0) 87 #endif 88 89 #define MAX(x,y) (((x)<(y))?(y):(x)) 90 #define MIN(x,y) (((x)<(y))?(x):(y)) 91 92 /* expanding macros and then turning them 93 into strings requires two levels of macro-izing */ 94 95 #define _(x) #x 96 #define STRING(x) _(x) 97 98 /* include (hopefully standard) SSE2 interface, along 99 with mnemonics for the small part of the ISA that 100 we need */ 101 102 #ifdef HAVE_SSE2 103 #include <emmintrin.h> 104 105 #define pload(addr) _mm_load_si128((__m128i const *)(addr)) 106 #define ploadu(addr) _mm_loadu_si128((__m128i const *)(addr)) 107 #define pload_lo32(addr) (__m128i)_mm_load_ss((float *)(addr)) 108 #define pload_lo64(addr) (__m128i)_mm_load_sd((double const *)(addr)) 109 #define pload_hi64(x, addr) (__m128i)_mm_loadh_pd((__m128d)x, (double const *)(addr)) 110 #define pstore(x, addr) _mm_store_si128((__m128i *)(addr), x) 111 #define pstoreu(x, addr) _mm_storeu_si128((__m128i *)(addr), x) 112 #define pstore_lo32(x, addr) _mm_store_ss((float *)(addr), (__m128)x) 113 #define pstore_lo64(x, addr) _mm_store_sd((double *)(addr), (__m128d)x) 114 #define pstore_hi64(x, addr) _mm_storeh_pd((double *)(addr), (__m128d)x) 115 #define pand _mm_and_si128 116 #define pxor _mm_xor_si128 117 #define psetzero() _mm_setzero_si128() 118 #define paddd _mm_add_epi32 119 #define paddq _mm_add_epi64 120 #define psubd _mm_sub_epi32 121 #define psubq _mm_sub_epi64 122 #define pmuludq _mm_mul_epu32 123 #define pslld _mm_slli_epi32 124 #define psllq _mm_slli_epi64 125 #define psrld _mm_srli_epi32 126 #define psrlq _mm_srli_epi64 127 #define pshufd _mm_shuffle_epi32 128 #define pcmpgtd _mm_cmpgt_epi32 129 #define punpcklo32 _mm_unpacklo_epi32 130 #define punpcklo64 _mm_unpacklo_epi64 131 #define pcvt_i32 _mm_cvtsi32_si128 132 133 #if defined(_WIN64) || defined(__x86_64__) 134 #define pcvt_i64 _mm_cvtsi64_si128 135 #define pstore_i64(out, in) out = _mm_cvtsi128_si64(in) 136 #else 137 #define pcvt_i64(x) _mm_loadl_epi64((__m128i const *)&(x)) 138 #define pstore_i64(out, in) _mm_storel_epi64((__m128i *)&(out), in) 139 #endif 140 141 #endif 142 143 #ifndef alloca 144 #ifdef __GNUC__ 145 # define alloca __builtin_alloca 146 #elif defined (__DECC) 147 # define alloca(x) __ALLOCA(x) 148 #elif defined (_MSC_VER) 149 # include <malloc.h> 150 # define alloca _alloca 151 #elif defined(HAVE_ALLOCA_H) || defined (sun) 152 # include <alloca.h> 153 #elif defined (_AIX) || defined (_IBMR2) 154 #pragma alloca 155 #else 156 char *alloca (); 157 #endif 158 #endif 159 160 161 #endif /* _BASICDEFS_H */ 162