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