From 3f76cb860adad306319d9fb1ef5a076178fa4e7a Mon Sep 17 00:00:00 2001 From: ctw-ian Date: Thu, 11 Aug 2022 19:44:04 +0800 Subject: [PATCH] Modify range of index Issue:I5LY6K Signed-off-by: ctw-ian Change-Id: I483894835bee126cfb080359b3434a74e4e2c16b --- es2panda/compiler/core/pandagen.cpp | 16 ++++++++++++++-- es2panda/util/helpers.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index f6fd291cf15..78a49b5f538 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -1705,13 +1705,25 @@ Operand PandaGen::ToNamedPropertyKey(const ir::Expression *prop, bool isComputed Operand PandaGen::ToPropertyKey(const ir::Expression *prop, bool isComputed) { Operand op = ToNamedPropertyKey(prop, isComputed); - if (!std::holds_alternative(op)) { - ASSERT(std::holds_alternative(op) || std::holds_alternative(op)); + if (std::holds_alternative(op) || (std::holds_alternative(op) && + (std::get(op) <= util::Helpers::MAX_INT32))) { return op; } VReg propReg = AllocReg(); + /** + * Store index to vreg when index > MAX_INT32 to simplify ASM interpreter If byindex-related instructions support + * index > MAX_INT32, ASM interpreter will have to add a judgment whether index needs more than 32 bits which will + * cause inefficiency of it since cases when index > MAX_INT32 can be quite rare + **/ + if (std::holds_alternative(op) && (std::get(op) > util::Helpers::MAX_INT32)) { + LoadAccumulatorFloat(prop, std::get(op)); + StoreAccumulator(prop, propReg); + return propReg; + } + + ASSERT(std::holds_alternative(op)); prop->Compile(this); StoreAccumulator(prop, propReg); diff --git a/es2panda/util/helpers.h b/es2panda/util/helpers.h index 095e409ca34..a5dab4112a7 100644 --- a/es2panda/util/helpers.h +++ b/es2panda/util/helpers.h @@ -66,6 +66,7 @@ public: uint32_t index); static const uint32_t INVALID_INDEX = 4294967295L; + static const uint32_t MAX_INT32 = 2147483647; }; template -- Gitee