source: trunk/lib/builtin.hpp @ 1514

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

ICC defaults to GCC.

File size: 1.9 KB
RevLine 
[1509]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        }
[1514]40
41/* ICC defaults to GCC */
42/*
43#elif defined __INTEL_COMPILER
[1509]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) {
[1514]51                return _bit_scan_forward(x);
[1509]52        }
53        static IDISA_INLINE unsigned long cbzl(unsigned long x) {
[1514]54                return _bit_scan_reverse(int x)
[1509]55        }
[1514]56*/
57
58#elif defined __GNUC__
[1509]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) {
[1514]66                return __builtin_ctzl(x);
[1509]67        }
68        static IDISA_INLINE unsigned long cbzl(unsigned long x) {
[1514]69                return __builtin_clzl(x);
[1509]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.