]> git.uio.no Git - u/mrichter/AliRoot.git/blob - Vc/include/Vc/common/bitscanintrinsics.h
Vc package added (version 0.6.79-dev)
[u/mrichter/AliRoot.git] / Vc / include / Vc / common / bitscanintrinsics.h
1 /*  This file is part of the Vc library.
2
3     Copyright (C) 2011-2012 Matthias Kretz <kretz@kde.org>
4
5     Vc is free software: you can redistribute it and/or modify
6     it under the terms of the GNU Lesser General Public License as
7     published by the Free Software Foundation, either version 3 of
8     the License, or (at your option) any later version.
9
10     Vc is distributed in the hope that it will be useful, but
11     WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with Vc.  If not, see <http://www.gnu.org/licenses/>.
17
18 */
19
20 #ifndef VC_COMMON_BITSCANINTRINSICS_H
21 #define VC_COMMON_BITSCANINTRINSICS_H
22
23 #if defined(VC_GCC) || defined(VC_CLANG)
24 #  if VC_GCC >= 0x40500
25      // GCC 4.5.0 introduced _bit_scan_forward / _bit_scan_reverse
26 #    include <x86intrin.h>
27 #  else
28      // GCC <= 4.4 and clang have x86intrin.h, but not the required functions
29 #    define _bit_scan_forward(x) __builtin_ctz(x)
30 static inline int _Vc_bit_scan_reverse_asm(unsigned int x) {
31     int r;
32     __asm__("bsr %1,%0" : "=r"(r) : "X"(x));
33     return r;
34 }
35 #    define _bit_scan_reverse(x) _Vc_bit_scan_reverse_asm(x)
36 #  endif
37 #elif defined(VC_ICC)
38 // for all I know ICC supports the _bit_scan_* intrinsics
39 #elif defined(VC_OPEN64)
40 // TODO
41 #elif defined(VC_MSVC)
42 #include "windows_fix_intrin.h"
43 #pragma intrinsic(_BitScanForward)
44 #pragma intrinsic(_BitScanReverse)
45 static inline __forceinline unsigned long _bit_scan_forward(unsigned long x) {
46     unsigned long index;
47     _BitScanForward(&index, x);
48     return index;
49 }
50 static inline __forceinline unsigned long _bit_scan_reverse(unsigned long x) {
51     unsigned long index;
52     _BitScanReverse(&index, x);
53     return index;
54 }
55 #else
56 // just assume the compiler can do it
57 #endif
58
59
60 #endif // VC_COMMON_BITSCANINTRINSICS_H