Changeset 1528 for trunk/lib


Ignore:
Timestamp:
Oct 12, 2011, 8:54:19 PM (8 years ago)
Author:
ksherdy
Message:

Added builtins.hpp.

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/lib/builtins.hpp

    r1514 r1528  
    11/*
    2     builtin - Compiler dependent builtins.
     2    builtin - Compiler dependent builtin function wrappers.
    33
    44    Idealized SIMD Operations with SSE versions
    5     Copyright (C) 2011, Robert D. Cameron, Kenneth S. Herdy, Hua Huang and Nigel Medforth.
     5    Copyright (C) 2011, Robert D. Cameron, Kenneth S. Herdy.
    66    Licensed to the public under the Open Software License 3.0.
    77    Licensed to International Characters Inc.
     
    99 */
    1010
    11 #ifndef BUILTIN_HPP_
    12 #define BUILTIN_HPP_
     11#ifndef BUILTINS_HPP_
     12#define BUILTINS_HPP_
    1313
    1414#include "config.hpp"
    1515
    16 static IDISA_INLINE unsigned long cfzl(unsigned long x);
    17 static IDISA_INLINE unsigned long cbzl(unsigned long x);
    1816static IDISA_INLINE long likely(long x);
    1917static IDISA_INLINE long unlikely(long x);
     18static IDISA_INLINE unsigned long cfzl(unsigned long x) IDISA_ALWAYS_INLINE;
     19static IDISA_INLINE unsigned long cbzl(unsigned long x) IDISA_ALWAYS_INLINE;
     20static IDISA_INLINE unsigned long cfzll(unsigned long x) IDISA_ALWAYS_INLINE;
     21static IDISA_INLINE unsigned long cbzll(unsigned long x) IDISA_ALWAYS_INLINE;
    2022
    21 #if defined _MSC_VER
     23#if defined (_MSC_VER)
    2224        static IDISA_INLINE long likely(long x) {
    2325                return x;
     
    2628                return x;
    2729        }
     30
    2831        #include <intrin.h>
    2932        #pragma intrinsic(_BitScanForward)
     
    3336                return zeroes;
    3437        }
     38
    3539        static IDISA_INLINE unsigned long cbzl(unsigned long x) {
    3640                unsigned long zeroes;
     
    3943        }
    4044
    41 /* ICC defaults to GCC */
    42 /*
    43 #elif defined __INTEL_COMPILER
     45        static IDISA_INLINE unsigned long cfzll(unsigned long long x) { // TODO - test
     46                unsigned __int64 zeroes;
     47                _BitScanForward(&zeroes, x);
     48                return zeroes;
     49        }
     50
     51        static IDISA_INLINE unsigned long cbzll(unsigned long long x) { // TODO - test
     52                unsigned __int64 zeroes;
     53                _BitScanReverse(&zeroes, x);
     54                return zeroes;
     55        }
     56
     57#elif defined (__GNUC__)
    4458        static IDISA_INLINE long likely(long x) {
    4559                return __builtin_expect(x, 1);
    4660        }
     61
    4762        static IDISA_INLINE long unlikely(long x) {
    4863                return __builtin_expect(x, 0);
    4964        }
    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 */
    5765
    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         }
    6566        static IDISA_INLINE unsigned long cfzl(unsigned long x) {
    6667                return __builtin_ctzl(x);
    6768        }
     69
    6870        static IDISA_INLINE unsigned long cbzl(unsigned long x) {
    6971                return __builtin_clzl(x);
    7072        }
    7173
    72 #else
    73         #error "Compiler not supported. Aborting compilation."
     74        static IDISA_INLINE unsigned long cfzll(unsigned long long x) {
     75                return __builtin_ctzll(x);
     76        }
     77
     78        static IDISA_INLINE unsigned long cbzll(unsigned long long x) {
     79                return __builtin_clzll(x);
     80        }
     81
    7482#endif
    7583
    76 #endif /* BUILTIN */
     84#endif /* BUILTINS_HPP */
Note: See TracChangeset for help on using the changeset viewer.