From e3524d114246a9221c766bdf1992777b208cbd67 Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow <fsahmkow27@gmail.com>
Date: Mon, 10 Feb 2020 11:20:40 -0400
Subject: Common: Refactor & Document Wall clock.

---
 src/common/uint128.cpp | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

(limited to 'src/common/uint128.cpp')

diff --git a/src/common/uint128.cpp b/src/common/uint128.cpp
index 32bf56730f..7e77588db1 100644
--- a/src/common/uint128.cpp
+++ b/src/common/uint128.cpp
@@ -6,12 +6,34 @@
 #include <intrin.h>
 
 #pragma intrinsic(_umul128)
+#pragma intrinsic(_udiv128)
 #endif
 #include <cstring>
 #include "common/uint128.h"
 
 namespace Common {
 
+#ifdef _MSC_VER
+
+u64 MultiplyAndDivide64(u64 a, u64 b, u64 d) {
+    u128 r{};
+    r[0] = _umul128(a, b, &r[1]);
+    u64 remainder;
+    return _udiv128(r[1], r[0], d, &remainder);
+}
+
+#else
+
+u64 MultiplyAndDivide64(u64 a, u64 b, u64 d) {
+    const u64 diva = a / d;
+    const u64 moda = a % d;
+    const u64 divb = b / d;
+    const u64 modb = b % d;
+    return diva * b + moda * divb + moda * modb / d;
+}
+
+#endif
+
 u128 Multiply64Into128(u64 a, u64 b) {
     u128 result;
 #ifdef _MSC_VER
-- 
cgit v1.2.3-70-g09d2


From 59ce6e6d06e5ce8628f96bb247a342dec356fe43 Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow <fsahmkow27@gmail.com>
Date: Thu, 12 Mar 2020 20:10:51 -0400
Subject: Common/uint128: Correct MSVC Compilation in old versions.

---
 src/common/uint128.cpp | 4 ++++
 1 file changed, 4 insertions(+)

(limited to 'src/common/uint128.cpp')

diff --git a/src/common/uint128.cpp b/src/common/uint128.cpp
index 7e77588db1..16bf7c8283 100644
--- a/src/common/uint128.cpp
+++ b/src/common/uint128.cpp
@@ -19,7 +19,11 @@ u64 MultiplyAndDivide64(u64 a, u64 b, u64 d) {
     u128 r{};
     r[0] = _umul128(a, b, &r[1]);
     u64 remainder;
+#if _MSC_VER < 1923
+    return udiv128(r[1], r[0], d, &remainder);
+#else
     return _udiv128(r[1], r[0], d, &remainder);
+#endif
 }
 
 #else
-- 
cgit v1.2.3-70-g09d2