Ignore:
Timestamp:
Jan 14, 2012, 3:04:14 PM (7 years ago)
Author:
cameron
Message:

Partial refactoring to encapsulate 32 vs 64 bit scan

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/builtins.hpp

    r1847 r1848  
    8383#endif
    8484
     85#if 0
     86        /* Partially refactored to encapsulate 32/64 bit scan distinctions.*/
     87#include <stdint.h>
     88#if defined (_MSC_VER)
     89        #include <intrin.h>
     90
     91        #ifdef (_WIN64)
     92        typedef uint64_t scanword_t;
     93        #define ScanForwardIntrinsic _BitScanForward64
     94        #define ScanReverseIntrinsic _BitScanReverse64
     95        #else
     96        typedef uint32_t scanword_t;
     97        #define ScanForwardIntrinsic _BitScanForward
     98        #define ScanReverseIntrinsic _BitScanReverse
     99        #endif
     100
     101        #pragma intrinsic(ScanForwardIntrinsic)
     102        #pragma intrinsic(ScanReverseIntrinsic)
     103        IDISA_ALWAYS_INLINE uint32_t scan_forward_zeroes(scanword_t x) { // Precondition: x > 0
     104                unsigned long zeroes;
     105                ScanForwardIntrinsic(&zeroes, x);
     106                return (uint32_t) zeroes;
     107        }
     108
     109        IDISA_ALWAYS_INLINE uint32_t scan_backward_zeroes(scanword_t x) { // Precondition: x > 0
     110                unsigned long zeroes;
     111                ScanReverseIntrinsic(&zeroes, x);
     112                return (uint32_t) zeroes;
     113        }
     114
     115#elif defined (__GNUC__)
     116
     117        #if UINTPTR_MAX == 0xffffffffffffffff  /* 64-bit architecture */
     118        typedef uint64_t scanword_t;
     119        #define ScanForwardIntrinsic __builtin_ctzll
     120        #define ScanReverseIntrinsic __builtin_clzll
     121
     122        #else
     123        typedef uint32_t scanword_t;
     124        #define ScanForwardIntrinsic __builtin_ctzl
     125        #define ScanReverseIntrinsic __builtin_clzl
     126        #endif
     127
     128
     129        IDISA_ALWAYS_INLINE uint32_t scan_forward_zeroes(scanword_t x) { // Precondition: x > 0
     130                return (uint32_t) ScanForwardIntrinsic((scanword_t) x);
     131        }
     132
     133        IDISA_ALWAYS_INLINE uint32_t scan_backward_zeroes(scanword_t x) { // Precondition: x > 0
     134                return (uint32_t) ScanBackwardIntrinsic((scanword_t) x);
     135        }
     136
     137#else
     138  #warning "Neither _MSC_VER nor __GNUC__ defined: scan_forward/backward_zeroes not implemented."
     139#endif
     140
     141#endif
     142
    85143#endif /* BUILTINS_HPP */
Note: See TracChangeset for help on using the changeset viewer.