aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjoern A. Zeeb <bz@FreeBSD.org>2022-01-09 01:12:05 +0000
committerBjoern A. Zeeb <bz@FreeBSD.org>2022-01-16 22:38:57 +0000
commit2f6e37eded5e869c54330a748ae9a66459837444 (patch)
tree76624a7e9f27013f8e19ccd3ba9176a4c75fa72d
parentf88fcc52d888ce3d1be5b602964a42d8b3d90bc3 (diff)
downloadsrc-2f6e37eded5e869c54330a748ae9a66459837444.tar.gz
src-2f6e37eded5e869c54330a748ae9a66459837444.zip
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(). Reviewed by: hselasky Differential Revision: https://reviews.freebsd.org/D33799 (cherry picked from commit 2fb0569f1ff58209420ed9c5500476ad7d93e702)
-rw-r--r--sys/compat/linuxkpi/common/include/linux/bitfield.h42
1 files 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)