00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef JRI_MD_H
00043 #define JRI_MD_H
00044
00045 #include <assert.h>
00046 #include "prtypes.h"
00047
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 #if defined(XP_WIN) || defined(_WINDOWS) || defined(WIN32) || defined(_WIN32)
00073 # include <windows.h>
00074 # if defined(_MSC_VER) || defined(__GNUC__)
00075 # if defined(WIN32) || defined(_WIN32)
00076 # define JRI_PUBLIC_API(ResultType) __declspec(dllexport) ResultType
00077 # define JRI_PUBLIC_VAR(VarType) VarType
00078 # define JRI_PUBLIC_VAR_EXP(VarType) __declspec(dllexport) VarType
00079 # define JRI_PUBLIC_VAR_IMP(VarType) __declspec(dllimport) VarType
00080 # define JRI_NATIVE_STUB(ResultType) __declspec(dllexport) ResultType
00081 # define JRI_CALLBACK
00082 # else
00083 # if defined(_WINDLL)
00084 # define JRI_PUBLIC_API(ResultType) ResultType __cdecl __export __loadds
00085 # define JRI_PUBLIC_VAR(VarType) VarType
00086 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
00087 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
00088 # define JRI_NATIVE_STUB(ResultType) ResultType __cdecl __loadds
00089 # define JRI_CALLBACK __loadds
00090 # else
00091 # define JRI_PUBLIC_API(ResultType) ResultType __cdecl __export
00092 # define JRI_PUBLIC_VAR(VarType) VarType
00093 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
00094 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
00095 # define JRI_NATIVE_STUB(ResultType) ResultType __cdecl __export
00096 # define JRI_CALLBACK __export
00097 # endif
00098 # endif
00099 # elif defined(__BORLANDC__)
00100 # if defined(WIN32) || defined(_WIN32)
00101 # define JRI_PUBLIC_API(ResultType) __export ResultType
00102 # define JRI_PUBLIC_VAR(VarType) VarType
00103 # define JRI_PUBLIC_VAR_EXP(VarType) __export VarType
00104 # define JRI_PUBLIC_VAR_IMP(VarType) __import VarType
00105 # define JRI_NATIVE_STUB(ResultType) __export ResultType
00106 # define JRI_CALLBACK
00107 # else
00108 # define JRI_PUBLIC_API(ResultType) ResultType _cdecl _export _loadds
00109 # define JRI_PUBLIC_VAR(VarType) VarType
00110 # define JRI_PUBLIC_VAR_EXP(VarType) __cdecl __export VarType
00111 # define JRI_PUBLIC_VAR_IMP(VarType) __cdecl __import VarType
00112 # define JRI_NATIVE_STUB(ResultType) ResultType _cdecl _loadds
00113 # define JRI_CALLBACK _loadds
00114 # endif
00115 # else
00116 # error Unsupported PC development environment.
00117 # endif
00118 # ifndef IS_LITTLE_ENDIAN
00119 # define IS_LITTLE_ENDIAN
00120 # endif
00121
00122
00123 #elif defined(XP_OS2)
00124 # ifdef XP_OS2_VACPP
00125 # define JRI_PUBLIC_API(ResultType) ResultType _Optlink
00126 # define JRI_PUBLIC_VAR(VarType) VarType
00127 # define JRI_CALLBACK
00128 # elif defined(__declspec)
00129 # define JRI_PUBLIC_API(ResultType) __declspec(dllexport) ResultType
00130 # define JRI_PUBLIC_VAR(VarType) VarType
00131 # define JRI_PUBLIC_VAR_EXP(VarType) __declspec(dllexport) VarType
00132 # define JRI_PUBLIC_VAR_IMP(VarType) __declspec(dllimport) VarType
00133 # define JRI_NATIVE_STUB(ResultType) __declspec(dllexport) ResultType
00134 # define JRI_CALLBACK
00135 # else
00136 # define JRI_PUBLIC_API(ResultType) ResultType
00137 # define JRI_PUBLIC_VAR(VarType) VarType
00138 # define JRI_CALLBACK
00139 # endif
00140
00141
00142 #elif defined (macintosh) || Macintosh || THINK_C
00143 # if defined(__MWERKS__)
00144 # if !__option(enumsalwaysint)
00145 # error You need to define 'Enums Always Int' for your project.
00146 # endif
00147 # if defined(TARGET_CPU_68K) && !TARGET_RT_MAC_CFM
00148 # if !__option(fourbyteints)
00149 # error You need to define 'Struct Alignment: 68k' for your project.
00150 # endif
00151 # endif
00152 # define JRI_PUBLIC_API(ResultType) __declspec(export) ResultType
00153 # define JRI_PUBLIC_VAR(VarType) JRI_PUBLIC_API(VarType)
00154 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_API(VarType)
00155 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_API(VarType)
00156 # define JRI_NATIVE_STUB(ResultType) JRI_PUBLIC_API(ResultType)
00157 # elif defined(__SC__)
00158 # error What are the Symantec defines? (warren@netscape.com)
00159 # elif macintosh && applec
00160 # error Please upgrade to the latest MPW compiler (SC).
00161 # else
00162 # error Unsupported Mac development environment.
00163 # endif
00164 # define JRI_CALLBACK
00165
00166
00167 #else
00168 # define JRI_PUBLIC_API(ResultType) ResultType
00169 # define JRI_PUBLIC_VAR(VarType) VarType
00170 # define JRI_PUBLIC_VAR_EXP(VarType) JRI_PUBLIC_VAR(VarType)
00171 # define JRI_PUBLIC_VAR_IMP(VarType) JRI_PUBLIC_VAR(VarType)
00172 # define JRI_NATIVE_STUB(ResultType) ResultType
00173 # define JRI_CALLBACK
00174 #endif
00175
00176 #ifndef FAR
00177 #define FAR
00178 #endif
00179
00180
00181
00182
00183
00184 #if 0
00185 typedef short jchar;
00186 typedef short jshort;
00187 typedef float jfloat;
00188 typedef double jdouble;
00189 typedef juint jsize;
00190 #endif
00191
00192
00193 #ifdef __cplusplus
00194 typedef class _jobject *jref;
00195 #else
00196 typedef struct _jobject *jref;
00197 #endif
00198
00199 typedef unsigned char jbool;
00200 typedef signed char jbyte;
00201 #ifdef IS_64
00202 typedef unsigned int juint;
00203 typedef int jint;
00204 #else
00205 typedef unsigned long juint;
00206 typedef long jint;
00207 #endif
00208
00209
00210
00211
00212
00213
00214
00215
00216 #define JRI_BIT(n) ((juint)1 << (n))
00217 #define JRI_BITMASK(n) (JRI_BIT(n) - 1)
00218
00219 #ifdef HAVE_LONG_LONG
00220
00221 #ifdef OSF1
00222
00223
00224 typedef long jlong;
00225 typedef unsigned long julong;
00226 #define jlong_MAXINT 0x7fffffffffffffffL
00227 #define jlong_MININT 0x8000000000000000L
00228 #define jlong_ZERO 0x0L
00229
00230 #elif (defined(WIN32) || defined(_WIN32))
00231
00232 typedef LONGLONG jlong;
00233 typedef DWORDLONG julong;
00234 #define jlong_MAXINT 0x7fffffffffffffffi64
00235 #define jlong_MININT 0x8000000000000000i64
00236 #define jlong_ZERO 0x0i64
00237
00238 #else
00239
00240 typedef long long jlong;
00241 typedef unsigned long long julong;
00242 #define jlong_MAXINT 0x7fffffffffffffffLL
00243 #define jlong_MININT 0x8000000000000000LL
00244 #define jlong_ZERO 0x0LL
00245
00246 #endif
00247
00248 #define jlong_IS_ZERO(a) ((a) == 0)
00249 #define jlong_EQ(a, b) ((a) == (b))
00250 #define jlong_NE(a, b) ((a) != (b))
00251 #define jlong_GE_ZERO(a) ((a) >= 0)
00252 #define jlong_CMP(a, op, b) ((a) op (b))
00253
00254 #define jlong_AND(r, a, b) ((r) = (a) & (b))
00255 #define jlong_OR(r, a, b) ((r) = (a) | (b))
00256 #define jlong_XOR(r, a, b) ((r) = (a) ^ (b))
00257 #define jlong_OR2(r, a) ((r) = (r) | (a))
00258 #define jlong_NOT(r, a) ((r) = ~(a))
00259
00260 #define jlong_NEG(r, a) ((r) = -(a))
00261 #define jlong_ADD(r, a, b) ((r) = (a) + (b))
00262 #define jlong_SUB(r, a, b) ((r) = (a) - (b))
00263
00264 #define jlong_MUL(r, a, b) ((r) = (a) * (b))
00265 #define jlong_DIV(r, a, b) ((r) = (a) / (b))
00266 #define jlong_MOD(r, a, b) ((r) = (a) % (b))
00267
00268 #define jlong_SHL(r, a, b) ((r) = (a) << (b))
00269 #define jlong_SHR(r, a, b) ((r) = (a) >> (b))
00270 #define jlong_USHR(r, a, b) ((r) = (julong)(a) >> (b))
00271 #define jlong_ISHL(r, a, b) ((r) = ((jlong)(a)) << (b))
00272
00273 #define jlong_L2I(i, l) ((i) = (int)(l))
00274 #define jlong_L2UI(ui, l) ((ui) =(unsigned int)(l))
00275 #define jlong_L2F(f, l) ((f) = (l))
00276 #define jlong_L2D(d, l) ((d) = (l))
00277
00278 #define jlong_I2L(l, i) ((l) = (i))
00279 #define jlong_UI2L(l, ui) ((l) = (ui))
00280 #define jlong_F2L(l, f) ((l) = (f))
00281 #define jlong_D2L(l, d) ((l) = (d))
00282
00283 #define jlong_UDIVMOD(qp, rp, a, b) \
00284 (*(qp) = ((julong)(a) / (b)), \
00285 *(rp) = ((julong)(a) % (b)))
00286
00287 #else
00288
00289 typedef struct {
00290 #ifdef IS_LITTLE_ENDIAN
00291 juint lo, hi;
00292 #else
00293 juint hi, lo;
00294 #endif
00295 } jlong;
00296 typedef jlong julong;
00297
00298 extern jlong jlong_MAXINT, jlong_MININT, jlong_ZERO;
00299
00300 #define jlong_IS_ZERO(a) (((a).hi == 0) && ((a).lo == 0))
00301 #define jlong_EQ(a, b) (((a).hi == (b).hi) && ((a).lo == (b).lo))
00302 #define jlong_NE(a, b) (((a).hi != (b).hi) || ((a).lo != (b).lo))
00303 #define jlong_GE_ZERO(a) (((a).hi >> 31) == 0)
00304
00305
00306
00307
00308 #define jlong_CMP(a, op, b) (((int32)(a).hi op (int32)(b).hi) || \
00309 (((a).hi == (b).hi) && ((a).lo op (b).lo)))
00310 #define jlong_UCMP(a, op, b) (((a).hi op (b).hi) || \
00311 (((a).hi == (b).hi) && ((a).lo op (b).lo)))
00312
00313 #define jlong_AND(r, a, b) ((r).lo = (a).lo & (b).lo, \
00314 (r).hi = (a).hi & (b).hi)
00315 #define jlong_OR(r, a, b) ((r).lo = (a).lo | (b).lo, \
00316 (r).hi = (a).hi | (b).hi)
00317 #define jlong_XOR(r, a, b) ((r).lo = (a).lo ^ (b).lo, \
00318 (r).hi = (a).hi ^ (b).hi)
00319 #define jlong_OR2(r, a) ((r).lo = (r).lo | (a).lo, \
00320 (r).hi = (r).hi | (a).hi)
00321 #define jlong_NOT(r, a) ((r).lo = ~(a).lo, \
00322 (r).hi = ~(a).hi)
00323
00324 #define jlong_NEG(r, a) ((r).lo = -(int32)(a).lo, \
00325 (r).hi = -(int32)(a).hi - ((r).lo != 0))
00326 #define jlong_ADD(r, a, b) { \
00327 jlong _a, _b; \
00328 _a = a; _b = b; \
00329 (r).lo = _a.lo + _b.lo; \
00330 (r).hi = _a.hi + _b.hi + ((r).lo < _b.lo); \
00331 }
00332
00333 #define jlong_SUB(r, a, b) { \
00334 jlong _a, _b; \
00335 _a = a; _b = b; \
00336 (r).lo = _a.lo - _b.lo; \
00337 (r).hi = _a.hi - _b.hi - (_a.lo < _b.lo); \
00338 } \
00339
00340
00341
00342
00343
00344
00345 #define jlong_MUL(r, a, b) { \
00346 jlong _a, _b; \
00347 _a = a; _b = b; \
00348 jlong_MUL32(r, _a.lo, _b.lo); \
00349 (r).hi += _a.hi * _b.lo + _a.lo * _b.hi; \
00350 }
00351
00352
00353 #define _jlong_lo16(a) ((a) & JRI_BITMASK(16))
00354 #define _jlong_hi16(a) ((a) >> 16)
00355
00356
00357
00358
00359
00360 #define jlong_MUL32(r, a, b) { \
00361 juint _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3; \
00362 _a1 = _jlong_hi16(a), _a0 = _jlong_lo16(a); \
00363 _b1 = _jlong_hi16(b), _b0 = _jlong_lo16(b); \
00364 _y0 = _a0 * _b0; \
00365 _y1 = _a0 * _b1; \
00366 _y2 = _a1 * _b0; \
00367 _y3 = _a1 * _b1; \
00368 _y1 += _jlong_hi16(_y0); \
00369 _y1 += _y2; \
00370 if (_y1 < _y2) _y3 += 1 << 16; \
00371 (r).lo = (_jlong_lo16(_y1) << 16) + _jlong_lo16(_y0); \
00372 (r).hi = _y3 + _jlong_hi16(_y1); \
00373 }
00374
00375
00376
00377
00378
00379
00380 #define jlong_UDIVMOD(qp, rp, a, b) jlong_udivmod(qp, rp, a, b)
00381
00382 extern JRI_PUBLIC_API(void)
00383 jlong_udivmod(julong *qp, julong *rp, julong a, julong b);
00384
00385 #define jlong_DIV(r, a, b) { \
00386 jlong _a, _b; \
00387 juint _negative = (int32)(a).hi < 0; \
00388 if (_negative) { \
00389 jlong_NEG(_a, a); \
00390 } else { \
00391 _a = a; \
00392 } \
00393 if ((int32)(b).hi < 0) { \
00394 _negative ^= 1; \
00395 jlong_NEG(_b, b); \
00396 } else { \
00397 _b = b; \
00398 } \
00399 jlong_UDIVMOD(&(r), 0, _a, _b); \
00400 if (_negative) \
00401 jlong_NEG(r, r); \
00402 }
00403
00404 #define jlong_MOD(r, a, b) { \
00405 jlong _a, _b; \
00406 juint _negative = (int32)(a).hi < 0; \
00407 if (_negative) { \
00408 jlong_NEG(_a, a); \
00409 } else { \
00410 _a = a; \
00411 } \
00412 if ((int32)(b).hi < 0) { \
00413 jlong_NEG(_b, b); \
00414 } else { \
00415 _b = b; \
00416 } \
00417 jlong_UDIVMOD(0, &(r), _a, _b); \
00418 if (_negative) \
00419 jlong_NEG(r, r); \
00420 }
00421
00422
00423
00424
00425 #define jlong_SHL(r, a, b) { \
00426 if (b) { \
00427 jlong _a; \
00428 _a = a; \
00429 if ((b) < 32) { \
00430 (r).lo = _a.lo << (b); \
00431 (r).hi = (_a.hi << (b)) | (_a.lo >> (32 - (b))); \
00432 } else { \
00433 (r).lo = 0; \
00434 (r).hi = _a.lo << ((b) & 31); \
00435 } \
00436 } else { \
00437 (r) = (a); \
00438 } \
00439 }
00440
00441
00442 #define jlong_ISHL(r, a, b) { \
00443 if (b) { \
00444 jlong _a; \
00445 _a.lo = (a); \
00446 _a.hi = 0; \
00447 if ((b) < 32) { \
00448 (r).lo = (a) << (b); \
00449 (r).hi = ((a) >> (32 - (b))); \
00450 } else { \
00451 (r).lo = 0; \
00452 (r).hi = (a) << ((b) & 31); \
00453 } \
00454 } else { \
00455 (r).lo = (a); \
00456 (r).hi = 0; \
00457 } \
00458 }
00459
00460 #define jlong_SHR(r, a, b) { \
00461 if (b) { \
00462 jlong _a; \
00463 _a = a; \
00464 if ((b) < 32) { \
00465 (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> (b)); \
00466 (r).hi = (int32)_a.hi >> (b); \
00467 } else { \
00468 (r).lo = (int32)_a.hi >> ((b) & 31); \
00469 (r).hi = (int32)_a.hi >> 31; \
00470 } \
00471 } else { \
00472 (r) = (a); \
00473 } \
00474 }
00475
00476 #define jlong_USHR(r, a, b) { \
00477 if (b) { \
00478 jlong _a; \
00479 _a = a; \
00480 if ((b) < 32) { \
00481 (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> (b)); \
00482 (r).hi = _a.hi >> (b); \
00483 } else { \
00484 (r).lo = _a.hi >> ((b) & 31); \
00485 (r).hi = 0; \
00486 } \
00487 } else { \
00488 (r) = (a); \
00489 } \
00490 }
00491
00492 #define jlong_L2I(i, l) ((i) = (l).lo)
00493 #define jlong_L2UI(ui, l) ((ui) = (l).lo)
00494 #define jlong_L2F(f, l) { double _d; jlong_L2D(_d, l); (f) = (float) _d; }
00495
00496 #define jlong_L2D(d, l) { \
00497 int32 _negative; \
00498 jlong _absval; \
00499 \
00500 _negative = (l).hi >> 31; \
00501 if (_negative) { \
00502 jlong_NEG(_absval, l); \
00503 } else { \
00504 _absval = l; \
00505 } \
00506 (d) = (double)_absval.hi * 4.294967296e9 + _absval.lo; \
00507 if (_negative) \
00508 (d) = -(d); \
00509 }
00510
00511 #define jlong_I2L(l, i) ((l).hi = (i) >> 31, (l).lo = (i))
00512 #define jlong_UI2L(l, ui) ((l).hi = 0, (l).lo = (ui))
00513 #define jlong_F2L(l, f) { double _d = (double) f; jlong_D2L(l, _d); }
00514
00515 #define jlong_D2L(l, d) { \
00516 int _negative; \
00517 double _absval, _d_hi; \
00518 jlong _lo_d; \
00519 \
00520 _negative = ((d) < 0); \
00521 _absval = _negative ? -(d) : (d); \
00522 \
00523 (l).hi = (juint)(_absval / 4.294967296e9); \
00524 (l).lo = 0; \
00525 jlong_L2D(_d_hi, l); \
00526 _absval -= _d_hi; \
00527 _lo_d.hi = 0; \
00528 if (_absval < 0) { \
00529 _lo_d.lo = (juint) -_absval; \
00530 jlong_SUB(l, l, _lo_d); \
00531 } else { \
00532 _lo_d.lo = (juint) _absval; \
00533 jlong_ADD(l, l, _lo_d); \
00534 } \
00535 \
00536 if (_negative) \
00537 jlong_NEG(l, l); \
00538 }
00539
00540 #endif
00541
00542
00543
00544 #ifdef HAVE_ALIGNED_LONGLONGS
00545 #define JRI_GET_INT64(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \
00546 ((_t).x[1] = ((jint*)(_addr))[1]), \
00547 (_t).l )
00548 #define JRI_SET_INT64(_t, _addr, _v) ( (_t).l = (_v), \
00549 ((jint*)(_addr))[0] = (_t).x[0], \
00550 ((jint*)(_addr))[1] = (_t).x[1] )
00551 #else
00552 #define JRI_GET_INT64(_t,_addr) (*(jlong*)(_addr))
00553 #define JRI_SET_INT64(_t, _addr, _v) (*(jlong*)(_addr) = (_v))
00554 #endif
00555
00556
00557 #ifdef HAVE_ALIGNED_DOUBLES
00558 #define JRI_GET_DOUBLE(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \
00559 ((_t).x[1] = ((jint*)(_addr))[1]), \
00560 (_t).d )
00561 #define JRI_SET_DOUBLE(_t, _addr, _v) ( (_t).d = (_v), \
00562 ((jint*)(_addr))[0] = (_t).x[0], \
00563 ((jint*)(_addr))[1] = (_t).x[1] )
00564 #else
00565 #define JRI_GET_DOUBLE(_t,_addr) (*(jdouble*)(_addr))
00566 #define JRI_SET_DOUBLE(_t, _addr, _v) (*(jdouble*)(_addr) = (_v))
00567 #endif
00568
00569
00570 #ifdef __cplusplus
00571 }
00572 #endif
00573 #endif
00574