Fri, 12 Feb 2010 10:34:11 -0800
6926048: Improve Zero performance
Summary: Make Zero figure out result types in a similar way to C++ interpreter implementation.
Reviewed-by: kvn
Contributed-by: gbenson@redhat.com
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 */
26 // Inline interpreter functions for zero
28 inline jfloat BytecodeInterpreter::VMfloatAdd(jfloat op1, jfloat op2) {
29 return op1 + op2;
30 }
32 inline jfloat BytecodeInterpreter::VMfloatSub(jfloat op1, jfloat op2) {
33 return op1 - op2;
34 }
36 inline jfloat BytecodeInterpreter::VMfloatMul(jfloat op1, jfloat op2) {
37 return op1 * op2;
38 }
40 inline jfloat BytecodeInterpreter::VMfloatDiv(jfloat op1, jfloat op2) {
41 return op1 / op2;
42 }
44 inline jfloat BytecodeInterpreter::VMfloatRem(jfloat op1, jfloat op2) {
45 return fmod(op1, op2);
46 }
48 inline jfloat BytecodeInterpreter::VMfloatNeg(jfloat op) {
49 return -op;
50 }
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);
60 }
62 inline void BytecodeInterpreter::VMmemCopy64(uint32_t to[2],
63 const uint32_t from[2]) {
64 *(uint64_t *) to = *(uint64_t *) from;
65 }
67 inline jlong BytecodeInterpreter::VMlongAdd(jlong op1, jlong op2) {
68 return op1 + op2;
69 }
71 inline jlong BytecodeInterpreter::VMlongAnd(jlong op1, jlong op2) {
72 return op1 & op2;
73 }
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 }
81 inline jlong BytecodeInterpreter::VMlongMul(jlong op1, jlong op2) {
82 return op1 * op2;
83 }
85 inline jlong BytecodeInterpreter::VMlongOr(jlong op1, jlong op2) {
86 return op1 | op2;
87 }
89 inline jlong BytecodeInterpreter::VMlongSub(jlong op1, jlong op2) {
90 return op1 - op2;
91 }
93 inline jlong BytecodeInterpreter::VMlongXor(jlong op1, jlong op2) {
94 return op1 ^ op2;
95 }
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 }
103 inline jlong BytecodeInterpreter::VMlongUshr(jlong op1, jint op2) {
104 return ((unsigned long long) op1) >> (op2 & 0x3F);
105 }
107 inline jlong BytecodeInterpreter::VMlongShr(jlong op1, jint op2) {
108 return op1 >> (op2 & 0x3F);
109 }
111 inline jlong BytecodeInterpreter::VMlongShl(jlong op1, jint op2) {
112 return op1 << (op2 & 0x3F);
113 }
115 inline jlong BytecodeInterpreter::VMlongNeg(jlong op) {
116 return -op;
117 }
119 inline jlong BytecodeInterpreter::VMlongNot(jlong op) {
120 return ~op;
121 }
123 inline int32_t BytecodeInterpreter::VMlongLtz(jlong op) {
124 return (op <= 0);
125 }
127 inline int32_t BytecodeInterpreter::VMlongGez(jlong op) {
128 return (op >= 0);
129 }
131 inline int32_t BytecodeInterpreter::VMlongEqz(jlong op) {
132 return (op == 0);
133 }
135 inline int32_t BytecodeInterpreter::VMlongEq(jlong op1, jlong op2) {
136 return (op1 == op2);
137 }
139 inline int32_t BytecodeInterpreter::VMlongNe(jlong op1, jlong op2) {
140 return (op1 != op2);
141 }
143 inline int32_t BytecodeInterpreter::VMlongGe(jlong op1, jlong op2) {
144 return (op1 >= op2);
145 }
147 inline int32_t BytecodeInterpreter::VMlongLe(jlong op1, jlong op2) {
148 return (op1 <= op2);
149 }
151 inline int32_t BytecodeInterpreter::VMlongLt(jlong op1, jlong op2) {
152 return (op1 < op2);
153 }
155 inline int32_t BytecodeInterpreter::VMlongGt(jlong op1, jlong op2) {
156 return (op1 > op2);
157 }
159 inline int32_t BytecodeInterpreter::VMlongCompare(jlong op1, jlong op2) {
160 return (VMlongLt(op1, op2) ? -1 : VMlongGt(op1, op2) ? 1 : 0);
161 }
163 // Long conversions
165 inline jdouble BytecodeInterpreter::VMlong2Double(jlong val) {
166 return (jdouble) val;
167 }
169 inline jfloat BytecodeInterpreter::VMlong2Float(jlong val) {
170 return (jfloat) val;
171 }
173 inline jint BytecodeInterpreter::VMlong2Int(jlong val) {
174 return (jint) val;
175 }
177 // Double Arithmetic
179 inline jdouble BytecodeInterpreter::VMdoubleAdd(jdouble op1, jdouble op2) {
180 return op1 + op2;
181 }
183 inline jdouble BytecodeInterpreter::VMdoubleDiv(jdouble op1, jdouble op2) {
184 // Divide by zero... QQQ
185 return op1 / op2;
186 }
188 inline jdouble BytecodeInterpreter::VMdoubleMul(jdouble op1, jdouble op2) {
189 return op1 * op2;
190 }
192 inline jdouble BytecodeInterpreter::VMdoubleNeg(jdouble op) {
193 return -op;
194 }
196 inline jdouble BytecodeInterpreter::VMdoubleRem(jdouble op1, jdouble op2) {
197 return fmod(op1, op2);
198 }
200 inline jdouble BytecodeInterpreter::VMdoubleSub(jdouble op1, jdouble op2) {
201 return op1 - op2;
202 }
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 }
213 // Double Conversions
215 inline jfloat BytecodeInterpreter::VMdouble2Float(jdouble val) {
216 return (jfloat) val;
217 }
219 // Float Conversions
221 inline jdouble BytecodeInterpreter::VMfloat2Double(jfloat op) {
222 return (jdouble) op;
223 }
225 // Integer Arithmetic
227 inline jint BytecodeInterpreter::VMintAdd(jint op1, jint op2) {
228 return op1 + op2;
229 }
231 inline jint BytecodeInterpreter::VMintAnd(jint op1, jint op2) {
232 return op1 & op2;
233 }
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 }
241 inline jint BytecodeInterpreter::VMintMul(jint op1, jint op2) {
242 return op1 * op2;
243 }
245 inline jint BytecodeInterpreter::VMintNeg(jint op) {
246 return -op;
247 }
249 inline jint BytecodeInterpreter::VMintOr(jint op1, jint op2) {
250 return op1 | op2;
251 }
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 }
259 inline jint BytecodeInterpreter::VMintShl(jint op1, jint op2) {
260 return op1 << (op2 & 0x1F);
261 }
263 inline jint BytecodeInterpreter::VMintShr(jint op1, jint op2) {
264 return op1 >> (op2 & 0x1F);
265 }
267 inline jint BytecodeInterpreter::VMintSub(jint op1, jint op2) {
268 return op1 - op2;
269 }
271 inline jint BytecodeInterpreter::VMintUshr(jint op1, jint op2) {
272 return ((juint) op1) >> (op2 & 0x1F);
273 }
275 inline jint BytecodeInterpreter::VMintXor(jint op1, jint op2) {
276 return op1 ^ op2;
277 }
279 inline jdouble BytecodeInterpreter::VMint2Double(jint val) {
280 return (jdouble) val;
281 }
283 inline jfloat BytecodeInterpreter::VMint2Float(jint val) {
284 return (jfloat) val;
285 }
287 inline jlong BytecodeInterpreter::VMint2Long(jint val) {
288 return (jlong) val;
289 }
291 inline jchar BytecodeInterpreter::VMint2Char(jint val) {
292 return (jchar) val;
293 }
295 inline jshort BytecodeInterpreter::VMint2Short(jint val) {
296 return (jshort) val;
297 }
299 inline jbyte BytecodeInterpreter::VMint2Byte(jint val) {
300 return (jbyte) val;
301 }