Graphing tweaks.
[beedb.git] / include / bitop.h
blob085e348ccb1db186e34632fad826b1e3af76d29b
1 /*
2 Copyright 2008 Kristian Nielsen
4 This file is part of BeeDB.
6 Foobar is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
11 Foobar is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Foobar. If not, see <http://www.gnu.org/licenses/>.
20 /* ToDo: take this from autoconf instead. */
21 #if defined(__x86_64__)
22 #define SIZEOF_LONG 8
23 #define SIZEOF_LONG_LONG 8
24 #elif defined(__i386__)
25 #define SIZEOF_LONG 4
26 #define SIZEOF_LONG_LONG 8
27 #else
28 #error Unknown sizeof(long)
29 #endif
31 #ifdef __GNUC__
34 Count leading zero bits, compiler intrinsics to get access to CPU native
35 instructions, if available.
37 #if SIZEOF_LONG == 8
38 #define COUNT_LEADING_ZEROS_64(x) __builtin_clzl((x))
39 #elif SIZEOF_LONG_LONG == 8
40 #define COUNT_LEADING_ZEROS_64(x) __builtin_clzll((x))
41 #else
42 #error No 64-bit integer type available
43 #endif
45 #else
46 #error No COUNT_LEADING_ZEROS_64 defined for compiler
47 #endif
50 Non-temporal stores.
52 These write directly to memory bypassing cache.
55 #ifdef __GNUC__
56 #define STORE_NON_TEMPORAL_64(p, v) asm("movnti %1, %0" : "=m" (*(p)) : "r" (v))
57 // __builtin_ia32_movntq((long long unsigned int*)(p), (long long unsigned)(v))
58 #else
59 #define STORE_NON_TEMPORAL_64(p, v) (*(uint64_t *)(p) = (uint64_t)(v))
60 #endif