1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/sparc/vm/bytecodeInterpreter_sparc.inline.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,338 @@ 1.4 +/* 1.5 + * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef CPU_SPARC_VM_BYTECODEINTERPRETER_SPARC_INLINE_HPP 1.29 +#define CPU_SPARC_VM_BYTECODEINTERPRETER_SPARC_INLINE_HPP 1.30 + 1.31 +// Inline interpreter functions for sparc 1.32 + 1.33 +inline jfloat BytecodeInterpreter::VMfloatAdd(jfloat op1, jfloat op2) { return op1 + op2; } 1.34 +inline jfloat BytecodeInterpreter::VMfloatSub(jfloat op1, jfloat op2) { return op1 - op2; } 1.35 +inline jfloat BytecodeInterpreter::VMfloatMul(jfloat op1, jfloat op2) { return op1 * op2; } 1.36 +inline jfloat BytecodeInterpreter::VMfloatDiv(jfloat op1, jfloat op2) { return op1 / op2; } 1.37 +inline jfloat BytecodeInterpreter::VMfloatRem(jfloat op1, jfloat op2) { return fmod(op1, op2); } 1.38 + 1.39 +inline jfloat BytecodeInterpreter::VMfloatNeg(jfloat op) { return -op; } 1.40 + 1.41 +inline int32_t BytecodeInterpreter::VMfloatCompare(jfloat op1, jfloat op2, int32_t direction) { 1.42 + return ( op1 < op2 ? -1 : 1.43 + op1 > op2 ? 1 : 1.44 + op1 == op2 ? 0 : 1.45 + (direction == -1 || direction == 1) ? direction : 0); 1.46 + 1.47 +} 1.48 + 1.49 +inline void BytecodeInterpreter::VMmemCopy64(uint32_t to[2], const uint32_t from[2]) { 1.50 + // x86 can do unaligned copies but not 64bits at a time 1.51 + to[0] = from[0]; to[1] = from[1]; 1.52 +} 1.53 + 1.54 +// The long operations depend on compiler support for "long long" on x86 1.55 + 1.56 +inline jlong BytecodeInterpreter::VMlongAdd(jlong op1, jlong op2) { 1.57 + return op1 + op2; 1.58 +} 1.59 + 1.60 +inline jlong BytecodeInterpreter::VMlongAnd(jlong op1, jlong op2) { 1.61 + return op1 & op2; 1.62 +} 1.63 + 1.64 +inline jlong BytecodeInterpreter::VMlongDiv(jlong op1, jlong op2) { 1.65 + // QQQ what about check and throw... 1.66 + return op1 / op2; 1.67 +} 1.68 + 1.69 +inline jlong BytecodeInterpreter::VMlongMul(jlong op1, jlong op2) { 1.70 + return op1 * op2; 1.71 +} 1.72 + 1.73 +inline jlong BytecodeInterpreter::VMlongOr(jlong op1, jlong op2) { 1.74 + return op1 | op2; 1.75 +} 1.76 + 1.77 +inline jlong BytecodeInterpreter::VMlongSub(jlong op1, jlong op2) { 1.78 + return op1 - op2; 1.79 +} 1.80 + 1.81 +inline jlong BytecodeInterpreter::VMlongXor(jlong op1, jlong op2) { 1.82 + return op1 ^ op2; 1.83 +} 1.84 + 1.85 +inline jlong BytecodeInterpreter::VMlongRem(jlong op1, jlong op2) { 1.86 + return op1 % op2; 1.87 +} 1.88 + 1.89 +inline jlong BytecodeInterpreter::VMlongUshr(jlong op1, jint op2) { 1.90 + // CVM did this 0x3f mask, is the really needed??? QQQ 1.91 + return ((unsigned long long) op1) >> (op2 & 0x3F); 1.92 +} 1.93 + 1.94 +inline jlong BytecodeInterpreter::VMlongShr(jlong op1, jint op2) { 1.95 + return op1 >> (op2 & 0x3F); 1.96 +} 1.97 + 1.98 +inline jlong BytecodeInterpreter::VMlongShl(jlong op1, jint op2) { 1.99 + return op1 << (op2 & 0x3F); 1.100 +} 1.101 + 1.102 +inline jlong BytecodeInterpreter::VMlongNeg(jlong op) { 1.103 + return -op; 1.104 +} 1.105 + 1.106 +inline jlong BytecodeInterpreter::VMlongNot(jlong op) { 1.107 + return ~op; 1.108 +} 1.109 + 1.110 +inline int32_t BytecodeInterpreter::VMlongLtz(jlong op) { 1.111 + return (op <= 0); 1.112 +} 1.113 + 1.114 +inline int32_t BytecodeInterpreter::VMlongGez(jlong op) { 1.115 + return (op >= 0); 1.116 +} 1.117 + 1.118 +inline int32_t BytecodeInterpreter::VMlongEqz(jlong op) { 1.119 + return (op == 0); 1.120 +} 1.121 + 1.122 +inline int32_t BytecodeInterpreter::VMlongEq(jlong op1, jlong op2) { 1.123 + return (op1 == op2); 1.124 +} 1.125 + 1.126 +inline int32_t BytecodeInterpreter::VMlongNe(jlong op1, jlong op2) { 1.127 + return (op1 != op2); 1.128 +} 1.129 + 1.130 +inline int32_t BytecodeInterpreter::VMlongGe(jlong op1, jlong op2) { 1.131 + return (op1 >= op2); 1.132 +} 1.133 + 1.134 +inline int32_t BytecodeInterpreter::VMlongLe(jlong op1, jlong op2) { 1.135 + return (op1 <= op2); 1.136 +} 1.137 + 1.138 +inline int32_t BytecodeInterpreter::VMlongLt(jlong op1, jlong op2) { 1.139 + return (op1 < op2); 1.140 +} 1.141 + 1.142 +inline int32_t BytecodeInterpreter::VMlongGt(jlong op1, jlong op2) { 1.143 + return (op1 > op2); 1.144 +} 1.145 + 1.146 +inline int32_t BytecodeInterpreter::VMlongCompare(jlong op1, jlong op2) { 1.147 + return (VMlongLt(op1, op2) ? -1 : VMlongGt(op1, op2) ? 1 : 0); 1.148 +} 1.149 + 1.150 +// Long conversions 1.151 + 1.152 +inline jdouble BytecodeInterpreter::VMlong2Double(jlong val) { 1.153 + return (jdouble) val; 1.154 +} 1.155 + 1.156 +inline jfloat BytecodeInterpreter::VMlong2Float(jlong val) { 1.157 + return (jfloat) val; 1.158 +} 1.159 + 1.160 +inline jint BytecodeInterpreter::VMlong2Int(jlong val) { 1.161 + return (jint) val; 1.162 +} 1.163 + 1.164 +// Double Arithmetic 1.165 + 1.166 +inline jdouble BytecodeInterpreter::VMdoubleAdd(jdouble op1, jdouble op2) { 1.167 + return op1 + op2; 1.168 +} 1.169 + 1.170 +inline jdouble BytecodeInterpreter::VMdoubleDiv(jdouble op1, jdouble op2) { 1.171 + // Divide by zero... QQQ 1.172 + return op1 / op2; 1.173 +} 1.174 + 1.175 +inline jdouble BytecodeInterpreter::VMdoubleMul(jdouble op1, jdouble op2) { 1.176 + return op1 * op2; 1.177 +} 1.178 + 1.179 +inline jdouble BytecodeInterpreter::VMdoubleNeg(jdouble op) { 1.180 + return -op; 1.181 +} 1.182 + 1.183 +inline jdouble BytecodeInterpreter::VMdoubleRem(jdouble op1, jdouble op2) { 1.184 + return fmod(op1, op2); 1.185 +} 1.186 + 1.187 +inline jdouble BytecodeInterpreter::VMdoubleSub(jdouble op1, jdouble op2) { 1.188 + return op1 - op2; 1.189 +} 1.190 + 1.191 +inline int32_t BytecodeInterpreter::VMdoubleCompare(jdouble op1, jdouble op2, int32_t direction) { 1.192 + return ( op1 < op2 ? -1 : 1.193 + op1 > op2 ? 1 : 1.194 + op1 == op2 ? 0 : 1.195 + (direction == -1 || direction == 1) ? direction : 0); 1.196 +} 1.197 + 1.198 +// Double Conversions 1.199 + 1.200 +inline jfloat BytecodeInterpreter::VMdouble2Float(jdouble val) { 1.201 + return (jfloat) val; 1.202 +} 1.203 + 1.204 +// Float Conversions 1.205 + 1.206 +inline jdouble BytecodeInterpreter::VMfloat2Double(jfloat op) { 1.207 + return (jdouble) op; 1.208 +} 1.209 + 1.210 +// Integer Arithmetic 1.211 + 1.212 +inline jint BytecodeInterpreter::VMintAdd(jint op1, jint op2) { 1.213 + return op1 + op2; 1.214 +} 1.215 + 1.216 +inline jint BytecodeInterpreter::VMintAnd(jint op1, jint op2) { 1.217 + return op1 & op2; 1.218 +} 1.219 + 1.220 +inline jint BytecodeInterpreter::VMintDiv(jint op1, jint op2) { 1.221 + /* it's possible we could catch this special case implicitly */ 1.222 + if (op1 == 0x80000000 && op2 == -1) return op1; 1.223 + else return op1 / op2; 1.224 +} 1.225 + 1.226 +inline jint BytecodeInterpreter::VMintMul(jint op1, jint op2) { 1.227 + return op1 * op2; 1.228 +} 1.229 + 1.230 +inline jint BytecodeInterpreter::VMintNeg(jint op) { 1.231 + return -op; 1.232 +} 1.233 + 1.234 +inline jint BytecodeInterpreter::VMintOr(jint op1, jint op2) { 1.235 + return op1 | op2; 1.236 +} 1.237 + 1.238 +inline jint BytecodeInterpreter::VMintRem(jint op1, jint op2) { 1.239 + /* it's possible we could catch this special case implicitly */ 1.240 + if (op1 == 0x80000000 && op2 == -1) return 0; 1.241 + else return op1 % op2; 1.242 +} 1.243 + 1.244 +inline jint BytecodeInterpreter::VMintShl(jint op1, jint op2) { 1.245 + return op1 << (op2 & 0x1f); 1.246 +} 1.247 + 1.248 +inline jint BytecodeInterpreter::VMintShr(jint op1, jint op2) { 1.249 + return op1 >> (op2 & 0x1f); 1.250 +} 1.251 + 1.252 +inline jint BytecodeInterpreter::VMintSub(jint op1, jint op2) { 1.253 + return op1 - op2; 1.254 +} 1.255 + 1.256 +inline juint BytecodeInterpreter::VMintUshr(jint op1, jint op2) { 1.257 + return ((juint) op1) >> (op2 & 0x1f); 1.258 +} 1.259 + 1.260 +inline jint BytecodeInterpreter::VMintXor(jint op1, jint op2) { 1.261 + return op1 ^ op2; 1.262 +} 1.263 + 1.264 +inline jdouble BytecodeInterpreter::VMint2Double(jint val) { 1.265 + return (jdouble) val; 1.266 +} 1.267 + 1.268 +inline jfloat BytecodeInterpreter::VMint2Float(jint val) { 1.269 + return (jfloat) val; 1.270 +} 1.271 + 1.272 +inline jlong BytecodeInterpreter::VMint2Long(jint val) { 1.273 + return (jlong) val; 1.274 +} 1.275 + 1.276 +inline jchar BytecodeInterpreter::VMint2Char(jint val) { 1.277 + return (jchar) val; 1.278 +} 1.279 + 1.280 +inline jshort BytecodeInterpreter::VMint2Short(jint val) { 1.281 + return (jshort) val; 1.282 +} 1.283 + 1.284 +inline jbyte BytecodeInterpreter::VMint2Byte(jint val) { 1.285 + return (jbyte) val; 1.286 +} 1.287 + 1.288 +// The implementations are platform dependent. We have to worry about alignment 1.289 +// issues on some machines which can change on the same platform depending on 1.290 +// whether it is an LP64 machine also. 1.291 + 1.292 +// We know that on LP32 mode that longs/doubles are the only thing that gives 1.293 +// us alignment headaches. We also know that the worst we have is 32bit alignment 1.294 +// so thing are not really too bad. 1.295 +// (Also sparcworks compiler does the right thing for free if we don't use -arch.. 1.296 +// switches. Only gcc gives us a hard time. In LP64 mode I think we have no issue 1.297 +// with alignment. 1.298 + 1.299 +#ifdef _GNU_SOURCE 1.300 + #define ALIGN_CONVERTER /* Needs alignment converter */ 1.301 +#else 1.302 + #undef ALIGN_CONVERTER /* No alignment converter */ 1.303 +#endif /* _GNU_SOURCE */ 1.304 + 1.305 +#ifdef ALIGN_CONVERTER 1.306 +class u8_converter { 1.307 + 1.308 + private: 1.309 + 1.310 + public: 1.311 + static jdouble get_jdouble(address p) { 1.312 + VMJavaVal64 tmp; 1.313 + tmp.v[0] = ((uint32_t*)p)[0]; 1.314 + tmp.v[1] = ((uint32_t*)p)[1]; 1.315 + return tmp.d; 1.316 + } 1.317 + 1.318 + static void put_jdouble(address p, jdouble d) { 1.319 + VMJavaVal64 tmp; 1.320 + tmp.d = d; 1.321 + ((uint32_t*)p)[0] = tmp.v[0]; 1.322 + ((uint32_t*)p)[1] = tmp.v[1]; 1.323 + } 1.324 + 1.325 + static jlong get_jlong(address p) { 1.326 + VMJavaVal64 tmp; 1.327 + tmp.v[0] = ((uint32_t*)p)[0]; 1.328 + tmp.v[1] = ((uint32_t*)p)[1]; 1.329 + return tmp.l; 1.330 + } 1.331 + 1.332 + static void put_jlong(address p, jlong l) { 1.333 + VMJavaVal64 tmp; 1.334 + tmp.l = l; 1.335 + ((uint32_t*)p)[0] = tmp.v[0]; 1.336 + ((uint32_t*)p)[1] = tmp.v[1]; 1.337 + } 1.338 +}; 1.339 +#endif /* ALIGN_CONVERTER */ 1.340 + 1.341 +#endif // CPU_SPARC_VM_BYTECODEINTERPRETER_SPARC_INLINE_HPP