From 17d8b59d42b090c082ec239783ac94269783b977 Mon Sep 17 00:00:00 2001 From: Ishin Pavel Date: Fri, 27 Jan 2023 18:19:54 +0300 Subject: [PATCH] Support mod in profiling Signed-off-by: Ishin Pavel --- compiler/intrinsics_inline_ecmascript.inl | 5 ++- irtoc_scripts/interpreter_handlers.irt | 22 ++++++++++-- isa/isa.yaml | 3 +- runtime/interpreter/ecma-interpreter-inl.h | 2 ++ tests/checked/type_resolving.js | 42 +++++++++++++++++++++- 5 files changed, 69 insertions(+), 5 deletions(-) diff --git a/compiler/intrinsics_inline_ecmascript.inl b/compiler/intrinsics_inline_ecmascript.inl index 2472f5615..07f009200 100644 --- a/compiler/intrinsics_inline_ecmascript.inl +++ b/compiler/intrinsics_inline_ecmascript.inl @@ -89,7 +89,10 @@ case RuntimeInterface::IntrinsicId::INTRINSIC_DIV2_DYN: { ASSERT(types_.size() == 2); return panda::compiler::IrtocInlineDivDyn(intrinsic, types_[0], types_[1]); } -case RuntimeInterface::IntrinsicId::INTRINSIC_NOT_DYN: { +case RuntimeInterface::IntrinsicId::INTRINSIC_MOD2_DYN: { + ASSERT(types_.size() == 2); + return panda::compiler::IrtocInlineModDyn(intrinsic, types_[0], types_[1]); +} case RuntimeInterface::IntrinsicId::INTRINSIC_NOT_DYN: { ASSERT(types_.size() == 1); return panda::compiler::IrtocInlineNotDyn(intrinsic, types_[0]); } diff --git a/irtoc_scripts/interpreter_handlers.irt b/irtoc_scripts/interpreter_handlers.irt index 6fbbad07d..88d02a42f 100644 --- a/irtoc_scripts/interpreter_handlers.irt +++ b/irtoc_scripts/interpreter_handlers.irt @@ -406,6 +406,8 @@ end #################################################################### # MOD # +# We implemented handle_ecma_mod2dyn separately, because compiler calls C++ implementation for float mode. +# But no compiler doesn't supported the call for IrToc macro(:handle_ecma_mod2dyn) do |l, r| IfImm(And(cmpanyi32(l), cmpanyi32(r)).b).Imm(0).CC(:CC_EQ).b { Goto(:Slow) @@ -416,10 +418,8 @@ macro(:handle_ecma_mod2dyn) do |l, r| IfImm(And(Compare(il, 0).CC(:CC_GT).b, Compare(ir, 0).CC(:CC_GT).b).b).Imm(0).CC(:CC_EQ).b { Goto(:Slow) } - res := i32toany(Mod(il, ir).i32) Goto(:Exit) - Label(:Slow) slow_res := ecma_intrinsic_invoke("Mod2DynSlow", l, r).any Label(:Exit) @@ -430,6 +430,22 @@ function(:EcmaMod2dyn, params: {'a'=>'any', 'b'=>'any'}, mode: [:Interpreter, :D Return(handle_ecma_mod2dyn(a, b)) end +macro(:mod2dyn_smi_smi) do |l, r| + f64toany(Mod(i32tof64(anytoi32(l.any)), i32tof64(anytoi32(r.any))).f64) +end + +macro(:mod2dyn_smi_double) do |l, r| + f64toany(Mod(i32tof64(anytoi32(l.any)), anytof64(r.any)).f64) +end + +macro(:mod2dyn_double_smi) do |l, r| + f64toany(Mod(anytof64(l.any), i32tof64(anytoi32(r.any))).f64) +end + +macro(:mod2dyn_double_double) do |l, r| + f64toany(Mod(anytof64(l.any), anytof64(r.any)).f64) +end + macro(:handle_ecma_tonumber) do |v| IfImm(cmpany_notNumber(v.any)).Imm(0).CC(:CC_NE).b { slow_res := ecma_intrinsic_invoke("TonumberSlow", v.u64) @@ -672,7 +688,9 @@ end end Return(send(:"handle_ecma_#{op}2dyn", a, b)).any end +end +[:add, :sub, :and, :or, :xor, :mul, :div, :mod, :shl, :shr].each do |op| i_i_macro = :"#{op}2dyn_smi_smi" i_f_macro = :"#{op}2dyn_smi_double" f_i_macro = :"#{op}2dyn_double_smi" diff --git a/isa/isa.yaml b/isa/isa.yaml index 2df643e48..293808d44 100644 --- a/isa/isa.yaml +++ b/isa/isa.yaml @@ -289,9 +289,10 @@ groups: - sig: ecma.mod2dyn v:in:top acc: inout:top prefix: ecma - format: [pref_op_v_8] + format: [pref_op_v_8_prof_16] properties: [inlinable] intrinsic_name: INTRINSIC_MOD2_DYN + profile: BinaryArith - sig: ecma.eqdyn v:in:top acc: inout:top diff --git a/runtime/interpreter/ecma-interpreter-inl.h b/runtime/interpreter/ecma-interpreter-inl.h index 9cdaea069..7116cbdb0 100644 --- a/runtime/interpreter/ecma-interpreter-inl.h +++ b/runtime/interpreter/ecma-interpreter-inl.h @@ -1221,6 +1221,8 @@ public: uint64_t left = GetRegAsTaggedValue(v0).GetRawData(); uint64_t right = GetAccAsTaggedValue().GetRawData(); + UPDATE_BINARY_ARITH_PROFILE(left, right); + INTRINSIC_CALL_CHECK_SETACC(intrinsics::Mod2Dyn(this->GetJSThread(), left, right)); this->template MoveToNextInst(); } diff --git a/tests/checked/type_resolving.js b/tests/checked/type_resolving.js index 160da8c04..c73befbe5 100644 --- a/tests/checked/type_resolving.js +++ b/tests/checked/type_resolving.js @@ -60,6 +60,10 @@ //! check_aot.call(:Div, 'Div2Dyn', 'i_f', /f64 +Div /) //! check_aot.call(:Div, 'Div2Dyn', 'f_i', /f64 +Div /) //! check_aot.call(:Div, 'Div2Dyn', 'f_f', /f64 +Div /) +//! check_aot.call(:Mod, 'Mod2Dyn', 'i_i', /f64 +Mod /) +//! check_aot.call(:Mod, 'Mod2Dyn', 'i_f', /f64 +Mod /) +//! check_aot.call(:Mod, 'Mod2Dyn', 'f_i', /f64 +Mod /) +//! check_aot.call(:Mod, 'Mod2Dyn', 'f_f', /f64 +Mod /) //! check_aot.call(:Not, 'NotDyn', 'i', /i32 +Not/) //! check_aot.call(:Not, 'NotDyn', 'f', /i32 +Not/) //! check_aot.call(:Neg, 'NegDyn', 'i', /NegOverflowAndZeroCheck/) @@ -99,7 +103,7 @@ //! RUN options: "--interpreter-type irtoc", entry: "_GLOBAL::func_main_0", force_jit: false //! //! EVENT_NOT /Deoptimization.*/ -//! [:add, :sub, :and, :or, :xor, :shl, :shr, :mul, :div, :cmp].each do |op| +//! [:add, :sub, :and, :or, :xor, :shl, :shr, :mul, :div, :mod, :cmp].each do |op| //! ['i_i', 'i_f', 'f_i', 'f_f'].each { |form| //! EVENT /AotEntrypointFound,_GLOBAL::func_test_#{op}_#{form}_\d+/ //! } @@ -430,6 +434,41 @@ function test_div() { } } +function test_mod_i_i() { + let a = 4; + let b = 3; + return a % b; // 1 +} + +function test_mod_i_f() { + let a = 10; + let b = 3.4; + return a % b; // 3.2 +} + +function test_mod_f_i() { + let a = 6.5; + let b = 3; + return a % b; // 0.5 +} + +function test_mod_f_f() { + let a = 5.4; + let b = 2.2; + return a % b; // 1 +} + +function test_mod() { + let res = 0; + res += test_mod_i_i(); + res += test_mod_i_f(); + res += test_mod_f_i(); + res += test_mod_f_f(); + if (res != 5.7) { + throw "test_mod is failed"; + } +} + function test_not_i() { let a = 1; return ~a; // -2 @@ -642,6 +681,7 @@ test_shl(); test_shr(); test_mul(); test_div(); +test_mod(); test_not(); test_neg(); test_inc(); -- Gitee