OLD | NEW |
---|---|
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits.h> | 5 #include <limits.h> |
6 #include <stdarg.h> | 6 #include <stdarg.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "src/v8.h" | 10 #include "src/v8.h" |
(...skipping 1264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1275 void Simulator::set_fcsr_rounding_mode(FPURoundingMode mode) { | 1275 void Simulator::set_fcsr_rounding_mode(FPURoundingMode mode) { |
1276 FCSR_ |= mode & kFPURoundingModeMask; | 1276 FCSR_ |= mode & kFPURoundingModeMask; |
1277 } | 1277 } |
1278 | 1278 |
1279 | 1279 |
1280 unsigned int Simulator::get_fcsr_rounding_mode() { | 1280 unsigned int Simulator::get_fcsr_rounding_mode() { |
1281 return FCSR_ & kFPURoundingModeMask; | 1281 return FCSR_ & kFPURoundingModeMask; |
1282 } | 1282 } |
1283 | 1283 |
1284 | 1284 |
1285 // Sets the rounding error codes in FCSR based on the result of the rounding. | |
1286 // Returns true if the operation was invalid. | |
1287 bool Simulator::set_fcsr_round_error(double original, double rounded) { | 1285 bool Simulator::set_fcsr_round_error(double original, double rounded) { |
1288 bool ret = false; | 1286 bool ret = false; |
1289 double max_int32 = std::numeric_limits<int32_t>::max(); | 1287 double max_int32 = std::numeric_limits<int32_t>::max(); |
1290 double min_int32 = std::numeric_limits<int32_t>::min(); | 1288 double min_int32 = std::numeric_limits<int32_t>::min(); |
1291 | 1289 |
1292 if (!std::isfinite(original) || !std::isfinite(rounded)) { | 1290 if (!std::isfinite(original) || !std::isfinite(rounded)) { |
1293 set_fcsr_bit(kFCSRInvalidOpFlagBit, true); | 1291 set_fcsr_bit(kFCSRInvalidOpFlagBit, true); |
1294 ret = true; | 1292 ret = true; |
1295 } | 1293 } |
1296 | 1294 |
1297 if (original != rounded) { | 1295 if (original != rounded) { |
1298 set_fcsr_bit(kFCSRInexactFlagBit, true); | 1296 set_fcsr_bit(kFCSRInexactFlagBit, true); |
1299 } | 1297 } |
1300 | 1298 |
1301 if (rounded < DBL_MIN && rounded > -DBL_MIN && rounded != 0) { | 1299 if (rounded < DBL_MIN && rounded > -DBL_MIN && rounded != 0) { |
1302 set_fcsr_bit(kFCSRUnderflowFlagBit, true); | 1300 set_fcsr_bit(kFCSRUnderflowFlagBit, true); |
1303 ret = true; | 1301 ret = true; |
1304 } | 1302 } |
1305 | 1303 |
1306 if (rounded > max_int32 || rounded < min_int32) { | 1304 if (rounded >= max_int32 || rounded <= min_int32) { |
1307 set_fcsr_bit(kFCSROverflowFlagBit, true); | 1305 set_fcsr_bit(kFCSROverflowFlagBit, true); |
1308 // The reference is not really clear but it seems this is required: | 1306 // The reference is not really clear but it seems this is required: |
1309 set_fcsr_bit(kFCSRInvalidOpFlagBit, true); | 1307 set_fcsr_bit(kFCSRInvalidOpFlagBit, true); |
1308 ret = true; | |
1309 } | |
1310 | |
1311 return ret; | |
1312 } | |
1313 | |
1314 | |
1315 // Sets the rounding error codes in FCSR based on the result of the rounding. | |
1316 // Returns true if the operation was invalid. | |
1317 bool Simulator::set_fcsr_round64_error(double original, double rounded) { | |
1318 bool ret = false; | |
1319 double max_int64 = std::numeric_limits<int64_t>::max(); | |
1320 double min_int64 = std::numeric_limits<int64_t>::min(); | |
1321 | |
1322 if (!std::isfinite(original) || !std::isfinite(rounded)) { | |
1323 set_fcsr_bit(kFCSRInvalidOpFlagBit, true); | |
1324 ret = true; | |
1325 } | |
1326 | |
1327 if (original != rounded) { | |
1328 set_fcsr_bit(kFCSRInexactFlagBit, true); | |
1329 } | |
1330 | |
1331 if (rounded < DBL_MIN && rounded > -DBL_MIN && rounded != 0) { | |
1332 set_fcsr_bit(kFCSRUnderflowFlagBit, true); | |
1333 ret = true; | |
1334 } | |
1335 | |
1336 if (rounded >= max_int64 || rounded <= min_int64) { | |
1337 set_fcsr_bit(kFCSROverflowFlagBit, true); | |
1338 // The reference is not really clear but it seems this is required: | |
1339 set_fcsr_bit(kFCSRInvalidOpFlagBit, true); | |
1340 ret = true; | |
1341 } | |
1342 | |
1343 return ret; | |
1344 } | |
1345 | |
1346 | |
1347 bool Simulator::set_fcsr_round_error(float original, float rounded) { | |
1348 bool ret = false; | |
1349 double max_int32 = std::numeric_limits<int32_t>::max(); | |
1350 double min_int32 = std::numeric_limits<int32_t>::min(); | |
1351 | |
1352 if (!std::isfinite(original) || !std::isfinite(rounded)) { | |
1353 set_fcsr_bit(kFCSRInvalidOpFlagBit, true); | |
1354 ret = true; | |
1355 } | |
1356 | |
1357 if (original != rounded) { | |
1358 set_fcsr_bit(kFCSRInexactFlagBit, true); | |
1359 } | |
1360 | |
1361 if (rounded < FLT_MIN && rounded > -FLT_MIN && rounded != 0) { | |
1362 set_fcsr_bit(kFCSRUnderflowFlagBit, true); | |
1363 ret = true; | |
1364 } | |
1365 | |
1366 if (rounded >= max_int32 || rounded <= min_int32) { | |
1367 set_fcsr_bit(kFCSROverflowFlagBit, true); | |
1368 // The reference is not really clear but it seems this is required: | |
1369 set_fcsr_bit(kFCSRInvalidOpFlagBit, true); | |
1370 ret = true; | |
1371 } | |
1372 | |
1373 return ret; | |
1374 } | |
1375 | |
1376 | |
1377 // Sets the rounding error codes in FCSR based on the result of the rounding. | |
1378 // Returns true if the operation was invalid. | |
1379 bool Simulator::set_fcsr_round64_error(float original, float rounded) { | |
1380 bool ret = false; | |
1381 double max_int64 = std::numeric_limits<int64_t>::max(); | |
1382 double min_int64 = std::numeric_limits<int64_t>::min(); | |
1383 | |
1384 if (!std::isfinite(original) || !std::isfinite(rounded)) { | |
1385 set_fcsr_bit(kFCSRInvalidOpFlagBit, true); | |
1386 ret = true; | |
1387 } | |
1388 | |
1389 if (original != rounded) { | |
1390 set_fcsr_bit(kFCSRInexactFlagBit, true); | |
1391 } | |
1392 | |
1393 if (rounded < FLT_MIN && rounded > -FLT_MIN && rounded != 0) { | |
1394 set_fcsr_bit(kFCSRUnderflowFlagBit, true); | |
1395 ret = true; | |
1396 } | |
1397 | |
1398 if (rounded >= max_int64 || rounded <= min_int64) { | |
1399 set_fcsr_bit(kFCSROverflowFlagBit, true); | |
1400 // The reference is not really clear but it seems this is required: | |
1401 set_fcsr_bit(kFCSRInvalidOpFlagBit, true); | |
1310 ret = true; | 1402 ret = true; |
1311 } | 1403 } |
1312 | 1404 |
1313 return ret; | 1405 return ret; |
1314 } | 1406 } |
1315 | 1407 |
1316 | 1408 |
1317 void Simulator::round_according_to_fcsr(double toRound, double& rounded, | 1409 void Simulator::round_according_to_fcsr(double toRound, double& rounded, |
1318 int32_t& rounded_int, double fs) { | 1410 int32_t& rounded_int, double fs) { |
1319 // 0 RN (round to nearest): Round a result to the nearest | 1411 // 0 RN (round to nearest): Round a result to the nearest |
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2184 | 2276 |
2185 void Simulator::DecodeTypeRegisterDRsType(Instruction* instr, | 2277 void Simulator::DecodeTypeRegisterDRsType(Instruction* instr, |
2186 const int32_t& fr_reg, | 2278 const int32_t& fr_reg, |
2187 const int32_t& fs_reg, | 2279 const int32_t& fs_reg, |
2188 const int32_t& ft_reg, | 2280 const int32_t& ft_reg, |
2189 const int32_t& fd_reg) { | 2281 const int32_t& fd_reg) { |
2190 double ft, fs, fd; | 2282 double ft, fs, fd; |
2191 uint32_t cc, fcsr_cc; | 2283 uint32_t cc, fcsr_cc; |
2192 int64_t i64; | 2284 int64_t i64; |
2193 fs = get_fpu_register_double(fs_reg); | 2285 fs = get_fpu_register_double(fs_reg); |
2194 ft = get_fpu_register_double(ft_reg); | 2286 if (instr->FunctionFieldRaw() != MOVF) { |
2287 ft = get_fpu_register_double(ft_reg); | |
2288 } | |
2289 fd = get_fpu_register_double(fd_reg); | |
2195 int64_t ft_int = bit_cast<int64_t>(ft); | 2290 int64_t ft_int = bit_cast<int64_t>(ft); |
2196 int64_t fd_int = bit_cast<int64_t>(fd); | 2291 int64_t fd_int = bit_cast<int64_t>(fd); |
2197 cc = instr->FCccValue(); | 2292 cc = instr->FCccValue(); |
2198 fcsr_cc = get_fcsr_condition_bit(cc); | 2293 fcsr_cc = get_fcsr_condition_bit(cc); |
2199 switch (instr->FunctionFieldRaw()) { | 2294 switch (instr->FunctionFieldRaw()) { |
2200 case RINT: { | 2295 case RINT: { |
2201 DCHECK(IsMipsArchVariant(kMips32r6)); | 2296 DCHECK(IsMipsArchVariant(kMips32r6)); |
2202 double result, temp, temp_result; | 2297 double result, temp, temp_result; |
2203 double upper = std::ceil(fs); | 2298 double upper = std::ceil(fs); |
2204 double lower = std::floor(fs); | 2299 double lower = std::floor(fs); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2239 set_fpu_register_double(fd_reg, (fd_int & 0x1) == 0 ? fs : ft); | 2334 set_fpu_register_double(fd_reg, (fd_int & 0x1) == 0 ? fs : ft); |
2240 break; | 2335 break; |
2241 case SELEQZ_C: | 2336 case SELEQZ_C: |
2242 DCHECK(IsMipsArchVariant(kMips32r6)); | 2337 DCHECK(IsMipsArchVariant(kMips32r6)); |
2243 set_fpu_register_double(fd_reg, (ft_int & 0x1) == 0 ? fs : 0.0); | 2338 set_fpu_register_double(fd_reg, (ft_int & 0x1) == 0 ? fs : 0.0); |
2244 break; | 2339 break; |
2245 case SELNEZ_C: | 2340 case SELNEZ_C: |
2246 DCHECK(IsMipsArchVariant(kMips32r6)); | 2341 DCHECK(IsMipsArchVariant(kMips32r6)); |
2247 set_fpu_register_double(fd_reg, (ft_int & 0x1) != 0 ? fs : 0.0); | 2342 set_fpu_register_double(fd_reg, (ft_int & 0x1) != 0 ? fs : 0.0); |
2248 break; | 2343 break; |
2344 case MOVZ_C: { | |
2345 DCHECK(IsMipsArchVariant(kMips32r2)); | |
2346 int32_t rt_reg = instr->RtValue(); | |
2347 int32_t rt = get_register(rt_reg); | |
2348 if (rt == 0) { | |
2349 set_fpu_register_double(fd_reg, fs); | |
2350 } | |
2351 break; | |
2352 } | |
2353 case MOVN_C: { | |
2354 DCHECK(IsMipsArchVariant(kMips32r2)); | |
2355 int32_t rt_reg = instr->RtValue(); | |
2356 int32_t rt = get_register(rt_reg); | |
2357 if (rt != 0) { | |
2358 set_fpu_register_double(fd_reg, fs); | |
2359 } | |
2360 break; | |
2361 } | |
2362 case MOVF: { | |
2363 // Same function field for MOVT.D and MOVF.D | |
2364 uint32_t ft_cc = (ft_reg >> 2) & 0x7; | |
2365 ft_cc = get_fcsr_condition_bit(ft_cc); | |
2366 if (instr->Bit(16)) { // Read Tf bit. | |
2367 // MOVT.D | |
2368 if (test_fcsr_bit(ft_cc)) set_fpu_register_double(fd_reg, fs); | |
2369 } else { | |
2370 // MOVF.D | |
2371 if (!test_fcsr_bit(ft_cc)) set_fpu_register_double(fd_reg, fs); | |
2372 } | |
2373 break; | |
2374 } | |
2249 case MIN: | 2375 case MIN: |
2250 DCHECK(IsMipsArchVariant(kMips32r6)); | 2376 DCHECK(IsMipsArchVariant(kMips32r6)); |
2251 fs = get_fpu_register_double(fs_reg); | 2377 fs = get_fpu_register_double(fs_reg); |
2252 if (std::isnan(fs) && std::isnan(ft)) { | 2378 if (std::isnan(fs) && std::isnan(ft)) { |
2253 set_fpu_register_double(fd_reg, fs); | 2379 set_fpu_register_double(fd_reg, fs); |
2254 } else if (std::isnan(fs) && !std::isnan(ft)) { | 2380 } else if (std::isnan(fs) && !std::isnan(ft)) { |
2255 set_fpu_register_double(fd_reg, ft); | 2381 set_fpu_register_double(fd_reg, ft); |
2256 } else if (!std::isnan(fs) && std::isnan(ft)) { | 2382 } else if (!std::isnan(fs) && std::isnan(ft)) { |
2257 set_fpu_register_double(fd_reg, fs); | 2383 set_fpu_register_double(fd_reg, fs); |
2258 } else { | 2384 } else { |
2259 set_fpu_register_double(fd_reg, (fs >= ft) ? ft : fs); | 2385 set_fpu_register_double(fd_reg, (fs >= ft) ? ft : fs); |
2260 } | 2386 } |
2261 break; | 2387 break; |
2388 case MINA: | |
2389 DCHECK(IsMipsArchVariant(kMips32r6)); | |
2390 fs = get_fpu_register_double(fs_reg); | |
2391 if (std::isnan(fs) && std::isnan(ft)) { | |
2392 set_fpu_register_double(fd_reg, fs); | |
2393 } else if (std::isnan(fs) && !std::isnan(ft)) { | |
2394 set_fpu_register_double(fd_reg, ft); | |
2395 } else if (!std::isnan(fs) && std::isnan(ft)) { | |
2396 set_fpu_register_double(fd_reg, fs); | |
2397 } else { | |
2398 double result; | |
2399 if (fabs(fs) > fabs(ft)) { | |
2400 result = ft; | |
2401 } else if (fabs(fs) < fabs(ft)) { | |
2402 result = fs; | |
2403 } else { | |
2404 result = (fs > ft ? fs : ft); | |
2405 } | |
2406 set_fpu_register_double(fd_reg, result); | |
2407 } | |
2408 break; | |
2409 case MAXA: | |
2410 DCHECK(IsMipsArchVariant(kMips32r6)); | |
2411 fs = get_fpu_register_double(fs_reg); | |
2412 if (std::isnan(fs) && std::isnan(ft)) { | |
2413 set_fpu_register_double(fd_reg, fs); | |
2414 } else if (std::isnan(fs) && !std::isnan(ft)) { | |
2415 set_fpu_register_double(fd_reg, ft); | |
2416 } else if (!std::isnan(fs) && std::isnan(ft)) { | |
2417 set_fpu_register_double(fd_reg, fs); | |
2418 } else { | |
2419 double result; | |
2420 if (fabs(fs) < fabs(ft)) { | |
2421 result = ft; | |
2422 } else if (fabs(fs) > fabs(ft)) { | |
2423 result = fs; | |
2424 } else { | |
2425 result = (fs > ft ? fs : ft); | |
2426 } | |
2427 set_fpu_register_double(fd_reg, result); | |
2428 } | |
2429 break; | |
2262 case MAX: | 2430 case MAX: |
2263 DCHECK(IsMipsArchVariant(kMips32r6)); | 2431 DCHECK(IsMipsArchVariant(kMips32r6)); |
2264 fs = get_fpu_register_double(fs_reg); | 2432 fs = get_fpu_register_double(fs_reg); |
2265 if (std::isnan(fs) && std::isnan(ft)) { | 2433 if (std::isnan(fs) && std::isnan(ft)) { |
2266 set_fpu_register_double(fd_reg, fs); | 2434 set_fpu_register_double(fd_reg, fs); |
2267 } else if (std::isnan(fs) && !std::isnan(ft)) { | 2435 } else if (std::isnan(fs) && !std::isnan(ft)) { |
2268 set_fpu_register_double(fd_reg, ft); | 2436 set_fpu_register_double(fd_reg, ft); |
2269 } else if (!std::isnan(fs) && std::isnan(ft)) { | 2437 } else if (!std::isnan(fs) && std::isnan(ft)) { |
2270 set_fpu_register_double(fd_reg, fs); | 2438 set_fpu_register_double(fd_reg, fs); |
2271 } else { | 2439 } else { |
(...skipping 18 matching lines...) Expand all Loading... | |
2290 break; | 2458 break; |
2291 case MOV_D: | 2459 case MOV_D: |
2292 set_fpu_register_double(fd_reg, fs); | 2460 set_fpu_register_double(fd_reg, fs); |
2293 break; | 2461 break; |
2294 case NEG_D: | 2462 case NEG_D: |
2295 set_fpu_register_double(fd_reg, -fs); | 2463 set_fpu_register_double(fd_reg, -fs); |
2296 break; | 2464 break; |
2297 case SQRT_D: | 2465 case SQRT_D: |
2298 set_fpu_register_double(fd_reg, fast_sqrt(fs)); | 2466 set_fpu_register_double(fd_reg, fast_sqrt(fs)); |
2299 break; | 2467 break; |
2468 case RSQRT_D: { | |
2469 double result = 1.0 / fast_sqrt(fs); | |
2470 set_fpu_register_double(fd_reg, result); | |
2471 break; | |
2472 } | |
2473 case RECIP: { | |
2474 double result = 1.0 / fs; | |
2475 set_fpu_register_double(fd_reg, result); | |
2476 break; | |
2477 } | |
2300 case C_UN_D: | 2478 case C_UN_D: |
2301 set_fcsr_bit(fcsr_cc, std::isnan(fs) || std::isnan(ft)); | 2479 set_fcsr_bit(fcsr_cc, std::isnan(fs) || std::isnan(ft)); |
2302 break; | 2480 break; |
2303 case C_EQ_D: | 2481 case C_EQ_D: |
2304 set_fcsr_bit(fcsr_cc, (fs == ft)); | 2482 set_fcsr_bit(fcsr_cc, (fs == ft)); |
2305 break; | 2483 break; |
2306 case C_UEQ_D: | 2484 case C_UEQ_D: |
2307 set_fcsr_bit(fcsr_cc, (fs == ft) || (std::isnan(fs) || std::isnan(ft))); | 2485 set_fcsr_bit(fcsr_cc, (fs == ft) || (std::isnan(fs) || std::isnan(ft))); |
2308 break; | 2486 break; |
2309 case C_OLT_D: | 2487 case C_OLT_D: |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2370 } break; | 2548 } break; |
2371 case CVT_S_D: // Convert double to float (single). | 2549 case CVT_S_D: // Convert double to float (single). |
2372 set_fpu_register_float(fd_reg, static_cast<float>(fs)); | 2550 set_fpu_register_float(fd_reg, static_cast<float>(fs)); |
2373 break; | 2551 break; |
2374 case CVT_L_D: { // Mips32r2: Truncate double to 64-bit long-word. | 2552 case CVT_L_D: { // Mips32r2: Truncate double to 64-bit long-word. |
2375 double rounded = trunc(fs); | 2553 double rounded = trunc(fs); |
2376 i64 = static_cast<int64_t>(rounded); | 2554 i64 = static_cast<int64_t>(rounded); |
2377 if (IsFp64Mode()) { | 2555 if (IsFp64Mode()) { |
2378 set_fpu_register(fd_reg, i64); | 2556 set_fpu_register(fd_reg, i64); |
2379 } else { | 2557 } else { |
2380 set_fpu_register_word(fd_reg, i64 & 0xffffffff); | 2558 UNSUPPORTED(); |
2381 set_fpu_register_word(fd_reg + 1, i64 >> 32); | |
2382 } | 2559 } |
2383 break; | 2560 break; |
2384 } | 2561 } |
2385 case TRUNC_L_D: { // Mips32r2 instruction. | 2562 case TRUNC_L_D: { // Mips32r2 instruction. |
paul.l...
2015/05/09 01:07:48
Since you are touching this code, consider adding
Djordje.Pesic
2015/05/14 13:22:30
Done.
| |
2386 double rounded = trunc(fs); | 2563 double rounded = trunc(fs); |
2387 i64 = static_cast<int64_t>(rounded); | 2564 i64 = static_cast<int64_t>(rounded); |
2388 if (IsFp64Mode()) { | 2565 if (IsFp64Mode()) { |
2389 set_fpu_register(fd_reg, i64); | 2566 set_fpu_register(fd_reg, i64); |
2567 if (set_fcsr_round64_error(fs, rounded)) { | |
2568 set_fpu_register(fd_reg, kFPU64InvalidResult); | |
2569 } | |
2390 } else { | 2570 } else { |
2391 set_fpu_register_word(fd_reg, i64 & 0xffffffff); | 2571 UNSUPPORTED(); |
2392 set_fpu_register_word(fd_reg + 1, i64 >> 32); | |
2393 } | 2572 } |
2394 break; | 2573 break; |
2395 } | 2574 } |
2396 case ROUND_L_D: { // Mips32r2 instruction. | 2575 case ROUND_L_D: { // Mips32r2 instruction. |
2397 double rounded = fs > 0 ? std::floor(fs + 0.5) : std::ceil(fs - 0.5); | 2576 double rounded = std::floor(fs + 0.5); |
2398 i64 = static_cast<int64_t>(rounded); | 2577 int64_t result = static_cast<int64_t>(rounded); |
2578 if ((result & 1) != 0 && result - fs == 0.5) { | |
2579 // If the number is halfway between two integers, | |
2580 // round to the even one. | |
2581 result--; | |
2582 } | |
2583 int64_t i64 = static_cast<int64_t>(result); | |
2399 if (IsFp64Mode()) { | 2584 if (IsFp64Mode()) { |
2400 set_fpu_register(fd_reg, i64); | 2585 set_fpu_register(fd_reg, i64); |
2586 if (set_fcsr_round64_error(fs, rounded)) { | |
2587 set_fpu_register(fd_reg, kFPU64InvalidResult); | |
2588 } | |
2401 } else { | 2589 } else { |
2402 set_fpu_register_word(fd_reg, i64 & 0xffffffff); | 2590 UNSUPPORTED(); |
2403 set_fpu_register_word(fd_reg + 1, i64 >> 32); | |
2404 } | 2591 } |
2405 break; | 2592 break; |
2406 } | 2593 } |
2407 case FLOOR_L_D: // Mips32r2 instruction. | 2594 case FLOOR_L_D: { // Mips32r2 instruction. |
2408 i64 = static_cast<int64_t>(std::floor(fs)); | 2595 double rounded = std::floor(fs); |
2596 int64_t i64 = static_cast<int64_t>(rounded); | |
2409 if (IsFp64Mode()) { | 2597 if (IsFp64Mode()) { |
2410 set_fpu_register(fd_reg, i64); | 2598 set_fpu_register(fd_reg, i64); |
2599 if (set_fcsr_round64_error(fs, rounded)) { | |
2600 set_fpu_register(fd_reg, kFPU64InvalidResult); | |
2601 } | |
2411 } else { | 2602 } else { |
2412 set_fpu_register_word(fd_reg, i64 & 0xffffffff); | 2603 UNSUPPORTED(); |
2413 set_fpu_register_word(fd_reg + 1, i64 >> 32); | |
2414 } | 2604 } |
2415 break; | 2605 break; |
2416 case CEIL_L_D: // Mips32r2 instruction. | 2606 } |
2417 i64 = static_cast<int64_t>(std::ceil(fs)); | 2607 case CEIL_L_D: { // Mips32r2 instruction. |
2608 double rounded = std::ceil(fs); | |
2609 int64_t i64 = static_cast<int64_t>(rounded); | |
2418 if (IsFp64Mode()) { | 2610 if (IsFp64Mode()) { |
2419 set_fpu_register(fd_reg, i64); | 2611 set_fpu_register(fd_reg, i64); |
2612 if (set_fcsr_round64_error(fs, rounded)) { | |
2613 set_fpu_register(fd_reg, kFPU64InvalidResult); | |
2614 } | |
2420 } else { | 2615 } else { |
2421 set_fpu_register_word(fd_reg, i64 & 0xffffffff); | 2616 UNSUPPORTED(); |
2422 set_fpu_register_word(fd_reg + 1, i64 >> 32); | |
2423 } | 2617 } |
2424 break; | 2618 break; |
2619 } | |
2425 case C_F_D: | 2620 case C_F_D: |
2426 UNIMPLEMENTED_MIPS(); | 2621 UNIMPLEMENTED_MIPS(); |
2427 break; | 2622 break; |
2428 default: | 2623 default: |
2429 UNREACHABLE(); | 2624 UNREACHABLE(); |
2430 } | 2625 } |
2431 } | 2626 } |
2432 | 2627 |
2433 | 2628 |
2434 void Simulator::DecodeTypeRegisterWRsType(Instruction* instr, int32_t& alu_out, | 2629 void Simulator::DecodeTypeRegisterWRsType(Instruction* instr, int32_t& alu_out, |
(...skipping 11 matching lines...) Expand all Loading... | |
2446 default: // Mips64r6 CMP.S instructions unimplemented. | 2641 default: // Mips64r6 CMP.S instructions unimplemented. |
2447 UNREACHABLE(); | 2642 UNREACHABLE(); |
2448 } | 2643 } |
2449 } | 2644 } |
2450 | 2645 |
2451 | 2646 |
2452 void Simulator::DecodeTypeRegisterSRsType(Instruction* instr, | 2647 void Simulator::DecodeTypeRegisterSRsType(Instruction* instr, |
2453 const int32_t& ft_reg, | 2648 const int32_t& ft_reg, |
2454 const int32_t& fs_reg, | 2649 const int32_t& fs_reg, |
2455 const int32_t& fd_reg) { | 2650 const int32_t& fd_reg) { |
2456 float fs, ft; | 2651 float fs, ft, fd; |
2457 fs = get_fpu_register_float(fs_reg); | 2652 fs = get_fpu_register_float(fs_reg); |
2458 ft = get_fpu_register_float(ft_reg); | 2653 ft = get_fpu_register_float(ft_reg); |
2459 int64_t ft_int = static_cast<int64_t>(get_fpu_register_double(ft_reg)); | 2654 fd = get_fpu_register_float(fd_reg); |
2655 int32_t ft_int = bit_cast<int32_t>(ft); | |
2656 int32_t fd_int = bit_cast<int32_t>(fd); | |
2460 uint32_t cc, fcsr_cc; | 2657 uint32_t cc, fcsr_cc; |
2461 cc = instr->FCccValue(); | 2658 cc = instr->FCccValue(); |
2462 fcsr_cc = get_fcsr_condition_bit(cc); | 2659 fcsr_cc = get_fcsr_condition_bit(cc); |
2463 switch (instr->FunctionFieldRaw()) { | 2660 switch (instr->FunctionFieldRaw()) { |
2661 case RINT: { | |
2662 DCHECK(IsMipsArchVariant(kMips32r6)); | |
2663 float result, temp_result; | |
2664 double temp; | |
2665 float upper = std::ceil(fs); | |
2666 float lower = std::floor(fs); | |
2667 switch (get_fcsr_rounding_mode()) { | |
2668 case kRoundToNearest: | |
2669 if (upper - fs < fs - lower) { | |
2670 result = upper; | |
2671 } else if (upper - fs > fs - lower) { | |
2672 result = lower; | |
2673 } else { | |
2674 temp_result = upper / 2; | |
2675 float reminder = modf(temp_result, &temp); | |
2676 if (reminder == 0) { | |
2677 result = upper; | |
2678 } else { | |
2679 result = lower; | |
2680 } | |
2681 } | |
2682 break; | |
2683 case kRoundToZero: | |
2684 result = (fs > 0 ? lower : upper); | |
2685 break; | |
2686 case kRoundToPlusInf: | |
2687 result = upper; | |
2688 break; | |
2689 case kRoundToMinusInf: | |
2690 result = lower; | |
2691 break; | |
2692 } | |
2693 set_fpu_register_float(fd_reg, result); | |
2694 if (result != fs) { | |
2695 set_fcsr_bit(kFCSRInexactFlagBit, true); | |
2696 } | |
2697 break; | |
2698 } | |
2464 case ADD_D: | 2699 case ADD_D: |
2465 set_fpu_register_float(fd_reg, fs + ft); | 2700 set_fpu_register_float(fd_reg, fs + ft); |
2466 break; | 2701 break; |
2467 case SUB_D: | 2702 case SUB_D: |
2468 set_fpu_register_float(fd_reg, fs - ft); | 2703 set_fpu_register_float(fd_reg, fs - ft); |
2469 break; | 2704 break; |
2470 case MUL_D: | 2705 case MUL_D: |
2471 set_fpu_register_float(fd_reg, fs * ft); | 2706 set_fpu_register_float(fd_reg, fs * ft); |
2472 break; | 2707 break; |
2473 case DIV_D: | 2708 case DIV_D: |
2474 set_fpu_register_float(fd_reg, fs / ft); | 2709 set_fpu_register_float(fd_reg, fs / ft); |
2475 break; | 2710 break; |
2476 case ABS_D: | 2711 case ABS_D: |
2477 set_fpu_register_float(fd_reg, fabs(fs)); | 2712 set_fpu_register_float(fd_reg, fabs(fs)); |
2478 break; | 2713 break; |
2479 case MOV_D: | 2714 case MOV_D: |
2480 set_fpu_register_float(fd_reg, fs); | 2715 set_fpu_register_float(fd_reg, fs); |
2481 break; | 2716 break; |
2482 case NEG_D: | 2717 case NEG_D: |
2483 set_fpu_register_float(fd_reg, -fs); | 2718 set_fpu_register_float(fd_reg, -fs); |
2484 break; | 2719 break; |
2485 case SQRT_D: | 2720 case SQRT_D: |
2486 set_fpu_register_float(fd_reg, fast_sqrt(fs)); | 2721 set_fpu_register_float(fd_reg, fast_sqrt(fs)); |
2487 break; | 2722 break; |
2723 case RSQRT_D: { | |
2724 float result = 1.0 / fast_sqrt(fs); | |
2725 set_fpu_register_float(fd_reg, result); | |
2726 break; | |
2727 } | |
2728 case RECIP: { | |
2729 float result = 1.0 / fs; | |
2730 set_fpu_register_float(fd_reg, result); | |
2731 break; | |
2732 } | |
2488 case C_UN_D: | 2733 case C_UN_D: |
2489 set_fcsr_bit(fcsr_cc, std::isnan(fs) || std::isnan(ft)); | 2734 set_fcsr_bit(fcsr_cc, std::isnan(fs) || std::isnan(ft)); |
2490 break; | 2735 break; |
2491 case C_EQ_D: | 2736 case C_EQ_D: |
2492 set_fcsr_bit(fcsr_cc, (fs == ft)); | 2737 set_fcsr_bit(fcsr_cc, (fs == ft)); |
2493 break; | 2738 break; |
2494 case C_UEQ_D: | 2739 case C_UEQ_D: |
2495 set_fcsr_bit(fcsr_cc, (fs == ft) || (std::isnan(fs) || std::isnan(ft))); | 2740 set_fcsr_bit(fcsr_cc, (fs == ft) || (std::isnan(fs) || std::isnan(ft))); |
2496 break; | 2741 break; |
2497 case C_OLT_D: | 2742 case C_OLT_D: |
2498 set_fcsr_bit(fcsr_cc, (fs < ft)); | 2743 set_fcsr_bit(fcsr_cc, (fs < ft)); |
2499 break; | 2744 break; |
2500 case C_ULT_D: | 2745 case C_ULT_D: |
2501 set_fcsr_bit(fcsr_cc, (fs < ft) || (std::isnan(fs) || std::isnan(ft))); | 2746 set_fcsr_bit(fcsr_cc, (fs < ft) || (std::isnan(fs) || std::isnan(ft))); |
2502 break; | 2747 break; |
2503 case C_OLE_D: | 2748 case C_OLE_D: |
2504 set_fcsr_bit(fcsr_cc, (fs <= ft)); | 2749 set_fcsr_bit(fcsr_cc, (fs <= ft)); |
2505 break; | 2750 break; |
2506 case C_ULE_D: | 2751 case C_ULE_D: |
2507 set_fcsr_bit(fcsr_cc, (fs <= ft) || (std::isnan(fs) || std::isnan(ft))); | 2752 set_fcsr_bit(fcsr_cc, (fs <= ft) || (std::isnan(fs) || std::isnan(ft))); |
2508 break; | 2753 break; |
2509 case CVT_D_S: | 2754 case CVT_D_S: |
2510 set_fpu_register_double(fd_reg, static_cast<double>(fs)); | 2755 set_fpu_register_double(fd_reg, static_cast<double>(fs)); |
2511 break; | 2756 break; |
2757 case SEL: | |
2758 DCHECK(IsMipsArchVariant(kMips32r6)); | |
2759 set_fpu_register_float(fd_reg, (fd_int & 0x1) == 0 ? fs : ft); | |
2760 break; | |
2512 case SELEQZ_C: | 2761 case SELEQZ_C: |
2513 DCHECK(IsMipsArchVariant(kMips32r6)); | 2762 DCHECK(IsMipsArchVariant(kMips32r6)); |
2514 set_fpu_register_double( | 2763 set_fpu_register_float( |
2515 fd_reg, (ft_int & 0x1) == 0 ? get_fpu_register_double(fs_reg) : 0.0); | 2764 fd_reg, (ft_int & 0x1) == 0 ? get_fpu_register_float(fs_reg) : 0.0); |
2516 break; | 2765 break; |
2517 case SELNEZ_C: | 2766 case SELNEZ_C: |
2518 DCHECK(IsMipsArchVariant(kMips32r6)); | 2767 DCHECK(IsMipsArchVariant(kMips32r6)); |
2519 set_fpu_register_double( | 2768 set_fpu_register_float( |
2520 fd_reg, (ft_int & 0x1) != 0 ? get_fpu_register_double(fs_reg) : 0.0); | 2769 fd_reg, (ft_int & 0x1) != 0 ? get_fpu_register_float(fs_reg) : 0.0); |
2770 break; | |
2771 case MOVZ_C: { | |
2772 DCHECK(IsMipsArchVariant(kMips32r2)); | |
2773 int32_t rt_reg = instr->RtValue(); | |
2774 int32_t rt = get_register(rt_reg); | |
2775 if (rt == 0) { | |
2776 set_fpu_register_float(fd_reg, fs); | |
2777 } | |
2778 break; | |
2779 } | |
2780 case MOVN_C: { | |
2781 DCHECK(IsMipsArchVariant(kMips32r2)); | |
2782 int32_t rt_reg = instr->RtValue(); | |
2783 int32_t rt = get_register(rt_reg); | |
2784 if (rt != 0) { | |
2785 set_fpu_register_float(fd_reg, fs); | |
2786 } | |
2787 break; | |
2788 } | |
2789 case MOVF: { | |
2790 // Same function field for MOVT.D and MOVF.D | |
2791 uint32_t ft_cc = (ft_reg >> 2) & 0x7; | |
2792 ft_cc = get_fcsr_condition_bit(ft_cc); | |
2793 | |
2794 if (instr->Bit(16)) { // Read Tf bit. | |
2795 // MOVT.D | |
2796 if (test_fcsr_bit(ft_cc)) set_fpu_register_float(fd_reg, fs); | |
2797 } else { | |
2798 // MOVF.D | |
2799 if (!test_fcsr_bit(ft_cc)) set_fpu_register_float(fd_reg, fs); | |
2800 } | |
2801 break; | |
2802 } | |
2803 case TRUNC_W_S: { // Truncate single to word (round towards 0). | |
2804 float rounded = trunc(fs); | |
2805 int32_t result = static_cast<int32_t>(rounded); | |
2806 set_fpu_register_word(fd_reg, result); | |
2807 if (set_fcsr_round_error(fs, rounded)) { | |
2808 set_fpu_register_word(fd_reg, kFPUInvalidResult); | |
2809 } | |
2810 } break; | |
2811 case TRUNC_L_S: { // Mips32r2 instruction. | |
2812 float rounded = trunc(fs); | |
2813 int64_t i64 = static_cast<int64_t>(rounded); | |
2814 if (IsFp64Mode()) { | |
2815 set_fpu_register(fd_reg, i64); | |
2816 if (set_fcsr_round64_error(fs, rounded)) { | |
2817 set_fpu_register(fd_reg, kFPU64InvalidResult); | |
2818 } | |
2819 } else { | |
2820 UNSUPPORTED(); | |
2821 } | |
2822 break; | |
2823 } | |
2824 case FLOOR_W_S: // Round double to word towards negative infinity. | |
2825 { | |
2826 float rounded = std::floor(fs); | |
2827 int32_t result = static_cast<int32_t>(rounded); | |
2828 set_fpu_register_word(fd_reg, result); | |
2829 if (set_fcsr_round_error(fs, rounded)) { | |
2830 set_fpu_register_word(fd_reg, kFPUInvalidResult); | |
2831 } | |
2832 } break; | |
2833 case FLOOR_L_S: { // Mips32r2 instruction. | |
2834 float rounded = std::floor(fs); | |
2835 int64_t i64 = static_cast<int64_t>(rounded); | |
2836 if (IsFp64Mode()) { | |
2837 set_fpu_register(fd_reg, i64); | |
2838 if (set_fcsr_round64_error(fs, rounded)) { | |
2839 set_fpu_register(fd_reg, kFPU64InvalidResult); | |
2840 } | |
2841 } else { | |
2842 UNSUPPORTED(); | |
2843 } | |
2844 break; | |
2845 } | |
2846 case ROUND_W_S: { | |
2847 float rounded = std::floor(fs + 0.5); | |
2848 int32_t result = static_cast<int32_t>(rounded); | |
2849 if ((result & 1) != 0 && result - fs == 0.5) { | |
2850 // If the number is halfway between two integers, | |
2851 // round to the even one. | |
2852 result--; | |
2853 } | |
2854 set_fpu_register_word(fd_reg, result); | |
2855 if (set_fcsr_round_error(fs, rounded)) { | |
2856 set_fpu_register_word(fd_reg, kFPUInvalidResult); | |
2857 } | |
2858 break; | |
2859 } | |
2860 case ROUND_L_S: { // Mips32r2 instruction. | |
2861 float rounded = std::floor(fs + 0.5); | |
2862 int64_t result = static_cast<int64_t>(rounded); | |
2863 if ((result & 1) != 0 && result - fs == 0.5) { | |
2864 // If the number is halfway between two integers, | |
2865 // round to the even one. | |
2866 result--; | |
2867 } | |
2868 int64_t i64 = static_cast<int64_t>(result); | |
2869 if (IsFp64Mode()) { | |
2870 set_fpu_register(fd_reg, i64); | |
2871 if (set_fcsr_round64_error(fs, rounded)) { | |
2872 set_fpu_register(fd_reg, kFPU64InvalidResult); | |
2873 } | |
2874 } else { | |
2875 UNSUPPORTED(); | |
2876 } | |
2877 break; | |
2878 } | |
2879 case CEIL_W_S: // Round double to word towards positive infinity. | |
2880 { | |
2881 float rounded = std::ceil(fs); | |
2882 int32_t result = static_cast<int32_t>(rounded); | |
2883 set_fpu_register_word(fd_reg, result); | |
2884 if (set_fcsr_round_error(fs, rounded)) { | |
2885 set_fpu_register_word(fd_reg, kFPUInvalidResult); | |
2886 } | |
2887 } break; | |
2888 case CEIL_L_S: { // Mips32r2 instruction. | |
2889 float rounded = std::ceil(fs); | |
2890 int64_t i64 = static_cast<int64_t>(rounded); | |
2891 if (IsFp64Mode()) { | |
2892 set_fpu_register(fd_reg, i64); | |
2893 if (set_fcsr_round64_error(fs, rounded)) { | |
2894 set_fpu_register(fd_reg, kFPU64InvalidResult); | |
2895 } | |
2896 } else { | |
2897 UNSUPPORTED(); | |
2898 } | |
2899 break; | |
2900 } | |
2901 case MIN: | |
2902 DCHECK(IsMipsArchVariant(kMips32r6)); | |
2903 fs = get_fpu_register_float(fs_reg); | |
2904 if (std::isnan(fs) && std::isnan(ft)) { | |
2905 set_fpu_register_float(fd_reg, fs); | |
2906 } else if (std::isnan(fs) && !std::isnan(ft)) { | |
2907 set_fpu_register_float(fd_reg, ft); | |
2908 } else if (!std::isnan(fs) && std::isnan(ft)) { | |
2909 set_fpu_register_float(fd_reg, fs); | |
2910 } else { | |
2911 set_fpu_register_float(fd_reg, (fs >= ft) ? ft : fs); | |
2912 } | |
2913 break; | |
2914 case MAX: | |
2915 DCHECK(IsMipsArchVariant(kMips32r6)); | |
2916 fs = get_fpu_register_float(fs_reg); | |
2917 if (std::isnan(fs) && std::isnan(ft)) { | |
2918 set_fpu_register_float(fd_reg, fs); | |
2919 } else if (std::isnan(fs) && !std::isnan(ft)) { | |
2920 set_fpu_register_float(fd_reg, ft); | |
2921 } else if (!std::isnan(fs) && std::isnan(ft)) { | |
2922 set_fpu_register_float(fd_reg, fs); | |
2923 } else { | |
2924 set_fpu_register_float(fd_reg, (fs <= ft) ? ft : fs); | |
2925 } | |
2926 break; | |
2927 case MINA: | |
2928 DCHECK(IsMipsArchVariant(kMips32r6)); | |
2929 fs = get_fpu_register_float(fs_reg); | |
2930 if (std::isnan(fs) && std::isnan(ft)) { | |
2931 set_fpu_register_float(fd_reg, fs); | |
2932 } else if (std::isnan(fs) && !std::isnan(ft)) { | |
2933 set_fpu_register_float(fd_reg, ft); | |
2934 } else if (!std::isnan(fs) && std::isnan(ft)) { | |
2935 set_fpu_register_float(fd_reg, fs); | |
2936 } else { | |
2937 float result; | |
2938 if (fabs(fs) > fabs(ft)) { | |
2939 result = ft; | |
2940 } else if (fabs(fs) < fabs(ft)) { | |
2941 result = fs; | |
2942 } else { | |
2943 result = (fs > ft ? fs : ft); | |
2944 } | |
2945 set_fpu_register_float(fd_reg, result); | |
2946 } | |
2947 break; | |
2948 case MAXA: | |
2949 DCHECK(IsMipsArchVariant(kMips32r6)); | |
2950 fs = get_fpu_register_float(fs_reg); | |
2951 if (std::isnan(fs) && std::isnan(ft)) { | |
2952 set_fpu_register_float(fd_reg, fs); | |
2953 } else if (std::isnan(fs) && !std::isnan(ft)) { | |
2954 set_fpu_register_float(fd_reg, ft); | |
2955 } else if (!std::isnan(fs) && std::isnan(ft)) { | |
2956 set_fpu_register_float(fd_reg, fs); | |
2957 } else { | |
2958 float result; | |
2959 if (fabs(fs) < fabs(ft)) { | |
2960 result = ft; | |
2961 } else if (fabs(fs) > fabs(ft)) { | |
2962 result = fs; | |
2963 } else { | |
2964 result = (fs > ft ? fs : ft); | |
2965 } | |
2966 set_fpu_register_float(fd_reg, result); | |
2967 } | |
2521 break; | 2968 break; |
2522 default: | 2969 default: |
2523 // CVT_W_S CVT_L_S TRUNC_W_S ROUND_W_S ROUND_L_S FLOOR_W_S FLOOR_L_S | 2970 // CVT_W_S CVT_L_S ROUND_W_S ROUND_L_S FLOOR_W_S FLOOR_L_S |
2524 // CEIL_W_S CEIL_L_S CVT_PS_S are unimplemented. | 2971 // CEIL_W_S CEIL_L_S CVT_PS_S are unimplemented. |
2525 UNREACHABLE(); | 2972 UNREACHABLE(); |
2526 } | 2973 } |
2527 } | 2974 } |
2528 | 2975 |
2529 | 2976 |
2530 void Simulator::DecodeTypeRegisterLRsType(Instruction* instr, | 2977 void Simulator::DecodeTypeRegisterLRsType(Instruction* instr, |
2531 const int32_t& ft_reg, | 2978 const int32_t& ft_reg, |
2532 const int32_t& fs_reg, | 2979 const int32_t& fs_reg, |
2533 const int32_t& fd_reg) { | 2980 const int32_t& fd_reg) { |
(...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3534 } | 3981 } |
3535 | 3982 |
3536 | 3983 |
3537 #undef UNSUPPORTED | 3984 #undef UNSUPPORTED |
3538 | 3985 |
3539 } } // namespace v8::internal | 3986 } } // namespace v8::internal |
3540 | 3987 |
3541 #endif // USE_SIMULATOR | 3988 #endif // USE_SIMULATOR |
3542 | 3989 |
3543 #endif // V8_TARGET_ARCH_MIPS | 3990 #endif // V8_TARGET_ARCH_MIPS |
OLD | NEW |