VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/prlong.h@ 11551

最後變更 在這個檔案從11551是 11551,由 vboxsync 提交於 16 年 前

API/xpcom: prefix any C symbols in VBoxXPCOM.so, to avoid namespace pollution. Enabled only on Linux at the moment.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 13.9 KB
 
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
58PR_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#if defined(HAVE_WATCOM_BUG_2)
70PRInt64 __pascal __loadds __export
71 LL_MaxInt(void);
72PRInt64 __pascal __loadds __export
73 LL_MinInt(void);
74PRInt64 __pascal __loadds __export
75 LL_Zero(void);
76PRUint64 __pascal __loadds __export
77 LL_MaxUint(void);
78#else
79NSPR_API(PRInt64) LL_MaxInt(void);
80NSPR_API(PRInt64) LL_MinInt(void);
81NSPR_API(PRInt64) LL_Zero(void);
82NSPR_API(PRUint64) LL_MaxUint(void);
83#endif
84
85#define LL_MAXINT LL_MaxInt()
86#define LL_MININT LL_MinInt()
87#define LL_ZERO LL_Zero()
88#define LL_MAXUINT LL_MaxUint()
89
90#if defined(HAVE_LONG_LONG)
91
92#if PR_BYTES_PER_LONG == 8
93#define LL_INIT(hi, lo) ((hi ## L << 32) + lo ## L)
94#elif (defined(WIN32) || defined(WIN16)) && !defined(__GNUC__)
95#define LL_INIT(hi, lo) ((hi ## i64 << 32) + lo ## i64)
96#else
97#define LL_INIT(hi, lo) ((hi ## LL << 32) + lo ## LL)
98#endif
99
100/***********************************************************************
101** MACROS: LL_*
102** DESCRIPTION:
103** The following macros define portable access to the 64 bit
104** math facilities.
105**
106***********************************************************************/
107
108/***********************************************************************
109** MACROS: LL_<relational operators>
110**
111** LL_IS_ZERO Test for zero
112** LL_EQ Test for equality
113** LL_NE Test for inequality
114** LL_GE_ZERO Test for zero or positive
115** LL_CMP Compare two values
116***********************************************************************/
117#define LL_IS_ZERO(a) ((a) == 0)
118#define LL_EQ(a, b) ((a) == (b))
119#define LL_NE(a, b) ((a) != (b))
120#define LL_GE_ZERO(a) ((a) >= 0)
121#define LL_CMP(a, op, b) ((PRInt64)(a) op (PRInt64)(b))
122#define LL_UCMP(a, op, b) ((PRUint64)(a) op (PRUint64)(b))
123
124/***********************************************************************
125** MACROS: LL_<logical operators>
126**
127** LL_AND Logical and
128** LL_OR Logical or
129** LL_XOR Logical exclusion
130** LL_OR2 A disgusting deviation
131** LL_NOT Negation (one's complement)
132***********************************************************************/
133#define LL_AND(r, a, b) ((r) = (a) & (b))
134#define LL_OR(r, a, b) ((r) = (a) | (b))
135#define LL_XOR(r, a, b) ((r) = (a) ^ (b))
136#define LL_OR2(r, a) ((r) = (r) | (a))
137#define LL_NOT(r, a) ((r) = ~(a))
138
139/***********************************************************************
140** MACROS: LL_<mathematical operators>
141**
142** LL_NEG Negation (two's complement)
143** LL_ADD Summation (two's complement)
144** LL_SUB Difference (two's complement)
145***********************************************************************/
146#define LL_NEG(r, a) ((r) = -(a))
147#define LL_ADD(r, a, b) ((r) = (a) + (b))
148#define LL_SUB(r, a, b) ((r) = (a) - (b))
149
150/***********************************************************************
151** MACROS: LL_<mathematical operators>
152**
153** LL_MUL Product (two's complement)
154** LL_DIV Quotient (two's complement)
155** LL_MOD Modulus (two's complement)
156***********************************************************************/
157#define LL_MUL(r, a, b) ((r) = (a) * (b))
158#define LL_DIV(r, a, b) ((r) = (a) / (b))
159#define LL_MOD(r, a, b) ((r) = (a) % (b))
160
161/***********************************************************************
162** MACROS: LL_<shifting operators>
163**
164** LL_SHL Shift left [0..64] bits
165** LL_SHR Shift right [0..64] bits with sign extension
166** LL_USHR Unsigned shift right [0..64] bits
167** LL_ISHL Signed shift left [0..64] bits
168***********************************************************************/
169#define LL_SHL(r, a, b) ((r) = (PRInt64)(a) << (b))
170#define LL_SHR(r, a, b) ((r) = (PRInt64)(a) >> (b))
171#define LL_USHR(r, a, b) ((r) = (PRUint64)(a) >> (b))
172#define LL_ISHL(r, a, b) ((r) = (PRInt64)(a) << (b))
173
174/***********************************************************************
175** MACROS: LL_<conversion operators>
176**
177** LL_L2I Convert to signed 32 bit
178** LL_L2UI Convert to unsigned 32 bit
179** LL_L2F Convert to floating point
180** LL_L2D Convert to floating point
181** LL_I2L Convert signed to 64 bit
182** LL_UI2L Convert unsigned to 64 bit
183** LL_F2L Convert float to 64 bit
184** LL_D2L Convert float to 64 bit
185***********************************************************************/
186#define LL_L2I(i, l) ((i) = (PRInt32)(l))
187#define LL_L2UI(ui, l) ((ui) = (PRUint32)(l))
188#define LL_L2F(f, l) ((f) = (PRFloat64)(l))
189#define LL_L2D(d, l) ((d) = (PRFloat64)(l))
190
191#define LL_I2L(l, i) ((l) = (PRInt64)(i))
192#define LL_UI2L(l, ui) ((l) = (PRInt64)(ui))
193#define LL_F2L(l, f) ((l) = (PRInt64)(f))
194#define LL_D2L(l, d) ((l) = (PRInt64)(d))
195
196/***********************************************************************
197** MACROS: LL_UDIVMOD
198** DESCRIPTION:
199** Produce both a quotient and a remainder given an unsigned
200** INPUTS: PRUint64 a: The dividend of the operation
201** PRUint64 b: The quotient of the operation
202** OUTPUTS: PRUint64 *qp: pointer to quotient
203** PRUint64 *rp: pointer to remainder
204***********************************************************************/
205#define LL_UDIVMOD(qp, rp, a, b) \
206 (*(qp) = ((PRUint64)(a) / (b)), \
207 *(rp) = ((PRUint64)(a) % (b)))
208
209#else /* !HAVE_LONG_LONG */
210
211#ifdef IS_LITTLE_ENDIAN
212#define LL_INIT(hi, lo) {PR_UINT32(lo), PR_UINT32(hi)}
213#else
214#define LL_INIT(hi, lo) {PR_UINT32(hi), PR_UINT32(lo)}
215#endif
216
217#define LL_IS_ZERO(a) (((a).hi == 0) && ((a).lo == 0))
218#define LL_EQ(a, b) (((a).hi == (b).hi) && ((a).lo == (b).lo))
219#define LL_NE(a, b) (((a).hi != (b).hi) || ((a).lo != (b).lo))
220#define LL_GE_ZERO(a) (((a).hi >> 31) == 0)
221
222#define LL_CMP(a, op, b) (((a).hi == (b).hi) ? ((a).lo op (b).lo) : \
223 ((PRInt32)(a).hi op (PRInt32)(b).hi))
224#define LL_UCMP(a, op, b) (((a).hi == (b).hi) ? ((a).lo op (b).lo) : \
225 ((a).hi op (b).hi))
226
227#define LL_AND(r, a, b) ((r).lo = (a).lo & (b).lo, \
228 (r).hi = (a).hi & (b).hi)
229#define LL_OR(r, a, b) ((r).lo = (a).lo | (b).lo, \
230 (r).hi = (a).hi | (b).hi)
231#define LL_XOR(r, a, b) ((r).lo = (a).lo ^ (b).lo, \
232 (r).hi = (a).hi ^ (b).hi)
233#define LL_OR2(r, a) ((r).lo = (r).lo | (a).lo, \
234 (r).hi = (r).hi | (a).hi)
235#define LL_NOT(r, a) ((r).lo = ~(a).lo, \
236 (r).hi = ~(a).hi)
237
238#define LL_NEG(r, a) ((r).lo = -(PRInt32)(a).lo, \
239 (r).hi = -(PRInt32)(a).hi - ((r).lo != 0))
240#define LL_ADD(r, a, b) { \
241 PRInt64 _a, _b; \
242 _a = a; _b = b; \
243 (r).lo = _a.lo + _b.lo; \
244 (r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
245}
246
247#define LL_SUB(r, a, b) { \
248 PRInt64 _a, _b; \
249 _a = a; _b = b; \
250 (r).lo = _a.lo - _b.lo; \
251 (r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
252}
253
254#define LL_MUL(r, a, b) { \
255 PRInt64 _a, _b; \
256 _a = a; _b = b; \
257 LL_MUL32(r, _a.lo, _b.lo); \
258 (r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
259}
260
261#define _lo16(a) ((a) & PR_BITMASK(16))
262#define _hi16(a) ((a) >> 16)
263
264#define LL_MUL32(r, a, b) { \
265 PRUint32 _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
266 _a1 = _hi16(a), _a0 = _lo16(a); \
267 _b1 = _hi16(b), _b0 = _lo16(b); \
268 _y0 = _a0 * _b0; \
269 _y1 = _a0 * _b1; \
270 _y2 = _a1 * _b0; \
271 _y3 = _a1 * _b1; \
272 _y1 += _hi16(_y0); /* can't carry */ \
273 _y1 += _y2; /* might carry */ \
274 if (_y1 < _y2) \
275 _y3 += (PRUint32)(PR_BIT(16)); /* propagate */ \
276 (r).lo = (_lo16(_y1) << 16) + _lo16(_y0); \
277 (r).hi = _y3 + _hi16(_y1); \
278}
279
280#define LL_UDIVMOD(qp, rp, a, b) ll_udivmod(qp, rp, a, b)
281
282NSPR_API(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b);
283
284#define LL_DIV(r, a, b) { \
285 PRInt64 _a, _b; \
286 PRUint32 _negative = (PRInt32)(a).hi < 0; \
287 if (_negative) { \
288 LL_NEG(_a, a); \
289 } else { \
290 _a = a; \
291 } \
292 if ((PRInt32)(b).hi < 0) { \
293 _negative ^= 1; \
294 LL_NEG(_b, b); \
295 } else { \
296 _b = b; \
297 } \
298 LL_UDIVMOD(&(r), 0, _a, _b); \
299 if (_negative) \
300 LL_NEG(r, r); \
301}
302
303#define LL_MOD(r, a, b) { \
304 PRInt64 _a, _b; \
305 PRUint32 _negative = (PRInt32)(a).hi < 0; \
306 if (_negative) { \
307 LL_NEG(_a, a); \
308 } else { \
309 _a = a; \
310 } \
311 if ((PRInt32)(b).hi < 0) { \
312 LL_NEG(_b, b); \
313 } else { \
314 _b = b; \
315 } \
316 LL_UDIVMOD(0, &(r), _a, _b); \
317 if (_negative) \
318 LL_NEG(r, r); \
319}
320
321#define LL_SHL(r, a, b) { \
322 if (b) { \
323 PRInt64 _a; \
324 _a = a; \
325 if ((b) < 32) { \
326 (r).lo = _a.lo << ((b) & 31); \
327 (r).hi = (_a.hi << ((b) & 31)) | (_a.lo >> (32 - (b))); \
328 } else { \
329 (r).lo = 0; \
330 (r).hi = _a.lo << ((b) & 31); \
331 } \
332 } else { \
333 (r) = (a); \
334 } \
335}
336
337/* a is an PRInt32, b is PRInt32, r is PRInt64 */
338#define LL_ISHL(r, a, b) { \
339 if (b) { \
340 PRInt64 _a; \
341 _a.lo = (a); \
342 _a.hi = 0; \
343 if ((b) < 32) { \
344 (r).lo = (a) << ((b) & 31); \
345 (r).hi = ((a) >> (32 - (b))); \
346 } else { \
347 (r).lo = 0; \
348 (r).hi = (a) << ((b) & 31); \
349 } \
350 } else { \
351 (r).lo = (a); \
352 (r).hi = 0; \
353 } \
354}
355
356#define LL_SHR(r, a, b) { \
357 if (b) { \
358 PRInt64 _a; \
359 _a = a; \
360 if ((b) < 32) { \
361 (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
362 (r).hi = (PRInt32)_a.hi >> ((b) & 31); \
363 } else { \
364 (r).lo = (PRInt32)_a.hi >> ((b) & 31); \
365 (r).hi = (PRInt32)_a.hi >> 31; \
366 } \
367 } else { \
368 (r) = (a); \
369 } \
370}
371
372#define LL_USHR(r, a, b) { \
373 if (b) { \
374 PRInt64 _a; \
375 _a = a; \
376 if ((b) < 32) { \
377 (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> ((b) & 31)); \
378 (r).hi = _a.hi >> ((b) & 31); \
379 } else { \
380 (r).lo = _a.hi >> ((b) & 31); \
381 (r).hi = 0; \
382 } \
383 } else { \
384 (r) = (a); \
385 } \
386}
387
388#define LL_L2I(i, l) ((i) = (l).lo)
389#define LL_L2UI(ui, l) ((ui) = (l).lo)
390#define LL_L2F(f, l) { double _d; LL_L2D(_d, l); (f) = (PRFloat64)_d; }
391
392#define LL_L2D(d, l) { \
393 int _negative; \
394 PRInt64 _absval; \
395 \
396 _negative = (l).hi >> 31; \
397 if (_negative) { \
398 LL_NEG(_absval, l); \
399 } else { \
400 _absval = l; \
401 } \
402 (d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
403 if (_negative) \
404 (d) = -(d); \
405}
406
407#define LL_I2L(l, i) { PRInt32 _i = ((PRInt32)(i)) >> 31; (l).lo = (i); (l).hi = _i; }
408#define LL_UI2L(l, ui) ((l).lo = (ui), (l).hi = 0)
409#define LL_F2L(l, f) { double _d = (double)f; LL_D2L(l, _d); }
410
411#define LL_D2L(l, d) { \
412 int _negative; \
413 double _absval, _d_hi; \
414 PRInt64 _lo_d; \
415 \
416 _negative = ((d) < 0); \
417 _absval = _negative ? -(d) : (d); \
418 \
419 (l).hi = _absval / 4.294967296e9; \
420 (l).lo = 0; \
421 LL_L2D(_d_hi, l); \
422 _absval -= _d_hi; \
423 _lo_d.hi = 0; \
424 if (_absval < 0) { \
425 _lo_d.lo = -_absval; \
426 LL_SUB(l, l, _lo_d); \
427 } else { \
428 _lo_d.lo = _absval; \
429 LL_ADD(l, l, _lo_d); \
430 } \
431 \
432 if (_negative) \
433 LL_NEG(l, l); \
434}
435
436#endif /* !HAVE_LONG_LONG */
437
438PR_END_EXTERN_C
439
440#endif /* prlong_h___ */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette