2 * Copyright (C) 2012 Regents of the University of California
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 * Derived from arch/x86/include/asm/word-at-a-time.h
15 #ifndef _ASM_RISCV_WORD_AT_A_TIME_H
16 #define _ASM_RISCV_WORD_AT_A_TIME_H
19 #include <linux/kernel.h>
21 struct word_at_a_time {
22 const unsigned long one_bits, high_bits;
25 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
27 static inline unsigned long has_zero(unsigned long val,
28 unsigned long *bits, const struct word_at_a_time *c)
30 unsigned long mask = ((val - c->one_bits) & ~val) & c->high_bits;
35 static inline unsigned long prep_zero_mask(unsigned long val,
36 unsigned long bits, const struct word_at_a_time *c)
41 static inline unsigned long create_zero_mask(unsigned long bits)
43 bits = (bits - 1) & ~bits;
47 static inline unsigned long find_zero(unsigned long mask)
49 return fls64(mask) >> 3;
52 /* The mask we created is directly usable as a bytemask */
53 #define zero_bytemask(mask) (mask)
55 #endif /* _ASM_RISCV_WORD_AT_A_TIME_H */