1 /* 2 largeint.h 3 4 Header for 64 bit integer arithmetics library 5 6 */ 7 #ifndef _LARGEINT_H 8 #define _LARGEINT_H 9 10 #include <windows.h> 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 #ifdef _HAVE_INT64 17 #define _toi (__int64) 18 #define _toui (unsigned __int64) 19 #else 20 #error "64 bit integers not supported" 21 #endif 22 23 /* 24 We don't let the compiler see the prototypes if we are compiling the 25 library because if it does it will choke on conflicting types in the 26 prototypes. 27 */ 28 29 #if defined(LARGEINT_PROTOS) || defined(__COMPILING_LARGEINT) 30 31 #ifndef __COMPILING_LARGEINT 32 /* addition/subtraction */ 33 LARGE_INTEGER WINAPI LargeIntegerAdd (LARGE_INTEGER, LARGE_INTEGER); 34 LARGE_INTEGER WINAPI LargeIntegerSubtract (LARGE_INTEGER, LARGE_INTEGER); 35 36 /* bit operations */ 37 LARGE_INTEGER WINAPI LargeIntegerArithmeticShift (LARGE_INTEGER, int); 38 LARGE_INTEGER WINAPI LargeIntegerShiftLeft (LARGE_INTEGER, int); 39 LARGE_INTEGER WINAPI LargeIntegerShiftRight (LARGE_INTEGER, int); 40 LARGE_INTEGER WINAPI LargeIntegerNegate (LARGE_INTEGER); 41 42 /* conversion */ 43 LARGE_INTEGER WINAPI ConvertLongToLargeInteger (LONG); 44 LARGE_INTEGER WINAPI ConvertUlongToLargeInteger (ULONG); 45 46 /* multiplication */ 47 LARGE_INTEGER WINAPI EnlargedIntegerMultiply (LONG, LONG); 48 LARGE_INTEGER WINAPI EnlargedUnsignedMultiply (ULONG, ULONG); 49 LARGE_INTEGER WINAPI ExtendedIntegerMultiply (LARGE_INTEGER, LONG); 50 /* FIXME: is this not part of largeint? */ 51 LARGE_INTEGER WINAPI LargeIntegerMultiply (LARGE_INTEGER, LARGE_INTEGER); 52 #endif /* __COMPILING_LARGEINT */ 53 54 #else 55 56 #define LargeIntegerAdd(a,b) (LARGE_INTEGER)(_toi(a) + _toi(b)) 57 #define LargeIntegerSubtract(a,b) (LARGE_INTEGER)(_toi(a) - _toi(b)) 58 #define LargeIntegerRightShift(i,n) (LARGE_INTEGER)(_toi(i) >> (n)) 59 #define LargeIntegerArithmeticShift LargeIntegerRightShift 60 #define LargeIntegerLeftShift(i,n) (LARGE_INTEGER)(_toi(i) << (n)) 61 #define LargeIntegerNegate(i) (LARGE_INTEGER)(- _toi(i)) 62 #define EnlargedIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b)) 63 #define EnlargedUnsignedMultiply(a,b) (LARGE_INTEGER)(_toui(a) * _toui(b)) 64 #define ExtendedIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b)) 65 /* FIXME: should this exist */ 66 #define LargeIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b)) 67 #define ConvertLongToLargeInteger(l) (LARGE_INTEGER)(_toi(l)) 68 #define ConvertUlongToLargeInteger(ul) (LARGE_INTEGER)(_toui(ul)) 69 70 #endif /* LARGEINT_PROTOS || __COMPILING_LARGEINT */ 71 72 #ifndef __COMPILING_LARGEINT 73 /* division; no macros of these because of multiple expansion */ 74 LARGE_INTEGER WINAPI LargeIntegerDivide (LARGE_INTEGER, LARGE_INTEGER, PLARGE_INTEGER); 75 ULONG WINAPI EnlargedUnsignedDivide (ULARGE_INTEGER, ULONG, PULONG); 76 LARGE_INTEGER WINAPI ExtendedLargeIntegerDivide (LARGE_INTEGER, ULONG, PULONG); 77 LARGE_INTEGER WINAPI ExtendedMagicDivide (LARGE_INTEGER, LARGE_INTEGER, int); 78 #endif /* __COMPILING_LARGEINT */ 79 80 #define LargeIntegerAnd(dest, src, m) \ 81 { \ 82 dest._STRUCT_NAME(u.)LowPart = s._STRUCT_NAME(u.)LowPart & m._STRUCT_NAME(u.)LowPart; \ 83 dest._STRUCT_NAME(u.)HighPart = s._STRUCT_NAME(u.)HighPart & m._STRUCT_NAME(u.)HighPart; \ 84 } 85 86 /* comparision */ 87 #define LargeIntegerGreaterThan(a,b) (_toi(a) > _toi(b)) 88 #define LargeIntegerGreaterThanOrEqual(a,b) (_toi(a) >= _toi(b)) 89 #define LargeIntegerEqualTo(a,b) (_toi(a) == _toi(b)) 90 #define LargeIntegerNotEqualTo(a,b) (_toi(a) != _toi(b)) 91 #define LargeIntegerLessThan(a,b) (_toi(a) < _toi(b)) 92 #define LargeIntegerLessThanOrEqualTo(a,b) (_toi(a) <= _toi(b)) 93 #define LargeIntegerGreaterThanZero(a) (_toi(a) > 0) 94 #define LargeIntegerGreaterOrEqualToZero(a) ((a)._STRUCT_NAME(u.)HighPart > 0) 95 #define LargeIntegerEqualToZero(a) !((a)._STRUCT_NAME(u.)LowPart | (a)._STRUCT_NAME(u.)HighPart) 96 #define LargeIntegerNotEqualToZero(a) ((a)._STRUCT_NAME(u.)LowPart | (a)._STRUCT_NAME(u.)HighPart) 97 #define LargeIntegerLessThanZero(a) ((a)._STRUCT_NAME(u.)HighPart < 0) 98 #define LargeIntegerLessOrEqualToZero(a) (_toi(a) <= 0) 99 100 #ifndef __COMPILING_LARGEINT 101 #undef _toi 102 #undef _toui 103 #endif 104 105 #ifdef __cplusplus 106 } 107 #endif 108 109 #endif /* _LARGEINT_H */ 110