word-at-a-time.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef _ASM_WORD_AT_A_TIME_H
  2. #define _ASM_WORD_AT_A_TIME_H
  3. #include <asm/byteorder.h>
  4. struct word_at_a_time { /* unused */ };
  5. #define WORD_AT_A_TIME_CONSTANTS {}
  6. /* Generate 0x01 byte values for zero bytes using a SIMD instruction. */
  7. static inline unsigned long has_zero(unsigned long val, unsigned long *data,
  8. const struct word_at_a_time *c)
  9. {
  10. #ifdef __tilegx__
  11. unsigned long mask = __insn_v1cmpeqi(val, 0);
  12. #else /* tilepro */
  13. unsigned long mask = __insn_seqib(val, 0);
  14. #endif
  15. *data = mask;
  16. return mask;
  17. }
  18. /* These operations are both nops. */
  19. #define prep_zero_mask(val, data, c) (data)
  20. #define create_zero_mask(data) (data)
  21. /* And this operation just depends on endianness. */
  22. static inline long find_zero(unsigned long mask)
  23. {
  24. #ifdef __BIG_ENDIAN
  25. return __builtin_clzl(mask) >> 3;
  26. #else
  27. return __builtin_ctzl(mask) >> 3;
  28. #endif
  29. }
  30. #ifdef __BIG_ENDIAN
  31. #define zero_bytemask(mask) (~1ul << (63 - __builtin_clzl(mask)))
  32. #else
  33. #define zero_bytemask(mask) ((2ul << __builtin_ctzl(mask)) - 1)
  34. #endif
  35. #endif /* _ASM_WORD_AT_A_TIME_H */