xref: /openbmc/linux/arch/riscv/include/asm/word-at-a-time.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*50acfb2bSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
25d8544e2SPalmer Dabbelt /*
35d8544e2SPalmer Dabbelt  * Copyright (C) 2012 Regents of the University of California
45d8544e2SPalmer Dabbelt  *
55d8544e2SPalmer Dabbelt  * Derived from arch/x86/include/asm/word-at-a-time.h
65d8544e2SPalmer Dabbelt  */
75d8544e2SPalmer Dabbelt 
85d8544e2SPalmer Dabbelt #ifndef _ASM_RISCV_WORD_AT_A_TIME_H
95d8544e2SPalmer Dabbelt #define _ASM_RISCV_WORD_AT_A_TIME_H
105d8544e2SPalmer Dabbelt 
115d8544e2SPalmer Dabbelt 
125d8544e2SPalmer Dabbelt #include <linux/kernel.h>
135d8544e2SPalmer Dabbelt 
145d8544e2SPalmer Dabbelt struct word_at_a_time {
155d8544e2SPalmer Dabbelt 	const unsigned long one_bits, high_bits;
165d8544e2SPalmer Dabbelt };
175d8544e2SPalmer Dabbelt 
185d8544e2SPalmer Dabbelt #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
195d8544e2SPalmer Dabbelt 
has_zero(unsigned long val,unsigned long * bits,const struct word_at_a_time * c)205d8544e2SPalmer Dabbelt static inline unsigned long has_zero(unsigned long val,
215d8544e2SPalmer Dabbelt 	unsigned long *bits, const struct word_at_a_time *c)
225d8544e2SPalmer Dabbelt {
235d8544e2SPalmer Dabbelt 	unsigned long mask = ((val - c->one_bits) & ~val) & c->high_bits;
245d8544e2SPalmer Dabbelt 	*bits = mask;
255d8544e2SPalmer Dabbelt 	return mask;
265d8544e2SPalmer Dabbelt }
275d8544e2SPalmer Dabbelt 
prep_zero_mask(unsigned long val,unsigned long bits,const struct word_at_a_time * c)285d8544e2SPalmer Dabbelt static inline unsigned long prep_zero_mask(unsigned long val,
295d8544e2SPalmer Dabbelt 	unsigned long bits, const struct word_at_a_time *c)
305d8544e2SPalmer Dabbelt {
315d8544e2SPalmer Dabbelt 	return bits;
325d8544e2SPalmer Dabbelt }
335d8544e2SPalmer Dabbelt 
create_zero_mask(unsigned long bits)345d8544e2SPalmer Dabbelt static inline unsigned long create_zero_mask(unsigned long bits)
355d8544e2SPalmer Dabbelt {
365d8544e2SPalmer Dabbelt 	bits = (bits - 1) & ~bits;
375d8544e2SPalmer Dabbelt 	return bits >> 7;
385d8544e2SPalmer Dabbelt }
395d8544e2SPalmer Dabbelt 
find_zero(unsigned long mask)405d8544e2SPalmer Dabbelt static inline unsigned long find_zero(unsigned long mask)
415d8544e2SPalmer Dabbelt {
425d8544e2SPalmer Dabbelt 	return fls64(mask) >> 3;
435d8544e2SPalmer Dabbelt }
445d8544e2SPalmer Dabbelt 
455d8544e2SPalmer Dabbelt /* The mask we created is directly usable as a bytemask */
465d8544e2SPalmer Dabbelt #define zero_bytemask(mask) (mask)
475d8544e2SPalmer Dabbelt 
485d8544e2SPalmer Dabbelt #endif /* _ASM_RISCV_WORD_AT_A_TIME_H */
49