From de36f16642a889cd054108fd696ac814e0a18e58 Mon Sep 17 00:00:00 2001 From: Milad Fa Date: Fri, 27 Jan 2023 15:17:25 +0000 Subject: [PATCH] PPC/S390[baseline]: Separate signed and unsigned conditions ppc/s390 use separate instructions for signed/unsigned comparisons in order to set flags. We need to be able to differentiate between these two types in order to emit the correct instruction. Change-Id: Ia1b4508994c6e21a7d86ab070234eb37f76aca29 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4198317 Reviewed-by: Junliang Yan Commit-Queue: Milad Farazmand Cr-Commit-Position: refs/heads/main@{#85527} --- src/baseline/ppc/baseline-assembler-ppc-inl.h | 6 ++-- .../s390/baseline-assembler-s390-inl.h | 6 ++-- src/codegen/ppc/constants-ppc.h | 35 +++++++++++++++---- src/codegen/s390/constants-s390.h | 35 +++++++++++++++---- 4 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/baseline/ppc/baseline-assembler-ppc-inl.h b/src/baseline/ppc/baseline-assembler-ppc-inl.h index fbf89af4de..4196551aa1 100644 --- a/src/baseline/ppc/baseline-assembler-ppc-inl.h +++ b/src/baseline/ppc/baseline-assembler-ppc-inl.h @@ -94,7 +94,7 @@ static void JumpIfHelper(MacroAssembler* assm, Condition cc, Register lhs, __ CmpU32(lhs, rhs); } } - __ b(cc, target); + __ b(check_condition(cc), target); } #undef __ @@ -160,7 +160,7 @@ void BaselineAssembler::TestAndBranch(Register value, int mask, Condition cc, Label* target, Label::Distance) { ASM_CODE_COMMENT(masm_); __ AndU64(r0, value, Operand(mask), ip, SetRC); - __ b(cc, target, cr0); + __ b(check_condition(cc), target, cr0); } void BaselineAssembler::JumpIf(Condition cc, Register lhs, const Operand& rhs, @@ -171,7 +171,7 @@ void BaselineAssembler::JumpIf(Condition cc, Register lhs, const Operand& rhs, } else { __ CmpU64(lhs, rhs, r0); } - __ b(cc, target); + __ b(check_condition(cc), target); } void BaselineAssembler::JumpIfObjectType(Condition cc, Register object, diff --git a/src/baseline/s390/baseline-assembler-s390-inl.h b/src/baseline/s390/baseline-assembler-s390-inl.h index bd77cb309b..087c4f1b12 100644 --- a/src/baseline/s390/baseline-assembler-s390-inl.h +++ b/src/baseline/s390/baseline-assembler-s390-inl.h @@ -93,7 +93,7 @@ static void JumpIfHelper(MacroAssembler* assm, Condition cc, Register lhs, __ CmpU32(lhs, rhs); } } - __ b(cc, target); + __ b(check_condition(cc), target); } #undef __ @@ -159,7 +159,7 @@ void BaselineAssembler::TestAndBranch(Register value, int mask, Condition cc, Label* target, Label::Distance) { ASM_CODE_COMMENT(masm_); __ AndP(r0, value, Operand(mask)); - __ b(cc, target); + __ b(check_condition(cc), target); } void BaselineAssembler::JumpIf(Condition cc, Register lhs, const Operand& rhs, @@ -170,7 +170,7 @@ void BaselineAssembler::JumpIf(Condition cc, Register lhs, const Operand& rhs, } else { __ CmpU64(lhs, rhs); } - __ b(cc, target); + __ b(check_condition(cc), target); } void BaselineAssembler::JumpIfObjectType(Condition cc, Register object, diff --git a/src/codegen/ppc/constants-ppc.h b/src/codegen/ppc/constants-ppc.h index 7cea25ad3a..8d00d36570 100644 --- a/src/codegen/ppc/constants-ppc.h +++ b/src/codegen/ppc/constants-ppc.h @@ -132,22 +132,45 @@ enum Condition { al = 10, // Always. // Unified cross-platform condition names/aliases. + // Do not set unsigned constants equal to their signed variants. + // We need to be able to differentiate between signed and unsigned enum + // constants in order to emit the right instructions (i.e CmpS64 vs CmpU64). kEqual = eq, kNotEqual = ne, kLessThan = lt, kGreaterThan = gt, kLessThanEqual = le, kGreaterThanEqual = ge, - kUnsignedLessThan = lt, - kUnsignedGreaterThan = gt, - kUnsignedLessThanEqual = le, - kUnsignedGreaterThanEqual = ge, + kUnsignedLessThan = 11, + kUnsignedGreaterThan = 12, + kUnsignedLessThanEqual = 13, + kUnsignedGreaterThanEqual = 14, kOverflow = overflow, kNoOverflow = nooverflow, - kZero = eq, - kNotZero = ne, + kZero = 15, + kNotZero = 16, }; +inline Condition check_condition(Condition cond) { + switch (cond) { + case kUnsignedLessThan: + return lt; + case kUnsignedGreaterThan: + return gt; + case kUnsignedLessThanEqual: + return le; + case kUnsignedGreaterThanEqual: + return ge; + case kZero: + return eq; + case kNotZero: + return ne; + default: + break; + } + return cond; +} + inline Condition NegateCondition(Condition cond) { DCHECK(cond != al); return static_cast(cond ^ ne); diff --git a/src/codegen/s390/constants-s390.h b/src/codegen/s390/constants-s390.h index 009b46e9cc..8bade7b2ab 100644 --- a/src/codegen/s390/constants-s390.h +++ b/src/codegen/s390/constants-s390.h @@ -104,22 +104,45 @@ enum Condition { mask0xF = 15, // Unified cross-platform condition names/aliases. + // Do not set unsigned constants equal to their signed variants. + // We need to be able to differentiate between signed and unsigned enum + // constants in order to emit the right instructions (i.e CmpS64 vs CmpU64). kEqual = eq, kNotEqual = ne, kLessThan = lt, kGreaterThan = gt, kLessThanEqual = le, kGreaterThanEqual = ge, - kUnsignedLessThan = lt, - kUnsignedGreaterThan = gt, - kUnsignedLessThanEqual = le, - kUnsignedGreaterThanEqual = ge, + kUnsignedLessThan = 16, + kUnsignedGreaterThan = 17, + kUnsignedLessThanEqual = 18, + kUnsignedGreaterThanEqual = 19, kOverflow = overflow, kNoOverflow = nooverflow, - kZero = eq, - kNotZero = ne, + kZero = 20, + kNotZero = 21, }; +inline Condition check_condition(Condition cond) { + switch (cond) { + case kUnsignedLessThan: + return lt; + case kUnsignedGreaterThan: + return gt; + case kUnsignedLessThanEqual: + return le; + case kUnsignedGreaterThanEqual: + return ge; + case kZero: + return eq; + case kNotZero: + return ne; + default: + break; + } + return cond; +} + inline Condition NegateCondition(Condition cond) { DCHECK(cond != al); switch (cond) {