1
/* This file is part of the Vc library.
3
Copyright (C) 2011-2012 Matthias Kretz <kretz@kde.org>
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.
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.
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/>.
20
#ifndef VC_COMMON_BITSCANINTRINSICS_H
21
#define VC_COMMON_BITSCANINTRINSICS_H
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>
28
// GCC <= 4.4 and clang have x86intrin.h, but not the required functions
29
# define _bit_scan_forward(x) __builtin_ctz(x)
31
static Vc_ALWAYS_INLINE Vc_CONST int _Vc_bit_scan_reverse_asm(unsigned int x) {
33
__asm__("bsr %1,%0" : "=r"(r) : "X"(x));
36
#include "undomacros.h"
37
# define _bit_scan_reverse(x) _Vc_bit_scan_reverse_asm(x)
40
// for all I know ICC supports the _bit_scan_* intrinsics
41
#elif defined(VC_OPEN64)
43
#elif defined(VC_MSVC)
44
#include "windows_fix_intrin.h"
45
#pragma intrinsic(_BitScanForward)
46
#pragma intrinsic(_BitScanReverse)
47
static inline __forceinline unsigned long _bit_scan_forward(unsigned long x) {
49
_BitScanForward(&index, x);
52
static inline __forceinline unsigned long _bit_scan_reverse(unsigned long x) {
54
_BitScanReverse(&index, x);
58
// just assume the compiler can do it
62
#endif // VC_COMMON_BITSCANINTRINSICS_H