\r
#include <Base.h>\r
#include <Library/SafeIntLib.h>\r
+#include <Library/BaseLib.h>\r
\r
\r
//\r
// Magnitude of MIN_INT64 as expressed by a UINT64 number.\r
//\r
-#define MIN_INT64_MAGNITUDE ((((UINT64) - (MIN_INT64 + 1))) + 1)\r
+#define MIN_INT64_MAGNITUDE (((UINT64)(- (MIN_INT64 + 1))) + 1)\r
\r
//\r
// Conversion functions\r
// b * c must be less than 2^32 or there would be bits in the high 64-bits\r
// then there must be no overflow of the resulting values summed up.\r
//\r
- DwordA = (UINT32)(Multiplicand >> 32);\r
- DwordC = (UINT32)(Multiplier >> 32);\r
+ DwordA = (UINT32)RShiftU64 (Multiplicand, 32);\r
+ DwordC = (UINT32)RShiftU64 (Multiplier, 32);\r
\r
//\r
// common case -- if high dwords are both zero, no chance for overflow\r
// now sum them all up checking for overflow.\r
// shifting is safe because we already checked for overflow above\r
//\r
- if (!RETURN_ERROR (SafeUint64Add (ProductBC << 32, ProductAD << 32, &UnsignedResult))) {\r
+ if (!RETURN_ERROR (SafeUint64Add (LShiftU64 (ProductBC, 32), LShiftU64 (ProductAD, 32), &UnsignedResult))) {\r
//\r
// b * d\r
//\r
OUT INT32 *Result\r
)\r
{\r
- return SafeInt64ToInt32 (((INT64)Multiplicand) *((INT64)Multiplier), Result);\r
+ return SafeInt64ToInt32 (MultS64x64 (Multiplicand, Multiplier), Result);\r
}\r
\r
/**\r
if (UnsignedResult > MIN_INT64_MAGNITUDE) {\r
*Result = INT64_ERROR;\r
Status = RETURN_BUFFER_TOO_SMALL;\r
+ } else if (UnsignedResult == MIN_INT64_MAGNITUDE) {\r
+ *Result = MIN_INT64;\r
} else {\r
*Result = - ((INT64)UnsignedResult);\r
}\r