From b50d59f4ca5557a7719dc26157f8f2fd9006913a Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 20 Sep 2024 17:28:33 +0100 Subject: Verify hardware supports ISA features in tests When running codegen tests, verify that the ISA features used in the codegen are supported by the hardware. This strengthens checks for gtests that may use ISA features which are not supported by the hardware and therefore should not be run on that hardware. Test: art/test.py --gtest art_compiler_tests Change-Id: I56ebd6e964947fe004f466010a18faceb019bfae --- compiler/optimizing/codegen_test_utils.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'compiler/optimizing/codegen_test_utils.h') diff --git a/compiler/optimizing/codegen_test_utils.h b/compiler/optimizing/codegen_test_utils.h index a8425c9915..130c796652 100644 --- a/compiler/optimizing/codegen_test_utils.h +++ b/compiler/optimizing/codegen_test_utils.h @@ -167,15 +167,30 @@ class TestCodeGeneratorX86 : public x86::CodeGeneratorX86 { }; #endif -static bool CanExecuteOnHardware(InstructionSet target_isa) { +// Check that the current runtime ISA matches the target ISA. +static bool DoesHardwareSupportISA(InstructionSet target_isa) { return (target_isa == kRuntimeISA) // Handle the special case of ARM, with two instructions sets (ARM32 and Thumb-2). || (kRuntimeISA == InstructionSet::kArm && target_isa == InstructionSet::kThumb2); } -static bool CanExecute(InstructionSet target_isa) { +// Check that the current runtime ISA matches the target ISA and the ISA features requested are +// available on the hardware. +static bool CanExecuteOnHardware(const CodeGenerator& codegen) { + const InstructionSetFeatures* isa_features = + codegen.GetCompilerOptions().GetInstructionSetFeatures(); + return DoesHardwareSupportISA(codegen.GetInstructionSet()) + && InstructionSetFeatures::FromHwcap()->HasAtLeast(isa_features); +} + +static bool CanExecuteISA(InstructionSet target_isa) { CodeSimulatorContainer simulator(target_isa); - return CanExecuteOnHardware(target_isa) || simulator.CanSimulate(); + return DoesHardwareSupportISA(target_isa) || simulator.CanSimulate(); +} + +static bool CanExecute(const CodeGenerator& codegen) { + CodeSimulatorContainer simulator(codegen.GetInstructionSet()); + return CanExecuteOnHardware(codegen) || simulator.CanSimulate(); } template @@ -200,14 +215,14 @@ inline int64_t SimulatorExecute(CodeSimulator* simulator, int64_t (*f)( } template -static void VerifyGeneratedCode(InstructionSet target_isa, +static void VerifyGeneratedCode(const CodeGenerator& codegen, Expected (*f)(), bool has_result, Expected expected) { - ASSERT_TRUE(CanExecute(target_isa)) << "Target isa is not executable."; + ASSERT_TRUE(CanExecute(codegen)) << "Target isa is not executable."; // Verify on simulator. - CodeSimulatorContainer simulator(target_isa); + CodeSimulatorContainer simulator(codegen.GetInstructionSet()); if (simulator.CanSimulate()) { Expected result = SimulatorExecute(simulator.Get(), f); if (has_result) { @@ -216,7 +231,7 @@ static void VerifyGeneratedCode(InstructionSet target_isa, } // Verify on hardware. - if (CanExecuteOnHardware(target_isa)) { + if (CanExecuteOnHardware(codegen)) { Expected result = f(); if (has_result) { ASSERT_EQ(expected, result); @@ -241,7 +256,7 @@ static void Run(const CodeGenerator& codegen, using fptr = Expected (*)(); fptr f = reinterpret_cast(reinterpret_cast(method_code)); - VerifyGeneratedCode(target_isa, f, has_result, expected); + VerifyGeneratedCode(codegen, f, has_result, expected); } static void ValidateGraph(HGraph* graph) { -- cgit v1.2.3-59-g8ed1b