Index: src/arm/macro-assembler-arm.cc |
diff --git a/src/arm/macro-assembler-arm.cc b/src/arm/macro-assembler-arm.cc |
index 0be9722ca87434174130e45f391ef787c14936f5..4d7198bff68bb108dd9032c44ef8666ebf37dae3 100644 |
--- a/src/arm/macro-assembler-arm.cc |
+++ b/src/arm/macro-assembler-arm.cc |
@@ -3684,10 +3684,15 @@ void MacroAssembler::ClampDoubleToUint8(Register result_reg, |
// In 0-255 range, round and truncate. |
bind(&in_bounds); |
- Vmov(temp_double_reg, 0.5); |
- vadd(temp_double_reg, input_reg, temp_double_reg); |
- vcvt_u32_f64(temp_double_reg.low(), temp_double_reg); |
- vmov(result_reg, temp_double_reg.low()); |
+ // Save FPSCR. |
+ vmrs(ip); |
+ // Set rounding mode to round to the nearest integer by clearing bits[23:22]. |
+ bic(result_reg, ip, Operand(kVFPRoundingModeMask)); |
+ vmsr(result_reg); |
+ vcvt_s32_f64(input_reg.low(), input_reg, kFPSCRRounding); |
+ vmov(result_reg, input_reg.low()); |
+ // Restore FPSCR. |
+ vmsr(ip); |
bind(&done); |
} |