diff options
| author | riastradh <riastradh@NetBSD.org> | 2021-12-19 01:33:59 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2021-12-19 01:33:59 +0000 |
| commit | 4b7202ecc329987a35dc69522bab858ff678e7ea (patch) | |
| tree | cde2e9cd7688913a319cb8fb772bf63628df41da /sys/external/bsd/common/include/linux | |
| parent | 387f7f22e352316e9cd3062fed1d24e98fa879a4 (diff) | |
sign_extend64, GENMASK_ULL, for_each_clear_bit
Diffstat (limited to 'sys/external/bsd/common/include/linux')
| -rw-r--r-- | sys/external/bsd/common/include/linux/bitops.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/sys/external/bsd/common/include/linux/bitops.h b/sys/external/bsd/common/include/linux/bitops.h index d1d6e1d4a7c..7d02c2e411e 100644 --- a/sys/external/bsd/common/include/linux/bitops.h +++ b/sys/external/bsd/common/include/linux/bitops.h @@ -1,4 +1,4 @@ -/* $NetBSD: bitops.h,v 1.10 2021/12/19 01:04:12 riastradh Exp $ */ +/* $NetBSD: bitops.h,v 1.11 2021/12/19 01:33:59 riastradh Exp $ */ /*- * Copyright (c) 2013 The NetBSD Foundation, Inc. @@ -96,6 +96,12 @@ hweight64(uint64_t n) return popcount64(n); } +static inline int64_t +sign_extend64(uint64_t x, unsigned n) +{ + return (int64_t)(x << (63 - n)) >> (63 - n); +} + /* * XXX Don't define BITS_PER_LONG as sizeof(unsigned long)*CHAR_BIT * because that won't work in preprocessor conditionals, where it often @@ -110,7 +116,8 @@ hweight64(uint64_t n) #define BIT(n) ((unsigned long)__BIT(n)) #define BIT_ULL(n) ((unsigned long long)__BIT(n)) -#define GENMASK(h,l) __BITS(h,l) +#define GENMASK(h,l) ((unsigned long)__BITS(h,l)) +#define GENMASK_ULL(h,l)((unsigned long long)__BITS(h,l)) static inline int test_bit(unsigned int n, const volatile unsigned long *p) @@ -275,4 +282,9 @@ find_first_zero_bit(const unsigned long *ptr, unsigned long nbits) (BIT) < (NBITS); \ (BIT) = find_next_bit((PTR), (NBITS), (BIT) + 1)) +#define for_each_clear_bit(BIT, PTR, NBITS) \ + for ((BIT) = find_first_zero_bit((PTR), (NBITS)); \ + (BIT) < (NBITS); \ + (BIT) = find_next_zero_bit((PTR), (NBITS), (BIT) + 1)) + #endif /* _LINUX_BITOPS_H_ */ |
