1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
---|
2 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
4 | *
|
---|
5 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
6 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
7 | * the License. You may obtain a copy of the License at
|
---|
8 | * http://www.mozilla.org/MPL/
|
---|
9 | *
|
---|
10 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
12 | * for the specific language governing rights and limitations under the
|
---|
13 | * License.
|
---|
14 | *
|
---|
15 | * The Original Code is the Netscape Portable Runtime (NSPR).
|
---|
16 | *
|
---|
17 | * The Initial Developer of the Original Code is
|
---|
18 | * Netscape Communications Corporation.
|
---|
19 | * Portions created by the Initial Developer are Copyright (C) 1998-2000
|
---|
20 | * the Initial Developer. All Rights Reserved.
|
---|
21 | *
|
---|
22 | * Contributor(s):
|
---|
23 | *
|
---|
24 | * Alternatively, the contents of this file may be used under the terms of
|
---|
25 | * either the GNU General Public License Version 2 or later (the "GPL"), or
|
---|
26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
---|
27 | * in which case the provisions of the GPL or the LGPL are applicable instead
|
---|
28 | * of those above. If you wish to allow use of your version of this file only
|
---|
29 | * under the terms of either the GPL or the LGPL, and not to allow others to
|
---|
30 | * use your version of this file under the terms of the MPL, indicate your
|
---|
31 | * decision by deleting the provisions above and replace them with the notice
|
---|
32 | * and other provisions required by the GPL or the LGPL. If you do not delete
|
---|
33 | * the provisions above, a recipient may use your version of this file under
|
---|
34 | * the terms of any one of the MPL, the GPL or the LGPL.
|
---|
35 | *
|
---|
36 | * ***** END LICENSE BLOCK ***** */
|
---|
37 |
|
---|
38 | /*
|
---|
39 | ** File: prlong.h
|
---|
40 | ** Description: Portable access to 64 bit numerics
|
---|
41 | **
|
---|
42 | ** Long-long (64-bit signed integer type) support. Some C compilers
|
---|
43 | ** don't support 64 bit integers yet, so we use these macros to
|
---|
44 | ** support both machines that do and don't.
|
---|
45 | **/
|
---|
46 | #ifndef prlong_h___
|
---|
47 | #define prlong_h___
|
---|
48 |
|
---|
49 | #include "prtypes.h"
|
---|
50 |
|
---|
51 | #ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
|
---|
52 | #define LL_MaxInt VBoxNsllLL_MaxInt
|
---|
53 | #define LL_MaxUint VBoxNsllLL_MaxUint
|
---|
54 | #define LL_MinInt VBoxNsllLL_MinInt
|
---|
55 | #define LL_Zero VBoxNsllLL_Zero
|
---|
56 | #endif /* VBOX_WITH_XPCOM_NAMESPACE_CLEANUP */
|
---|
57 |
|
---|
58 | PR_BEGIN_EXTERN_C
|
---|
59 |
|
---|
60 | /***********************************************************************
|
---|
61 | ** DEFINES: LL_MaxInt
|
---|
62 | ** LL_MinInt
|
---|
63 | ** LL_Zero
|
---|
64 | ** LL_MaxUint
|
---|
65 | ** DESCRIPTION:
|
---|
66 | ** Various interesting constants and static variable
|
---|
67 | ** initializer
|
---|
68 | ***********************************************************************/
|
---|
69 | NSPR_API(PRInt64) LL_MaxInt(void);
|
---|
70 | NSPR_API(PRInt64) LL_MinInt(void);
|
---|
71 | NSPR_API(PRInt64) LL_Zero(void);
|
---|
72 | NSPR_API(PRUint64) LL_MaxUint(void);
|
---|
73 |
|
---|
74 | #define LL_MAXINT LL_MaxInt()
|
---|
75 | #define LL_MININT LL_MinInt()
|
---|
76 | #define LL_ZERO LL_Zero()
|
---|
77 | #define LL_MAXUINT LL_MaxUint()
|
---|
78 |
|
---|
79 | #if PR_BYTES_PER_LONG == 8
|
---|
80 | #define LL_INIT(hi, lo) ((hi ## L << 32) + lo ## L)
|
---|
81 | #elif (defined(WIN32) || defined(WIN16)) && !defined(__GNUC__)
|
---|
82 | #define LL_INIT(hi, lo) ((hi ## i64 << 32) + lo ## i64)
|
---|
83 | #else
|
---|
84 | #define LL_INIT(hi, lo) ((hi ## LL << 32) + lo ## LL)
|
---|
85 | #endif
|
---|
86 |
|
---|
87 | /***********************************************************************
|
---|
88 | ** MACROS: LL_*
|
---|
89 | ** DESCRIPTION:
|
---|
90 | ** The following macros define portable access to the 64 bit
|
---|
91 | ** math facilities.
|
---|
92 | **
|
---|
93 | ***********************************************************************/
|
---|
94 |
|
---|
95 | /***********************************************************************
|
---|
96 | ** MACROS: LL_<relational operators>
|
---|
97 | **
|
---|
98 | ** LL_IS_ZERO Test for zero
|
---|
99 | ** LL_EQ Test for equality
|
---|
100 | ** LL_NE Test for inequality
|
---|
101 | ** LL_GE_ZERO Test for zero or positive
|
---|
102 | ** LL_CMP Compare two values
|
---|
103 | ***********************************************************************/
|
---|
104 | #define LL_IS_ZERO(a) ((a) == 0)
|
---|
105 | #define LL_EQ(a, b) ((a) == (b))
|
---|
106 | #define LL_NE(a, b) ((a) != (b))
|
---|
107 | #define LL_GE_ZERO(a) ((a) >= 0)
|
---|
108 | #define LL_CMP(a, op, b) ((PRInt64)(a) op (PRInt64)(b))
|
---|
109 | #define LL_UCMP(a, op, b) ((PRUint64)(a) op (PRUint64)(b))
|
---|
110 |
|
---|
111 | /***********************************************************************
|
---|
112 | ** MACROS: LL_<logical operators>
|
---|
113 | **
|
---|
114 | ** LL_AND Logical and
|
---|
115 | ** LL_OR Logical or
|
---|
116 | ** LL_XOR Logical exclusion
|
---|
117 | ** LL_OR2 A disgusting deviation
|
---|
118 | ** LL_NOT Negation (one's complement)
|
---|
119 | ***********************************************************************/
|
---|
120 | #define LL_AND(r, a, b) ((r) = (a) & (b))
|
---|
121 | #define LL_OR(r, a, b) ((r) = (a) | (b))
|
---|
122 | #define LL_XOR(r, a, b) ((r) = (a) ^ (b))
|
---|
123 | #define LL_OR2(r, a) ((r) = (r) | (a))
|
---|
124 | #define LL_NOT(r, a) ((r) = ~(a))
|
---|
125 |
|
---|
126 | /***********************************************************************
|
---|
127 | ** MACROS: LL_<mathematical operators>
|
---|
128 | **
|
---|
129 | ** LL_NEG Negation (two's complement)
|
---|
130 | ** LL_ADD Summation (two's complement)
|
---|
131 | ** LL_SUB Difference (two's complement)
|
---|
132 | ***********************************************************************/
|
---|
133 | #define LL_NEG(r, a) ((r) = -(a))
|
---|
134 | #define LL_ADD(r, a, b) ((r) = (a) + (b))
|
---|
135 | #define LL_SUB(r, a, b) ((r) = (a) - (b))
|
---|
136 |
|
---|
137 | /***********************************************************************
|
---|
138 | ** MACROS: LL_<mathematical operators>
|
---|
139 | **
|
---|
140 | ** LL_MUL Product (two's complement)
|
---|
141 | ** LL_DIV Quotient (two's complement)
|
---|
142 | ** LL_MOD Modulus (two's complement)
|
---|
143 | ***********************************************************************/
|
---|
144 | #define LL_MUL(r, a, b) ((r) = (a) * (b))
|
---|
145 | #define LL_DIV(r, a, b) ((r) = (a) / (b))
|
---|
146 | #define LL_MOD(r, a, b) ((r) = (a) % (b))
|
---|
147 |
|
---|
148 | /***********************************************************************
|
---|
149 | ** MACROS: LL_<shifting operators>
|
---|
150 | **
|
---|
151 | ** LL_SHL Shift left [0..64] bits
|
---|
152 | ** LL_SHR Shift right [0..64] bits with sign extension
|
---|
153 | ** LL_USHR Unsigned shift right [0..64] bits
|
---|
154 | ** LL_ISHL Signed shift left [0..64] bits
|
---|
155 | ***********************************************************************/
|
---|
156 | #define LL_SHL(r, a, b) ((r) = (PRInt64)(a) << (b))
|
---|
157 | #define LL_SHR(r, a, b) ((r) = (PRInt64)(a) >> (b))
|
---|
158 | #define LL_USHR(r, a, b) ((r) = (PRUint64)(a) >> (b))
|
---|
159 | #define LL_ISHL(r, a, b) ((r) = (PRInt64)(a) << (b))
|
---|
160 |
|
---|
161 | /***********************************************************************
|
---|
162 | ** MACROS: LL_<conversion operators>
|
---|
163 | **
|
---|
164 | ** LL_L2I Convert to signed 32 bit
|
---|
165 | ** LL_L2UI Convert to unsigned 32 bit
|
---|
166 | ** LL_L2F Convert to floating point
|
---|
167 | ** LL_L2D Convert to floating point
|
---|
168 | ** LL_I2L Convert signed to 64 bit
|
---|
169 | ** LL_UI2L Convert unsigned to 64 bit
|
---|
170 | ** LL_F2L Convert float to 64 bit
|
---|
171 | ** LL_D2L Convert float to 64 bit
|
---|
172 | ***********************************************************************/
|
---|
173 | #define LL_L2I(i, l) ((i) = (PRInt32)(l))
|
---|
174 | #define LL_L2UI(ui, l) ((ui) = (PRUint32)(l))
|
---|
175 | #define LL_L2F(f, l) ((f) = (PRFloat64)(l))
|
---|
176 | #define LL_L2D(d, l) ((d) = (PRFloat64)(l))
|
---|
177 |
|
---|
178 | #define LL_I2L(l, i) ((l) = (PRInt64)(i))
|
---|
179 | #define LL_UI2L(l, ui) ((l) = (PRInt64)(ui))
|
---|
180 | #define LL_F2L(l, f) ((l) = (PRInt64)(f))
|
---|
181 | #define LL_D2L(l, d) ((l) = (PRInt64)(d))
|
---|
182 |
|
---|
183 | /***********************************************************************
|
---|
184 | ** MACROS: LL_UDIVMOD
|
---|
185 | ** DESCRIPTION:
|
---|
186 | ** Produce both a quotient and a remainder given an unsigned
|
---|
187 | ** INPUTS: PRUint64 a: The dividend of the operation
|
---|
188 | ** PRUint64 b: The quotient of the operation
|
---|
189 | ** OUTPUTS: PRUint64 *qp: pointer to quotient
|
---|
190 | ** PRUint64 *rp: pointer to remainder
|
---|
191 | ***********************************************************************/
|
---|
192 | #define LL_UDIVMOD(qp, rp, a, b) \
|
---|
193 | (*(qp) = ((PRUint64)(a) / (b)), \
|
---|
194 | *(rp) = ((PRUint64)(a) % (b)))
|
---|
195 |
|
---|
196 | PR_END_EXTERN_C
|
---|
197 |
|
---|
198 | #endif /* prlong_h___ */
|
---|