summaryrefslogtreecommitdiff
path: root/src/pal/inc/rt/intsafe.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/pal/inc/rt/intsafe.h')
-rw-r--r--src/pal/inc/rt/intsafe.h165
1 files changed, 0 insertions, 165 deletions
diff --git a/src/pal/inc/rt/intsafe.h b/src/pal/inc/rt/intsafe.h
index 4ed70e7423..6e28175e22 100644
--- a/src/pal/inc/rt/intsafe.h
+++ b/src/pal/inc/rt/intsafe.h
@@ -18,26 +18,6 @@
#include <specstrings.h> // for IN, etc.
-
-#if defined(_AMD64_)
-#ifdef __cplusplus
-extern "C" {
-#endif
-#define UnsignedMultiply128 _umul128
-ULONG64
-UnsignedMultiply128 (
- IN ULONG64 Multiplier,
- IN ULONG64 Multiplicand,
- OUT ULONG64 *HighProduct
- );
-#ifdef _MSC_VER
-#pragma intrinsic(_umul128)
-#endif // _MSC_VER
-#ifdef __cplusplus
-}
-#endif
-#endif // _AMD64_
-
#define INTSAFE_E_ARITHMETIC_OVERFLOW ((HRESULT)0x80070216L) // 0x216 = 534 = ERROR_ARITHMETIC_OVERFLOW
#ifndef LOWORD
@@ -1402,23 +1382,6 @@ UIntMult(
}
//
-// UINT_PTR multiplication
-//
-#ifdef _WIN64
-#define UIntPtrMult ULongLongMult
-#else
-__inline
-HRESULT
-UIntPtrMult(
- IN UINT_PTR ulMultiplicand,
- IN UINT_PTR ulMultiplier,
- OUT UINT_PTR* pulResult)
-{
- return UIntMult((UINT)ulMultiplicand, (UINT)ulMultiplier, (UINT*)pulResult);
-}
-#endif // _WIN64
-
-//
// ULONG multiplication
//
__inline
@@ -1434,24 +1397,6 @@ ULongMult(
}
//
-// ULONG_PTR multiplication
-//
-#ifdef _WIN64
-#define ULongPtrMult ULongLongMult
-#else
-__inline
-HRESULT
-ULongPtrMult(
- IN ULONG_PTR ulMultiplicand,
- IN ULONG_PTR ulMultiplier,
- OUT ULONG_PTR* pulResult)
-{
- return ULongMult((ULONG)ulMultiplicand, (ULONG)ulMultiplier, (ULONG*)pulResult);
-}
-#endif // _WIN64
-
-
-//
// DWORD multiplication
//
#define DWordMult ULongMult
@@ -1461,114 +1406,4 @@ ULongPtrMult(
//
#define DWordPtrMult ULongPtrMult
-//
-// size_t multiplication
-//
-#define SizeTMult UIntPtrMult
-
-//
-// SIZE_T multiplication
-//
-#define SIZETMult ULongPtrMult
-
-//
-// ULONGLONG multiplication
-//
-__inline
-HRESULT
-ULongLongMult(
- IN ULONGLONG ullMultiplicand,
- IN ULONGLONG ullMultiplier,
- OUT ULONGLONG* pullResult)
-{
- HRESULT hr = INTSAFE_E_ARITHMETIC_OVERFLOW;
-#ifdef _AMD64_
- ULONGLONG u64ResultHigh;
- ULONGLONG u64ResultLow;
-
- *pullResult = ULONGLONG_ERROR;
-
- u64ResultLow = UnsignedMultiply128(ullMultiplicand, ullMultiplier, &u64ResultHigh);
- if (u64ResultHigh == 0)
- {
- *pullResult = u64ResultLow;
- hr = S_OK;
- }
-#else
- // 64x64 into 128 is like 32.32 x 32.32.
- //
- // a.b * c.d = a*(c.d) + .b*(c.d) = a*c + a*.d + .b*c + .b*.d
- // back in non-decimal notation where A=a*2^32 and C=c*2^32:
- // A*C + A*d + b*C + b*d
- // So there are four components to add together.
- // result = (a*c*2^64) + (a*d*2^32) + (b*c*2^32) + (b*d)
- //
- // a * c must be 0 or there would be bits in the high 64-bits
- // a * d must be less than 2^32 or there would be bits in the high 64-bits
- // b * c must be less than 2^32 or there would be bits in the high 64-bits
- // then there must be no overflow of the resulting values summed up.
-
- ULONG dw_a;
- ULONG dw_b;
- ULONG dw_c;
- ULONG dw_d;
- ULONGLONG ad = 0;
- ULONGLONG bc = 0;
- ULONGLONG bd = 0;
- ULONGLONG ullResult = 0;
-
- *pullResult = ULONGLONG_ERROR;
-
- dw_a = (ULONG)(ullMultiplicand >> 32);
- dw_c = (ULONG)(ullMultiplier >> 32);
-
- // common case -- if high dwords are both zero, no chance for overflow
- if ((dw_a == 0) && (dw_c == 0))
- {
- dw_b = (DWORD)ullMultiplicand;
- dw_d = (DWORD)ullMultiplier;
-
- *pullResult = (((ULONGLONG)dw_b) * (ULONGLONG)dw_d);
- hr = S_OK;
- }
- else
- {
- // a * c must be 0 or there would be bits set in the high 64-bits
- if ((dw_a == 0) ||
- (dw_c == 0))
- {
- dw_d = (DWORD)ullMultiplier;
-
- // a * d must be less than 2^32 or there would be bits set in the high 64-bits
- ad = (((ULONGLONG)dw_a) * (ULONGLONG)dw_d);
- if ((ad & HIDWORD_MASK) == 0)
- {
- dw_b = (DWORD)ullMultiplicand;
-
- // b * c must be less than 2^32 or there would be bits set in the high 64-bits
- bc = (((ULONGLONG)dw_b) * (ULONGLONG)dw_c);
- if ((bc & HIDWORD_MASK) == 0)
- {
- // now sum them all up checking for overflow.
- // shifting is safe because we already checked for overflow above
- if (SUCCEEDED(ULongLongAdd(bc << 32, ad << 32, &ullResult)))
- {
- // b * d
- bd = (((ULONGLONG)dw_b) * (ULONGLONG)dw_d);
-
- if (SUCCEEDED(ULongLongAdd(ullResult, bd, &ullResult)))
- {
- *pullResult = ullResult;
- hr = S_OK;
- }
- }
- }
- }
- }
- }
-#endif // _AMD64_
-
- return hr;
-}
-
#endif // _INTSAFE_H_INCLUDED_