1 /*
2  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
3  * Copyright 2007, 2010 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21  * or visit www.oracle.com if you need additional information or have any
22  * questions.
23  *
24  */
25 
26 #ifndef CPU_ZERO_VM_BYTECODEINTERPRETER_ZERO_INLINE_HPP
27 #define CPU_ZERO_VM_BYTECODEINTERPRETER_ZERO_INLINE_HPP
28 
29 // Inline interpreter functions for zero
30 
VMfloatAdd(jfloat op1,jfloat op2)31 inline jfloat BytecodeInterpreter::VMfloatAdd(jfloat op1, jfloat op2) {
32   return op1 + op2;
33 }
34 
VMfloatSub(jfloat op1,jfloat op2)35 inline jfloat BytecodeInterpreter::VMfloatSub(jfloat op1, jfloat op2) {
36   return op1 - op2;
37 }
38 
VMfloatMul(jfloat op1,jfloat op2)39 inline jfloat BytecodeInterpreter::VMfloatMul(jfloat op1, jfloat op2) {
40   return op1 * op2;
41 }
42 
VMfloatDiv(jfloat op1,jfloat op2)43 inline jfloat BytecodeInterpreter::VMfloatDiv(jfloat op1, jfloat op2) {
44   return op1 / op2;
45 }
46 
VMfloatRem(jfloat op1,jfloat op2)47 inline jfloat BytecodeInterpreter::VMfloatRem(jfloat op1, jfloat op2) {
48   return fmod(op1, op2);
49 }
50 
VMfloatNeg(jfloat op)51 inline jfloat BytecodeInterpreter::VMfloatNeg(jfloat op) {
52   return -op;
53 }
54 
VMfloatCompare(jfloat op1,jfloat op2,int32_t direction)55 inline int32_t BytecodeInterpreter::VMfloatCompare(jfloat  op1,
56                                                    jfloat  op2,
57                                                    int32_t direction) {
58   return ( op1 < op2 ? -1 :
59                op1 > op2 ? 1 :
60                    op1 == op2 ? 0 :
61                        (direction == -1 || direction == 1) ? direction : 0);
62 
63 }
64 
VMmemCopy64(uint32_t to[2],const uint32_t from[2])65 inline void BytecodeInterpreter::VMmemCopy64(uint32_t       to[2],
66                                              const uint32_t from[2]) {
67   *(uint64_t *) to = *(uint64_t *) from;
68 }
69 
VMlongAdd(jlong op1,jlong op2)70 inline jlong BytecodeInterpreter::VMlongAdd(jlong op1, jlong op2) {
71   return op1 + op2;
72 }
73 
VMlongAnd(jlong op1,jlong op2)74 inline jlong BytecodeInterpreter::VMlongAnd(jlong op1, jlong op2) {
75   return op1 & op2;
76 }
77 
VMlongDiv(jlong op1,jlong op2)78 inline jlong BytecodeInterpreter::VMlongDiv(jlong op1, jlong op2) {
79   /* it's possible we could catch this special case implicitly */
80   if (op1 == (jlong) 0x8000000000000000LL && op2 == -1) return op1;
81   else return op1 / op2;
82 }
83 
VMlongMul(jlong op1,jlong op2)84 inline jlong BytecodeInterpreter::VMlongMul(jlong op1, jlong op2) {
85   return op1 * op2;
86 }
87 
VMlongOr(jlong op1,jlong op2)88 inline jlong BytecodeInterpreter::VMlongOr(jlong op1, jlong op2) {
89   return op1 | op2;
90 }
91 
VMlongSub(jlong op1,jlong op2)92 inline jlong BytecodeInterpreter::VMlongSub(jlong op1, jlong op2) {
93   return op1 - op2;
94 }
95 
VMlongXor(jlong op1,jlong op2)96 inline jlong BytecodeInterpreter::VMlongXor(jlong op1, jlong op2) {
97   return op1 ^ op2;
98 }
99 
VMlongRem(jlong op1,jlong op2)100 inline jlong BytecodeInterpreter::VMlongRem(jlong op1, jlong op2) {
101   /* it's possible we could catch this special case implicitly */
102   if (op1 == (jlong) 0x8000000000000000LL && op2 == -1) return 0;
103   else return op1 % op2;
104 }
105 
VMlongUshr(jlong op1,jint op2)106 inline jlong BytecodeInterpreter::VMlongUshr(jlong op1, jint op2) {
107   return ((unsigned long long) op1) >> (op2 & 0x3F);
108 }
109 
VMlongShr(jlong op1,jint op2)110 inline jlong BytecodeInterpreter::VMlongShr(jlong op1, jint op2) {
111   return op1 >> (op2 & 0x3F);
112 }
113 
VMlongShl(jlong op1,jint op2)114 inline jlong BytecodeInterpreter::VMlongShl(jlong op1, jint op2) {
115   return op1 << (op2 & 0x3F);
116 }
117 
VMlongNeg(jlong op)118 inline jlong BytecodeInterpreter::VMlongNeg(jlong op) {
119   return -op;
120 }
121 
VMlongNot(jlong op)122 inline jlong BytecodeInterpreter::VMlongNot(jlong op) {
123   return ~op;
124 }
125 
VMlongLtz(jlong op)126 inline int32_t BytecodeInterpreter::VMlongLtz(jlong op) {
127   return (op <= 0);
128 }
129 
VMlongGez(jlong op)130 inline int32_t BytecodeInterpreter::VMlongGez(jlong op) {
131   return (op >= 0);
132 }
133 
VMlongEqz(jlong op)134 inline int32_t BytecodeInterpreter::VMlongEqz(jlong op) {
135   return (op == 0);
136 }
137 
VMlongEq(jlong op1,jlong op2)138 inline int32_t BytecodeInterpreter::VMlongEq(jlong op1, jlong op2) {
139   return (op1 == op2);
140 }
141 
VMlongNe(jlong op1,jlong op2)142 inline int32_t BytecodeInterpreter::VMlongNe(jlong op1, jlong op2) {
143   return (op1 != op2);
144 }
145 
VMlongGe(jlong op1,jlong op2)146 inline int32_t BytecodeInterpreter::VMlongGe(jlong op1, jlong op2) {
147   return (op1 >= op2);
148 }
149 
VMlongLe(jlong op1,jlong op2)150 inline int32_t BytecodeInterpreter::VMlongLe(jlong op1, jlong op2) {
151   return (op1 <= op2);
152 }
153 
VMlongLt(jlong op1,jlong op2)154 inline int32_t BytecodeInterpreter::VMlongLt(jlong op1, jlong op2) {
155   return (op1 < op2);
156 }
157 
VMlongGt(jlong op1,jlong op2)158 inline int32_t BytecodeInterpreter::VMlongGt(jlong op1, jlong op2) {
159   return (op1 > op2);
160 }
161 
VMlongCompare(jlong op1,jlong op2)162 inline int32_t BytecodeInterpreter::VMlongCompare(jlong op1, jlong op2) {
163   return (VMlongLt(op1, op2) ? -1 : VMlongGt(op1, op2) ? 1 : 0);
164 }
165 
166 // Long conversions
167 
VMlong2Double(jlong val)168 inline jdouble BytecodeInterpreter::VMlong2Double(jlong val) {
169   return (jdouble) val;
170 }
171 
VMlong2Float(jlong val)172 inline jfloat BytecodeInterpreter::VMlong2Float(jlong val) {
173   return (jfloat) val;
174 }
175 
VMlong2Int(jlong val)176 inline jint BytecodeInterpreter::VMlong2Int(jlong val) {
177   return (jint) val;
178 }
179 
180 // Double Arithmetic
181 
VMdoubleAdd(jdouble op1,jdouble op2)182 inline jdouble BytecodeInterpreter::VMdoubleAdd(jdouble op1, jdouble op2) {
183   return op1 + op2;
184 }
185 
VMdoubleDiv(jdouble op1,jdouble op2)186 inline jdouble BytecodeInterpreter::VMdoubleDiv(jdouble op1, jdouble op2) {
187   // Divide by zero... QQQ
188   return op1 / op2;
189 }
190 
VMdoubleMul(jdouble op1,jdouble op2)191 inline jdouble BytecodeInterpreter::VMdoubleMul(jdouble op1, jdouble op2) {
192   return op1 * op2;
193 }
194 
VMdoubleNeg(jdouble op)195 inline jdouble BytecodeInterpreter::VMdoubleNeg(jdouble op) {
196   return -op;
197 }
198 
VMdoubleRem(jdouble op1,jdouble op2)199 inline jdouble BytecodeInterpreter::VMdoubleRem(jdouble op1, jdouble op2) {
200   return fmod(op1, op2);
201 }
202 
VMdoubleSub(jdouble op1,jdouble op2)203 inline jdouble BytecodeInterpreter::VMdoubleSub(jdouble op1, jdouble op2) {
204   return op1 - op2;
205 }
206 
VMdoubleCompare(jdouble op1,jdouble op2,int32_t direction)207 inline int32_t BytecodeInterpreter::VMdoubleCompare(jdouble op1,
208                                                     jdouble op2,
209                                                     int32_t direction) {
210   return ( op1 < op2 ? -1 :
211                op1 > op2 ? 1 :
212                    op1 == op2 ? 0 :
213                        (direction == -1 || direction == 1) ? direction : 0);
214 }
215 
216 // Double Conversions
217 
VMdouble2Float(jdouble val)218 inline jfloat BytecodeInterpreter::VMdouble2Float(jdouble val) {
219   return (jfloat) val;
220 }
221 
222 // Float Conversions
223 
VMfloat2Double(jfloat op)224 inline jdouble BytecodeInterpreter::VMfloat2Double(jfloat op) {
225   return (jdouble) op;
226 }
227 
228 // Integer Arithmetic
229 
VMintAdd(jint op1,jint op2)230 inline jint BytecodeInterpreter::VMintAdd(jint op1, jint op2) {
231   return op1 + op2;
232 }
233 
VMintAnd(jint op1,jint op2)234 inline jint BytecodeInterpreter::VMintAnd(jint op1, jint op2) {
235   return op1 & op2;
236 }
237 
VMintDiv(jint op1,jint op2)238 inline jint BytecodeInterpreter::VMintDiv(jint op1, jint op2) {
239   /* it's possible we could catch this special case implicitly */
240   if (op1 == (jint) 0x80000000 && op2 == -1) return op1;
241   else return op1 / op2;
242 }
243 
VMintMul(jint op1,jint op2)244 inline jint BytecodeInterpreter::VMintMul(jint op1, jint op2) {
245   return op1 * op2;
246 }
247 
VMintNeg(jint op)248 inline jint BytecodeInterpreter::VMintNeg(jint op) {
249   return -op;
250 }
251 
VMintOr(jint op1,jint op2)252 inline jint BytecodeInterpreter::VMintOr(jint op1, jint op2) {
253   return op1 | op2;
254 }
255 
VMintRem(jint op1,jint op2)256 inline jint BytecodeInterpreter::VMintRem(jint op1, jint op2) {
257   /* it's possible we could catch this special case implicitly */
258   if (op1 == (jint) 0x80000000 && op2 == -1) return 0;
259   else return op1 % op2;
260 }
261 
VMintShl(jint op1,jint op2)262 inline jint BytecodeInterpreter::VMintShl(jint op1, jint op2) {
263   return op1 << (op2 & 0x1F);
264 }
265 
VMintShr(jint op1,jint op2)266 inline jint BytecodeInterpreter::VMintShr(jint op1, jint op2) {
267   return op1 >> (op2 & 0x1F);
268 }
269 
VMintSub(jint op1,jint op2)270 inline jint BytecodeInterpreter::VMintSub(jint op1, jint op2) {
271   return op1 - op2;
272 }
273 
VMintUshr(jint op1,jint op2)274 inline juint BytecodeInterpreter::VMintUshr(jint op1, jint op2) {
275   return ((juint) op1) >> (op2 & 0x1F);
276 }
277 
VMintXor(jint op1,jint op2)278 inline jint BytecodeInterpreter::VMintXor(jint op1, jint op2) {
279   return op1 ^ op2;
280 }
281 
VMint2Double(jint val)282 inline jdouble BytecodeInterpreter::VMint2Double(jint val) {
283   return (jdouble) val;
284 }
285 
VMint2Float(jint val)286 inline jfloat BytecodeInterpreter::VMint2Float(jint val) {
287   return (jfloat) val;
288 }
289 
VMint2Long(jint val)290 inline jlong BytecodeInterpreter::VMint2Long(jint val) {
291   return (jlong) val;
292 }
293 
VMint2Char(jint val)294 inline jchar BytecodeInterpreter::VMint2Char(jint val) {
295   return (jchar) val;
296 }
297 
VMint2Short(jint val)298 inline jshort BytecodeInterpreter::VMint2Short(jint val) {
299   return (jshort) val;
300 }
301 
VMint2Byte(jint val)302 inline jbyte BytecodeInterpreter::VMint2Byte(jint val) {
303   return (jbyte) val;
304 }
305 
306 #endif // CPU_ZERO_VM_BYTECODEINTERPRETER_ZERO_INLINE_HPP
307