fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / external / np_sdk / npsdk / jri_md.h
blobab631d1904a7a2e6240f5a9c5e067b1e13483091
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_PC) || defined(_WINDOWS) || defined(WIN32) || defined(_WIN32)
72 # include <windows.h>
73 # if defined(_MSC_VER) || defined(__MINGW32__)
74 # if defined(WIN32) || defined(_WIN32)
75 # define JRI_PUBLIC_API(ResultType) __declspec(dllexport) ResultType
76 # define JRI_PUBLIC_VAR(VarType) VarType
77 # define JRI_PUBLIC_VAR_EXP(VarType) __declspec(dllexport) VarType
78 # define JRI_PUBLIC_VAR_IMP(VarType) __declspec(dllimport) VarType
79 # define JRI_NATIVE_STUB(ResultType) __declspec(dllexport) ResultType
80 # define JRI_CALLBACK
81 # else /* !_WIN32 */
82 # if defined(_WINDLL)
83 # define JRI_PUBLIC_API(ResultType) ResultType __cdecl __export __loadds
84 # define JRI_PUBLIC_VAR(VarType) VarType
85 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
86 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
87 # define JRI_NATIVE_STUB(ResultType) ResultType __cdecl __loadds
88 # define JRI_CALLBACK __loadds
89 # else /* !WINDLL */
90 # define JRI_PUBLIC_API(ResultType) ResultType __cdecl __export
91 # define JRI_PUBLIC_VAR(VarType) VarType
92 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
93 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
94 # define JRI_NATIVE_STUB(ResultType) ResultType __cdecl __export
95 # define JRI_CALLBACK __export
96 # endif /* !WINDLL */
97 # endif /* !_WIN32 */
98 # elif defined(__BORLANDC__)
99 # if defined(WIN32) || defined(_WIN32)
100 # define JRI_PUBLIC_API(ResultType) __export ResultType
101 # define JRI_PUBLIC_VAR(VarType) VarType
102 # define JRI_PUBLIC_VAR_EXP(VarType) __export VarType
103 # define JRI_PUBLIC_VAR_IMP(VarType) __import VarType
104 # define JRI_NATIVE_STUB(ResultType) __export ResultType
105 # define JRI_CALLBACK
106 # else /* !_WIN32 */
107 # define JRI_PUBLIC_API(ResultType) ResultType _cdecl _export _loadds
108 # define JRI_PUBLIC_VAR(VarType) VarType
109 # define JRI_PUBLIC_VAR_EXP(VarType) __cdecl __export VarType
110 # define JRI_PUBLIC_VAR_IMP(VarType) __cdecl __import VarType
111 # define JRI_NATIVE_STUB(ResultType) ResultType _cdecl _loadds
112 # define JRI_CALLBACK _loadds
113 # endif
114 # else
115 # error Unsupported PC development environment.
116 # endif
117 # ifndef IS_LITTLE_ENDIAN
118 # define IS_LITTLE_ENDIAN
119 # endif
121 /* Mac */
122 #elif defined (macintosh) || defined(Macintosh) || defined(THINK_C)
123 # if defined(__MWERKS__) /* Metrowerks */
124 # if !__option(enumsalwaysint)
125 # error You need to define 'Enums Always Int' for your project.
126 # endif
127 # if defined(TARGET_CPU_68K) && !TARGET_RT_MAC_CFM
128 # if !__option(fourbyteints)
129 # error You need to define 'Struct Alignment: 68k' for your project.
130 # endif
131 # endif /* !GENERATINGCFM */
132 # define JRI_PUBLIC_API(ResultType) __declspec(export) ResultType
133 # define JRI_PUBLIC_VAR(VarType) JRI_PUBLIC_API(VarType)
134 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_API(VarType)
135 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_API(VarType)
136 # define JRI_NATIVE_STUB(ResultType) JRI_PUBLIC_API(ResultType)
137 # elif defined(__SC__) /* Symantec */
138 # error What are the Symantec defines? (warren@netscape.com)
139 # elif macintosh && applec /* MPW */
140 # error Please upgrade to the latest MPW compiler (SC).
141 # else
142 # error Unsupported Mac development environment.
143 # endif
144 # define JRI_CALLBACK
146 /* Unix or else */
147 #else
148 # define JRI_PUBLIC_API(ResultType) ResultType
149 # define JRI_PUBLIC_VAR(VarType) VarType
150 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
151 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
152 # define JRI_NATIVE_STUB(ResultType) ResultType
153 # define JRI_CALLBACK
154 #endif
156 #ifndef FAR /* for non-Win16 */
157 #define FAR
158 #endif
160 /******************************************************************************/
162 /* Java Scalar Types */
164 /* moved from jni.h -- Sun's new jni.h doesn't have this anymore */
165 #ifdef __cplusplus
166 typedef class _jobject *jref;
167 #else
168 typedef struct _jobject *jref;
169 #endif
171 typedef unsigned char jbool;
172 typedef char jbyte;
173 typedef short jchar;
174 typedef short jshort;
175 #ifdef IS_64 /* XXX ok for alpha, but not right on all 64-bit architectures */
176 typedef unsigned int juint;
177 typedef int jint;
178 #else
179 typedef unsigned long juint;
180 typedef long jint;
181 #endif
183 typedef float jfloat;
184 typedef double jdouble;
186 typedef juint jsize;
189 /*******************************************************************************
190 * jlong : long long (64-bit signed integer type) support.
191 ******************************************************************************/
194 ** Bit masking macros. (n must be <= 31 to be portable)
196 #define JRI_BIT(n) ((juint)1 << (n))
197 #define JRI_BITMASK(n) (JRI_BIT(n) - 1)
199 #ifdef HAVE_LONG_LONG
201 #if (defined(WIN32) || defined(_WIN32))
203 typedef LONGLONG jlong;
204 typedef DWORDLONG julong;
205 #define jlong_MAXINT 0x7fffffffffffffffi64
206 #define jlong_MININT 0x8000000000000000i64
207 #define jlong_ZERO 0x0i64
209 #else
211 typedef long long jlong;
212 typedef unsigned long long julong;
213 #define jlong_MAXINT 0x7fffffffffffffffLL
214 #define jlong_MININT 0x8000000000000000LL
215 #define jlong_ZERO 0x0LL
217 #endif
219 #define jlong_IS_ZERO(a) ((a) == 0)
220 #define jlong_EQ(a, b) ((a) == (b))
221 #define jlong_NE(a, b) ((a) != (b))
222 #define jlong_GE_ZERO(a) ((a) >= 0)
223 #define jlong_CMP(a, op, b) ((a) op (b))
225 #define jlong_AND(r, a, b) ((r) = (a) & (b))
226 #define jlong_OR(r, a, b) ((r) = (a) | (b))
227 #define jlong_XOR(r, a, b) ((r) = (a) ^ (b))
228 #define jlong_OR2(r, a) ((r) = (r) | (a))
229 #define jlong_NOT(r, a) ((r) = ~(a))
231 #define jlong_NEG(r, a) ((r) = -(a))
232 #define jlong_ADD(r, a, b) ((r) = (a) + (b))
233 #define jlong_SUB(r, a, b) ((r) = (a) - (b))
235 #define jlong_MUL(r, a, b) ((r) = (a) * (b))
236 #define jlong_DIV(r, a, b) ((r) = (a) / (b))
237 #define jlong_MOD(r, a, b) ((r) = (a) % (b))
239 #define jlong_SHL(r, a, b) ((r) = (a) << (b))
240 #define jlong_SHR(r, a, b) ((r) = (a) >> (b))
241 #define jlong_USHR(r, a, b) ((r) = (julong)(a) >> (b))
242 #define jlong_ISHL(r, a, b) ((r) = ((jlong)(a)) << (b))
244 #define jlong_L2I(i, l) ((i) = (int)(l))
245 #define jlong_L2UI(ui, l) ((ui) =(unsigned int)(l))
246 #define jlong_L2F(f, l) ((f) = (l))
247 #define jlong_L2D(d, l) ((d) = (l))
249 #define jlong_I2L(l, i) ((l) = (i))
250 #define jlong_UI2L(l, ui) ((l) = (ui))
251 #define jlong_F2L(l, f) ((l) = (f))
252 #define jlong_D2L(l, d) ((l) = (d))
254 #define jlong_UDIVMOD(qp, rp, a, b) \
255 (*(qp) = ((julong)(a) / (b)), \
256 *(rp) = ((julong)(a) % (b)))
258 #else /* !HAVE_LONG_LONG */
260 typedef struct {
261 #ifdef IS_LITTLE_ENDIAN
262 juint lo, hi;
263 #else
264 juint hi, lo;
265 #endif
266 } jlong;
267 typedef jlong julong;
269 extern jlong jlong_MAXINT, jlong_MININT, jlong_ZERO;
271 #define jlong_IS_ZERO(a) (((a).hi == 0) && ((a).lo == 0))
272 #define jlong_EQ(a, b) (((a).hi == (b).hi) && ((a).lo == (b).lo))
273 #define jlong_NE(a, b) (((a).hi != (b).hi) || ((a).lo != (b).lo))
274 #define jlong_GE_ZERO(a) (((a).hi >> 31) == 0)
277 * NB: jlong_CMP and jlong_UCMP work only for strict relationals (<, >).
279 #define jlong_CMP(a, op, b) (((int32)(a).hi op (int32)(b).hi) || \
280 (((a).hi == (b).hi) && ((a).lo op (b).lo)))
281 #define jlong_UCMP(a, op, b) (((a).hi op (b).hi) || \
282 (((a).hi == (b).hi) && ((a).lo op (b).lo)))
284 #define jlong_AND(r, a, b) ((r).lo = (a).lo & (b).lo, \
285 (r).hi = (a).hi & (b).hi)
286 #define jlong_OR(r, a, b) ((r).lo = (a).lo | (b).lo, \
287 (r).hi = (a).hi | (b).hi)
288 #define jlong_XOR(r, a, b) ((r).lo = (a).lo ^ (b).lo, \
289 (r).hi = (a).hi ^ (b).hi)
290 #define jlong_OR2(r, a) ((r).lo = (r).lo | (a).lo, \
291 (r).hi = (r).hi | (a).hi)
292 #define jlong_NOT(r, a) ((r).lo = ~(a).lo, \
293 (r).hi = ~(a).hi)
295 #define jlong_NEG(r, a) ((r).lo = -(int32)(a).lo, \
296 (r).hi = -(int32)(a).hi - ((r).lo != 0))
297 #define jlong_ADD(r, a, b) { \
298 jlong _a, _b; \
299 _a = a; _b = b; \
300 (r).lo = _a.lo + _b.lo; \
301 (r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
304 #define jlong_SUB(r, a, b) { \
305 jlong _a, _b; \
306 _a = a; _b = b; \
307 (r).lo = _a.lo - _b.lo; \
308 (r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
312 * Multiply 64-bit operands a and b to get 64-bit result r.
313 * First multiply the low 32 bits of a and b to get a 64-bit result in r.
314 * Then add the outer and inner products to r.hi.
316 #define jlong_MUL(r, a, b) { \
317 jlong _a, _b; \
318 _a = a; _b = b; \
319 jlong_MUL32(r, _a.lo, _b.lo); \
320 (r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
323 /* XXX _jlong_lo16(a) = ((a) << 16 >> 16) is better on some archs (not on mips) */
324 #define _jlong_lo16(a) ((a) & JRI_BITMASK(16))
325 #define _jlong_hi16(a) ((a) >> 16)
328 * Multiply 32-bit operands a and b to get 64-bit result r.
329 * Use polynomial expansion based on primitive field element (1 << 16).
331 #define jlong_MUL32(r, a, b) { \
332 juint _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
333 _a1 = _jlong_hi16(a), _a0 = _jlong_lo16(a); \
334 _b1 = _jlong_hi16(b), _b0 = _jlong_lo16(b); \
335 _y0 = _a0 * _b0; \
336 _y1 = _a0 * _b1; \
337 _y2 = _a1 * _b0; \
338 _y3 = _a1 * _b1; \
339 _y1 += _jlong_hi16(_y0); /* can't carry */ \
340 _y1 += _y2; /* might carry */ \
341 if (_y1 < _y2) _y3 += 1 << 16; /* propagate */ \
342 (r).lo = (_jlong_lo16(_y1) << 16) + _jlong_lo16(_y0); \
343 (r).hi = _y3 + _jlong_hi16(_y1); \
347 * Divide 64-bit unsigned operand a by 64-bit unsigned operand b, setting *qp
348 * to the 64-bit unsigned quotient, and *rp to the 64-bit unsigned remainder.
349 * Minimize effort if one of qp and rp is null.
351 #define jlong_UDIVMOD(qp, rp, a, b) jlong_udivmod(qp, rp, a, b)
353 extern JRI_PUBLIC_API(void)
354 jlong_udivmod(julong *qp, julong *rp, julong a, julong b);
356 #define jlong_DIV(r, a, b) { \
357 jlong _a, _b; \
358 juint _negative = (int32)(a).hi < 0; \
359 if (_negative) { \
360 jlong_NEG(_a, a); \
361 } else { \
362 _a = a; \
364 if ((int32)(b).hi < 0) { \
365 _negative ^= 1; \
366 jlong_NEG(_b, b); \
367 } else { \
368 _b = b; \
370 jlong_UDIVMOD(&(r), 0, _a, _b); \
371 if (_negative) \
372 jlong_NEG(r, r); \
375 #define jlong_MOD(r, a, b) { \
376 jlong _a, _b; \
377 juint _negative = (int32)(a).hi < 0; \
378 if (_negative) { \
379 jlong_NEG(_a, a); \
380 } else { \
381 _a = a; \
383 if ((int32)(b).hi < 0) { \
384 jlong_NEG(_b, b); \
385 } else { \
386 _b = b; \
388 jlong_UDIVMOD(0, &(r), _a, _b); \
389 if (_negative) \
390 jlong_NEG(r, r); \
394 * NB: b is a juint, not jlong or julong, for the shift ops.
396 #define jlong_SHL(r, a, b) { \
397 if (b) { \
398 jlong _a; \
399 _a = a; \
400 if ((b) < 32) { \
401 (r).lo = _a.lo << (b); \
402 (r).hi = (_a.hi << (b)) | (_a.lo >> (32 - (b))); \
403 } else { \
404 (r).lo = 0; \
405 (r).hi = _a.lo << ((b) & 31); \
407 } else { \
408 (r) = (a); \
412 /* a is an int32, b is int32, r is jlong */
413 #define jlong_ISHL(r, a, b) { \
414 if (b) { \
415 jlong _a; \
416 _a.lo = (a); \
417 _a.hi = 0; \
418 if ((b) < 32) { \
419 (r).lo = (a) << (b); \
420 (r).hi = ((a) >> (32 - (b))); \
421 } else { \
422 (r).lo = 0; \
423 (r).hi = (a) << ((b) & 31); \
425 } else { \
426 (r).lo = (a); \
427 (r).hi = 0; \
431 #define jlong_SHR(r, a, b) { \
432 if (b) { \
433 jlong _a; \
434 _a = a; \
435 if ((b) < 32) { \
436 (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> (b)); \
437 (r).hi = (int32)_a.hi >> (b); \
438 } else { \
439 (r).lo = (int32)_a.hi >> ((b) & 31); \
440 (r).hi = (int32)_a.hi >> 31; \
442 } else { \
443 (r) = (a); \
447 #define jlong_USHR(r, a, b) { \
448 if (b) { \
449 jlong _a; \
450 _a = a; \
451 if ((b) < 32) { \
452 (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> (b)); \
453 (r).hi = _a.hi >> (b); \
454 } else { \
455 (r).lo = _a.hi >> ((b) & 31); \
456 (r).hi = 0; \
458 } else { \
459 (r) = (a); \
463 #define jlong_L2I(i, l) ((i) = (l).lo)
464 #define jlong_L2UI(ui, l) ((ui) = (l).lo)
465 #define jlong_L2F(f, l) { double _d; jlong_L2D(_d, l); (f) = (float) _d; }
467 #define jlong_L2D(d, l) { \
468 int32 _negative; \
469 jlong _absval; \
471 _negative = (l).hi >> 31; \
472 if (_negative) { \
473 jlong_NEG(_absval, l); \
474 } else { \
475 _absval = l; \
477 (d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
478 if (_negative) \
479 (d) = -(d); \
482 #define jlong_I2L(l, i) ((l).hi = (i) >> 31, (l).lo = (i))
483 #define jlong_UI2L(l, ui) ((l).hi = 0, (l).lo = (ui))
484 #define jlong_F2L(l, f) { double _d = (double) f; jlong_D2L(l, _d); }
486 #define jlong_D2L(l, d) { \
487 int _negative; \
488 double _absval, _d_hi; \
489 jlong _lo_d; \
491 _negative = ((d) < 0); \
492 _absval = _negative ? -(d) : (d); \
494 (l).hi = (juint)(_absval / 4.294967296e9); \
495 (l).lo = 0; \
496 jlong_L2D(_d_hi, l); \
497 _absval -= _d_hi; \
498 _lo_d.hi = 0; \
499 if (_absval < 0) { \
500 _lo_d.lo = (juint) -_absval; \
501 jlong_SUB(l, l, _lo_d); \
502 } else { \
503 _lo_d.lo = (juint) _absval; \
504 jlong_ADD(l, l, _lo_d); \
507 if (_negative) \
508 jlong_NEG(l, l); \
511 #endif /* !HAVE_LONG_LONG */
513 /******************************************************************************/
515 #ifdef HAVE_ALIGNED_LONGLONGS
516 #define JRI_GET_INT64(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \
517 ((_t).x[1] = ((jint*)(_addr))[1]), \
518 (_t).l )
519 #define JRI_SET_INT64(_t, _addr, _v) ( (_t).l = (_v), \
520 ((jint*)(_addr))[0] = (_t).x[0], \
521 ((jint*)(_addr))[1] = (_t).x[1] )
522 #else
523 #define JRI_GET_INT64(_t,_addr) (*(jlong*)(_addr))
524 #define JRI_SET_INT64(_t, _addr, _v) (*(jlong*)(_addr) = (_v))
525 #endif
527 /* If double's must be aligned on doubleword boundaries then define this */
528 #ifdef HAVE_ALIGNED_DOUBLES
529 #define JRI_GET_DOUBLE(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \
530 ((_t).x[1] = ((jint*)(_addr))[1]), \
531 (_t).d )
532 #define JRI_SET_DOUBLE(_t, _addr, _v) ( (_t).d = (_v), \
533 ((jint*)(_addr))[0] = (_t).x[0], \
534 ((jint*)(_addr))[1] = (_t).x[1] )
535 #else
536 #define JRI_GET_DOUBLE(_t,_addr) (*(jdouble*)(_addr))
537 #define JRI_SET_DOUBLE(_t, _addr, _v) (*(jdouble*)(_addr) = (_v))
538 #endif
540 /******************************************************************************/
541 #ifdef __cplusplus
543 #endif
544 #endif /* JRI_MD_H */
545 /******************************************************************************/