word-at-a-time.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (C) 2012 Regents of the University of California
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. * Derived from arch/x86/include/asm/word-at-a-time.h
  13. */
  14. #ifndef _ASM_RISCV_WORD_AT_A_TIME_H
  15. #define _ASM_RISCV_WORD_AT_A_TIME_H
  16. #include <linux/kernel.h>
  17. struct word_at_a_time {
  18. const unsigned long one_bits, high_bits;
  19. };
  20. #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
  21. static inline unsigned long has_zero(unsigned long val,
  22. unsigned long *bits, const struct word_at_a_time *c)
  23. {
  24. unsigned long mask = ((val - c->one_bits) & ~val) & c->high_bits;
  25. *bits = mask;
  26. return mask;
  27. }
  28. static inline unsigned long prep_zero_mask(unsigned long val,
  29. 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. static inline unsigned long find_zero(unsigned long mask)
  39. {
  40. return fls64(mask) >> 3;
  41. }
  42. /* The mask we created is directly usable as a bytemask */
  43. #define zero_bytemask(mask) (mask)
  44. #endif /* _ASM_RISCV_WORD_AT_A_TIME_H */