1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Copyright (C) 2012 Regents of the University of California 4 * 5 * Derived from arch/x86/include/asm/word-at-a-time.h 6 */ 7 8 #ifndef _ASM_RISCV_WORD_AT_A_TIME_H 9 #define _ASM_RISCV_WORD_AT_A_TIME_H 10 11 12 #include <linux/kernel.h> 13 14 struct word_at_a_time { 15 const unsigned long one_bits, high_bits; 16 }; 17 18 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) } 19 20 static inline unsigned long has_zero(unsigned long val, 21 unsigned long *bits, const struct word_at_a_time *c) 22 { 23 unsigned long mask = ((val - c->one_bits) & ~val) & c->high_bits; 24 *bits = mask; 25 return mask; 26 } 27 28 static inline unsigned long prep_zero_mask(unsigned long val, 29 unsigned long bits, const struct word_at_a_time *c) 30 { 31 return bits; 32 } 33 34 static inline unsigned long create_zero_mask(unsigned long bits) 35 { 36 bits = (bits - 1) & ~bits; 37 return bits >> 7; 38 } 39 40 static inline unsigned long find_zero(unsigned long mask) 41 { 42 return fls64(mask) >> 3; 43 } 44 45 /* The mask we created is directly usable as a bytemask */ 46 #define zero_bytemask(mask) (mask) 47 48 #endif /* _ASM_RISCV_WORD_AT_A_TIME_H */ 49