diff options
author | 2021-06-02 17:35:16 +0100 | |
---|---|---|
committer | 2021-06-03 14:00:34 +0100 | |
commit | c8451cb4302e028d4e106c1a2a44749d5cb9bb31 (patch) | |
tree | c59b852b27ef441c5a09c4755e33628315d2e678 | |
parent | 322eced250f893a85dce0f78c74ef91eba5fdb1a (diff) |
Factor out arch-independent ScaleFactor definition.
Bug: 65872996
Test: m test-art-host-gtest
Test: art/test.py --host -r --optimizing
Change-Id: I27763286847b45a5a3a493c3dba48418575b3eb6
-rw-r--r-- | compiler/optimizing/code_generator.cc | 24 | ||||
-rw-r--r-- | compiler/optimizing/code_generator.h | 2 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_x86.cc | 27 | ||||
-rw-r--r-- | compiler/optimizing/code_generator_x86_64.cc | 26 | ||||
-rw-r--r-- | compiler/utils/arm/constants_arm.h | 7 | ||||
-rw-r--r-- | compiler/utils/assembler.h | 7 | ||||
-rw-r--r-- | compiler/utils/x86/assembler_x86_test.cc | 40 | ||||
-rw-r--r-- | compiler/utils/x86/constants_x86.h | 7 | ||||
-rw-r--r-- | compiler/utils/x86_64/assembler_x86_64_test.cc | 48 | ||||
-rw-r--r-- | compiler/utils/x86_64/constants_x86_64.h | 7 |
10 files changed, 80 insertions, 115 deletions
diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc index 886cabbe0a..a096338ee2 100644 --- a/compiler/optimizing/code_generator.cc +++ b/compiler/optimizing/code_generator.cc @@ -1830,4 +1830,28 @@ QuickEntrypointEnum CodeGenerator::GetArrayAllocationEntrypoint(HNewArray* new_a UNREACHABLE(); } +ScaleFactor CodeGenerator::ScaleFactorForType(DataType::Type type) { + switch (type) { + case DataType::Type::kBool: + case DataType::Type::kUint8: + case DataType::Type::kInt8: + return TIMES_1; + case DataType::Type::kUint16: + case DataType::Type::kInt16: + return TIMES_2; + case DataType::Type::kInt32: + case DataType::Type::kUint32: + case DataType::Type::kFloat32: + case DataType::Type::kReference: + return TIMES_4; + case DataType::Type::kInt64: + case DataType::Type::kUint64: + case DataType::Type::kFloat64: + return TIMES_8; + case DataType::Type::kVoid: + LOG(FATAL) << "Unreachable type " << type; + UNREACHABLE(); + } +} + } // namespace art diff --git a/compiler/optimizing/code_generator.h b/compiler/optimizing/code_generator.h index 338aac0afc..99de61ddce 100644 --- a/compiler/optimizing/code_generator.h +++ b/compiler/optimizing/code_generator.h @@ -36,6 +36,7 @@ #include "optimizing_compiler_stats.h" #include "read_barrier_option.h" #include "stack.h" +#include "utils/assembler.h" #include "utils/label.h" namespace art { @@ -701,6 +702,7 @@ class CodeGenerator : public DeletableArenaObject<kArenaAllocCodeGenerator> { virtual void GenerateNop() = 0; static QuickEntrypointEnum GetArrayAllocationEntrypoint(HNewArray* new_array); + static ScaleFactor ScaleFactorForType(DataType::Type type); protected: // Patch info used for recording locations of required linker patches and their targets, diff --git a/compiler/optimizing/code_generator_x86.cc b/compiler/optimizing/code_generator_x86.cc index 51444af4a6..52852f2ce6 100644 --- a/compiler/optimizing/code_generator_x86.cc +++ b/compiler/optimizing/code_generator_x86.cc @@ -6159,30 +6159,6 @@ void LocationsBuilderX86::VisitArrayGet(HArrayGet* instruction) { } } -static ScaleFactor ScaleFactorForType(DataType::Type type) { - switch (type) { - case DataType::Type::kBool: - case DataType::Type::kUint8: - case DataType::Type::kInt8: - return TIMES_1; - case DataType::Type::kUint16: - case DataType::Type::kInt16: - return TIMES_2; - case DataType::Type::kInt32: - case DataType::Type::kUint32: - case DataType::Type::kFloat32: - case DataType::Type::kReference: - return TIMES_4; - case DataType::Type::kInt64: - case DataType::Type::kUint64: - case DataType::Type::kFloat64: - return TIMES_8; - case DataType::Type::kVoid: - LOG(FATAL) << "Unreachable type " << type; - UNREACHABLE(); - } -} - void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { LocationSummary* locations = instruction->GetLocations(); Location obj_loc = locations->InAt(0); @@ -6237,7 +6213,8 @@ void InstructionCodeGeneratorX86::VisitArrayGet(HArrayGet* instruction) { __ movzxw(out, CodeGeneratorX86::ArrayAddress(obj, index, TIMES_2, data_offset)); __ Bind(&done); } else { - Address src = CodeGeneratorX86::ArrayAddress(obj, index, ScaleFactorForType(type), data_offset); + ScaleFactor scale = CodeGenerator::ScaleFactorForType(type); + Address src = CodeGeneratorX86::ArrayAddress(obj, index, scale, data_offset); codegen_->LoadFromMemoryNoBarrier(type, out_loc, src, instruction); } } diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc index f543dd4df5..80762210f5 100644 --- a/compiler/optimizing/code_generator_x86_64.cc +++ b/compiler/optimizing/code_generator_x86_64.cc @@ -5348,30 +5348,6 @@ void LocationsBuilderX86_64::VisitArrayGet(HArrayGet* instruction) { } } -static ScaleFactor ScaleFactorForType(DataType::Type type) { - switch (type) { - case DataType::Type::kBool: - case DataType::Type::kUint8: - case DataType::Type::kInt8: - return TIMES_1; - case DataType::Type::kUint16: - case DataType::Type::kInt16: - return TIMES_2; - case DataType::Type::kInt32: - case DataType::Type::kUint32: - case DataType::Type::kFloat32: - case DataType::Type::kReference: - return TIMES_4; - case DataType::Type::kInt64: - case DataType::Type::kUint64: - case DataType::Type::kFloat64: - return TIMES_8; - case DataType::Type::kVoid: - LOG(FATAL) << "Unreachable type " << type; - UNREACHABLE(); - } -} - void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { LocationSummary* locations = instruction->GetLocations(); Location obj_loc = locations->InAt(0); @@ -5427,7 +5403,7 @@ void InstructionCodeGeneratorX86_64::VisitArrayGet(HArrayGet* instruction) { __ movzxw(out, CodeGeneratorX86_64::ArrayAddress(obj, index, TIMES_2, data_offset)); __ Bind(&done); } else { - ScaleFactor scale = ScaleFactorForType(type); + ScaleFactor scale = CodeGenerator::ScaleFactorForType(type); Address src = CodeGeneratorX86_64::ArrayAddress(obj, index, scale, data_offset); codegen_->LoadFromMemoryNoReference(type, out_loc, src); } diff --git a/compiler/utils/arm/constants_arm.h b/compiler/utils/arm/constants_arm.h index 3e316c8e84..688c09396f 100644 --- a/compiler/utils/arm/constants_arm.h +++ b/compiler/utils/arm/constants_arm.h @@ -51,13 +51,6 @@ enum DmbOptions { NSHST = 0x6 }; -enum ScaleFactor { - TIMES_1 = 0, - TIMES_2 = 1, - TIMES_4 = 2, - TIMES_8 = 3 -}; - // Values for double-precision floating point registers. enum DRegister { // private marker to avoid generate-operator-out.py from processing. D0 = 0, diff --git a/compiler/utils/assembler.h b/compiler/utils/assembler.h index e863b9a071..67f38bcbe6 100644 --- a/compiler/utils/assembler.h +++ b/compiler/utils/assembler.h @@ -409,6 +409,13 @@ class Assembler : public DeletableArenaObject<kArenaAllocAssembler> { DebugFrameOpCodeWriterForAssembler cfi_; }; +enum ScaleFactor { + TIMES_1 = 0, + TIMES_2 = 1, + TIMES_4 = 2, + TIMES_8 = 3 +}; + } // namespace art #endif // ART_COMPILER_UTILS_ASSEMBLER_H_ diff --git a/compiler/utils/x86/assembler_x86_test.cc b/compiler/utils/x86/assembler_x86_test.cc index 32d138f81f..030479c63b 100644 --- a/compiler/utils/x86/assembler_x86_test.cc +++ b/compiler/utils/x86/assembler_x86_test.cc @@ -64,24 +64,24 @@ class AssemblerX86Test : public AssemblerTest<x86::X86Assembler, void SetUpHelpers() override { if (addresses_singleton_.size() == 0) { // One addressing mode to test the repeat drivers. - addresses_singleton_.push_back(x86::Address(x86::EAX, x86::EBX, x86::TIMES_1, 2)); + addresses_singleton_.push_back(x86::Address(x86::EAX, x86::EBX, TIMES_1, 2)); } if (addresses_.size() == 0) { // Several addressing modes. - addresses_.push_back(x86::Address(x86::EDI, x86::EAX, x86::TIMES_1, 15)); - addresses_.push_back(x86::Address(x86::EDI, x86::EBX, x86::TIMES_2, 16)); - addresses_.push_back(x86::Address(x86::EDI, x86::ECX, x86::TIMES_4, 17)); - addresses_.push_back(x86::Address(x86::EDI, x86::EDX, x86::TIMES_8, 18)); + addresses_.push_back(x86::Address(x86::EDI, x86::EAX, TIMES_1, 15)); + addresses_.push_back(x86::Address(x86::EDI, x86::EBX, TIMES_2, 16)); + addresses_.push_back(x86::Address(x86::EDI, x86::ECX, TIMES_4, 17)); + addresses_.push_back(x86::Address(x86::EDI, x86::EDX, TIMES_8, 18)); addresses_.push_back(x86::Address(x86::EAX, -1)); addresses_.push_back(x86::Address(x86::EBX, 0)); addresses_.push_back(x86::Address(x86::ESI, 1)); addresses_.push_back(x86::Address(x86::EDI, 987654321)); // Several addressing modes with the special ESP. - addresses_.push_back(x86::Address(x86::ESP, x86::EAX, x86::TIMES_1, 15)); - addresses_.push_back(x86::Address(x86::ESP, x86::EBX, x86::TIMES_2, 16)); - addresses_.push_back(x86::Address(x86::ESP, x86::ECX, x86::TIMES_4, 17)); - addresses_.push_back(x86::Address(x86::ESP, x86::EDX, x86::TIMES_8, 18)); + addresses_.push_back(x86::Address(x86::ESP, x86::EAX, TIMES_1, 15)); + addresses_.push_back(x86::Address(x86::ESP, x86::EBX, TIMES_2, 16)); + addresses_.push_back(x86::Address(x86::ESP, x86::ECX, TIMES_4, 17)); + addresses_.push_back(x86::Address(x86::ESP, x86::EDX, TIMES_8, 18)); addresses_.push_back(x86::Address(x86::ESP, -1)); addresses_.push_back(x86::Address(x86::ESP, 0)); addresses_.push_back(x86::Address(x86::ESP, 1)); @@ -278,16 +278,16 @@ TEST_F(AssemblerX86Test, PoplAllAddresses) { continue; } else if (*base == *index) { // Index only. - all_addresses.push_back(x86::Address(*index, x86::TIMES_1, -1)); - all_addresses.push_back(x86::Address(*index, x86::TIMES_2, 0)); - all_addresses.push_back(x86::Address(*index, x86::TIMES_4, 1)); - all_addresses.push_back(x86::Address(*index, x86::TIMES_8, 123456789)); + all_addresses.push_back(x86::Address(*index, TIMES_1, -1)); + all_addresses.push_back(x86::Address(*index, TIMES_2, 0)); + all_addresses.push_back(x86::Address(*index, TIMES_4, 1)); + all_addresses.push_back(x86::Address(*index, TIMES_8, 123456789)); } // Base and index. - all_addresses.push_back(x86::Address(*base, *index, x86::TIMES_1, -1)); - all_addresses.push_back(x86::Address(*base, *index, x86::TIMES_2, 0)); - all_addresses.push_back(x86::Address(*base, *index, x86::TIMES_4, 1)); - all_addresses.push_back(x86::Address(*base, *index, x86::TIMES_8, 123456789)); + all_addresses.push_back(x86::Address(*base, *index, TIMES_1, -1)); + all_addresses.push_back(x86::Address(*base, *index, TIMES_2, 0)); + all_addresses.push_back(x86::Address(*base, *index, TIMES_4, 1)); + all_addresses.push_back(x86::Address(*base, *index, TIMES_8, 123456789)); } } DriverStr(RepeatA(&x86::X86Assembler::popl, all_addresses, "popl {mem}"), "popq"); @@ -551,11 +551,11 @@ TEST_F(AssemblerX86Test, RoundSD) { TEST_F(AssemblerX86Test, CmovlAddress) { GetAssembler()->cmovl(x86::kEqual, x86::Register(x86::EAX), x86::Address( - x86::Register(x86::EDI), x86::Register(x86::EBX), x86::TIMES_4, 12)); + x86::Register(x86::EDI), x86::Register(x86::EBX), TIMES_4, 12)); GetAssembler()->cmovl(x86::kNotEqual, x86::Register(x86::EDI), x86::Address( - x86::Register(x86::ESI), x86::Register(x86::EBX), x86::TIMES_4, 12)); + x86::Register(x86::ESI), x86::Register(x86::EBX), TIMES_4, 12)); GetAssembler()->cmovl(x86::kEqual, x86::Register(x86::EDI), x86::Address( - x86::Register(x86::EDI), x86::Register(x86::EAX), x86::TIMES_4, 12)); + x86::Register(x86::EDI), x86::Register(x86::EAX), TIMES_4, 12)); const char* expected = "cmovzl 0xc(%EDI,%EBX,4), %eax\n" "cmovnzl 0xc(%ESI,%EBX,4), %edi\n" diff --git a/compiler/utils/x86/constants_x86.h b/compiler/utils/x86/constants_x86.h index a782b16c6b..477b915bb9 100644 --- a/compiler/utils/x86/constants_x86.h +++ b/compiler/utils/x86/constants_x86.h @@ -54,13 +54,6 @@ enum X87Register { }; std::ostream& operator<<(std::ostream& os, const X87Register& reg); -enum ScaleFactor { - TIMES_1 = 0, - TIMES_2 = 1, - TIMES_4 = 2, - TIMES_8 = 3 -}; - enum Condition { kOverflow = 0, kNoOverflow = 1, diff --git a/compiler/utils/x86_64/assembler_x86_64_test.cc b/compiler/utils/x86_64/assembler_x86_64_test.cc index 1efe1699f0..5952a6d19e 100644 --- a/compiler/utils/x86_64/assembler_x86_64_test.cc +++ b/compiler/utils/x86_64/assembler_x86_64_test.cc @@ -153,23 +153,23 @@ class AssemblerX86_64Test : public AssemblerTest<x86_64::X86_64Assembler, // One addressing mode to test the repeat drivers. addresses_singleton_.push_back( x86_64::Address(x86_64::CpuRegister(x86_64::RAX), - x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_1, -1)); + x86_64::CpuRegister(x86_64::RBX), TIMES_1, -1)); } if (addresses_.size() == 0) { // Several addressing modes. addresses_.push_back( x86_64::Address(x86_64::CpuRegister(x86_64::RDI), - x86_64::CpuRegister(x86_64::RAX), x86_64::TIMES_1, 15)); + x86_64::CpuRegister(x86_64::RAX), TIMES_1, 15)); addresses_.push_back( x86_64::Address(x86_64::CpuRegister(x86_64::RDI), - x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_2, 16)); + x86_64::CpuRegister(x86_64::RBX), TIMES_2, 16)); addresses_.push_back( x86_64::Address(x86_64::CpuRegister(x86_64::RDI), - x86_64::CpuRegister(x86_64::RCX), x86_64::TIMES_4, 17)); + x86_64::CpuRegister(x86_64::RCX), TIMES_4, 17)); addresses_.push_back( x86_64::Address(x86_64::CpuRegister(x86_64::RDI), - x86_64::CpuRegister(x86_64::RDX), x86_64::TIMES_8, 18)); + x86_64::CpuRegister(x86_64::RDX), TIMES_8, 18)); addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RAX), -1)); addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RBX), 0)); addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RSI), 1)); @@ -177,16 +177,16 @@ class AssemblerX86_64Test : public AssemblerTest<x86_64::X86_64Assembler, // Several addressing modes with the special ESP. addresses_.push_back( x86_64::Address(x86_64::CpuRegister(x86_64::RSP), - x86_64::CpuRegister(x86_64::RAX), x86_64::TIMES_1, 15)); + x86_64::CpuRegister(x86_64::RAX), TIMES_1, 15)); addresses_.push_back( x86_64::Address(x86_64::CpuRegister(x86_64::RSP), - x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_2, 16)); + x86_64::CpuRegister(x86_64::RBX), TIMES_2, 16)); addresses_.push_back( x86_64::Address(x86_64::CpuRegister(x86_64::RSP), - x86_64::CpuRegister(x86_64::RCX), x86_64::TIMES_4, 17)); + x86_64::CpuRegister(x86_64::RCX), TIMES_4, 17)); addresses_.push_back( x86_64::Address(x86_64::CpuRegister(x86_64::RSP), - x86_64::CpuRegister(x86_64::RDX), x86_64::TIMES_8, 18)); + x86_64::CpuRegister(x86_64::RDX), TIMES_8, 18)); addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), -1)); addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 0)); addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::RSP), 1)); @@ -194,7 +194,7 @@ class AssemblerX86_64Test : public AssemblerTest<x86_64::X86_64Assembler, // Several addressing modes with the higher registers. addresses_.push_back( x86_64::Address(x86_64::CpuRegister(x86_64::R8), - x86_64::CpuRegister(x86_64::R15), x86_64::TIMES_2, -1)); + x86_64::CpuRegister(x86_64::R15), TIMES_2, -1)); addresses_.push_back(x86_64::Address(x86_64::CpuRegister(x86_64::R15), 123456789)); } @@ -526,16 +526,16 @@ TEST_F(AssemblerX86_64Test, PopqAllAddresses) { continue; } else if (base->AsRegister() == index->AsRegister()) { // Index only. - all_addresses.push_back(x86_64::Address(*index, x86_64::TIMES_1, -1)); - all_addresses.push_back(x86_64::Address(*index, x86_64::TIMES_2, 0)); - all_addresses.push_back(x86_64::Address(*index, x86_64::TIMES_4, 1)); - all_addresses.push_back(x86_64::Address(*index, x86_64::TIMES_8, 123456789)); + all_addresses.push_back(x86_64::Address(*index, TIMES_1, -1)); + all_addresses.push_back(x86_64::Address(*index, TIMES_2, 0)); + all_addresses.push_back(x86_64::Address(*index, TIMES_4, 1)); + all_addresses.push_back(x86_64::Address(*index, TIMES_8, 123456789)); } // Base and index. - all_addresses.push_back(x86_64::Address(*base, *index, x86_64::TIMES_1, -1)); - all_addresses.push_back(x86_64::Address(*base, *index, x86_64::TIMES_2, 0)); - all_addresses.push_back(x86_64::Address(*base, *index, x86_64::TIMES_4, 1)); - all_addresses.push_back(x86_64::Address(*base, *index, x86_64::TIMES_8, 123456789)); + all_addresses.push_back(x86_64::Address(*base, *index, TIMES_1, -1)); + all_addresses.push_back(x86_64::Address(*base, *index, TIMES_2, 0)); + all_addresses.push_back(x86_64::Address(*base, *index, TIMES_4, 1)); + all_addresses.push_back(x86_64::Address(*base, *index, TIMES_8, 123456789)); } } DriverStr(RepeatA(&x86_64::X86_64Assembler::popq, all_addresses, "popq {mem}"), "popq"); @@ -2161,11 +2161,11 @@ TEST_F(AssemblerX86_64Test, PopcntqAddress) { TEST_F(AssemblerX86_64Test, CmovlAddress) { GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::R10), x86_64::Address( - x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), false); + x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), TIMES_4, 12), false); GetAssembler()->cmov(x86_64::kNotEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address( - x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), false); + x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), TIMES_4, 12), false); GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address( - x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), false); + x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), TIMES_4, 12), false); const char* expected = "cmovzl 0xc(%RDI,%RBX,4), %R10d\n" "cmovnzl 0xc(%R10,%RBX,4), %edi\n" @@ -2175,11 +2175,11 @@ TEST_F(AssemblerX86_64Test, CmovlAddress) { TEST_F(AssemblerX86_64Test, CmovqAddress) { GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::R10), x86_64::Address( - x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), true); + x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::RBX), TIMES_4, 12), true); GetAssembler()->cmov(x86_64::kNotEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address( - x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), x86_64::TIMES_4, 12), true); + x86_64::CpuRegister(x86_64::R10), x86_64::CpuRegister(x86_64::RBX), TIMES_4, 12), true); GetAssembler()->cmov(x86_64::kEqual, x86_64::CpuRegister(x86_64::RDI), x86_64::Address( - x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), x86_64::TIMES_4, 12), true); + x86_64::CpuRegister(x86_64::RDI), x86_64::CpuRegister(x86_64::R9), TIMES_4, 12), true); const char* expected = "cmovzq 0xc(%RDI,%RBX,4), %R10\n" "cmovnzq 0xc(%R10,%RBX,4), %rdi\n" diff --git a/compiler/utils/x86_64/constants_x86_64.h b/compiler/utils/x86_64/constants_x86_64.h index 5335398de9..cd61e6d619 100644 --- a/compiler/utils/x86_64/constants_x86_64.h +++ b/compiler/utils/x86_64/constants_x86_64.h @@ -81,13 +81,6 @@ enum X87Register { }; std::ostream& operator<<(std::ostream& os, const X87Register& reg); -enum ScaleFactor { - TIMES_1 = 0, - TIMES_2 = 1, - TIMES_4 = 2, - TIMES_8 = 3 -}; - enum Condition { kOverflow = 0, kNoOverflow = 1, |