~ubuntu-branches/ubuntu/raring/vc/raring-proposed

« back to all changes in this revision

Viewing changes to common/bitscanintrinsics.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-03-08 12:50:59 UTC
  • Revision ID: package-import@ubuntu.com-20130308125059-2vpu3hm02kgrqv96
Tags: upstream-0.7.0
ImportĀ upstreamĀ versionĀ 0.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "macros.h"
 
31
static Vc_ALWAYS_INLINE Vc_CONST int _Vc_bit_scan_reverse_asm(unsigned int x) {
 
32
    int r;
 
33
    __asm__("bsr %1,%0" : "=r"(r) : "X"(x));
 
34
    return r;
 
35
}
 
36
#include "undomacros.h"
 
37
#    define _bit_scan_reverse(x) _Vc_bit_scan_reverse_asm(x)
 
38
#  endif
 
39
#elif defined(VC_ICC)
 
40
// for all I know ICC supports the _bit_scan_* intrinsics
 
41
#elif defined(VC_OPEN64)
 
42
// TODO
 
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) {
 
48
    unsigned long index;
 
49
    _BitScanForward(&index, x);
 
50
    return index;
 
51
}
 
52
static inline __forceinline unsigned long _bit_scan_reverse(unsigned long x) {
 
53
    unsigned long index;
 
54
    _BitScanReverse(&index, x);
 
55
    return index;
 
56
}
 
57
#else
 
58
// just assume the compiler can do it
 
59
#endif
 
60
 
 
61
 
 
62
#endif // VC_COMMON_BITSCANINTRINSICS_H