|
1 /* |
|
2 * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved. |
|
3 * Copyright 2007 Red Hat, Inc. |
|
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 * |
|
6 * This code is free software; you can redistribute it and/or modify it |
|
7 * under the terms of the GNU General Public License version 2 only, as |
|
8 * published by the Free Software Foundation. |
|
9 * |
|
10 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 * version 2 for more details (a copy is included in the LICENSE file that |
|
14 * accompanied this code). |
|
15 * |
|
16 * You should have received a copy of the GNU General Public License version |
|
17 * 2 along with this work; if not, write to the Free Software Foundation, |
|
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 * |
|
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
21 * CA 95054 USA or visit www.sun.com if you need additional information or |
|
22 * have any questions. |
|
23 * |
|
24 */ |
|
25 |
|
26 // Inline interpreter functions for zero |
|
27 |
|
28 inline jfloat BytecodeInterpreter::VMfloatAdd(jfloat op1, jfloat op2) { |
|
29 return op1 + op2; |
|
30 } |
|
31 |
|
32 inline jfloat BytecodeInterpreter::VMfloatSub(jfloat op1, jfloat op2) { |
|
33 return op1 - op2; |
|
34 } |
|
35 |
|
36 inline jfloat BytecodeInterpreter::VMfloatMul(jfloat op1, jfloat op2) { |
|
37 return op1 * op2; |
|
38 } |
|
39 |
|
40 inline jfloat BytecodeInterpreter::VMfloatDiv(jfloat op1, jfloat op2) { |
|
41 return op1 / op2; |
|
42 } |
|
43 |
|
44 inline jfloat BytecodeInterpreter::VMfloatRem(jfloat op1, jfloat op2) { |
|
45 return fmod(op1, op2); |
|
46 } |
|
47 |
|
48 inline jfloat BytecodeInterpreter::VMfloatNeg(jfloat op) { |
|
49 return -op; |
|
50 } |
|
51 |
|
52 inline int32_t BytecodeInterpreter::VMfloatCompare(jfloat op1, |
|
53 jfloat op2, |
|
54 int32_t direction) { |
|
55 return ( op1 < op2 ? -1 : |
|
56 op1 > op2 ? 1 : |
|
57 op1 == op2 ? 0 : |
|
58 (direction == -1 || direction == 1) ? direction : 0); |
|
59 |
|
60 } |
|
61 |
|
62 inline void BytecodeInterpreter::VMmemCopy64(uint32_t to[2], |
|
63 const uint32_t from[2]) { |
|
64 *(uint64_t *) to = *(uint64_t *) from; |
|
65 } |
|
66 |
|
67 inline jlong BytecodeInterpreter::VMlongAdd(jlong op1, jlong op2) { |
|
68 return op1 + op2; |
|
69 } |
|
70 |
|
71 inline jlong BytecodeInterpreter::VMlongAnd(jlong op1, jlong op2) { |
|
72 return op1 & op2; |
|
73 } |
|
74 |
|
75 inline jlong BytecodeInterpreter::VMlongDiv(jlong op1, jlong op2) { |
|
76 /* it's possible we could catch this special case implicitly */ |
|
77 if (op1 == (jlong) 0x8000000000000000LL && op2 == -1) return op1; |
|
78 else return op1 / op2; |
|
79 } |
|
80 |
|
81 inline jlong BytecodeInterpreter::VMlongMul(jlong op1, jlong op2) { |
|
82 return op1 * op2; |
|
83 } |
|
84 |
|
85 inline jlong BytecodeInterpreter::VMlongOr(jlong op1, jlong op2) { |
|
86 return op1 | op2; |
|
87 } |
|
88 |
|
89 inline jlong BytecodeInterpreter::VMlongSub(jlong op1, jlong op2) { |
|
90 return op1 - op2; |
|
91 } |
|
92 |
|
93 inline jlong BytecodeInterpreter::VMlongXor(jlong op1, jlong op2) { |
|
94 return op1 ^ op2; |
|
95 } |
|
96 |
|
97 inline jlong BytecodeInterpreter::VMlongRem(jlong op1, jlong op2) { |
|
98 /* it's possible we could catch this special case implicitly */ |
|
99 if (op1 == (jlong) 0x8000000000000000LL && op2 == -1) return 0; |
|
100 else return op1 % op2; |
|
101 } |
|
102 |
|
103 inline jlong BytecodeInterpreter::VMlongUshr(jlong op1, jint op2) { |
|
104 return ((unsigned long long) op1) >> (op2 & 0x3F); |
|
105 } |
|
106 |
|
107 inline jlong BytecodeInterpreter::VMlongShr(jlong op1, jint op2) { |
|
108 return op1 >> (op2 & 0x3F); |
|
109 } |
|
110 |
|
111 inline jlong BytecodeInterpreter::VMlongShl(jlong op1, jint op2) { |
|
112 return op1 << (op2 & 0x3F); |
|
113 } |
|
114 |
|
115 inline jlong BytecodeInterpreter::VMlongNeg(jlong op) { |
|
116 return -op; |
|
117 } |
|
118 |
|
119 inline jlong BytecodeInterpreter::VMlongNot(jlong op) { |
|
120 return ~op; |
|
121 } |
|
122 |
|
123 inline int32_t BytecodeInterpreter::VMlongLtz(jlong op) { |
|
124 return (op <= 0); |
|
125 } |
|
126 |
|
127 inline int32_t BytecodeInterpreter::VMlongGez(jlong op) { |
|
128 return (op >= 0); |
|
129 } |
|
130 |
|
131 inline int32_t BytecodeInterpreter::VMlongEqz(jlong op) { |
|
132 return (op == 0); |
|
133 } |
|
134 |
|
135 inline int32_t BytecodeInterpreter::VMlongEq(jlong op1, jlong op2) { |
|
136 return (op1 == op2); |
|
137 } |
|
138 |
|
139 inline int32_t BytecodeInterpreter::VMlongNe(jlong op1, jlong op2) { |
|
140 return (op1 != op2); |
|
141 } |
|
142 |
|
143 inline int32_t BytecodeInterpreter::VMlongGe(jlong op1, jlong op2) { |
|
144 return (op1 >= op2); |
|
145 } |
|
146 |
|
147 inline int32_t BytecodeInterpreter::VMlongLe(jlong op1, jlong op2) { |
|
148 return (op1 <= op2); |
|
149 } |
|
150 |
|
151 inline int32_t BytecodeInterpreter::VMlongLt(jlong op1, jlong op2) { |
|
152 return (op1 < op2); |
|
153 } |
|
154 |
|
155 inline int32_t BytecodeInterpreter::VMlongGt(jlong op1, jlong op2) { |
|
156 return (op1 > op2); |
|
157 } |
|
158 |
|
159 inline int32_t BytecodeInterpreter::VMlongCompare(jlong op1, jlong op2) { |
|
160 return (VMlongLt(op1, op2) ? -1 : VMlongGt(op1, op2) ? 1 : 0); |
|
161 } |
|
162 |
|
163 // Long conversions |
|
164 |
|
165 inline jdouble BytecodeInterpreter::VMlong2Double(jlong val) { |
|
166 return (jdouble) val; |
|
167 } |
|
168 |
|
169 inline jfloat BytecodeInterpreter::VMlong2Float(jlong val) { |
|
170 return (jfloat) val; |
|
171 } |
|
172 |
|
173 inline jint BytecodeInterpreter::VMlong2Int(jlong val) { |
|
174 return (jint) val; |
|
175 } |
|
176 |
|
177 // Double Arithmetic |
|
178 |
|
179 inline jdouble BytecodeInterpreter::VMdoubleAdd(jdouble op1, jdouble op2) { |
|
180 return op1 + op2; |
|
181 } |
|
182 |
|
183 inline jdouble BytecodeInterpreter::VMdoubleDiv(jdouble op1, jdouble op2) { |
|
184 // Divide by zero... QQQ |
|
185 return op1 / op2; |
|
186 } |
|
187 |
|
188 inline jdouble BytecodeInterpreter::VMdoubleMul(jdouble op1, jdouble op2) { |
|
189 return op1 * op2; |
|
190 } |
|
191 |
|
192 inline jdouble BytecodeInterpreter::VMdoubleNeg(jdouble op) { |
|
193 return -op; |
|
194 } |
|
195 |
|
196 inline jdouble BytecodeInterpreter::VMdoubleRem(jdouble op1, jdouble op2) { |
|
197 return fmod(op1, op2); |
|
198 } |
|
199 |
|
200 inline jdouble BytecodeInterpreter::VMdoubleSub(jdouble op1, jdouble op2) { |
|
201 return op1 - op2; |
|
202 } |
|
203 |
|
204 inline int32_t BytecodeInterpreter::VMdoubleCompare(jdouble op1, |
|
205 jdouble op2, |
|
206 int32_t direction) { |
|
207 return ( op1 < op2 ? -1 : |
|
208 op1 > op2 ? 1 : |
|
209 op1 == op2 ? 0 : |
|
210 (direction == -1 || direction == 1) ? direction : 0); |
|
211 } |
|
212 |
|
213 // Double Conversions |
|
214 |
|
215 inline jfloat BytecodeInterpreter::VMdouble2Float(jdouble val) { |
|
216 return (jfloat) val; |
|
217 } |
|
218 |
|
219 // Float Conversions |
|
220 |
|
221 inline jdouble BytecodeInterpreter::VMfloat2Double(jfloat op) { |
|
222 return (jdouble) op; |
|
223 } |
|
224 |
|
225 // Integer Arithmetic |
|
226 |
|
227 inline jint BytecodeInterpreter::VMintAdd(jint op1, jint op2) { |
|
228 return op1 + op2; |
|
229 } |
|
230 |
|
231 inline jint BytecodeInterpreter::VMintAnd(jint op1, jint op2) { |
|
232 return op1 & op2; |
|
233 } |
|
234 |
|
235 inline jint BytecodeInterpreter::VMintDiv(jint op1, jint op2) { |
|
236 /* it's possible we could catch this special case implicitly */ |
|
237 if (op1 == (jint) 0x80000000 && op2 == -1) return op1; |
|
238 else return op1 / op2; |
|
239 } |
|
240 |
|
241 inline jint BytecodeInterpreter::VMintMul(jint op1, jint op2) { |
|
242 return op1 * op2; |
|
243 } |
|
244 |
|
245 inline jint BytecodeInterpreter::VMintNeg(jint op) { |
|
246 return -op; |
|
247 } |
|
248 |
|
249 inline jint BytecodeInterpreter::VMintOr(jint op1, jint op2) { |
|
250 return op1 | op2; |
|
251 } |
|
252 |
|
253 inline jint BytecodeInterpreter::VMintRem(jint op1, jint op2) { |
|
254 /* it's possible we could catch this special case implicitly */ |
|
255 if (op1 == (jint) 0x80000000 && op2 == -1) return 0; |
|
256 else return op1 % op2; |
|
257 } |
|
258 |
|
259 inline jint BytecodeInterpreter::VMintShl(jint op1, jint op2) { |
|
260 return op1 << (op2 & 0x1F); |
|
261 } |
|
262 |
|
263 inline jint BytecodeInterpreter::VMintShr(jint op1, jint op2) { |
|
264 return op1 >> (op2 & 0x1F); |
|
265 } |
|
266 |
|
267 inline jint BytecodeInterpreter::VMintSub(jint op1, jint op2) { |
|
268 return op1 - op2; |
|
269 } |
|
270 |
|
271 inline jint BytecodeInterpreter::VMintUshr(jint op1, jint op2) { |
|
272 return ((juint) op1) >> (op2 & 0x1F); |
|
273 } |
|
274 |
|
275 inline jint BytecodeInterpreter::VMintXor(jint op1, jint op2) { |
|
276 return op1 ^ op2; |
|
277 } |
|
278 |
|
279 inline jdouble BytecodeInterpreter::VMint2Double(jint val) { |
|
280 return (jdouble) val; |
|
281 } |
|
282 |
|
283 inline jfloat BytecodeInterpreter::VMint2Float(jint val) { |
|
284 return (jfloat) val; |
|
285 } |
|
286 |
|
287 inline jlong BytecodeInterpreter::VMint2Long(jint val) { |
|
288 return (jlong) val; |
|
289 } |
|
290 |
|
291 inline jchar BytecodeInterpreter::VMint2Char(jint val) { |
|
292 return (jchar) val; |
|
293 } |
|
294 |
|
295 inline jshort BytecodeInterpreter::VMint2Short(jint val) { |
|
296 return (jshort) val; |
|
297 } |
|
298 |
|
299 inline jbyte BytecodeInterpreter::VMint2Byte(jint val) { |
|
300 return (jbyte) val; |
|
301 } |