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