Changeset 522


Ignore:
Timestamp:
Jul 21, 2010, 2:59:55 PM (9 years ago)
Author:
lindanl
Message:

Add count_backward_zeroes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/lib_simd.h

    r521 r522  
    120120  else if (v.elems[3] != 0) return 3*LONG_BIT + cfzl(v.elems[3]);
    121121#endif
     122#endif
     123  else return 8*sizeof(SIMD_type);
     124}
     125
     126static inline int count_backward_zeroes(SIMD_type bits) {
     127  union {SIMD_type vec; unsigned long elems[sizeof(SIMD_type)/sizeof(long)];} v;
     128  v.vec = bits;
     129#if LONG_BIT == 64
     130  if (v.elems[1] != 0) return 2*LONG_BIT + cbzl(v.elems[1]);
     131  else if (v.elems[0] != 0) return 3*LONG_BIT + cbzl(v.elems[0]);
     132#endif
     133#if LONG_BIT < 64
     134  if (v.elems[3] != 0) return cfzl(v.elems[3]);
     135  else if (v.elems[2] != 0) return LONG_BIT + cfzl(v.elems[2]);
     136  else if (v.elems[1] != 0) return 2*LONG_BIT + cfzl(v.elems[1]);
     137  else if (v.elems[0] != 0) return 3*LONG_BIT + cfzl(v.elems[0]);
    122138#endif
    123139  else return 8*sizeof(SIMD_type);
Note: See TracChangeset for help on using the changeset viewer.