Ignore:
Timestamp:
Oct 22, 2011, 2:14:12 PM (8 years ago)
Author:
ksherdy
Message:

Add count_forward_zeroes, count_backward_zeroes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/builtins.hpp

    r1528 r1550  
    1414#include "config.hpp"
    1515
    16 static IDISA_INLINE long likely(long x);
    17 static IDISA_INLINE long unlikely(long x);
    18 static IDISA_INLINE unsigned long cfzl(unsigned long x) IDISA_ALWAYS_INLINE;
    19 static IDISA_INLINE unsigned long cbzl(unsigned long x) IDISA_ALWAYS_INLINE;
    20 static IDISA_INLINE unsigned long cfzll(unsigned long x) IDISA_ALWAYS_INLINE;
    21 static IDISA_INLINE unsigned long cbzll(unsigned long x) IDISA_ALWAYS_INLINE;
     16static IDISA_ALWAYS_INLINE long likely(long x);
     17static IDISA_ALWAYS_INLINE long unlikely(long x);
     18static IDISA_ALWAYS_INLINE unsigned long cfzl(unsigned long x);
     19static IDISA_ALWAYS_INLINE unsigned long cbzl(unsigned long x);
     20static IDISA_ALWAYS_INLINE unsigned long cfzll(unsigned long long x);
     21static IDISA_ALWAYS_INLINE unsigned long cbzll(unsigned long long x);
    2222
    2323#if defined (_MSC_VER)
    24         static IDISA_INLINE long likely(long x) {
     24        IDISA_ALWAYS_INLINE long likely(long x) {
    2525                return x;
    2626        }
    27         static IDISA_INLINE long unlikely(long x) {
     27        IDISA_ALWAYS_INLINE long unlikely(long x) {
    2828                return x;
    2929        }
     
    3131        #include <intrin.h>
    3232        #pragma intrinsic(_BitScanForward)
    33         static IDISA_INLINE unsigned long cfzl(unsigned long x) { // Precondition: x > 0
     33        IDISA_ALWAYS_INLINE unsigned long cfzl(unsigned long x) { // Precondition: x > 0
    3434                unsigned long zeroes;
    3535                _BitScanForward(&zeroes, x);
     
    3737        }
    3838
    39         static IDISA_INLINE unsigned long cbzl(unsigned long x) {
     39        IDISA_ALWAYS_INLINE unsigned long cbzl(unsigned long x) {
    4040                unsigned long zeroes;
    4141                _BitScanReverse(&zeroes, x);
     
    4343        }
    4444
    45         static IDISA_INLINE unsigned long cfzll(unsigned long long x) { // TODO - test
     45        IDISA_ALWAYS_INLINE unsigned long cfzll(unsigned long long x) { // TODO - test
    4646                unsigned __int64 zeroes;
    4747                _BitScanForward(&zeroes, x);
     
    4949        }
    5050
    51         static IDISA_INLINE unsigned long cbzll(unsigned long long x) { // TODO - test
     51        IDISA_ALWAYS_INLINE unsigned long cbzll(unsigned long long x) { // TODO - test
    5252                unsigned __int64 zeroes;
    5353                _BitScanReverse(&zeroes, x);
     
    5656
    5757#elif defined (__GNUC__)
    58         static IDISA_INLINE long likely(long x) {
     58
     59        IDISA_ALWAYS_INLINE long likely(long x) {
    5960                return __builtin_expect(x, 1);
    6061        }
    6162
    62         static IDISA_INLINE long unlikely(long x) {
     63        IDISA_ALWAYS_INLINE long unlikely(long x) {
    6364                return __builtin_expect(x, 0);
    6465        }
    6566
    66         static IDISA_INLINE unsigned long cfzl(unsigned long x) {
     67        IDISA_ALWAYS_INLINE unsigned long cfzl(unsigned long x) {
    6768                return __builtin_ctzl(x);
    6869        }
    6970
    70         static IDISA_INLINE unsigned long cbzl(unsigned long x) {
     71        IDISA_ALWAYS_INLINE unsigned long cbzl(unsigned long x) {
    7172                return __builtin_clzl(x);
    7273        }
    7374
    74         static IDISA_INLINE unsigned long cfzll(unsigned long long x) {
     75        IDISA_ALWAYS_INLINE unsigned long cfzll(unsigned long long x) {
    7576                return __builtin_ctzll(x);
    7677        }
    7778
    78         static IDISA_INLINE unsigned long cbzll(unsigned long long x) {
     79        IDISA_ALWAYS_INLINE unsigned long cbzll(unsigned long long x) {
    7980                return __builtin_clzll(x);
    8081        }
Note: See TracChangeset for help on using the changeset viewer.