Factor out arch-independent ScaleFactor definition.
Bug: 65872996
Test: m test-art-host-gtest
Test: art/test.py --host -r --optimizing
Change-Id: I27763286847b45a5a3a493c3dba48418575b3eb6
diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc
index 886cabb..a096338 100644
--- a/compiler/optimizing/code_generator.cc
+++ b/compiler/optimizing/code_generator.cc
@@ -1830,4 +1830,28 @@
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 338aac0..99de61d 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 @@
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 51444af..52852f2 100644
--- a/compiler/optimizing/code_generator_x86.cc
+++ b/compiler/optimizing/code_generator_x86.cc
@@ -6159,30 +6159,6 @@
}
}
-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 @@
__ 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 f543dd4..8076221 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -5348,30 +5348,6 @@
}
}
-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 @@
__ 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 3e316c8..688c093 100644
--- a/compiler/utils/arm/constants_arm.h
+++ b/compiler/utils/arm/constants_arm.h
@@ -51,13 +51,6 @@
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 e863b9a..67f38bc 100644
--- a/compiler/utils/assembler.h
+++ b/compiler/utils/assembler.h
@@ -409,6 +409,13 @@
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 32d138f..030479c 100644
--- a/compiler/utils/x86/assembler_x86_test.cc
+++ b/compiler/utils/x86/assembler_x86_test.cc
@@ -64,24 +64,24 @@
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 @@
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, 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 a782b16..477b915 100644
--- a/compiler/utils/x86/constants_x86.h
+++ b/compiler/utils/x86/constants_x86.h
@@ -54,13 +54,6 @@
};
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 1efe169..5952a6d 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 @@
// 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 @@
// 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 @@
// 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 @@
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, 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, 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 5335398..cd61e6d 100644
--- a/compiler/utils/x86_64/constants_x86_64.h
+++ b/compiler/utils/x86_64/constants_x86_64.h
@@ -81,13 +81,6 @@
};
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,