word-at-a-time.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #define zero_bytemask(mask) (mask)
  41. #else /* __ARMEB__ */
  42. #include <asm-generic/word-at-a-time.h>
  43. #endif
  44. #ifdef CONFIG_DCACHE_WORD_ACCESS
  45. /*
  46. * Load an unaligned word from kernel space.
  47. *
  48. * In the (very unlikely) case of the word being a page-crosser
  49. * and the next page not being mapped, take the exception and
  50. * return zeroes in the non-existing part.
  51. */
  52. static inline unsigned long load_unaligned_zeropad(const void *addr)
  53. {
  54. unsigned long ret, offset;
  55. /* Load word from unaligned pointer addr */
  56. asm(
  57. "1: ldr %0, [%2]\n"
  58. "2:\n"
  59. " .pushsection .text.fixup,\"ax\"\n"
  60. " .align 2\n"
  61. "3: and %1, %2, #0x3\n"
  62. " bic %2, %2, #0x3\n"
  63. " ldr %0, [%2]\n"
  64. " lsl %1, %1, #0x3\n"
  65. #ifndef __ARMEB__
  66. " lsr %0, %0, %1\n"
  67. #else
  68. " lsl %0, %0, %1\n"
  69. #endif
  70. " b 2b\n"
  71. " .popsection\n"
  72. " .pushsection __ex_table,\"a\"\n"
  73. " .align 3\n"
  74. " .long 1b, 3b\n"
  75. " .popsection"
  76. : "=&r" (ret), "=&r" (offset)
  77. : "r" (addr), "Qo" (*(unsigned long *)addr));
  78. return ret;
  79. }
  80. #endif /* DCACHE_WORD_ACCESS */
  81. #endif /* __ASM_ARM_WORD_AT_A_TIME_H */