1 /* 2 * Copyright (C) 2012 Regents of the University of California 3 * 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. 7 * 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 13 */ 14 15 #ifndef _ASM_RISCV_WORD_AT_A_TIME_H 16 #define _ASM_RISCV_WORD_AT_A_TIME_H 17 18 19 #include <linux/kernel.h> 20 21 struct word_at_a_time { 22 const unsigned long one_bits, high_bits; 23 }; 24 25 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) } 26 27 static inline unsigned long has_zero(unsigned long val, 28 unsigned long *bits, const struct word_at_a_time *c) 29 { 30 unsigned long mask = ((val - c->one_bits) & ~val) & c->high_bits; 31 *bits = mask; 32 return mask; 33 } 34 35 static inline unsigned long prep_zero_mask(unsigned long val, 36 unsigned long bits, const struct word_at_a_time *c) 37 { 38 return bits; 39 } 40 41 static inline unsigned long create_zero_mask(unsigned long bits) 42 { 43 bits = (bits - 1) & ~bits; 44 return bits >> 7; 45 } 46 47 static inline unsigned long find_zero(unsigned long mask) 48 { 49 return fls64(mask) >> 3; 50 } 51 52 /* The mask we created is directly usable as a bytemask */ 53 #define zero_bytemask(mask) (mask) 54 55 #endif /* _ASM_RISCV_WORD_AT_A_TIME_H */ 56