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