Welcome to mirror list, hosted at ThFree Co, Russian Federation.

largeint.h « include « w32api « winsup - cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b2222a97fc5a591bddc4d159843597c237f3627a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
  largeint.h

  Header for 64 bit integer arithmetics library

 */
#ifndef _LARGEINT_H
#define _LARGEINT_H
#if __GNUC__ >=3
#pragma GCC system_header
#endif

#include <windows.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _HAVE_INT64
#define _toi (__int64)
#define _toui (unsigned __int64)
#else
#error "64 bit integers not supported"
#endif

/*
  We don't let the compiler see the prototypes if we are compiling the
  library because if it does it will choke on conflicting types in the
  prototypes.
*/

#if defined(LARGEINT_PROTOS) || defined(__COMPILING_LARGEINT)

#ifndef __COMPILING_LARGEINT
/* addition/subtraction */
LARGE_INTEGER WINAPI LargeIntegerAdd (LARGE_INTEGER, LARGE_INTEGER);
LARGE_INTEGER WINAPI LargeIntegerSubtract (LARGE_INTEGER, LARGE_INTEGER);

/* bit operations */
LARGE_INTEGER WINAPI LargeIntegerArithmeticShift (LARGE_INTEGER, int);
LARGE_INTEGER WINAPI LargeIntegerShiftLeft (LARGE_INTEGER, int);
LARGE_INTEGER WINAPI LargeIntegerShiftRight (LARGE_INTEGER, int);
LARGE_INTEGER WINAPI LargeIntegerNegate (LARGE_INTEGER);

/* conversion */
LARGE_INTEGER WINAPI ConvertLongToLargeInteger (LONG);
LARGE_INTEGER WINAPI ConvertUlongToLargeInteger (ULONG);

/* multiplication */
LARGE_INTEGER WINAPI EnlargedIntegerMultiply (LONG, LONG);
LARGE_INTEGER WINAPI EnlargedUnsignedMultiply (ULONG, ULONG);
LARGE_INTEGER WINAPI ExtendedIntegerMultiply (LARGE_INTEGER, LONG);
/* FIXME: is this not part of largeint? */
LARGE_INTEGER WINAPI LargeIntegerMultiply (LARGE_INTEGER, LARGE_INTEGER);
#endif /* __COMPILING_LARGEINT */

#else

#define LargeIntegerAdd(a,b) (LARGE_INTEGER)(_toi(a) + _toi(b))
#define LargeIntegerSubtract(a,b) (LARGE_INTEGER)(_toi(a) - _toi(b))
#define LargeIntegerRightShift(i,n) (LARGE_INTEGER)(_toi(i) >> (n))
#define LargeIntegerArithmeticShift LargeIntegerRightShift
#define LargeIntegerLeftShift(i,n) (LARGE_INTEGER)(_toi(i) << (n))
#define LargeIntegerNegate(i) (LARGE_INTEGER)(- _toi(i))
#define EnlargedIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b))
#define EnlargedUnsignedMultiply(a,b) (LARGE_INTEGER)(_toui(a) * _toui(b))
#define ExtendedIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b))
/* FIXME: should this exist */
#define LargeIntegerMultiply(a,b) (LARGE_INTEGER)(_toi(a) * _toi(b))
#define ConvertLongToLargeInteger(l) (LARGE_INTEGER)(_toi(l))
#define ConvertUlongToLargeInteger(ul) (LARGE_INTEGER)(_toui(ul))

#endif /* LARGEINT_PROTOS || __COMPILING_LARGEINT */

#ifndef __COMPILING_LARGEINT
/* division; no macros of these because of multiple expansion */
LARGE_INTEGER WINAPI LargeIntegerDivide (LARGE_INTEGER, LARGE_INTEGER, PLARGE_INTEGER);
ULONG WINAPI EnlargedUnsignedDivide (ULARGE_INTEGER, ULONG, PULONG);
LARGE_INTEGER WINAPI ExtendedLargeIntegerDivide (LARGE_INTEGER, ULONG, PULONG);
LARGE_INTEGER WINAPI ExtendedMagicDivide (LARGE_INTEGER, LARGE_INTEGER, int);
#endif /* __COMPILING_LARGEINT */

#define LargeIntegerAnd(dest, src, m) \
{ \
  dest._STRUCT_NAME(u.)LowPart = s._STRUCT_NAME(u.)LowPart & m._STRUCT_NAME(u.)LowPart; \
  dest._STRUCT_NAME(u.)HighPart = s._STRUCT_NAME(u.)HighPart & m._STRUCT_NAME(u.)HighPart; \
}

/* comparision */
#define LargeIntegerGreaterThan(a,b) (_toi(a) > _toi(b))
#define LargeIntegerGreaterThanOrEqual(a,b) (_toi(a) >= _toi(b))
#define LargeIntegerEqualTo(a,b) (_toi(a) == _toi(b))
#define LargeIntegerNotEqualTo(a,b) (_toi(a) != _toi(b))
#define LargeIntegerLessThan(a,b) (_toi(a) < _toi(b))
#define LargeIntegerLessThanOrEqualTo(a,b) (_toi(a) <= _toi(b))
#define LargeIntegerGreaterThanZero(a) (_toi(a) > 0)
#define LargeIntegerGreaterOrEqualToZero(a) ((a)._STRUCT_NAME(u.)HighPart > 0)
#define LargeIntegerEqualToZero(a) !((a)._STRUCT_NAME(u.)LowPart | (a)._STRUCT_NAME(u.)HighPart)
#define LargeIntegerNotEqualToZero(a) ((a)._STRUCT_NAME(u.)LowPart | (a)._STRUCT_NAME(u.)HighPart)
#define LargeIntegerLessThanZero(a) ((a)._STRUCT_NAME(u.)HighPart < 0)
#define LargeIntegerLessOrEqualToZero(a) (_toi(a) <= 0)

#ifndef __COMPILING_LARGEINT
#undef _toi
#undef _toui
#endif

#ifdef __cplusplus
}
#endif

#endif /* _LARGEINT_H */