[PATCH 02/15] math128, x86_64: Implement {mul,add}_u128 in 64bit asm

From: Juri Lelli
Date: Wed May 23 2012 - 17:44:23 EST


From: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>

Enable __int128 usage when available, if not, provide asm versions of
mul_u64_u64 and add_u128.

Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: H. Peter Anvin <hpa@xxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx>
Signed-off-by: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Link: http://lkml.kernel.org/n/tip-67zk6v8agsi8m7k1bdcd0srw@xxxxxxxxxxxxxx
---
arch/x86/include/asm/Kbuild | 1 -
arch/x86/include/asm/math128.h | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 arch/x86/include/asm/math128.h

diff --git a/arch/x86/include/asm/Kbuild b/arch/x86/include/asm/Kbuild
index 86441b9..f9c0d3b 100644
--- a/arch/x86/include/asm/Kbuild
+++ b/arch/x86/include/asm/Kbuild
@@ -26,4 +26,3 @@ header-y += vsyscall.h
genhdr-y += unistd_32.h
genhdr-y += unistd_64.h
genhdr-y += unistd_x32.h
-generic-y += math128.h
diff --git a/arch/x86/include/asm/math128.h b/arch/x86/include/asm/math128.h
new file mode 100644
index 0000000..c0e2a6c
--- /dev/null
+++ b/arch/x86/include/asm/math128.h
@@ -0,0 +1,39 @@
+#ifndef _ASM_MATH128_H
+#define _ASM_MATH128_H
+
+#ifdef CONFIG_X86_64
+
+#ifdef __SIZEOF_INT128__
+#define ARCH_HAS_INT128
+#endif
+
+#ifndef ARCH_HAS_INT128
+
+static inline u128 mul_u64_u64(u64 a, u64 b)
+{
+ u128 res;
+
+ asm("mulq %2"
+ : "=a" (res.lo), "=d" (res.hi)
+ : "rm" (b), "0" (a));
+
+ return res;
+}
+#define mul_u64_u64 mul_u64_u64
+
+static inline u128 add_u128(u128 a, u128 b)
+{
+ u128 res;
+
+ asm("addq %2,%0;\n"
+ "adcq %3,%1;\n"
+ : "=rm" (res.lo), "=rm" (res.hi)
+ : "r" (b.lo), "r" (b.hi), "0" (a.lo), "1" (a.hi));
+
+ return res;
+}
+#define add_u128 add_u128
+
+#endif /* ARCH_HAS_INT128 */
+#endif /* CONFIG_X86_64 */
+#endif /* _ASM_MATH128_H */
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/