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