Changes in boot/genarch/src/multiplication.c [9539be6:4872160] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/genarch/src/multiplication.c
r9539be6 r4872160 33 33 34 34 #include <genarch/multiplication.h> 35 #include <typedefs.h>36 35 37 /** Set 1 to return INT64_MAX or INT64_MINon overflow */36 /** Set 1 to return MAX_INT64 or MIN_INT64 on overflow */ 38 37 #ifndef SOFTINT_CHECK_OF 39 #define SOFTINT_CHECK_OF 38 #define SOFTINT_CHECK_OF 0 40 39 #endif 40 41 #define MAX_UINT16 (0xFFFFu) 42 #define MAX_UINT32 (0xFFFFFFFFu) 43 #define MAX_INT64 (0x7FFFFFFFFFFFFFFFll) 44 #define MIN_INT64 (0x8000000000000000ll) 41 45 42 46 /** Multiply two integers and return long long as result. … … 47 51 static unsigned long long mul(unsigned int a, unsigned int b) { 48 52 unsigned int a1 = a >> 16; 49 unsigned int a2 = a & UINT16_MAX;53 unsigned int a2 = a & MAX_UINT16; 50 54 unsigned int b1 = b >> 16; 51 unsigned int b2 = b & UINT16_MAX;55 unsigned int b2 = b & MAX_UINT16; 52 56 53 57 unsigned long long t1 = a1 * b1; … … 81 85 unsigned long long b1 = b >> 32; 82 86 83 unsigned long long a2 = a & ( UINT32_MAX);84 unsigned long long b2 = b & ( UINT32_MAX);87 unsigned long long a2 = a & (MAX_UINT32); 88 unsigned long long b2 = b & (MAX_UINT32); 85 89 86 90 if (SOFTINT_CHECK_OF && (a1 != 0) && (b1 != 0)) { 87 91 /* Error (overflow) */ 88 return (neg ? INT64_MIN : INT64_MAX);92 return (neg ? MIN_INT64 : MAX_INT64); 89 93 } 90 94 … … 94 98 unsigned long long t1 = mul(a1, b2) + mul(b1, a2); 95 99 96 if ((SOFTINT_CHECK_OF) && (t1 > UINT32_MAX)) {100 if ((SOFTINT_CHECK_OF) && (t1 > MAX_UINT32)) { 97 101 /* Error (overflow) */ 98 return (neg ? INT64_MIN : INT64_MAX);102 return (neg ? MIN_INT64 : MAX_INT64); 99 103 } 100 104 … … 108 112 if ((SOFTINT_CHECK_OF) && ((t2 < t1) || (t2 & (1ull << 63)))) { 109 113 /* Error (overflow) */ 110 return (neg ? INT64_MIN : INT64_MAX);114 return (neg ? MIN_INT64 : MAX_INT64); 111 115 } 112 116
Note:
See TracChangeset
for help on using the changeset viewer.