word-at-a-time.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef __ASM_ARM_WORD_AT_A_TIME_H
  2. #define __ASM_ARM_WORD_AT_A_TIME_H
  3. #ifndef __ARMEB__
  4. /*
  5. * Little-endian word-at-a-time zero byte handling.
  6. * Heavily based on the x86 algorithm.
  7. */
  8. #include <linux/kernel.h>
  9. struct word_at_a_time {
  10. const unsigned long one_bits, high_bits;
  11. };
  12. #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
  13. static inline unsigned long has_zero(unsigned long a, unsigned long *bits,
  14. const struct word_at_a_time *c)
  15. {
  16. unsigned long mask = ((a - c->one_bits) & ~a) & c->high_bits;
  17. *bits = mask;
  18. return mask;
  19. }
  20. #define prep_zero_mask(a, bits, c) (bits)
  21. static inline unsigned long create_zero_mask(unsigned long bits)
  22. {
  23. bits = (bits - 1) & ~bits;
  24. return bits >> 7;
  25. }
  26. static inline unsigned long find_zero(unsigned long mask)
  27. {
  28. unsigned long ret;
  29. #if __LINUX_ARM_ARCH__ >= 5
  30. /* We have clz available. */
  31. ret = fls(mask) >> 3;
  32. #else
  33. /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */
  34. ret = (0x0ff0001 + mask) >> 23;
  35. /* Fix the 1 for 00 case */
  36. ret &= mask;
  37. #endif
  38. return ret;
  39. }
  40. #else /* __ARMEB__ */
  41. #include <asm-generic/word-at-a-time.h>
  42. #endif
  43. #endif /* __ASM_ARM_WORD_AT_A_TIME_H */