From bb7d7755f56a85087b5b127e76d739f7f4eb9907 Mon Sep 17 00:00:00 2001 From: Rhys Perry Date: Wed, 22 Jan 2020 19:59:56 +0000 Subject: [PATCH] aco: add a few tests for the assembler and optimizer MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Rhys Perry Acked-by: Samuel Pitoiset Acked-by: Daniel Schürmann Acked-by: Timur Kristóf Part-of: --- src/amd/compiler/tests/meson.build | 2 + src/amd/compiler/tests/test_assembler.cpp | 41 ++++++++++++ src/amd/compiler/tests/test_optimizer.cpp | 82 +++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 src/amd/compiler/tests/test_assembler.cpp create mode 100644 src/amd/compiler/tests/test_optimizer.cpp diff --git a/src/amd/compiler/tests/meson.build b/src/amd/compiler/tests/meson.build index 13c7455d1b8..c63b860630a 100644 --- a/src/amd/compiler/tests/meson.build +++ b/src/amd/compiler/tests/meson.build @@ -22,6 +22,8 @@ aco_tests_files = files( 'helpers.cpp', 'helpers.h', 'main.cpp', + 'test_assembler.cpp', + 'test_optimizer.cpp', 'test_tests.cpp', ) diff --git a/src/amd/compiler/tests/test_assembler.cpp b/src/amd/compiler/tests/test_assembler.cpp new file mode 100644 index 00000000000..6f493a49fa2 --- /dev/null +++ b/src/amd/compiler/tests/test_assembler.cpp @@ -0,0 +1,41 @@ +/* + * Copyright © 2020 Valve Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ +#include "helpers.h" + +using namespace aco; + +BEGIN_TEST(assembler.s_memtime) + for (unsigned i = GFX6; i <= GFX10; i++) { + if (!setup_cs(NULL, (chip_class)i)) + continue; + + //~gfx[6-7]>> c7800000 + //~gfx[6-7]! bf810000 + //~gfx[8-9]>> s_memtime s[0:1] ; c0900000 00000000 + //~gfx10>> s_memtime s[0:1] ; f4900000 fa000000 + bld.smem(aco_opcode::s_memtime, bld.def(s2)).def(0).setFixed(PhysReg{0}); + + finish_assembler_test(); + } +END_TEST diff --git a/src/amd/compiler/tests/test_optimizer.cpp b/src/amd/compiler/tests/test_optimizer.cpp new file mode 100644 index 00000000000..d28f2cb3a03 --- /dev/null +++ b/src/amd/compiler/tests/test_optimizer.cpp @@ -0,0 +1,82 @@ +/* + * Copyright © 2020 Valve Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + * + */ +#include "helpers.h" + +using namespace aco; + +BEGIN_TEST(optimize.neg) + for (unsigned i = GFX9; i <= GFX10; i++) { + //>> v1: %a, v1: %b, s1: %c, s1: %d, s2: %_:exec = p_startpgm + if (!setup_cs("v1 v1 s1 s1", (chip_class)i)) + continue; + + //! v1: %res0 = v_mul_f32 %a, -%b + //! p_unit_test 0, %res0 + Temp neg_b = bld.vop2(aco_opcode::v_xor_b32, bld.def(v1), Operand(0x80000000u), inputs[1]); + writeout(0, bld.vop2(aco_opcode::v_mul_f32, bld.def(v1), inputs[0], neg_b)); + + //! v1: %neg_a = v_xor_b32 0x80000000, %a + //~gfx[6-9]! v1: %res1 = v_mul_f32 0x123456, %neg_a + //~gfx10! v1: %res1 = v_mul_f32 0x123456, -%a + //! p_unit_test 1, %res1 + Temp neg_a = bld.vop2(aco_opcode::v_xor_b32, bld.def(v1), Operand(0x80000000u), inputs[0]); + writeout(1, bld.vop2(aco_opcode::v_mul_f32, bld.def(v1), Operand(0x123456u), neg_a)); + + //! v1: %res2 = v_mul_f32 %a, %b + //! p_unit_test 2, %res2 + Temp neg_neg_a = bld.vop2(aco_opcode::v_xor_b32, bld.def(v1), Operand(0x80000000u), neg_a); + writeout(2, bld.vop2(aco_opcode::v_mul_f32, bld.def(v1), neg_neg_a, inputs[1])); + + /* we could optimize this case into just an abs(), but NIR already does this */ + //! v1: %res3 = v_mul_f32 |%neg_a|, %b + //! p_unit_test 3, %res3 + Temp abs_neg_a = bld.vop2(aco_opcode::v_and_b32, bld.def(v1), Operand(0x7FFFFFFFu), neg_a); + writeout(3, bld.vop2(aco_opcode::v_mul_f32, bld.def(v1), abs_neg_a, inputs[1])); + + //! v1: %res4 = v_mul_f32 -|%a|, %b + //! p_unit_test 4, %res4 + Temp abs_a = bld.vop2(aco_opcode::v_and_b32, bld.def(v1), Operand(0x7FFFFFFFu), inputs[0]); + Temp neg_abs_a = bld.vop2(aco_opcode::v_xor_b32, bld.def(v1), Operand(0x80000000u), abs_a); + writeout(4, bld.vop2(aco_opcode::v_mul_f32, bld.def(v1), neg_abs_a, inputs[1])); + + //! v1: %res5 = v_mul_f32 -%a, %b row_shl:1 bound_ctrl:1 + //! p_unit_test 5, %res5 + writeout(5, bld.vop2_dpp(aco_opcode::v_mul_f32, bld.def(v1), neg_a, inputs[1], dpp_row_sl(1))); + + //! v1: %res6 = v_subrev_f32 %a, %b + //! p_unit_test 6, %res6 + writeout(6, bld.vop2(aco_opcode::v_add_f32, bld.def(v1), neg_a, inputs[1])); + + //! v1: %res7 = v_sub_f32 %b, %a + //! p_unit_test 7, %res7 + writeout(7, bld.vop2(aco_opcode::v_add_f32, bld.def(v1), inputs[1], neg_a)); + + //! v1: %res8 = v_mul_f32 %a, -%c + //! p_unit_test 8, %res8 + Temp neg_c = bld.vop2(aco_opcode::v_xor_b32, bld.def(v1), Operand(0x80000000u), bld.copy(bld.def(v1), inputs[2])); + writeout(8, bld.vop2(aco_opcode::v_mul_f32, bld.def(v1), inputs[0], neg_c)); + + finish_opt_test(); + } +END_TEST -- 2.30.2