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