0001
0002 #ifndef _ASM_WORD_AT_A_TIME_H
0003 #define _ASM_WORD_AT_A_TIME_H
0004
0005 #include <linux/kernel.h>
0006
0007
0008
0009
0010
0011
0012
0013
0014 struct word_at_a_time {
0015 const unsigned long one_bits, high_bits;
0016 };
0017
0018 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
0019
0020 #ifdef CONFIG_64BIT
0021
0022
0023
0024
0025
0026
0027
0028 static inline long count_masked_bytes(unsigned long mask)
0029 {
0030 return mask*0x0001020304050608ul >> 56;
0031 }
0032
0033 #else
0034
0035
0036 static inline long count_masked_bytes(long mask)
0037 {
0038
0039 long a = (0x0ff0001+mask) >> 23;
0040
0041 return a & mask;
0042 }
0043
0044 #endif
0045
0046
0047 static inline unsigned long has_zero(unsigned long a, unsigned long *bits, const struct word_at_a_time *c)
0048 {
0049 unsigned long mask = ((a - c->one_bits) & ~a) & c->high_bits;
0050 *bits = mask;
0051 return mask;
0052 }
0053
0054 static inline unsigned long prep_zero_mask(unsigned long a, unsigned long bits, const struct word_at_a_time *c)
0055 {
0056 return bits;
0057 }
0058
0059 static inline unsigned long create_zero_mask(unsigned long bits)
0060 {
0061 bits = (bits - 1) & ~bits;
0062 return bits >> 7;
0063 }
0064
0065
0066 #define zero_bytemask(mask) (mask)
0067
0068 static inline unsigned long find_zero(unsigned long mask)
0069 {
0070 return count_masked_bytes(mask);
0071 }
0072
0073
0074
0075
0076
0077
0078
0079
0080 static inline unsigned long load_unaligned_zeropad(const void *addr)
0081 {
0082 unsigned long ret;
0083
0084 asm volatile(
0085 "1: mov %[mem], %[ret]\n"
0086 "2:\n"
0087 _ASM_EXTABLE_TYPE(1b, 2b, EX_TYPE_ZEROPAD)
0088 : [ret] "=r" (ret)
0089 : [mem] "m" (*(unsigned long *)addr));
0090
0091 return ret;
0092 }
0093
0094 #endif