word-at-a-time.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef _ASM_WORD_AT_A_TIME_H
  2. #define _ASM_WORD_AT_A_TIME_H
  3. /*
  4. * This says "generic", but it's actually big-endian only.
  5. * Little-endian can use more efficient versions of these
  6. * interfaces, see for example
  7. * arch/x86/include/asm/word-at-a-time.h
  8. * for those.
  9. */
  10. #include <linux/kernel.h>
  11. struct word_at_a_time {
  12. const unsigned long high_bits, low_bits;
  13. };
  14. #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0xfe) + 1, REPEAT_BYTE(0x7f) }
  15. /* Bit set in the bytes that have a zero */
  16. static inline long prep_zero_mask(unsigned long val, unsigned long rhs, const struct word_at_a_time *c)
  17. {
  18. unsigned long mask = (val & c->low_bits) + c->low_bits;
  19. return ~(mask | rhs);
  20. }
  21. #define create_zero_mask(mask) (mask)
  22. static inline long find_zero(unsigned long mask)
  23. {
  24. long byte = 0;
  25. #ifdef CONFIG_64BIT
  26. if (mask >> 32)
  27. mask >>= 32;
  28. else
  29. byte = 4;
  30. #endif
  31. if (mask >> 16)
  32. mask >>= 16;
  33. else
  34. byte += 2;
  35. return (mask >> 8) ? byte : byte + 1;
  36. }
  37. static inline bool has_zero(unsigned long val, unsigned long *data, const struct word_at_a_time *c)
  38. {
  39. unsigned long rhs = val | c->low_bits;
  40. *data = rhs;
  41. return (val + c->high_bits) & ~rhs;
  42. }
  43. #endif /* _ASM_WORD_AT_A_TIME_H */