Update ooo320-m1
[ooovba.git] / np_sdk / mozsrc / jri_md.h
blob6630a9b777818d982dae5be8f40bc978183cee3d
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Netscape Public License
6 * Version 1.1 (the "License"); you may not use this file except in
7 * compliance with the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/NPL/
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.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
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 NPL, 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 NPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /*******************************************************************************
39 * Java Runtime Interface - Machine Dependent Types
40 ******************************************************************************/
42 #ifndef JRI_MD_H
43 #define JRI_MD_H
45 #include <assert.h>
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
51 /*******************************************************************************
52 * WHAT'S UP WITH THIS FILE?
54 * This is where we define the mystical JRI_PUBLIC_API macro that works on all
55 * platforms. If you're running with Visual C++, Symantec C, or Borland's
56 * development environment on the PC, you're all set. Or if you're on the Mac
57 * with Metrowerks, Symantec or MPW with SC you're ok too. For UNIX it shouldn't
58 * matter.
60 * On UNIX though you probably care about a couple of other symbols though:
61 * IS_LITTLE_ENDIAN must be defined for little-endian systems
62 * HAVE_LONG_LONG must be defined on systems that have 'long long' integers
63 * HAVE_ALIGNED_LONGLONGS must be defined if long-longs must be 8 byte aligned
64 * HAVE_ALIGNED_DOUBLES must be defined if doubles must be 8 byte aligned
65 * IS_64 must be defined on 64-bit machines (like Dec Alpha)
66 ******************************************************************************/
68 /* DLL Entry modifiers... */
70 /* PC */
71 #if defined(XP_OS2)
72 # ifdef XP_OS2_VACPP
73 # define JRI_PUBLIC_API(ResultType) ResultType _Optlink
74 # define JRI_PUBLIC_VAR(VarType) VarType
75 # define JRI_CALLBACK
76 # else
77 # define JRI_PUBLIC_API(ResultType) ResultType
78 # define JRI_PUBLIC_VAR(VarType) VarType
79 # define JRI_CALLBACK
80 # endif
81 #elif defined(XP_PC) || defined(_WINDOWS) || defined(WIN32) || defined(_WIN32)
82 # include <windows.h>
83 # if defined(_MSC_VER) || defined(__MINGW32__)
84 # if defined(WIN32) || defined(_WIN32)
85 # define JRI_PUBLIC_API(ResultType) _declspec(dllexport) ResultType
86 # define JRI_PUBLIC_VAR(VarType) VarType
87 # define JRI_PUBLIC_VAR_EXP(VarType) _declspec(dllexport) VarType
88 # define JRI_PUBLIC_VAR_IMP(VarType) _declspec(dllimport) VarType
89 # define JRI_NATIVE_STUB(ResultType) _declspec(dllexport) ResultType
90 # define JRI_CALLBACK
91 # else /* !_WIN32 */
92 # if defined(_WINDLL)
93 # define JRI_PUBLIC_API(ResultType) ResultType __cdecl __export __loadds
94 # define JRI_PUBLIC_VAR(VarType) VarType
95 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
96 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
97 # define JRI_NATIVE_STUB(ResultType) ResultType __cdecl __loadds
98 # define JRI_CALLBACK __loadds
99 # else /* !WINDLL */
100 # define JRI_PUBLIC_API(ResultType) ResultType __cdecl __export
101 # define JRI_PUBLIC_VAR(VarType) VarType
102 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
103 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
104 # define JRI_NATIVE_STUB(ResultType) ResultType __cdecl __export
105 # define JRI_CALLBACK __export
106 # endif /* !WINDLL */
107 # endif /* !_WIN32 */
108 # elif defined(__BORLANDC__)
109 # if defined(WIN32) || defined(_WIN32)
110 # define JRI_PUBLIC_API(ResultType) __export ResultType
111 # define JRI_PUBLIC_VAR(VarType) VarType
112 # define JRI_PUBLIC_VAR_EXP(VarType) __export VarType
113 # define JRI_PUBLIC_VAR_IMP(VarType) __import VarType
114 # define JRI_NATIVE_STUB(ResultType) __export ResultType
115 # define JRI_CALLBACK
116 # else /* !_WIN32 */
117 # define JRI_PUBLIC_API(ResultType) ResultType _cdecl _export _loadds
118 # define JRI_PUBLIC_VAR(VarType) VarType
119 # define JRI_PUBLIC_VAR_EXP(VarType) __cdecl __export VarType
120 # define JRI_PUBLIC_VAR_IMP(VarType) __cdecl __import VarType
121 # define JRI_NATIVE_STUB(ResultType) ResultType _cdecl _loadds
122 # define JRI_CALLBACK _loadds
123 # endif
124 # else
125 # error Unsupported PC development environment.
126 # endif
127 # ifndef IS_LITTLE_ENDIAN
128 # define IS_LITTLE_ENDIAN
129 # endif
131 /* Mac */
132 #elif defined (macintosh) || Macintosh || THINK_C
133 # if defined(__MWERKS__) /* Metrowerks */
134 # if !__option(enumsalwaysint)
135 # error You need to define 'Enums Always Int' for your project.
136 # endif
137 # if defined(TARGET_CPU_68K) && !TARGET_RT_MAC_CFM
138 # if !__option(fourbyteints)
139 # error You need to define 'Struct Alignment: 68k' for your project.
140 # endif
141 # endif /* !GENERATINGCFM */
142 # define JRI_PUBLIC_API(ResultType) __declspec(export) ResultType
143 # define JRI_PUBLIC_VAR(VarType) JRI_PUBLIC_API(VarType)
144 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_API(VarType)
145 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_API(VarType)
146 # define JRI_NATIVE_STUB(ResultType) JRI_PUBLIC_API(ResultType)
147 # elif defined(__SC__) /* Symantec */
148 # error What are the Symantec defines? (warren@netscape.com)
149 # elif macintosh && applec /* MPW */
150 # error Please upgrade to the latest MPW compiler (SC).
151 # else
152 # error Unsupported Mac development environment.
153 # endif
154 # define JRI_CALLBACK
156 /* Unix or else */
157 #else
158 # define JRI_PUBLIC_API(ResultType) ResultType
159 # define JRI_PUBLIC_VAR(VarType) VarType
160 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
161 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
162 # define JRI_NATIVE_STUB(ResultType) ResultType
163 # define JRI_CALLBACK
164 #endif
166 #ifndef FAR /* for non-Win16 */
167 #define FAR
168 #endif
170 /******************************************************************************/
172 /* Java Scalar Types */
174 #if 0 /* now in jni.h */
175 typedef short jchar;
176 typedef short jshort;
177 typedef float jfloat;
178 typedef double jdouble;
179 typedef juint jsize;
180 #endif
182 /* moved from jni.h -- Sun's new jni.h doesn't have this anymore */
183 #ifdef __cplusplus
184 typedef class _jobject *jref;
185 #else
186 typedef struct _jobject *jref;
187 #endif
189 typedef unsigned char jbool;
190 typedef char jbyte;
191 typedef short jchar;
192 typedef short jshort;
193 #ifdef IS_64 /* XXX ok for alpha, but not right on all 64-bit architectures */
194 typedef unsigned int juint;
195 typedef int jint;
196 #else
197 typedef unsigned long juint;
198 typedef long jint;
199 #endif
201 typedef float jfloat;
202 typedef double jdouble;
204 typedef juint jsize;
207 /*******************************************************************************
208 * jlong : long long (64-bit signed integer type) support.
209 ******************************************************************************/
212 ** Bit masking macros. (n must be <= 31 to be portable)
214 #define JRI_BIT(n) ((juint)1 << (n))
215 #define JRI_BITMASK(n) (JRI_BIT(n) - 1)
217 #ifdef HAVE_LONG_LONG
219 #ifdef OSF1
221 /* long is default 64-bit on OSF1, -std1 does not allow long long */
222 typedef long jlong;
223 typedef unsigned long julong;
224 #define jlong_MAXINT 0x7fffffffffffffffL
225 #define jlong_MININT 0x8000000000000000L
226 #define jlong_ZERO 0x0L
228 #elif (defined(WIN32) || defined(_WIN32))
230 typedef LONGLONG jlong;
231 typedef DWORDLONG julong;
232 #define jlong_MAXINT 0x7fffffffffffffffi64
233 #define jlong_MININT 0x8000000000000000i64
234 #define jlong_ZERO 0x0i64
236 #else
238 typedef long long jlong;
239 typedef unsigned long long julong;
240 #define jlong_MAXINT 0x7fffffffffffffffLL
241 #define jlong_MININT 0x8000000000000000LL
242 #define jlong_ZERO 0x0LL
244 #endif
246 #define jlong_IS_ZERO(a) ((a) == 0)
247 #define jlong_EQ(a, b) ((a) == (b))
248 #define jlong_NE(a, b) ((a) != (b))
249 #define jlong_GE_ZERO(a) ((a) >= 0)
250 #define jlong_CMP(a, op, b) ((a) op (b))
252 #define jlong_AND(r, a, b) ((r) = (a) & (b))
253 #define jlong_OR(r, a, b) ((r) = (a) | (b))
254 #define jlong_XOR(r, a, b) ((r) = (a) ^ (b))
255 #define jlong_OR2(r, a) ((r) = (r) | (a))
256 #define jlong_NOT(r, a) ((r) = ~(a))
258 #define jlong_NEG(r, a) ((r) = -(a))
259 #define jlong_ADD(r, a, b) ((r) = (a) + (b))
260 #define jlong_SUB(r, a, b) ((r) = (a) - (b))
262 #define jlong_MUL(r, a, b) ((r) = (a) * (b))
263 #define jlong_DIV(r, a, b) ((r) = (a) / (b))
264 #define jlong_MOD(r, a, b) ((r) = (a) % (b))
266 #define jlong_SHL(r, a, b) ((r) = (a) << (b))
267 #define jlong_SHR(r, a, b) ((r) = (a) >> (b))
268 #define jlong_USHR(r, a, b) ((r) = (julong)(a) >> (b))
269 #define jlong_ISHL(r, a, b) ((r) = ((jlong)(a)) << (b))
271 #define jlong_L2I(i, l) ((i) = (int)(l))
272 #define jlong_L2UI(ui, l) ((ui) =(unsigned int)(l))
273 #define jlong_L2F(f, l) ((f) = (l))
274 #define jlong_L2D(d, l) ((d) = (l))
276 #define jlong_I2L(l, i) ((l) = (i))
277 #define jlong_UI2L(l, ui) ((l) = (ui))
278 #define jlong_F2L(l, f) ((l) = (f))
279 #define jlong_D2L(l, d) ((l) = (d))
281 #define jlong_UDIVMOD(qp, rp, a, b) \
282 (*(qp) = ((julong)(a) / (b)), \
283 *(rp) = ((julong)(a) % (b)))
285 #else /* !HAVE_LONG_LONG */
287 typedef struct {
288 #ifdef IS_LITTLE_ENDIAN
289 juint lo, hi;
290 #else
291 juint hi, lo;
292 #endif
293 } jlong;
294 typedef jlong julong;
296 extern jlong jlong_MAXINT, jlong_MININT, jlong_ZERO;
298 #define jlong_IS_ZERO(a) (((a).hi == 0) && ((a).lo == 0))
299 #define jlong_EQ(a, b) (((a).hi == (b).hi) && ((a).lo == (b).lo))
300 #define jlong_NE(a, b) (((a).hi != (b).hi) || ((a).lo != (b).lo))
301 #define jlong_GE_ZERO(a) (((a).hi >> 31) == 0)
304 * NB: jlong_CMP and jlong_UCMP work only for strict relationals (<, >).
306 #define jlong_CMP(a, op, b) (((int32)(a).hi op (int32)(b).hi) || \
307 (((a).hi == (b).hi) && ((a).lo op (b).lo)))
308 #define jlong_UCMP(a, op, b) (((a).hi op (b).hi) || \
309 (((a).hi == (b).hi) && ((a).lo op (b).lo)))
311 #define jlong_AND(r, a, b) ((r).lo = (a).lo & (b).lo, \
312 (r).hi = (a).hi & (b).hi)
313 #define jlong_OR(r, a, b) ((r).lo = (a).lo | (b).lo, \
314 (r).hi = (a).hi | (b).hi)
315 #define jlong_XOR(r, a, b) ((r).lo = (a).lo ^ (b).lo, \
316 (r).hi = (a).hi ^ (b).hi)
317 #define jlong_OR2(r, a) ((r).lo = (r).lo | (a).lo, \
318 (r).hi = (r).hi | (a).hi)
319 #define jlong_NOT(r, a) ((r).lo = ~(a).lo, \
320 (r).hi = ~(a).hi)
322 #define jlong_NEG(r, a) ((r).lo = -(int32)(a).lo, \
323 (r).hi = -(int32)(a).hi - ((r).lo != 0))
324 #define jlong_ADD(r, a, b) { \
325 jlong _a, _b; \
326 _a = a; _b = b; \
327 (r).lo = _a.lo + _b.lo; \
328 (r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
331 #define jlong_SUB(r, a, b) { \
332 jlong _a, _b; \
333 _a = a; _b = b; \
334 (r).lo = _a.lo - _b.lo; \
335 (r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
339 * Multiply 64-bit operands a and b to get 64-bit result r.
340 * First multiply the low 32 bits of a and b to get a 64-bit result in r.
341 * Then add the outer and inner products to r.hi.
343 #define jlong_MUL(r, a, b) { \
344 jlong _a, _b; \
345 _a = a; _b = b; \
346 jlong_MUL32(r, _a.lo, _b.lo); \
347 (r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
350 /* XXX _jlong_lo16(a) = ((a) << 16 >> 16) is better on some archs (not on mips) */
351 #define _jlong_lo16(a) ((a) & JRI_BITMASK(16))
352 #define _jlong_hi16(a) ((a) >> 16)
355 * Multiply 32-bit operands a and b to get 64-bit result r.
356 * Use polynomial expansion based on primitive field element (1 << 16).
358 #define jlong_MUL32(r, a, b) { \
359 juint _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
360 _a1 = _jlong_hi16(a), _a0 = _jlong_lo16(a); \
361 _b1 = _jlong_hi16(b), _b0 = _jlong_lo16(b); \
362 _y0 = _a0 * _b0; \
363 _y1 = _a0 * _b1; \
364 _y2 = _a1 * _b0; \
365 _y3 = _a1 * _b1; \
366 _y1 += _jlong_hi16(_y0); /* can't carry */ \
367 _y1 += _y2; /* might carry */ \
368 if (_y1 < _y2) _y3 += 1 << 16; /* propagate */ \
369 (r).lo = (_jlong_lo16(_y1) << 16) + _jlong_lo16(_y0); \
370 (r).hi = _y3 + _jlong_hi16(_y1); \
374 * Divide 64-bit unsigned operand a by 64-bit unsigned operand b, setting *qp
375 * to the 64-bit unsigned quotient, and *rp to the 64-bit unsigned remainder.
376 * Minimize effort if one of qp and rp is null.
378 #define jlong_UDIVMOD(qp, rp, a, b) jlong_udivmod(qp, rp, a, b)
380 extern JRI_PUBLIC_API(void)
381 jlong_udivmod(julong *qp, julong *rp, julong a, julong b);
383 #define jlong_DIV(r, a, b) { \
384 jlong _a, _b; \
385 juint _negative = (int32)(a).hi < 0; \
386 if (_negative) { \
387 jlong_NEG(_a, a); \
388 } else { \
389 _a = a; \
391 if ((int32)(b).hi < 0) { \
392 _negative ^= 1; \
393 jlong_NEG(_b, b); \
394 } else { \
395 _b = b; \
397 jlong_UDIVMOD(&(r), 0, _a, _b); \
398 if (_negative) \
399 jlong_NEG(r, r); \
402 #define jlong_MOD(r, a, b) { \
403 jlong _a, _b; \
404 juint _negative = (int32)(a).hi < 0; \
405 if (_negative) { \
406 jlong_NEG(_a, a); \
407 } else { \
408 _a = a; \
410 if ((int32)(b).hi < 0) { \
411 jlong_NEG(_b, b); \
412 } else { \
413 _b = b; \
415 jlong_UDIVMOD(0, &(r), _a, _b); \
416 if (_negative) \
417 jlong_NEG(r, r); \
421 * NB: b is a juint, not jlong or julong, for the shift ops.
423 #define jlong_SHL(r, a, b) { \
424 if (b) { \
425 jlong _a; \
426 _a = a; \
427 if ((b) < 32) { \
428 (r).lo = _a.lo << (b); \
429 (r).hi = (_a.hi << (b)) | (_a.lo >> (32 - (b))); \
430 } else { \
431 (r).lo = 0; \
432 (r).hi = _a.lo << ((b) & 31); \
434 } else { \
435 (r) = (a); \
439 /* a is an int32, b is int32, r is jlong */
440 #define jlong_ISHL(r, a, b) { \
441 if (b) { \
442 jlong _a; \
443 _a.lo = (a); \
444 _a.hi = 0; \
445 if ((b) < 32) { \
446 (r).lo = (a) << (b); \
447 (r).hi = ((a) >> (32 - (b))); \
448 } else { \
449 (r).lo = 0; \
450 (r).hi = (a) << ((b) & 31); \
452 } else { \
453 (r).lo = (a); \
454 (r).hi = 0; \
458 #define jlong_SHR(r, a, b) { \
459 if (b) { \
460 jlong _a; \
461 _a = a; \
462 if ((b) < 32) { \
463 (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> (b)); \
464 (r).hi = (int32)_a.hi >> (b); \
465 } else { \
466 (r).lo = (int32)_a.hi >> ((b) & 31); \
467 (r).hi = (int32)_a.hi >> 31; \
469 } else { \
470 (r) = (a); \
474 #define jlong_USHR(r, a, b) { \
475 if (b) { \
476 jlong _a; \
477 _a = a; \
478 if ((b) < 32) { \
479 (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> (b)); \
480 (r).hi = _a.hi >> (b); \
481 } else { \
482 (r).lo = _a.hi >> ((b) & 31); \
483 (r).hi = 0; \
485 } else { \
486 (r) = (a); \
490 #define jlong_L2I(i, l) ((i) = (l).lo)
491 #define jlong_L2UI(ui, l) ((ui) = (l).lo)
492 #define jlong_L2F(f, l) { double _d; jlong_L2D(_d, l); (f) = (float) _d; }
494 #define jlong_L2D(d, l) { \
495 int32 _negative; \
496 jlong _absval; \
498 _negative = (l).hi >> 31; \
499 if (_negative) { \
500 jlong_NEG(_absval, l); \
501 } else { \
502 _absval = l; \
504 (d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
505 if (_negative) \
506 (d) = -(d); \
509 #define jlong_I2L(l, i) ((l).hi = (i) >> 31, (l).lo = (i))
510 #define jlong_UI2L(l, ui) ((l).hi = 0, (l).lo = (ui))
511 #define jlong_F2L(l, f) { double _d = (double) f; jlong_D2L(l, _d); }
513 #define jlong_D2L(l, d) { \
514 int _negative; \
515 double _absval, _d_hi; \
516 jlong _lo_d; \
518 _negative = ((d) < 0); \
519 _absval = _negative ? -(d) : (d); \
521 (l).hi = (juint)(_absval / 4.294967296e9); \
522 (l).lo = 0; \
523 jlong_L2D(_d_hi, l); \
524 _absval -= _d_hi; \
525 _lo_d.hi = 0; \
526 if (_absval < 0) { \
527 _lo_d.lo = (juint) -_absval; \
528 jlong_SUB(l, l, _lo_d); \
529 } else { \
530 _lo_d.lo = (juint) _absval; \
531 jlong_ADD(l, l, _lo_d); \
534 if (_negative) \
535 jlong_NEG(l, l); \
538 #endif /* !HAVE_LONG_LONG */
540 /******************************************************************************/
542 #ifdef HAVE_ALIGNED_LONGLONGS
543 #define JRI_GET_INT64(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \
544 ((_t).x[1] = ((jint*)(_addr))[1]), \
545 (_t).l )
546 #define JRI_SET_INT64(_t, _addr, _v) ( (_t).l = (_v), \
547 ((jint*)(_addr))[0] = (_t).x[0], \
548 ((jint*)(_addr))[1] = (_t).x[1] )
549 #else
550 #define JRI_GET_INT64(_t,_addr) (*(jlong*)(_addr))
551 #define JRI_SET_INT64(_t, _addr, _v) (*(jlong*)(_addr) = (_v))
552 #endif
554 /* If double's must be aligned on doubleword boundaries then define this */
555 #ifdef HAVE_ALIGNED_DOUBLES
556 #define JRI_GET_DOUBLE(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \
557 ((_t).x[1] = ((jint*)(_addr))[1]), \
558 (_t).d )
559 #define JRI_SET_DOUBLE(_t, _addr, _v) ( (_t).d = (_v), \
560 ((jint*)(_addr))[0] = (_t).x[0], \
561 ((jint*)(_addr))[1] = (_t).x[1] )
562 #else
563 #define JRI_GET_DOUBLE(_t,_addr) (*(jdouble*)(_addr))
564 #define JRI_SET_DOUBLE(_t, _addr, _v) (*(jdouble*)(_addr) = (_v))
565 #endif
567 /******************************************************************************/
568 #ifdef __cplusplus
570 #endif
571 #endif /* JRI_MD_H */
572 /******************************************************************************/