Changeset 2428 for trunk/lib


Ignore:
Timestamp:
Oct 9, 2012, 12:26:35 PM (7 years ago)
Author:
nmedfort
Message:

bug fix for count reverse zeroes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/bitblock.hpp

    r2328 r2428  
    33
    44/*=============================================================================
    5     IDISA Library Import - Generic
    6     Copyright (C) 2011, Robert D. Cameron, Kenneth S. Herdy
    7     Licensed to the public under the Open Software License 3.0.
    8     Licensed to International Characters Inc.
    9        under the Academic Free License version 3.0.
     5        IDISA Library Import - Generic
     6        Copyright (C) 2011, Robert D. Cameron, Kenneth S. Herdy
     7        Licensed to the public under the Open Software License 3.0.
     8        Licensed to International Characters Inc.
     9           under the Academic Free License version 3.0.
    1010=============================================================================*/
    1111
     
    2626#endif
    2727#ifndef ATTRIBUTE_SIMD_ALIGN
    28     #if defined _MSC_VER
    29         //note: MSVC++ cannot accept sizeof or division within __declspec(align(...))
    30         #define ATTRIBUTE_SIMD_ALIGN __declspec(align(16))
    31     #elif defined __GNUC__
    32         #define ATTRIBUTE_SIMD_ALIGN __attribute__((aligned(sizeof(BitBlock))))
    33     #else
    34         #define ATTRIBUTE_SIMD_ALIGN
    35     #endif
     28        #if defined _MSC_VER
     29                //note: MSVC++ cannot accept sizeof or division within __declspec(align(...))
     30                #define ATTRIBUTE_SIMD_ALIGN __declspec(align(16))
     31        #elif defined __GNUC__
     32                #define ATTRIBUTE_SIMD_ALIGN __attribute__((aligned(sizeof(BitBlock))))
     33        #else
     34                #define ATTRIBUTE_SIMD_ALIGN
     35        #endif
    3636#endif
    3737
     
    7474        uint32_t so_far = 0;
    7575        for (unsigned int i = 0; i < sizeof(BitBlock)/sizeof(scanword_t); i++) {
    76                 if (u.elems[i] != 0) return so_far + scan_forward_zeroes(u.elems[i]);
     76                if (u.elems[i] != 0) return so_far | scan_forward_zeroes(u.elems[i]);
    7777                so_far += 8 * sizeof(scanword_t);
    7878        }
     
    8282IDISA_ALWAYS_INLINE BitBlock mask_forward_zeroes(uint32_t count) {
    8383        if (count >= sizeof(BitBlock) * 8) return simd<1>::constant<0>();
    84         else return bitblock::sll(simd<1>::constant<1>(), convert(count));
     84                else return bitblock::sll(simd<1>::constant<1>(), convert(count));
    8585}
    8686
     
    8989        u.bitblock = v;
    9090        uint32_t so_far = 0;
    91         for (unsigned int i = sizeof(BitBlock)/sizeof(scanword_t) - 1; i >= 0; i--) {
    92                 if (u.elems[i] != 0) return so_far + scan_backward_zeroes(u.elems[i]);
     91        for (unsigned int i = (sizeof(BitBlock)/sizeof(scanword_t)); i != 0; ) {
     92                if (u.elems[--i] != 0) return so_far | scan_backward_zeroes(u.elems[i]);
    9393                so_far += 8 * sizeof(scanword_t);
    9494        }
     
    9898IDISA_ALWAYS_INLINE BitBlock mask_reverse_zeroes(uint32_t count) {
    9999        if (count >= sizeof(BitBlock) * 8) return simd<1>::constant<0>();
    100         else return bitblock::srl(simd<1>::constant<1>(), convert(count));
     100                else return bitblock::srl(simd<1>::constant<1>(), convert(count));
    101101}
    102102
     
    116116
    117117static IDISA_ALWAYS_INLINE void assert_bitblock_align(void * addr) {
    118     assert(0 == ((intptr_t)(addr) & (sizeof(BitBlock)-1)));
     118        assert(0 == ((intptr_t)(addr) & (sizeof(BitBlock)-1)));
    119119}
    120120
    121121static IDISA_ALWAYS_INLINE void assert_bitblock_align(BitBlock v) {
    122     assert(0 == ((intptr_t)(&v) & (sizeof(BitBlock)-1)));
     122        assert(0 == ((intptr_t)(&v) & (sizeof(BitBlock)-1)));
    123123}
    124124
Note: See TracChangeset for help on using the changeset viewer.