git: 2fb0569f1ff5 - main - LinuxKPI: bitfields add more *replace_bits()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 09 Jan 2022 14:40:01 UTC
The branch main has been updated by bz:
URL: https://cgit.FreeBSD.org/src/commit/?id=2fb0569f1ff58209420ed9c5500476ad7d93e702
commit 2fb0569f1ff58209420ed9c5500476ad7d93e702
Author: Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-01-09 01:12:05 +0000
Commit: Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-01-09 14:39:19 +0000
LinuxKPI: bitfields add more *replace_bits()
Add or extend the already existing *_replace_bits() implementations
using macros as we do for the other parts in the file for
le<n>p_replace_bits(), u<n>p_replace_bits(), and _u<n>_replace_bits().
MFC after: 3 days
Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D33799
---
.../linuxkpi/common/include/linux/bitfield.h | 42 +++++++++++++++++++---
1 file changed, 37 insertions(+), 5 deletions(-)
diff --git a/sys/compat/linuxkpi/common/include/linux/bitfield.h b/sys/compat/linuxkpi/common/include/linux/bitfield.h
index a805c1bca5a1..14278a557809 100644
--- a/sys/compat/linuxkpi/common/include/linux/bitfield.h
+++ b/sys/compat/linuxkpi/common/include/linux/bitfield.h
@@ -86,12 +86,44 @@ _leX_encode_bits(64)
_leX_encode_bits(32)
_leX_encode_bits(16)
-static __inline void
-le32p_replace_bits(uint32_t *p, uint32_t v, uint32_t f)
-{
+#define _leXp_replace_bits(_n) \
+ static __inline void \
+ le ## _n ## p_replace_bits(uint ## _n ## _t *p, \
+ uint ## _n ## _t v, uint ## _n ## _t f) \
+ { \
+ *p = (*p & ~(cpu_to_le ## _n(f))) | \
+ le ## _n ## _encode_bits(v, f); \
+ }
+
+_leXp_replace_bits(64)
+_leXp_replace_bits(32)
+_leXp_replace_bits(16)
+
+#define _uXp_replace_bits(_n) \
+ static __inline void \
+ u ## _n ## p_replace_bits(uint ## _n ## _t *p, \
+ uint ## _n ## _t v, uint ## _n ## _t f) \
+ { \
+ *p = (*p & ~f) | u ## _n ## _encode_bits(v, f); \
+ }
+
+_uXp_replace_bits(64)
+_uXp_replace_bits(32)
+_uXp_replace_bits(16)
+_uXp_replace_bits(8)
+
+#define _uX_replace_bits(_n) \
+ static __inline uint ## _n ## _t \
+ u ## _n ## _replace_bits(uint ## _n ## _t p, \
+ uint ## _n ## _t v, uint ## _n ## _t f) \
+ { \
+ return ((p & ~f) | u ## _n ## _encode_bits(v, f)); \
+ }
- *p = (*p & ~(cpu_to_le32(f))) | le32_encode_bits(v, f);
-}
+_uX_replace_bits(64)
+_uX_replace_bits(32)
+_uX_replace_bits(16)
+_uX_replace_bits(8)
#define __bf_shf(x) (__builtin_ffsll(x) - 1)