word-at-a-time.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __ASM_SH_WORD_AT_A_TIME_H
  3. #define __ASM_SH_WORD_AT_A_TIME_H
  4. #ifdef CONFIG_CPU_BIG_ENDIAN
  5. # include <asm-generic/word-at-a-time.h>
  6. #else
  7. /*
  8. * Little-endian version cribbed from x86.
  9. */
  10. struct word_at_a_time {
  11. const unsigned long one_bits, high_bits;
  12. };
  13. #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
  14. /* Carl Chatfield / Jan Achrenius G+ version for 32-bit */
  15. static inline long count_masked_bytes(long mask)
  16. {
  17. /* (000000 0000ff 00ffff ffffff) -> ( 1 1 2 3 ) */
  18. long a = (0x0ff0001+mask) >> 23;
  19. /* Fix the 1 for 00 case */
  20. return a & mask;
  21. }
  22. /* Return nonzero if it has a zero */
  23. static inline unsigned long has_zero(unsigned long a, unsigned long *bits, const struct word_at_a_time *c)
  24. {
  25. unsigned long mask = ((a - c->one_bits) & ~a) & c->high_bits;
  26. *bits = mask;
  27. return mask;
  28. }
  29. static inline unsigned long prep_zero_mask(unsigned long a, unsigned long bits, const struct word_at_a_time *c)
  30. {
  31. return bits;
  32. }
  33. static inline unsigned long create_zero_mask(unsigned long bits)
  34. {
  35. bits = (bits - 1) & ~bits;
  36. return bits >> 7;
  37. }
  38. /* The mask we created is directly usable as a bytemask */
  39. #define zero_bytemask(mask) (mask)
  40. static inline unsigned long find_zero(unsigned long mask)
  41. {
  42. return count_masked_bytes(mask);
  43. }
  44. #endif
  45. #endif