From 3d1d4dea47dd95117befe436ed292ad79ca5ee13 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Tue, 28 Jun 2016 19:39:22 -0500 Subject: [PATCH] OPCODE_DOT_PRODUCT_4 constant propagation --- .../passes/constant_propagation_pass.cc | 8 ++++++++ src/xenia/cpu/hir/value.cc | 19 +++++++++++++++++++ src/xenia/cpu/hir/value.h | 1 + 3 files changed, 28 insertions(+) diff --git a/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc b/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc index b4f2df5f7..40a50d5e5 100644 --- a/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc +++ b/src/xenia/cpu/compiler/passes/constant_propagation_pass.cc @@ -657,6 +657,14 @@ bool ConstantPropagationPass::Run(HIRBuilder* builder) { } break; + case OPCODE_DOT_PRODUCT_4: + if (i->src1.value->IsConstant() && i->src2.value->IsConstant()) { + v->set_from(i->src1.value); + v->DotProduct4(i->src2.value); + i->Remove(); + } + break; + default: // Ignored. break; diff --git a/src/xenia/cpu/hir/value.cc b/src/xenia/cpu/hir/value.cc index 9703eb631..4b129d85a 100644 --- a/src/xenia/cpu/hir/value.cc +++ b/src/xenia/cpu/hir/value.cc @@ -1206,6 +1206,25 @@ void Value::DotProduct3(Value* other) { } } +void Value::DotProduct4(Value* other) { + assert_true(this->type == VEC128_TYPE && other->type == VEC128_TYPE); + switch (type) { + case VEC128_TYPE: + alignas(16) float result[4]; + __m128 src1 = _mm_load_ps(constant.v128.f32); + __m128 src2 = _mm_load_ps(other->constant.v128.f32); + __m128 dest = _mm_dp_ps(src1, src2, 0b11110001); + _mm_store_ps(result, dest); + // TODO(rick): is this sane? + type = FLOAT32_TYPE; + constant.f32 = result[0]; + break; + default: + assert_unhandled_case(type); + break; + } +} + void Value::ByteSwap() { switch (type) { case INT8_TYPE: diff --git a/src/xenia/cpu/hir/value.h b/src/xenia/cpu/hir/value.h index 39188f223..ffba80188 100644 --- a/src/xenia/cpu/hir/value.h +++ b/src/xenia/cpu/hir/value.h @@ -508,6 +508,7 @@ class Value { void VectorAdd(Value* other, TypeName type, bool is_unsigned, bool saturate); void VectorSub(Value* other, TypeName type, bool is_unsigned, bool saturate); void DotProduct3(Value* other); + void DotProduct4(Value* other); void ByteSwap(); void CountLeadingZeros(const Value* other); bool Compare(Opcode opcode, Value* other);