Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1433849

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

From zengzhaoxiu@163.com
Newsgroups linux.kernel
Subject [patch V4 09/31] bitops: Add x86-specific parity functions
Date 2016-06-29 17:30 +0200
Message-ID <rPpB7-5RI-5@gated-at.bofh.it> (permalink)
References <rzwnf-2Fv-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>

Signed-off-by: Zhaoxiu Zeng <zhaoxiu.zeng@gmail.com>
---
 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

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[patch V4 09/31] bitops: Add x86-specific parity functions zengzhaoxiu@163.com - 2016-06-29 17:30 +0200

csiph-web