[patch V4 09/31] bitops: Add x86-specific parity functions

From: zengzhaoxiu
Date: Wed Jun 29 2016 - 11:25:46 EST


From: Zhaoxiu Zeng <zhaoxiu.zeng@xxxxxxxxx>

Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@xxxxxxxxx>
---
arch/x86/include/asm/arch_parity.h | 60 ++++++++++++++++++++++++++++++++++++++
arch/x86/include/asm/bitops.h | 4 ++-
2 files changed, 63 insertions(+), 1 deletion(-)
create mode 100644 arch/x86/include/asm/arch_parity.h

diff --git a/arch/x86/include/asm/arch_parity.h b/arch/x86/include/asm/arch_parity.h
new file mode 100644
index 0000000..c7027f8
--- /dev/null
+++ b/arch/x86/include/asm/arch_parity.h
@@ -0,0 +1,60 @@
+#ifndef _ASM_X86_PARITY_H
+#define _ASM_X86_PARITY_H
+
+#include <asm/arch_parity.h>
+
+/*
+ * parity4,8,16 use the Parity Flag directly
+ *
+ * Parity flag - Set if the least-significant byte of the
+ * result contains an even number of 1 bits;
+ * cleared otherwise.
+ */
+
+static inline unsigned int __arch_parity4(unsigned int w)
+{
+ u8 res;
+
+ asm("test $0xf, %1; setpo %b0"
+ : "=qm" (res)
+ : "rm" (w)
+ : "cc");
+
+ return res;
+}
+
+static inline unsigned int __arch_parity8(unsigned int w)
+{
+ u8 res;
+
+ asm("test $0xff, %1; setpo %b0"
+ : "=qm" (res)
+ : "rm" (w)
+ : "cc");
+
+ return res;
+}
+
+static inline unsigned int __arch_parity16(unsigned int w)
+{
+ u8 res;
+
+ asm("xor %h1, %b1; setpo %b0"
+ : "=qm" (res), "+q" (w)
+ : : "cc");
+
+ return res;
+}
+
+static inline unsigned int __arch_parity32(unsigned int w)
+{
+ return __arch_hweight32(w) & 1;
+}
+
+static inline unsigned int __arch_parity64(__u64 w)
+{
+ return __arch_hweight64(w) & 1;
+}
+
+#endif
+
diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
index 7766d1c..f5b0122 100644
--- a/arch/x86/include/asm/bitops.h
+++ b/arch/x86/include/asm/bitops.h
@@ -498,9 +498,11 @@ static __always_inline int fls64(__u64 x)
#include <asm-generic/bitops/sched.h>

#include <asm/arch_hweight.h>
-
#include <asm-generic/bitops/const_hweight.h>

+#include <asm/arch_parity.h>
+#include <asm-generic/bitops/const_parity.h>
+
#include <asm-generic/bitops/le.h>

#include <asm-generic/bitops/ext2-atomic-setbit.h>
--
2.7.4