word-at-a-time.h 1.3 KB

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