From c21b31ae2bdd6b5235548d6bfef4fa5358239ccf Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Wed, 2 Nov 2022 09:36:22 +0100 Subject: [PATCH 1/7] xequal special instruction for floats --- .../tests/GenericVectorTests.cs | 2 -- src/mono/mono/mini/mini-amd64.c | 16 +++++++++++++++- src/mono/mono/mini/simd-intrinsics.c | 5 ++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs b/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs index a655f54590dc0..e1579185a4297 100644 --- a/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs @@ -855,7 +855,6 @@ public void VectorSingleEqualsNaNTest() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/74781", TestRuntimes.Mono)] public void VectorDoubleEqualsNonCanonicalNaNTest() { // max 8 bit exponent, just under half max mantissa @@ -880,7 +879,6 @@ public void VectorDoubleEqualsNonCanonicalNaNTest() } [Fact] - [ActiveIssue("https://github.com/dotnet/runtime/issues/74781", TestRuntimes.Mono)] public void VectorSingleEqualsNonCanonicalNaNTest() { // max 11 bit exponent, just under half max mantissa diff --git a/src/mono/mono/mini/mini-amd64.c b/src/mono/mono/mini/mini-amd64.c index bc4eedd8f86c5..fd4c5ffb7a74d 100644 --- a/src/mono/mono/mini/mini-amd64.c +++ b/src/mono/mono/mini/mini-amd64.c @@ -3882,8 +3882,22 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb) case OP_XEQUAL: { int temp_reg1 = mono_alloc_ireg (cfg); int temp_reg2 = mono_alloc_ireg (cfg); + int opcode= -1; + switch (ins->inst_c1) + { + case MONO_TYPE_R4: + opcode = OP_COMPPS; + break; + case MONO_TYPE_R8: { + opcode = OP_COMPPD; + break; + } + default: + opcode = OP_PCMPEQD; + } + ins->inst_c0 = 0; - NEW_SIMD_INS (cfg, ins, temp, OP_PCMPEQD, temp_reg1, ins->sreg1, ins->sreg2); + NEW_SIMD_INS (cfg, ins, temp, opcode, temp_reg1, ins->sreg1, ins->sreg2); NEW_SIMD_INS (cfg, ins, temp, OP_EXTRACT_MASK, temp_reg2, temp_reg1, -1); temp->type = STACK_I4; NEW_INS (cfg, ins, temp, OP_COMPARE_IMM); diff --git a/src/mono/mono/mini/simd-intrinsics.c b/src/mono/mono/mini/simd-intrinsics.c index 62f0b073851c2..b9a557b8eb98c 100644 --- a/src/mono/mono/mini/simd-intrinsics.c +++ b/src/mono/mono/mini/simd-intrinsics.c @@ -2312,7 +2312,10 @@ emit_sys_numerics_vector_t (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSig mono_metadata_type_equal (fsig->params [0], type) && mono_metadata_type_equal (fsig->params [1], type)); switch (id) { - case SN_op_Equality: return emit_xequal (cfg, klass, args [0], args [1]); + case SN_op_Equality: + ins = emit_xequal (cfg, klass, args [0], args [1]); + ins->inst_c1 = etype->type; + return ins; case SN_op_Inequality: return emit_not_xequal (cfg, klass, args [0], args [1]); default: g_assert_not_reached (); } From 3945d45d578072512a58667bbcf99a947a96e691 Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Wed, 2 Nov 2022 09:37:01 +0100 Subject: [PATCH 2/7] reduce code --- src/mono/mono/mini/mini-amd64.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/mono/mono/mini/mini-amd64.c b/src/mono/mono/mini/mini-amd64.c index fd4c5ffb7a74d..034e23bfb2e9f 100644 --- a/src/mono/mono/mini/mini-amd64.c +++ b/src/mono/mono/mini/mini-amd64.c @@ -3885,15 +3885,9 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb) int opcode= -1; switch (ins->inst_c1) { - case MONO_TYPE_R4: - opcode = OP_COMPPS; - break; - case MONO_TYPE_R8: { - opcode = OP_COMPPD; - break; - } - default: - opcode = OP_PCMPEQD; + case MONO_TYPE_R4: opcode = OP_COMPPS; break; + case MONO_TYPE_R8: opcode = OP_COMPPD; break; + default: opcode = OP_PCMPEQD; } ins->inst_c0 = 0; From 691565f860656061d7e3a9eaf58a7bb50a7e6d1e Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Wed, 2 Nov 2022 10:09:39 +0100 Subject: [PATCH 3/7] Moving type pass to emit_xequal --- src/mono/mono/mini/simd-intrinsics.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/mono/mono/mini/simd-intrinsics.c b/src/mono/mono/mini/simd-intrinsics.c index b9a557b8eb98c..fc6b397999261 100644 --- a/src/mono/mono/mini/simd-intrinsics.c +++ b/src/mono/mono/mini/simd-intrinsics.c @@ -492,7 +492,9 @@ emit_xequal (MonoCompile *cfg, MonoClass *klass, MonoInst *arg1, MonoInst *arg2) else return emit_simd_ins (cfg, klass, OP_XEQUAL, arg1->dreg, arg2->dreg); #else - return emit_simd_ins (cfg, klass, OP_XEQUAL, arg1->dreg, arg2->dreg); + MonoInst *ins = emit_simd_ins (cfg, klass, OP_XEQUAL, arg1->dreg, arg2->dreg); + ins->inst_c1 = mono_class_get_context (klass)->class_inst->type_argv [0]->type; + return ins; #endif } @@ -2312,10 +2314,7 @@ emit_sys_numerics_vector_t (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSig mono_metadata_type_equal (fsig->params [0], type) && mono_metadata_type_equal (fsig->params [1], type)); switch (id) { - case SN_op_Equality: - ins = emit_xequal (cfg, klass, args [0], args [1]); - ins->inst_c1 = etype->type; - return ins; + case SN_op_Equality: return emit_xequal (cfg, klass, args [0], args [1]); case SN_op_Inequality: return emit_not_xequal (cfg, klass, args [0], args [1]); default: g_assert_not_reached (); } From 91ebad925dc9275ccada8ea3c88ee3712b635e1e Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Thu, 3 Nov 2022 20:03:31 +0100 Subject: [PATCH 4/7] OP_EXTRACT_MASK --- src/mono/mono/mini/simd-intrinsics.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/mini/simd-intrinsics.c b/src/mono/mono/mini/simd-intrinsics.c index fc6b397999261..27e69070eaab8 100644 --- a/src/mono/mono/mini/simd-intrinsics.c +++ b/src/mono/mono/mini/simd-intrinsics.c @@ -493,7 +493,8 @@ emit_xequal (MonoCompile *cfg, MonoClass *klass, MonoInst *arg1, MonoInst *arg2) return emit_simd_ins (cfg, klass, OP_XEQUAL, arg1->dreg, arg2->dreg); #else MonoInst *ins = emit_simd_ins (cfg, klass, OP_XEQUAL, arg1->dreg, arg2->dreg); - ins->inst_c1 = mono_class_get_context (klass)->class_inst->type_argv [0]->type; + if (!COMPILE_LLVM (cfg)) + ins->inst_c1 = mono_class_get_context (klass)->class_inst->type_argv [0]->type; return ins; #endif } From 6d8e652cbd69aa94e4c4509d80db1b4b68539bc2 Mon Sep 17 00:00:00 2001 From: Matous Kozak Date: Thu, 3 Nov 2022 20:30:47 +0100 Subject: [PATCH 5/7] remove space --- src/mono/mono/mini/mini-amd64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/mini/mini-amd64.c b/src/mono/mono/mini/mini-amd64.c index 034e23bfb2e9f..55f4fb6fc5e3a 100644 --- a/src/mono/mono/mini/mini-amd64.c +++ b/src/mono/mono/mini/mini-amd64.c @@ -3886,7 +3886,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb) switch (ins->inst_c1) { case MONO_TYPE_R4: opcode = OP_COMPPS; break; - case MONO_TYPE_R8: opcode = OP_COMPPD; break; + case MONO_TYPE_R8: opcode = OP_COMPPD; break; default: opcode = OP_PCMPEQD; } ins->inst_c0 = 0; From 6dacd2605cb4b3b3774b2772855164bf2be47150 Mon Sep 17 00:00:00 2001 From: Fan Yang <52458914+fanyang-mono@users.noreply.github.com> Date: Mon, 7 Nov 2022 13:39:48 -0500 Subject: [PATCH 6/7] Update src/mono/mono/mini/mini-amd64.c --- src/mono/mono/mini/mini-amd64.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mono/mono/mini/mini-amd64.c b/src/mono/mono/mini/mini-amd64.c index 55f4fb6fc5e3a..f4bfeca124c7e 100644 --- a/src/mono/mono/mini/mini-amd64.c +++ b/src/mono/mono/mini/mini-amd64.c @@ -3889,7 +3889,6 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb) case MONO_TYPE_R8: opcode = OP_COMPPD; break; default: opcode = OP_PCMPEQD; } - ins->inst_c0 = 0; NEW_SIMD_INS (cfg, ins, temp, opcode, temp_reg1, ins->sreg1, ins->sreg2); NEW_SIMD_INS (cfg, ins, temp, OP_EXTRACT_MASK, temp_reg2, temp_reg1, -1); From 2762966e7dcffd1e1b1636094e9b19cf3653caec Mon Sep 17 00:00:00 2001 From: Fan Yang <52458914+fanyang-mono@users.noreply.github.com> Date: Tue, 8 Nov 2022 15:24:52 -0500 Subject: [PATCH 7/7] Update src/mono/mono/mini/mini-amd64.c --- src/mono/mono/mini/mini-amd64.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mono/mono/mini/mini-amd64.c b/src/mono/mono/mini/mini-amd64.c index f4bfeca124c7e..bfede8ad36c7f 100644 --- a/src/mono/mono/mini/mini-amd64.c +++ b/src/mono/mono/mini/mini-amd64.c @@ -3891,6 +3891,7 @@ mono_arch_lowering_pass (MonoCompile *cfg, MonoBasicBlock *bb) } NEW_SIMD_INS (cfg, ins, temp, opcode, temp_reg1, ins->sreg1, ins->sreg2); + temp->inst_c0 = 0; NEW_SIMD_INS (cfg, ins, temp, OP_EXTRACT_MASK, temp_reg2, temp_reg1, -1); temp->type = STACK_I4; NEW_INS (cfg, ins, temp, OP_COMPARE_IMM);