diff options
Diffstat (limited to 'deps/v8/src/mips/simulator-mips.cc')
-rw-r--r-- | deps/v8/src/mips/simulator-mips.cc | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/deps/v8/src/mips/simulator-mips.cc b/deps/v8/src/mips/simulator-mips.cc index 66d0da71fa..cf87f93602 100644 --- a/deps/v8/src/mips/simulator-mips.cc +++ b/deps/v8/src/mips/simulator-mips.cc @@ -2068,10 +2068,15 @@ void Simulator::DecodeTypeRegister(Instruction* instr) { // Rounding modes are not yet supported. ASSERT((FCSR_ & 3) == 0); // In rounding mode 0 it should behave like ROUND. - case ROUND_W_D: // Round double to word. + case ROUND_W_D: // Round double to word (round half to even). { - double rounded = fs > 0 ? floor(fs + 0.5) : ceil(fs - 0.5); + double rounded = floor(fs + 0.5); int32_t result = static_cast<int32_t>(rounded); + if ((result & 1) != 0 && result - fs == 0.5) { + // If the number is halfway between two integers, + // round to the even one. + result--; + } set_fpu_register(fd_reg, result); if (set_fcsr_round_error(fs, rounded)) { set_fpu_register(fd_reg, kFPUInvalidResult); |