1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2f2db633dSMichael Cree #ifndef _ASM_WORD_AT_A_TIME_H
3f2db633dSMichael Cree #define _ASM_WORD_AT_A_TIME_H
4f2db633dSMichael Cree
5f2db633dSMichael Cree #include <asm/compiler.h>
6f2db633dSMichael Cree
7f2db633dSMichael Cree /*
8f2db633dSMichael Cree * word-at-a-time interface for Alpha.
9f2db633dSMichael Cree */
10f2db633dSMichael Cree
11f2db633dSMichael Cree /*
12f2db633dSMichael Cree * We do not use the word_at_a_time struct on Alpha, but it needs to be
13f2db633dSMichael Cree * implemented to humour the generic code.
14f2db633dSMichael Cree */
15f2db633dSMichael Cree struct word_at_a_time {
16f2db633dSMichael Cree const unsigned long unused;
17f2db633dSMichael Cree };
18f2db633dSMichael Cree
19f2db633dSMichael Cree #define WORD_AT_A_TIME_CONSTANTS { 0 }
20f2db633dSMichael Cree
21f2db633dSMichael Cree /* Return nonzero if val has a zero */
has_zero(unsigned long val,unsigned long * bits,const struct word_at_a_time * c)22f2db633dSMichael Cree static inline unsigned long has_zero(unsigned long val, unsigned long *bits, const struct word_at_a_time *c)
23f2db633dSMichael Cree {
24f2db633dSMichael Cree unsigned long zero_locations = __kernel_cmpbge(0, val);
25f2db633dSMichael Cree *bits = zero_locations;
26f2db633dSMichael Cree return zero_locations;
27f2db633dSMichael Cree }
28f2db633dSMichael Cree
prep_zero_mask(unsigned long val,unsigned long bits,const struct word_at_a_time * c)29f2db633dSMichael Cree static inline unsigned long prep_zero_mask(unsigned long val, unsigned long bits, const struct word_at_a_time *c)
30f2db633dSMichael Cree {
31f2db633dSMichael Cree return bits;
32f2db633dSMichael Cree }
33f2db633dSMichael Cree
34f2db633dSMichael Cree #define create_zero_mask(bits) (bits)
35f2db633dSMichael Cree
find_zero(unsigned long bits)36f2db633dSMichael Cree static inline unsigned long find_zero(unsigned long bits)
37f2db633dSMichael Cree {
38f2db633dSMichael Cree #if defined(CONFIG_ALPHA_EV6) && defined(CONFIG_ALPHA_EV67)
39f2db633dSMichael Cree /* Simple if have CIX instructions */
40f2db633dSMichael Cree return __kernel_cttz(bits);
41f2db633dSMichael Cree #else
42f2db633dSMichael Cree unsigned long t1, t2, t3;
43f2db633dSMichael Cree /* Retain lowest set bit only */
44f2db633dSMichael Cree bits &= -bits;
45f2db633dSMichael Cree /* Binary search for lowest set bit */
46f2db633dSMichael Cree t1 = bits & 0xf0;
47f2db633dSMichael Cree t2 = bits & 0xcc;
48f2db633dSMichael Cree t3 = bits & 0xaa;
49f2db633dSMichael Cree if (t1) t1 = 4;
50f2db633dSMichael Cree if (t2) t2 = 2;
51f2db633dSMichael Cree if (t3) t3 = 1;
52f2db633dSMichael Cree return t1 + t2 + t3;
53f2db633dSMichael Cree #endif
54f2db633dSMichael Cree }
55f2db633dSMichael Cree
56c753bf34SChris Metcalf #define zero_bytemask(mask) ((2ul << (find_zero(mask) * 8)) - 1)
57c753bf34SChris Metcalf
58f2db633dSMichael Cree #endif /* _ASM_WORD_AT_A_TIME_H */
59