source: trunk/lib/builtin.hpp @ 1527

Last change on this file since 1527 was 1514, checked in by ksherdy, 8 years ago

ICC defaults to GCC.

File size: 1.9 KB
Line 
1/*
2    builtin - Compiler dependent builtins.
3
4    Idealized SIMD Operations with SSE versions
5    Copyright (C) 2011, Robert D. Cameron, Kenneth S. Herdy, Hua Huang and Nigel Medforth.
6    Licensed to the public under the Open Software License 3.0.
7    Licensed to International Characters Inc.
8       under the Academic Free License version 3.0.
9 */
10
11#ifndef BUILTIN_HPP_
12#define BUILTIN_HPP_
13
14#include "config.hpp"
15
16static IDISA_INLINE unsigned long cfzl(unsigned long x);
17static IDISA_INLINE unsigned long cbzl(unsigned long x);
18static IDISA_INLINE long likely(long x);
19static IDISA_INLINE long unlikely(long x);
20
21#if defined _MSC_VER
22        static IDISA_INLINE long likely(long x) {
23                return x;
24        }
25        static IDISA_INLINE long unlikely(long x) {
26                return x;
27        }
28        #include <intrin.h>
29        #pragma intrinsic(_BitScanForward)
30        static IDISA_INLINE unsigned long cfzl(unsigned long x) { // Precondition: x > 0
31                unsigned long zeroes;
32                _BitScanForward(&zeroes, x);
33                return zeroes;
34        }
35        static IDISA_INLINE unsigned long cbzl(unsigned long x) {
36                unsigned long zeroes;
37                _BitScanReverse(&zeroes, x);
38                return zeroes;
39        }
40
41/* ICC defaults to GCC */
42/*
43#elif defined __INTEL_COMPILER
44        static IDISA_INLINE long likely(long x) {
45                return __builtin_expect(x, 1);
46        }
47        static IDISA_INLINE long unlikely(long x) {
48                return __builtin_expect(x, 0);
49        }
50        static IDISA_INLINE unsigned long cfzl(unsigned long x) {
51                return _bit_scan_forward(x);
52        }
53        static IDISA_INLINE unsigned long cbzl(unsigned long x) {
54                return _bit_scan_reverse(int x)
55        }
56*/
57
58#elif defined __GNUC__
59        static IDISA_INLINE long likely(long x) {
60                return __builtin_expect(x, 1);
61        }
62        static IDISA_INLINE long unlikely(long x) {
63                return __builtin_expect(x, 0);
64        }
65        static IDISA_INLINE unsigned long cfzl(unsigned long x) {
66                return __builtin_ctzl(x);
67        }
68        static IDISA_INLINE unsigned long cbzl(unsigned long x) {
69                return __builtin_clzl(x);
70        }
71
72#else
73        #error "Compiler not supported. Aborting compilation."
74#endif
75
76#endif /* BUILTIN */
Note: See TracBrowser for help on using the repository browser.