From 6c0d03fad3d4c59868a0c8a37b89db2911294079 Mon Sep 17 00:00:00 2001 From: gibbed Date: Sat, 19 Jun 2021 16:53:50 -0500 Subject: [PATCH] [CPU] Reduce complexity of Value::Round. --- src/xenia/cpu/hir/value.cc | 71 +++++++++++--------------------------- 1 file changed, 20 insertions(+), 51 deletions(-) diff --git a/src/xenia/cpu/hir/value.cc b/src/xenia/cpu/hir/value.cc index 3dab4cca2..28ed07ee7 100644 --- a/src/xenia/cpu/hir/value.cc +++ b/src/xenia/cpu/hir/value.cc @@ -245,65 +245,34 @@ void Value::Convert(TypeName target_type, RoundMode round_mode) { } } +template +T __inline RoundValue(RoundMode round_mode, T value) { + switch (round_mode) { + case ROUND_TO_ZERO: + return std::trunc(value); + case ROUND_TO_NEAREST: + return std::round(value); + case ROUND_TO_MINUS_INFINITY: + return std::floor(value); + case ROUND_TO_POSITIVE_INFINITY: + return std::ceil(value); + default: + assert_unhandled_case(round_mode); + return value; + } +} + void Value::Round(RoundMode round_mode) { switch (type) { case FLOAT32_TYPE: - switch (round_mode) { - case ROUND_TO_ZERO: - constant.f32 = std::trunc(constant.f32); - break; - case ROUND_TO_NEAREST: - constant.f32 = std::round(constant.f32); - return; - case ROUND_TO_MINUS_INFINITY: - constant.f32 = std::floor(constant.f32); - break; - case ROUND_TO_POSITIVE_INFINITY: - constant.f32 = std::ceil(constant.f32); - break; - default: - assert_unhandled_case(round_mode); - return; - } + constant.f32 = RoundValue(round_mode, constant.f32); return; case FLOAT64_TYPE: - switch (round_mode) { - case ROUND_TO_ZERO: - constant.f64 = std::trunc(constant.f64); - break; - case ROUND_TO_NEAREST: - constant.f64 = std::round(constant.f64); - return; - case ROUND_TO_MINUS_INFINITY: - constant.f64 = std::floor(constant.f64); - break; - case ROUND_TO_POSITIVE_INFINITY: - constant.f64 = std::ceil(constant.f64); - break; - default: - assert_unhandled_case(round_mode); - return; - } + constant.f64 = RoundValue(round_mode, constant.f64); return; case VEC128_TYPE: for (int i = 0; i < 4; i++) { - switch (round_mode) { - case ROUND_TO_ZERO: - constant.v128.f32[i] = std::trunc(constant.v128.f32[i]); - break; - case ROUND_TO_NEAREST: - constant.v128.f32[i] = std::round(constant.v128.f32[i]); - break; - case ROUND_TO_MINUS_INFINITY: - constant.v128.f32[i] = std::floor(constant.v128.f32[i]); - break; - case ROUND_TO_POSITIVE_INFINITY: - constant.v128.f32[i] = std::ceil(constant.v128.f32[i]); - break; - default: - assert_unhandled_case(round_mode); - return; - } + constant.v128.f32[i] = RoundValue(round_mode, constant.v128.f32[i]); } return; default: