add more spacing
[personal-kdebase.git] / apps / nsplugins / sdk / jri_md.h
blobb759187f1ae55789492ff023f8b30711a2d6fb3b
1 //krazy:excludeall=license,copyright
2 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Netscape Public License
7 * Version 1.1 (the "License"); you may not use this file except in
8 * compliance with the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/NPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the NPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the NPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 /*******************************************************************************
40 * Java Runtime Interface - Machine Dependent Types
41 ******************************************************************************/
43 #ifndef JRI_MD_H
44 #define JRI_MD_H
46 #include <assert.h>
47 #include "prtypes.h" /* Needed for HAS_LONG_LONG ifdefs & _declspec */
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
53 /*******************************************************************************
54 * WHAT'S UP WITH THIS FILE?
56 * This is where we define the mystical JRI_PUBLIC_API macro that works on all
57 * platforms. If you're running with Visual C++, Symantec C, or Borland's
58 * development environment on the PC, you're all set. Or if you're on the Mac
59 * with Metrowerks, Symantec or MPW with SC you're ok too. For UNIX it shouldn't
60 * matter.
62 * On UNIX though you probably care about a couple of other symbols though:
63 * IS_LITTLE_ENDIAN must be defined for little-endian systems
64 * HAVE_LONG_LONG must be defined on systems that have 'long long' integers
65 * HAVE_ALIGNED_LONGLONGS must be defined if long-longs must be 8 byte aligned
66 * HAVE_ALIGNED_DOUBLES must be defined if doubles must be 8 byte aligned
67 * IS_64 must be defined on 64-bit machines (like Dec Alpha)
68 ******************************************************************************/
70 /* DLL Entry modifiers... */
72 /* PC */
73 #if defined(XP_OS2)
74 # ifdef XP_OS2_VACPP
75 # define JRI_PUBLIC_API(ResultType) ResultType _Optlink
76 # define JRI_PUBLIC_VAR(VarType) VarType
77 # define JRI_CALLBACK
78 # else
79 # define JRI_PUBLIC_API(ResultType) ResultType
80 # define JRI_PUBLIC_VAR(VarType) VarType
81 # define JRI_CALLBACK
82 # endif
83 #elif defined(XP_WIN) || defined(_WINDOWS) || defined(WIN32) || defined(_WIN32)
84 # include <windows.h>
85 # if defined(_MSC_VER) || defined(__GNUC__)
86 # if defined(WIN32) || defined(_WIN32)
87 # define JRI_PUBLIC_API(ResultType) _declspec(dllexport) ResultType
88 # define JRI_PUBLIC_VAR(VarType) VarType
89 # define JRI_PUBLIC_VAR_EXP(VarType) _declspec(dllexport) VarType
90 # define JRI_PUBLIC_VAR_IMP(VarType) _declspec(dllimport) VarType
91 # define JRI_NATIVE_STUB(ResultType) _declspec(dllexport) ResultType
92 # define JRI_CALLBACK
93 # else /* !_WIN32 */
94 # if defined(_WINDLL)
95 # define JRI_PUBLIC_API(ResultType) ResultType __cdecl __export __loadds
96 # define JRI_PUBLIC_VAR(VarType) VarType
97 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
98 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
99 # define JRI_NATIVE_STUB(ResultType) ResultType __cdecl __loadds
100 # define JRI_CALLBACK __loadds
101 # else /* !WINDLL */
102 # define JRI_PUBLIC_API(ResultType) ResultType __cdecl __export
103 # define JRI_PUBLIC_VAR(VarType) VarType
104 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
105 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
106 # define JRI_NATIVE_STUB(ResultType) ResultType __cdecl __export
107 # define JRI_CALLBACK __export
108 # endif /* !WINDLL */
109 # endif /* !_WIN32 */
110 # elif defined(__BORLANDC__)
111 # if defined(WIN32) || defined(_WIN32)
112 # define JRI_PUBLIC_API(ResultType) __export ResultType
113 # define JRI_PUBLIC_VAR(VarType) VarType
114 # define JRI_PUBLIC_VAR_EXP(VarType) __export VarType
115 # define JRI_PUBLIC_VAR_IMP(VarType) __import VarType
116 # define JRI_NATIVE_STUB(ResultType) __export ResultType
117 # define JRI_CALLBACK
118 # else /* !_WIN32 */
119 # define JRI_PUBLIC_API(ResultType) ResultType _cdecl _export _loadds
120 # define JRI_PUBLIC_VAR(VarType) VarType
121 # define JRI_PUBLIC_VAR_EXP(VarType) __cdecl __export VarType
122 # define JRI_PUBLIC_VAR_IMP(VarType) __cdecl __import VarType
123 # define JRI_NATIVE_STUB(ResultType) ResultType _cdecl _loadds
124 # define JRI_CALLBACK _loadds
125 # endif
126 # else
127 # error Unsupported PC development environment.
128 # endif
129 # ifndef IS_LITTLE_ENDIAN
130 # define IS_LITTLE_ENDIAN
131 # endif
133 /* Mac */
134 #elif defined (macintosh) || defined(Macintosh) || defined(THINK_C)
135 # if defined(__MWERKS__) /* Metrowerks */
136 # if !__option(enumsalwaysint)
137 # error You need to define 'Enums Always Int' for your project.
138 # endif
139 # if defined(TARGET_CPU_68K) && !TARGET_RT_MAC_CFM
140 # if !__option(fourbyteints)
141 # error You need to define 'Struct Alignment: 68k' for your project.
142 # endif
143 # endif /* !GENERATINGCFM */
144 # define JRI_PUBLIC_API(ResultType) __declspec(export) ResultType
145 # define JRI_PUBLIC_VAR(VarType) JRI_PUBLIC_API(VarType)
146 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_API(VarType)
147 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_API(VarType)
148 # define JRI_NATIVE_STUB(ResultType) JRI_PUBLIC_API(ResultType)
149 # elif defined(__SC__) /* Symantec */
150 # error What are the Symantec defines? (warren@netscape.com)
151 # elif macintosh && applec /* MPW */
152 # error Please upgrade to the latest MPW compiler (SC).
153 # else
154 # error Unsupported Mac development environment.
155 # endif
156 # define JRI_CALLBACK
158 /* Unix or else */
159 #else
160 # define JRI_PUBLIC_API(ResultType) ResultType
161 # define JRI_PUBLIC_VAR(VarType) VarType
162 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
163 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
164 # define JRI_NATIVE_STUB(ResultType) ResultType
165 # define JRI_CALLBACK
166 #endif
168 #ifndef FAR /* for non-Win16 */
169 #define FAR
170 #endif
172 /******************************************************************************/
174 /* Java Scalar Types */
176 #if 0 /* now in jni.h */
177 typedef short jchar;
178 typedef short jshort;
179 typedef float jfloat;
180 typedef double jdouble;
181 typedef juint jsize;
182 #endif
184 /* moved from jni.h -- Sun's new jni.h doesn't have this anymore */
185 #ifdef __cplusplus
186 typedef class _jobject *jref;
187 #else
188 typedef struct _jobject *jref;
189 #endif
191 typedef unsigned char jbool;
192 typedef signed char jbyte;
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 /*******************************************************************************
202 * jlong : long long (64-bit signed integer type) support.
203 ******************************************************************************/
206 ** Bit masking macros. (n must be <= 31 to be portable)
208 #define JRI_BIT(n) ((juint)1 << (n))
209 #define JRI_BITMASK(n) (JRI_BIT(n) - 1)
211 #ifdef HAVE_LONG_LONG
213 #ifdef OSF1
215 /* long is default 64-bit on OSF1, -std1 does not allow long long */
216 typedef long jlong;
217 typedef unsigned long julong;
218 #define jlong_MAXINT 0x7fffffffffffffffL
219 #define jlong_MININT 0x8000000000000000L
220 #define jlong_ZERO 0x0L
222 #elif (defined(WIN32) || defined(_WIN32))
224 typedef LONGLONG jlong;
225 typedef DWORDLONG julong;
226 #define jlong_MAXINT 0x7fffffffffffffffi64
227 #define jlong_MININT 0x8000000000000000i64
228 #define jlong_ZERO 0x0i64
230 #else
232 typedef long long jlong;
233 typedef unsigned long long julong;
234 #define jlong_MAXINT 0x7fffffffffffffffLL
235 #define jlong_MININT 0x8000000000000000LL
236 #define jlong_ZERO 0x0LL
238 #endif
240 #define jlong_IS_ZERO(a) ((a) == 0)
241 #define jlong_EQ(a, b) ((a) == (b))
242 #define jlong_NE(a, b) ((a) != (b))
243 #define jlong_GE_ZERO(a) ((a) >= 0)
244 #define jlong_CMP(a, op, b) ((a) op (b))
246 #define jlong_AND(r, a, b) ((r) = (a) & (b))
247 #define jlong_OR(r, a, b) ((r) = (a) | (b))
248 #define jlong_XOR(r, a, b) ((r) = (a) ^ (b))
249 #define jlong_OR2(r, a) ((r) = (r) | (a))
250 #define jlong_NOT(r, a) ((r) = ~(a))
252 #define jlong_NEG(r, a) ((r) = -(a))
253 #define jlong_ADD(r, a, b) ((r) = (a) + (b))
254 #define jlong_SUB(r, a, b) ((r) = (a) - (b))
256 #define jlong_MUL(r, a, b) ((r) = (a) * (b))
257 #define jlong_DIV(r, a, b) ((r) = (a) / (b))
258 #define jlong_MOD(r, a, b) ((r) = (a) % (b))
260 #define jlong_SHL(r, a, b) ((r) = (a) << (b))
261 #define jlong_SHR(r, a, b) ((r) = (a) >> (b))
262 #define jlong_USHR(r, a, b) ((r) = (julong)(a) >> (b))
263 #define jlong_ISHL(r, a, b) ((r) = ((jlong)(a)) << (b))
265 #define jlong_L2I(i, l) ((i) = (int)(l))
266 #define jlong_L2UI(ui, l) ((ui) =(unsigned int)(l))
267 #define jlong_L2F(f, l) ((f) = (l))
268 #define jlong_L2D(d, l) ((d) = (l))
270 #define jlong_I2L(l, i) ((l) = (i))
271 #define jlong_UI2L(l, ui) ((l) = (ui))
272 #define jlong_F2L(l, f) ((l) = (f))
273 #define jlong_D2L(l, d) ((l) = (d))
275 #define jlong_UDIVMOD(qp, rp, a, b) \
276 (*(qp) = ((julong)(a) / (b)), \
277 *(rp) = ((julong)(a) % (b)))
279 #else /* !HAVE_LONG_LONG */
281 typedef struct {
282 #ifdef IS_LITTLE_ENDIAN
283 juint lo, hi;
284 #else
285 juint hi, lo;
286 #endif
287 } jlong;
288 typedef jlong julong;
290 extern jlong jlong_MAXINT, jlong_MININT, jlong_ZERO;
292 #define jlong_IS_ZERO(a) (((a).hi == 0) && ((a).lo == 0))
293 #define jlong_EQ(a, b) (((a).hi == (b).hi) && ((a).lo == (b).lo))
294 #define jlong_NE(a, b) (((a).hi != (b).hi) || ((a).lo != (b).lo))
295 #define jlong_GE_ZERO(a) (((a).hi >> 31) == 0)
298 * NB: jlong_CMP and jlong_UCMP work only for strict relationals (<, >).
300 #define jlong_CMP(a, op, b) (((int32)(a).hi op (int32)(b).hi) || \
301 (((a).hi == (b).hi) && ((a).lo op (b).lo)))
302 #define jlong_UCMP(a, op, b) (((a).hi op (b).hi) || \
303 (((a).hi == (b).hi) && ((a).lo op (b).lo)))
305 #define jlong_AND(r, a, b) ((r).lo = (a).lo & (b).lo, \
306 (r).hi = (a).hi & (b).hi)
307 #define jlong_OR(r, a, b) ((r).lo = (a).lo | (b).lo, \
308 (r).hi = (a).hi | (b).hi)
309 #define jlong_XOR(r, a, b) ((r).lo = (a).lo ^ (b).lo, \
310 (r).hi = (a).hi ^ (b).hi)
311 #define jlong_OR2(r, a) ((r).lo = (r).lo | (a).lo, \
312 (r).hi = (r).hi | (a).hi)
313 #define jlong_NOT(r, a) ((r).lo = ~(a).lo, \
314 (r).hi = ~(a).hi)
316 #define jlong_NEG(r, a) ((r).lo = -(int32)(a).lo, \
317 (r).hi = -(int32)(a).hi - ((r).lo != 0))
318 #define jlong_ADD(r, a, b) { \
319 jlong _a, _b; \
320 _a = a; _b = b; \
321 (r).lo = _a.lo + _b.lo; \
322 (r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
325 #define jlong_SUB(r, a, b) { \
326 jlong _a, _b; \
327 _a = a; _b = b; \
328 (r).lo = _a.lo - _b.lo; \
329 (r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
333 * Multiply 64-bit operands a and b to get 64-bit result r.
334 * First multiply the low 32 bits of a and b to get a 64-bit result in r.
335 * Then add the outer and inner products to r.hi.
337 #define jlong_MUL(r, a, b) { \
338 jlong _a, _b; \
339 _a = a; _b = b; \
340 jlong_MUL32(r, _a.lo, _b.lo); \
341 (r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
344 /* XXX _jlong_lo16(a) = ((a) << 16 >> 16) is better on some archs (not on mips) */
345 #define _jlong_lo16(a) ((a) & JRI_BITMASK(16))
346 #define _jlong_hi16(a) ((a) >> 16)
349 * Multiply 32-bit operands a and b to get 64-bit result r.
350 * Use polynomial expansion based on primitive field element (1 << 16).
352 #define jlong_MUL32(r, a, b) { \
353 juint _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
354 _a1 = _jlong_hi16(a), _a0 = _jlong_lo16(a); \
355 _b1 = _jlong_hi16(b), _b0 = _jlong_lo16(b); \
356 _y0 = _a0 * _b0; \
357 _y1 = _a0 * _b1; \
358 _y2 = _a1 * _b0; \
359 _y3 = _a1 * _b1; \
360 _y1 += _jlong_hi16(_y0); /* can't carry */ \
361 _y1 += _y2; /* might carry */ \
362 if (_y1 < _y2) _y3 += 1 << 16; /* propagate */ \
363 (r).lo = (_jlong_lo16(_y1) << 16) + _jlong_lo16(_y0); \
364 (r).hi = _y3 + _jlong_hi16(_y1); \
368 * Divide 64-bit unsigned operand a by 64-bit unsigned operand b, setting *qp
369 * to the 64-bit unsigned quotient, and *rp to the 64-bit unsigned remainder.
370 * Minimize effort if one of qp and rp is null.
372 #define jlong_UDIVMOD(qp, rp, a, b) jlong_udivmod(qp, rp, a, b)
374 extern JRI_PUBLIC_API(void)
375 jlong_udivmod(julong *qp, julong *rp, julong a, julong b);
377 #define jlong_DIV(r, a, b) { \
378 jlong _a, _b; \
379 juint _negative = (int32)(a).hi < 0; \
380 if (_negative) { \
381 jlong_NEG(_a, a); \
382 } else { \
383 _a = a; \
385 if ((int32)(b).hi < 0) { \
386 _negative ^= 1; \
387 jlong_NEG(_b, b); \
388 } else { \
389 _b = b; \
391 jlong_UDIVMOD(&(r), 0, _a, _b); \
392 if (_negative) \
393 jlong_NEG(r, r); \
396 #define jlong_MOD(r, a, b) { \
397 jlong _a, _b; \
398 juint _negative = (int32)(a).hi < 0; \
399 if (_negative) { \
400 jlong_NEG(_a, a); \
401 } else { \
402 _a = a; \
404 if ((int32)(b).hi < 0) { \
405 jlong_NEG(_b, b); \
406 } else { \
407 _b = b; \
409 jlong_UDIVMOD(0, &(r), _a, _b); \
410 if (_negative) \
411 jlong_NEG(r, r); \
415 * NB: b is a juint, not jlong or julong, for the shift ops.
417 #define jlong_SHL(r, a, b) { \
418 if (b) { \
419 jlong _a; \
420 _a = a; \
421 if ((b) < 32) { \
422 (r).lo = _a.lo << (b); \
423 (r).hi = (_a.hi << (b)) | (_a.lo >> (32 - (b))); \
424 } else { \
425 (r).lo = 0; \
426 (r).hi = _a.lo << ((b) & 31); \
428 } else { \
429 (r) = (a); \
433 /* a is an int32, b is int32, r is jlong */
434 #define jlong_ISHL(r, a, b) { \
435 if (b) { \
436 jlong _a; \
437 _a.lo = (a); \
438 _a.hi = 0; \
439 if ((b) < 32) { \
440 (r).lo = (a) << (b); \
441 (r).hi = ((a) >> (32 - (b))); \
442 } else { \
443 (r).lo = 0; \
444 (r).hi = (a) << ((b) & 31); \
446 } else { \
447 (r).lo = (a); \
448 (r).hi = 0; \
452 #define jlong_SHR(r, a, b) { \
453 if (b) { \
454 jlong _a; \
455 _a = a; \
456 if ((b) < 32) { \
457 (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> (b)); \
458 (r).hi = (int32)_a.hi >> (b); \
459 } else { \
460 (r).lo = (int32)_a.hi >> ((b) & 31); \
461 (r).hi = (int32)_a.hi >> 31; \
463 } else { \
464 (r) = (a); \
468 #define jlong_USHR(r, a, b) { \
469 if (b) { \
470 jlong _a; \
471 _a = a; \
472 if ((b) < 32) { \
473 (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> (b)); \
474 (r).hi = _a.hi >> (b); \
475 } else { \
476 (r).lo = _a.hi >> ((b) & 31); \
477 (r).hi = 0; \
479 } else { \
480 (r) = (a); \
484 #define jlong_L2I(i, l) ((i) = (l).lo)
485 #define jlong_L2UI(ui, l) ((ui) = (l).lo)
486 #define jlong_L2F(f, l) { double _d; jlong_L2D(_d, l); (f) = (float) _d; }
488 #define jlong_L2D(d, l) { \
489 int32 _negative; \
490 jlong _absval; \
492 _negative = (l).hi >> 31; \
493 if (_negative) { \
494 jlong_NEG(_absval, l); \
495 } else { \
496 _absval = l; \
498 (d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
499 if (_negative) \
500 (d) = -(d); \
503 #define jlong_I2L(l, i) ((l).hi = (i) >> 31, (l).lo = (i))
504 #define jlong_UI2L(l, ui) ((l).hi = 0, (l).lo = (ui))
505 #define jlong_F2L(l, f) { double _d = (double) f; jlong_D2L(l, _d); }
507 #define jlong_D2L(l, d) { \
508 int _negative; \
509 double _absval, _d_hi; \
510 jlong _lo_d; \
512 _negative = ((d) < 0); \
513 _absval = _negative ? -(d) : (d); \
515 (l).hi = (juint)(_absval / 4.294967296e9); \
516 (l).lo = 0; \
517 jlong_L2D(_d_hi, l); \
518 _absval -= _d_hi; \
519 _lo_d.hi = 0; \
520 if (_absval < 0) { \
521 _lo_d.lo = (juint) -_absval; \
522 jlong_SUB(l, l, _lo_d); \
523 } else { \
524 _lo_d.lo = (juint) _absval; \
525 jlong_ADD(l, l, _lo_d); \
528 if (_negative) \
529 jlong_NEG(l, l); \
532 #endif /* !HAVE_LONG_LONG */
534 /******************************************************************************/
536 #ifdef HAVE_ALIGNED_LONGLONGS
537 #define JRI_GET_INT64(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \
538 ((_t).x[1] = ((jint*)(_addr))[1]), \
539 (_t).l )
540 #define JRI_SET_INT64(_t, _addr, _v) ( (_t).l = (_v), \
541 ((jint*)(_addr))[0] = (_t).x[0], \
542 ((jint*)(_addr))[1] = (_t).x[1] )
543 #else
544 #define JRI_GET_INT64(_t,_addr) (*(jlong*)(_addr))
545 #define JRI_SET_INT64(_t, _addr, _v) (*(jlong*)(_addr) = (_v))
546 #endif
548 /* If double's must be aligned on doubleword boundaries then define this */
549 #ifdef HAVE_ALIGNED_DOUBLES
550 #define JRI_GET_DOUBLE(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \
551 ((_t).x[1] = ((jint*)(_addr))[1]), \
552 (_t).d )
553 #define JRI_SET_DOUBLE(_t, _addr, _v) ( (_t).d = (_v), \
554 ((jint*)(_addr))[0] = (_t).x[0], \
555 ((jint*)(_addr))[1] = (_t).x[1] )
556 #else
557 #define JRI_GET_DOUBLE(_t,_addr) (*(jdouble*)(_addr))
558 #define JRI_SET_DOUBLE(_t, _addr, _v) (*(jdouble*)(_addr) = (_v))
559 #endif
561 /******************************************************************************/
562 #ifdef __cplusplus
564 #endif
565 #endif /* JRI_MD_H */
566 /******************************************************************************/