File indexing completed on 2024-04-28 16:07:44

0001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
0002 /* ***** BEGIN LICENSE BLOCK *****
0003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
0004  *
0005  * The contents of this file are subject to the Mozilla Public License Version
0006  * 1.1 (the "License"); you may not use this file except in compliance with
0007  * the License. You may obtain a copy of the License at
0008  * http://www.mozilla.org/MPL/
0009  *
0010  * Software distributed under the License is distributed on an "AS IS" basis,
0011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
0012  * for the specific language governing rights and limitations under the
0013  * License.
0014  *
0015  * The Original Code is mozilla.org code.
0016  *
0017  * The Initial Developer of the Original Code is
0018  * Netscape Communications Corporation.
0019  * Portions created by the Initial Developer are Copyright (C) 1998
0020  * the Initial Developer. All Rights Reserved.
0021  *
0022  * Contributor(s):
0023  *
0024  * Alternatively, the contents of this file may be used under the terms of
0025  * either the GNU General Public License Version 2 or later (the "GPL"), or
0026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
0027  * in which case the provisions of the GPL or the LGPL are applicable instead
0028  * of those above. If you wish to allow use of your version of this file only
0029  * under the terms of either the GPL or the LGPL, and not to allow others to
0030  * use your version of this file under the terms of the MPL, indicate your
0031  * decision by deleting the provisions above and replace them with the notice
0032  * and other provisions required by the GPL or the LGPL. If you do not delete
0033  * the provisions above, a recipient may use your version of this file under
0034  * the terms of any one of the MPL, the GPL or the LGPL.
0035  *
0036  * ***** END LICENSE BLOCK ***** */
0037 
0038 /*******************************************************************************
0039  * Java Runtime Interface - Machine Dependent Types
0040  ******************************************************************************/
0041  
0042 #ifndef JRI_MD_H
0043 #define JRI_MD_H
0044 
0045 #include <assert.h>
0046 #include "prtypes.h" /* Needed for HAS_LONG_LONG ifdefs */
0047 
0048 #ifdef __cplusplus
0049 extern "C" {
0050 #endif
0051 
0052 /*******************************************************************************
0053  * WHAT'S UP WITH THIS FILE?
0054  * 
0055  * This is where we define the mystical JRI_PUBLIC_API macro that works on all
0056  * platforms. If you're running with Visual C++, Symantec C, or Borland's 
0057  * development environment on the PC, you're all set. Or if you're on the Mac
0058  * with Metrowerks, Symantec or MPW with SC you're ok too. For UNIX it shouldn't
0059  * matter.
0060  *
0061  * On UNIX though you probably care about a couple of other symbols though:
0062  *  IS_LITTLE_ENDIAN must be defined for little-endian systems
0063  *  HAVE_LONG_LONG must be defined on systems that have 'long long' integers
0064  *  HAVE_ALIGNED_LONGLONGS must be defined if long-longs must be 8 byte aligned
0065  *  HAVE_ALIGNED_DOUBLES must be defined if doubles must be 8 byte aligned
0066  *  IS_64 must be defined on 64-bit machines (like Dec Alpha)
0067  ******************************************************************************/
0068 
0069 /* DLL Entry modifiers... */
0070 
0071 /* Windows */
0072 #if defined(XP_WIN) || defined(_WINDOWS) || defined(WIN32) || defined(_WIN32)
0073 #   include <windows.h>
0074 #   if defined(_MSC_VER) || defined(__GNUC__)
0075 #       if defined(WIN32) || defined(_WIN32)
0076 #           define JRI_PUBLIC_API(ResultType)  __declspec(dllexport) ResultType
0077 #           define JRI_PUBLIC_VAR(VarType)     VarType
0078 #           define JRI_PUBLIC_VAR_EXP(VarType) __declspec(dllexport) VarType
0079 #           define JRI_PUBLIC_VAR_IMP(VarType) __declspec(dllimport) VarType
0080 #           define JRI_NATIVE_STUB(ResultType) __declspec(dllexport) ResultType
0081 #           define JRI_CALLBACK
0082 #       else /* !_WIN32 */
0083 #           if defined(_WINDLL)
0084 #           define JRI_PUBLIC_API(ResultType)   ResultType __cdecl __export __loadds 
0085 #           define JRI_PUBLIC_VAR(VarType)      VarType
0086 #           define JRI_PUBLIC_VAR_EXP(VarType)  JRI_PUBLIC_VAR(VarType)
0087 #           define JRI_PUBLIC_VAR_IMP(VarType)  JRI_PUBLIC_VAR(VarType)
0088 #           define JRI_NATIVE_STUB(ResultType)  ResultType __cdecl __loadds
0089 #           define JRI_CALLBACK         __loadds
0090 #       else /* !WINDLL */
0091 #           define JRI_PUBLIC_API(ResultType)   ResultType __cdecl __export
0092 #           define JRI_PUBLIC_VAR(VarType)      VarType
0093 #           define JRI_PUBLIC_VAR_EXP(VarType)  JRI_PUBLIC_VAR(VarType)
0094 #           define JRI_PUBLIC_VAR_IMP(VarType)  JRI_PUBLIC_VAR(VarType)
0095 #           define JRI_NATIVE_STUB(ResultType)  ResultType __cdecl __export
0096 #           define JRI_CALLBACK         __export
0097 #                   endif /* !WINDLL */
0098 #       endif /* !_WIN32 */
0099 #   elif defined(__BORLANDC__)
0100 #       if defined(WIN32) || defined(_WIN32)
0101 #           define JRI_PUBLIC_API(ResultType)   __export ResultType
0102 #           define JRI_PUBLIC_VAR(VarType)      VarType
0103 #           define JRI_PUBLIC_VAR_EXP(VarType)  __export VarType
0104 #           define JRI_PUBLIC_VAR_IMP(VarType)  __import VarType
0105 #           define JRI_NATIVE_STUB(ResultType)   __export ResultType
0106 #           define JRI_CALLBACK
0107 #       else /* !_WIN32 */
0108 #           define JRI_PUBLIC_API(ResultType)   ResultType _cdecl _export _loadds 
0109 #           define JRI_PUBLIC_VAR(VarType)      VarType
0110 #           define JRI_PUBLIC_VAR_EXP(VarType)  __cdecl __export VarType
0111 #           define JRI_PUBLIC_VAR_IMP(VarType)  __cdecl __import VarType
0112 #           define JRI_NATIVE_STUB(ResultType)  ResultType _cdecl _loadds
0113 #           define JRI_CALLBACK         _loadds
0114 #       endif
0115 #   else
0116 #       error Unsupported PC development environment.   
0117 #   endif
0118 #   ifndef IS_LITTLE_ENDIAN
0119 #       define IS_LITTLE_ENDIAN
0120 #   endif
0121 
0122 /* OS/2 */
0123 #elif defined(XP_OS2)
0124 #   ifdef __declspec
0125 #       define JRI_PUBLIC_API(ResultType)   __declspec(dllexport) ResultType
0126 #       define JRI_PUBLIC_VAR(VarType)      VarType
0127 #       define JRI_PUBLIC_VAR_EXP(VarType)  __declspec(dllexport) VarType
0128 #       define JRI_PUBLIC_VAR_IMP(VarType)  __declspec(dllimport) VarType
0129 #       define JRI_NATIVE_STUB(ResultType)  __declspec(dllexport) ResultType
0130 #       define JRI_CALLBACK
0131 #   else
0132 #       define JRI_PUBLIC_API(ResultType)   ResultType
0133 #       define JRI_PUBLIC_VAR(VarType)      VarType
0134 #       define JRI_CALLBACK
0135 #   endif
0136 
0137 /* Mac */
0138 #elif defined (macintosh) || Macintosh || THINK_C
0139 #   if defined(__MWERKS__)              /* Metrowerks */
0140 #       if !__option(enumsalwaysint)
0141 #           error You need to define 'Enums Always Int' for your project.
0142 #       endif
0143 #       if defined(TARGET_CPU_68K) && !TARGET_RT_MAC_CFM 
0144 #           if !__option(fourbyteints) 
0145 #               error You need to define 'Struct Alignment: 68k' for your project.
0146 #           endif
0147 #       endif /* !GENERATINGCFM */
0148 #       define JRI_PUBLIC_API(ResultType)   __declspec(export) ResultType
0149 #       define JRI_PUBLIC_VAR(VarType)      JRI_PUBLIC_API(VarType)
0150 #       define JRI_PUBLIC_VAR_EXP(VarType)  JRI_PUBLIC_API(VarType)
0151 #       define JRI_PUBLIC_VAR_IMP(VarType)  JRI_PUBLIC_API(VarType)
0152 #       define JRI_NATIVE_STUB(ResultType)  JRI_PUBLIC_API(ResultType)
0153 #   elif defined(__SC__)                /* Symantec */
0154 #       error What are the Symantec defines? (warren@netscape.com)
0155 #   elif macintosh && applec            /* MPW */
0156 #       error Please upgrade to the latest MPW compiler (SC).
0157 #   else
0158 #       error Unsupported Mac development environment.
0159 #   endif
0160 #   define JRI_CALLBACK
0161 
0162 /* Unix or else */
0163 #else
0164 #   define JRI_PUBLIC_API(ResultType)       ResultType
0165 #   define JRI_PUBLIC_VAR(VarType)          VarType
0166 #   define JRI_PUBLIC_VAR_EXP(VarType)      JRI_PUBLIC_VAR(VarType)
0167 #   define JRI_PUBLIC_VAR_IMP(VarType)      JRI_PUBLIC_VAR(VarType)
0168 #   define JRI_NATIVE_STUB(ResultType)      ResultType
0169 #   define JRI_CALLBACK
0170 #endif
0171 
0172 #ifndef FAR     /* for non-Win16 */
0173 #define FAR
0174 #endif
0175 
0176 /******************************************************************************/
0177 
0178 /* Java Scalar Types */
0179 
0180 #if 0   /* now in jni.h */
0181 typedef short           jchar;
0182 typedef short           jshort;
0183 typedef float           jfloat;
0184 typedef double          jdouble;
0185 typedef juint           jsize;
0186 #endif
0187 
0188 /* moved from jni.h -- Sun's new jni.h doesn't have this anymore */
0189 #ifdef __cplusplus
0190 typedef class _jobject *jref;
0191 #else
0192 typedef struct _jobject *jref;
0193 #endif
0194 
0195 typedef unsigned char   jbool;
0196 typedef signed char jbyte;
0197 #ifdef IS_64 /* XXX ok for alpha, but not right on all 64-bit architectures */
0198 typedef unsigned int    juint;
0199 typedef int             jint;
0200 #else
0201 typedef unsigned long   juint;
0202 typedef long            jint;
0203 #endif
0204 
0205 /*******************************************************************************
0206  * jlong : long long (64-bit signed integer type) support.
0207  ******************************************************************************/
0208 
0209 /*
0210 ** Bit masking macros.  (n must be <= 31 to be portable)
0211 */
0212 #define JRI_BIT(n)          ((juint)1 << (n))
0213 #define JRI_BITMASK(n)      (JRI_BIT(n) - 1)
0214 
0215 #ifdef HAVE_LONG_LONG
0216 
0217 #ifdef OSF1
0218 
0219 /* long is default 64-bit on OSF1, -std1 does not allow long long */
0220 typedef long                  jlong;
0221 typedef unsigned long         julong;
0222 #define jlong_MAXINT          0x7fffffffffffffffL
0223 #define jlong_MININT          0x8000000000000000L
0224 #define jlong_ZERO            0x0L
0225 
0226 #elif (defined(WIN32) || defined(_WIN32))
0227 
0228 typedef LONGLONG              jlong;
0229 typedef DWORDLONG             julong;
0230 #define jlong_MAXINT          0x7fffffffffffffffi64
0231 #define jlong_MININT          0x8000000000000000i64
0232 #define jlong_ZERO            0x0i64
0233 
0234 #else
0235 
0236 typedef long long             jlong;
0237 typedef unsigned long long    julong;
0238 #define jlong_MAXINT          0x7fffffffffffffffLL
0239 #define jlong_MININT          0x8000000000000000LL
0240 #define jlong_ZERO            0x0LL
0241 
0242 #endif
0243 
0244 #define jlong_IS_ZERO(a)    ((a) == 0)
0245 #define jlong_EQ(a, b)      ((a) == (b))
0246 #define jlong_NE(a, b)      ((a) != (b))
0247 #define jlong_GE_ZERO(a)    ((a) >= 0)
0248 #define jlong_CMP(a, op, b) ((a) op (b))
0249 
0250 #define jlong_AND(r, a, b)  ((r) = (a) & (b))
0251 #define jlong_OR(r, a, b)   ((r) = (a) | (b))
0252 #define jlong_XOR(r, a, b)  ((r) = (a) ^ (b))
0253 #define jlong_OR2(r, a)     ((r) = (r) | (a))
0254 #define jlong_NOT(r, a)     ((r) = ~(a))
0255 
0256 #define jlong_NEG(r, a)     ((r) = -(a))
0257 #define jlong_ADD(r, a, b)  ((r) = (a) + (b))
0258 #define jlong_SUB(r, a, b)  ((r) = (a) - (b))
0259 
0260 #define jlong_MUL(r, a, b)  ((r) = (a) * (b))
0261 #define jlong_DIV(r, a, b)  ((r) = (a) / (b))
0262 #define jlong_MOD(r, a, b)  ((r) = (a) % (b))
0263 
0264 #define jlong_SHL(r, a, b)  ((r) = (a) << (b))
0265 #define jlong_SHR(r, a, b)  ((r) = (a) >> (b))
0266 #define jlong_USHR(r, a, b) ((r) = (julong)(a) >> (b))
0267 #define jlong_ISHL(r, a, b) ((r) = ((jlong)(a)) << (b))
0268 
0269 #define jlong_L2I(i, l)     ((i) = (int)(l))
0270 #define jlong_L2UI(ui, l)   ((ui) =(unsigned int)(l))
0271 #define jlong_L2F(f, l)     ((f) = (l))
0272 #define jlong_L2D(d, l)     ((d) = (l))
0273 
0274 #define jlong_I2L(l, i)     ((l) = (i))
0275 #define jlong_UI2L(l, ui)   ((l) = (ui))
0276 #define jlong_F2L(l, f)     ((l) = (f))
0277 #define jlong_D2L(l, d)     ((l) = (d))
0278 
0279 #define jlong_UDIVMOD(qp, rp, a, b)  \
0280     (*(qp) = ((julong)(a) / (b)), \
0281      *(rp) = ((julong)(a) % (b)))
0282 
0283 #else  /* !HAVE_LONG_LONG */
0284 
0285 typedef struct {
0286 #ifdef IS_LITTLE_ENDIAN
0287     juint lo, hi;
0288 #else
0289     juint hi, lo;
0290 #endif
0291 } jlong;
0292 typedef jlong               julong;
0293 
0294 extern jlong jlong_MAXINT, jlong_MININT, jlong_ZERO;
0295 
0296 #define jlong_IS_ZERO(a)    (((a).hi == 0) && ((a).lo == 0))
0297 #define jlong_EQ(a, b)      (((a).hi == (b).hi) && ((a).lo == (b).lo))
0298 #define jlong_NE(a, b)      (((a).hi != (b).hi) || ((a).lo != (b).lo))
0299 #define jlong_GE_ZERO(a)    (((a).hi >> 31) == 0)
0300 
0301 /*
0302  * NB: jlong_CMP and jlong_UCMP work only for strict relationals (<, >).
0303  */
0304 #define jlong_CMP(a, op, b) (((int32)(a).hi op (int32)(b).hi) ||          \
0305                  (((a).hi == (b).hi) && ((a).lo op (b).lo)))
0306 #define jlong_UCMP(a, op, b)    (((a).hi op (b).hi) ||                    \
0307                  (((a).hi == (b).hi) && ((a).lo op (b).lo)))
0308 
0309 #define jlong_AND(r, a, b)  ((r).lo = (a).lo & (b).lo,                    \
0310                  (r).hi = (a).hi & (b).hi)
0311 #define jlong_OR(r, a, b)   ((r).lo = (a).lo | (b).lo,                    \
0312                  (r).hi = (a).hi | (b).hi)
0313 #define jlong_XOR(r, a, b)  ((r).lo = (a).lo ^ (b).lo,                    \
0314                  (r).hi = (a).hi ^ (b).hi)
0315 #define jlong_OR2(r, a)     ((r).lo = (r).lo | (a).lo,                    \
0316                  (r).hi = (r).hi | (a).hi)
0317 #define jlong_NOT(r, a)     ((r).lo = ~(a).lo,                            \
0318                  (r).hi = ~(a).hi)
0319 
0320 #define jlong_NEG(r, a)     ((r).lo = -(int32)(a).lo,                     \
0321                  (r).hi = -(int32)(a).hi - ((r).lo != 0))
0322 #define jlong_ADD(r, a, b) {                                              \
0323     jlong _a, _b;                                                         \
0324     _a = a; _b = b;                                                       \
0325     (r).lo = _a.lo + _b.lo;                                               \
0326     (r).hi = _a.hi + _b.hi + ((r).lo < _b.lo);                            \
0327 }
0328 
0329 #define jlong_SUB(r, a, b) {                                              \
0330     jlong _a, _b;                                                         \
0331     _a = a; _b = b;                                                       \
0332     (r).lo = _a.lo - _b.lo;                                               \
0333     (r).hi = _a.hi - _b.hi - (_a.lo < _b.lo);                             \
0334 }                                                                         \
0335 
0336 /*
0337  * Multiply 64-bit operands a and b to get 64-bit result r.
0338  * First multiply the low 32 bits of a and b to get a 64-bit result in r.
0339  * Then add the outer and inner products to r.hi.
0340  */
0341 #define jlong_MUL(r, a, b) {                                              \
0342     jlong _a, _b;                                                         \
0343     _a = a; _b = b;                                                       \
0344     jlong_MUL32(r, _a.lo, _b.lo);                                         \
0345     (r).hi += _a.hi * _b.lo + _a.lo * _b.hi;                              \
0346 }
0347 
0348 /* XXX _jlong_lo16(a) = ((a) << 16 >> 16) is better on some archs (not on mips) */
0349 #define _jlong_lo16(a)      ((a) & JRI_BITMASK(16))
0350 #define _jlong_hi16(a)      ((a) >> 16)
0351 
0352 /*
0353  * Multiply 32-bit operands a and b to get 64-bit result r.
0354  * Use polynomial expansion based on primitive field element (1 << 16).
0355  */
0356 #define jlong_MUL32(r, a, b) {                                            \
0357      juint _a1, _a0, _b1, _b0, _y0, _y1, _y2, _y3;                        \
0358      _a1 = _jlong_hi16(a), _a0 = _jlong_lo16(a);                          \
0359      _b1 = _jlong_hi16(b), _b0 = _jlong_lo16(b);                          \
0360      _y0 = _a0 * _b0;                                                     \
0361      _y1 = _a0 * _b1;                                                     \
0362      _y2 = _a1 * _b0;                                                     \
0363      _y3 = _a1 * _b1;                                                     \
0364      _y1 += _jlong_hi16(_y0);                   /* can't carry */         \
0365      _y1 += _y2;                                /* might carry */         \
0366      if (_y1 < _y2) _y3 += 1 << 16;             /* propagate */           \
0367      (r).lo = (_jlong_lo16(_y1) << 16) + _jlong_lo16(_y0);                \
0368      (r).hi = _y3 + _jlong_hi16(_y1);                                     \
0369 }
0370 
0371 /*
0372  * Divide 64-bit unsigned operand a by 64-bit unsigned operand b, setting *qp
0373  * to the 64-bit unsigned quotient, and *rp to the 64-bit unsigned remainder.
0374  * Minimize effort if one of qp and rp is null.
0375  */
0376 #define jlong_UDIVMOD(qp, rp, a, b) jlong_udivmod(qp, rp, a, b)
0377 
0378 extern JRI_PUBLIC_API(void)
0379 jlong_udivmod(julong *qp, julong *rp, julong a, julong b);
0380 
0381 #define jlong_DIV(r, a, b) {                                              \
0382     jlong _a, _b;                                                         \
0383     juint _negative = (int32)(a).hi < 0;                                  \
0384     if (_negative) {                                                      \
0385     jlong_NEG(_a, a);                                                     \
0386     } else {                                                              \
0387     _a = a;                                                               \
0388     }                                                                     \
0389     if ((int32)(b).hi < 0) {                                              \
0390     _negative ^= 1;                                                       \
0391     jlong_NEG(_b, b);                                                     \
0392     } else {                                                              \
0393     _b = b;                                                               \
0394     }                                                                     \
0395     jlong_UDIVMOD(&(r), 0, _a, _b);                                       \
0396     if (_negative)                                                        \
0397     jlong_NEG(r, r);                                                      \
0398 }
0399 
0400 #define jlong_MOD(r, a, b) {                                              \
0401     jlong _a, _b;                                                         \
0402     juint _negative = (int32)(a).hi < 0;                                  \
0403     if (_negative) {                                                      \
0404     jlong_NEG(_a, a);                                                     \
0405     } else {                                                              \
0406     _a = a;                                                               \
0407     }                                                                     \
0408     if ((int32)(b).hi < 0) {                                              \
0409     jlong_NEG(_b, b);                                                     \
0410     } else {                                                              \
0411     _b = b;                                                               \
0412     }                                                                     \
0413     jlong_UDIVMOD(0, &(r), _a, _b);                                       \
0414     if (_negative)                                                        \
0415     jlong_NEG(r, r);                                                      \
0416 }
0417 
0418 /*
0419  * NB: b is a juint, not jlong or julong, for the shift ops.
0420  */
0421 #define jlong_SHL(r, a, b) {                                              \
0422     if (b) {                                                              \
0423     jlong _a;                                                             \
0424         _a = a;                                                           \
0425         if ((b) < 32) {                                                   \
0426         (r).lo = _a.lo << (b);                                            \
0427         (r).hi = (_a.hi << (b)) | (_a.lo >> (32 - (b)));                  \
0428     } else {                                                              \
0429         (r).lo = 0;                                                       \
0430         (r).hi = _a.lo << ((b) & 31);                                     \
0431     }                                                                     \
0432     } else {                                                              \
0433     (r) = (a);                                                            \
0434     }                                                                     \
0435 }
0436 
0437 /* a is an int32, b is int32, r is jlong */
0438 #define jlong_ISHL(r, a, b) {                                             \
0439     if (b) {                                                              \
0440     jlong _a;                                                             \
0441     _a.lo = (a);                                                          \
0442     _a.hi = 0;                                                            \
0443         if ((b) < 32) {                                                   \
0444         (r).lo = (a) << (b);                                              \
0445         (r).hi = ((a) >> (32 - (b)));                                     \
0446     } else {                                                              \
0447         (r).lo = 0;                                                       \
0448         (r).hi = (a) << ((b) & 31);                                       \
0449     }                                                                     \
0450     } else {                                                              \
0451     (r).lo = (a);                                                         \
0452     (r).hi = 0;                                                           \
0453     }                                                                     \
0454 }
0455 
0456 #define jlong_SHR(r, a, b) {                                              \
0457     if (b) {                                                              \
0458     jlong _a;                                                             \
0459         _a = a;                                                           \
0460     if ((b) < 32) {                                                       \
0461         (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> (b));                  \
0462         (r).hi = (int32)_a.hi >> (b);                                     \
0463     } else {                                                              \
0464         (r).lo = (int32)_a.hi >> ((b) & 31);                              \
0465         (r).hi = (int32)_a.hi >> 31;                                      \
0466     }                                                                     \
0467     } else {                                                              \
0468     (r) = (a);                                                            \
0469     }                                                                     \
0470 }
0471 
0472 #define jlong_USHR(r, a, b) {                                             \
0473     if (b) {                                                              \
0474     jlong _a;                                                             \
0475         _a = a;                                                           \
0476     if ((b) < 32) {                                                       \
0477         (r).lo = (_a.hi << (32 - (b))) | (_a.lo >> (b));                  \
0478         (r).hi = _a.hi >> (b);                                            \
0479     } else {                                                              \
0480         (r).lo = _a.hi >> ((b) & 31);                                     \
0481         (r).hi = 0;                                                       \
0482     }                                                                     \
0483     } else {                                                              \
0484     (r) = (a);                                                            \
0485     }                                                                     \
0486 }
0487 
0488 #define jlong_L2I(i, l)     ((i) = (l).lo)
0489 #define jlong_L2UI(ui, l)   ((ui) = (l).lo)
0490 #define jlong_L2F(f, l)     { double _d; jlong_L2D(_d, l); (f) = (float) _d; }
0491 
0492 #define jlong_L2D(d, l) {                                                 \
0493     int32 _negative;                                                      \
0494     jlong _absval;                                                        \
0495                                                                           \
0496     _negative = (l).hi >> 31;                                             \
0497     if (_negative) {                                                      \
0498     jlong_NEG(_absval, l);                                                \
0499     } else {                                                              \
0500     _absval = l;                                                          \
0501     }                                                                     \
0502     (d) = (double)_absval.hi * 4.294967296e9 + _absval.lo;                \
0503     if (_negative)                                                        \
0504     (d) = -(d);                                                           \
0505 }
0506 
0507 #define jlong_I2L(l, i)     ((l).hi = (i) >> 31, (l).lo = (i))
0508 #define jlong_UI2L(l, ui)   ((l).hi = 0, (l).lo = (ui))
0509 #define jlong_F2L(l, f)     { double _d = (double) f; jlong_D2L(l, _d); }
0510 
0511 #define jlong_D2L(l, d) {                                                 \
0512     int _negative;                                                        \
0513     double _absval, _d_hi;                                                \
0514     jlong _lo_d;                                                          \
0515                                                                           \
0516     _negative = ((d) < 0);                                                \
0517     _absval = _negative ? -(d) : (d);                                     \
0518                                                                           \
0519     (l).hi = (juint)(_absval / 4.294967296e9);                            \
0520     (l).lo = 0;                                                           \
0521     jlong_L2D(_d_hi, l);                                                  \
0522     _absval -= _d_hi;                                                     \
0523     _lo_d.hi = 0;                                                         \
0524     if (_absval < 0) {                                                    \
0525     _lo_d.lo = (juint) -_absval;                                          \
0526     jlong_SUB(l, l, _lo_d);                                               \
0527     } else {                                                              \
0528     _lo_d.lo = (juint) _absval;                                           \
0529     jlong_ADD(l, l, _lo_d);                                               \
0530     }                                                                     \
0531                                                                           \
0532     if (_negative)                                                        \
0533     jlong_NEG(l, l);                                                      \
0534 }
0535 
0536 #endif /* !HAVE_LONG_LONG */
0537 
0538 /******************************************************************************/
0539 
0540 #ifdef HAVE_ALIGNED_LONGLONGS
0541 #define JRI_GET_INT64(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \
0542                               ((_t).x[1] = ((jint*)(_addr))[1]),      \
0543                               (_t).l )
0544 #define JRI_SET_INT64(_t, _addr, _v) ( (_t).l = (_v),                \
0545                                    ((jint*)(_addr))[0] = (_t).x[0], \
0546                                    ((jint*)(_addr))[1] = (_t).x[1] )
0547 #else
0548 #define JRI_GET_INT64(_t,_addr) (*(jlong*)(_addr))
0549 #define JRI_SET_INT64(_t, _addr, _v) (*(jlong*)(_addr) = (_v))
0550 #endif
0551 
0552 /* If double's must be aligned on doubleword boundaries then define this */
0553 #ifdef HAVE_ALIGNED_DOUBLES
0554 #define JRI_GET_DOUBLE(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \
0555                                ((_t).x[1] = ((jint*)(_addr))[1]),      \
0556                                (_t).d )
0557 #define JRI_SET_DOUBLE(_t, _addr, _v) ( (_t).d = (_v),                \
0558                                     ((jint*)(_addr))[0] = (_t).x[0], \
0559                                     ((jint*)(_addr))[1] = (_t).x[1] )
0560 #else
0561 #define JRI_GET_DOUBLE(_t,_addr) (*(jdouble*)(_addr))
0562 #define JRI_SET_DOUBLE(_t, _addr, _v) (*(jdouble*)(_addr) = (_v))
0563 #endif
0564 
0565 /******************************************************************************/
0566 #ifdef __cplusplus
0567 }
0568 #endif
0569 #endif /* JRI_MD_H */
0570 /******************************************************************************/