word-at-a-time.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2012 Regents of the University of California
  4. *
  5. * Derived from arch/x86/include/asm/word-at-a-time.h
  6. */
  7. #ifndef _ASM_RISCV_WORD_AT_A_TIME_H
  8. #define _ASM_RISCV_WORD_AT_A_TIME_H
  9. #include <linux/kernel.h>
  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. static inline unsigned long has_zero(unsigned long val,
  15. unsigned long *bits, const struct word_at_a_time *c)
  16. {
  17. unsigned long mask = ((val - c->one_bits) & ~val) & c->high_bits;
  18. *bits = mask;
  19. return mask;
  20. }
  21. static inline unsigned long prep_zero_mask(unsigned long val,
  22. unsigned long bits, const struct word_at_a_time *c)
  23. {
  24. return bits;
  25. }
  26. static inline unsigned long create_zero_mask(unsigned long bits)
  27. {
  28. bits = (bits - 1) & ~bits;
  29. return bits >> 7;
  30. }
  31. static inline unsigned long find_zero(unsigned long mask)
  32. {
  33. return fls64(mask) >> 3;
  34. }
  35. /* The mask we created is directly usable as a bytemask */
  36. #define zero_bytemask(mask) (mask)
  37. #endif /* _ASM_RISCV_WORD_AT_A_TIME_H */