lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 29 Jun 2016 23:04:57 +0800
From:	zengzhaoxiu@....com
To:	hpa@...or.com, peterz@...radead.org, bp@...e.de,
	gnomes@...rguk.ukuu.org.uk, andi@...stfloor.org,
	dvyukov@...gle.com, tglx@...utronix.de, mingo@...hat.com,
	dvlasenk@...hat.com, x86@...nel.org, linux-kernel@...r.kernel.org
Cc:	Zhaoxiu Zeng <zhaoxiu.zeng@...il.com>
Subject: [patch V4 09/31] bitops: Add x86-specific parity functions

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

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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ