]> Git Repo - cpuminer-multi.git/commitdiff
Move x86 mul128 implementation
authorlucas <[email protected]>
Sun, 25 May 2014 00:14:52 +0000 (01:14 +0100)
committerlucas <[email protected]>
Sun, 25 May 2014 00:14:52 +0000 (01:14 +0100)
Makefile.am
aesb-x86.S
crypto/aesb-x86-impl.c [new file with mode: 0644]

index 9a40f2a49b2ba5dd618dfd4a9735ca192aa56d68..be9eedf58ba2ba6ae496f63d7d9d5bc429076204 100644 (file)
@@ -51,7 +51,7 @@ minerd_SOURCES        = elist.h \
                  crypto/hash.c \
                  crypto/aesb.c
 if ARCH_x86
-minerd_SOURCES += sha2-x86.S scrypt-x86.S aesb-x86.S
+minerd_SOURCES += sha2-x86.S scrypt-x86.S aesb-x86.S crypto/aesb-x86-impl.c
 endif
 if ARCH_x86_64
 minerd_SOURCES += sha2-x64.S scrypt-x64.S aesb-x64.S
index 706ceaad358e4c42074883d94f8f995415f03cf8..4011ef6637050205e31d7c2d765265dbbd7912a3 100644 (file)
@@ -19,20 +19,3 @@ _fast_aesb_single_round:
 fast_aesb_pseudo_round_mut:
 _fast_aesb_pseudo_round_mut:
     ret
-
-    .text
-    .globl mul128
-    .globl _mul128
-mul128:
-_mul128:
-#if defined(_WIN32) || defined(__CYGWIN__)
-       mov %rcx, %rax
-       mul %rdx
-       mov %r8, (%r8)
-#else
-       mov %rdx, %r8
-       mov %rdi, %rax
-       mul %rsi
-       mov %rdx, (%r8)
-#endif
-       ret
diff --git a/crypto/aesb-x86-impl.c b/crypto/aesb-x86-impl.c
new file mode 100644 (file)
index 0000000..f964ef2
--- /dev/null
@@ -0,0 +1,27 @@
+#pragma once
+
+uint64_t mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi) {
+  // multiplier   = ab = a * 2^32 + b
+  // multiplicand = cd = c * 2^32 + d
+  // ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d
+  uint64_t a = hi_dword(multiplier);
+  uint64_t b = lo_dword(multiplier);
+  uint64_t c = hi_dword(multiplicand);
+  uint64_t d = lo_dword(multiplicand);
+
+  uint64_t ac = a * c;
+  uint64_t ad = a * d;
+  uint64_t bc = b * c;
+  uint64_t bd = b * d;
+
+  uint64_t adbc = ad + bc;
+  uint64_t adbc_carry = adbc < ad ? 1 : 0;
+
+  // multiplier * multiplicand = product_hi * 2^64 + product_lo
+  uint64_t product_lo = bd + (adbc << 32);
+  uint64_t product_lo_carry = product_lo < bd ? 1 : 0;
+  *product_hi = ac + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry;
+  assert(ac <= *product_hi);
+
+  return product_lo;
+}
This page took 0.02483 seconds and 4 git commands to generate.