Path: blob/21.2-virgl/src/amd/compiler/tests/test_builder.cpp
7108 views
/*1* Copyright © 2020 Valve Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*22*/23#include "helpers.h"2425using namespace aco;2627BEGIN_TEST(builder.v_mul_imm)28for (unsigned i = GFX8; i <= GFX10; i++) {29//>> v1: %a, v1: %b, s1: %c, s1: %d = p_startpgm30if (!setup_cs("v1 v1 s1 s1", (chip_class)i))31continue;3233/* simple optimizations */3435//! p_unit_test 0, 036writeout(0, bld.v_mul_imm(bld.def(v1), inputs[0], 0));3738//! p_unit_test 1, %a39writeout(1, bld.v_mul_imm(bld.def(v1), inputs[0], 1));4041//! v1: %res2 = v_lshlrev_b32 2, %a42//! p_unit_test 2, %res243writeout(2, bld.v_mul_imm(bld.def(v1), inputs[0], 4));4445//! v1: %res3 = v_lshlrev_b32 31, %a46//! p_unit_test 3, %res347writeout(3, bld.v_mul_imm(bld.def(v1), inputs[0], 2147483648u));4849/* single lshl+add/sub */5051//~gfx8! v1: %res4_tmp = v_lshlrev_b32 3, %a52//~gfx8! v1: %res4, s2: %_ = v_add_co_u32 %res4_tmp, %a53//~gfx(9|10)! v1: %res4 = v_lshl_add_u32 %a, 3, %a54//! p_unit_test 4, %res455writeout(4, bld.v_mul_imm(bld.def(v1), inputs[0], 9));5657//~gfx[89]! v1: %res5_tmp = v_lshlrev_b32 3, %a58//~gfx8! v1: %res5, s2: %_ = v_sub_co_u32 %res5_tmp, %a59//~gfx9! v1: %res5 = v_sub_u32 %res5_tmp, %a60//~gfx10! v1: %res5 = v_mul_lo_u32 7, %a61//! p_unit_test 5, %res562writeout(5, bld.v_mul_imm(bld.def(v1), inputs[0], 7));6364/* lshl+add optimization with literal */6566//~gfx8! v1: %res6_tmp0 = v_lshlrev_b32 2, %a67//~gfx8! v1: %res6_tmp1 = v_lshlrev_b32 6, %a68//~gfx8! v1: %res6, s2: %_ = v_add_co_u32 %res6_tmp1, %res6_tmp069//~gfx9! v1: %res6_tmp = v_lshlrev_b32 2, %a70//~gfx9! v1: %res6 = v_lshl_add_u32 %a, 6, %res6_tmp71//~gfx10! v1: %res6 = v_mul_lo_u32 0x44, %a72//! p_unit_test 6, %res673writeout(6, bld.v_mul_imm(bld.def(v1), inputs[0], 4 | 64));7475//~gfx8! s1: %res7_tmp = p_parallelcopy 0x14476//~gfx8! v1: %res7 = v_mul_lo_u32 %res7_tmp, %a77//~gfx9! v1: %res7_tmp0 = v_lshlrev_b32 2, %a78//~gfx9! v1: %res7_tmp1 = v_lshl_add_u32 %a, 6, %res7_tmp079//~gfx9! v1: %res7 = v_lshl_add_u32 %a, 8, %res7_tmp180//~gfx10! v1: %res7 = v_mul_lo_u32 0x144, %a81//! p_unit_test 7, %res782writeout(7, bld.v_mul_imm(bld.def(v1), inputs[0], 4 | 64 | 256));8384//~gfx8! s1: %res8_tmp = p_parallelcopy 0x94485//~gfx8! v1: %res8 = v_mul_lo_u32 %res8_tmp, %a86//~gfx9! v1: %res8_tmp0 = v_lshlrev_b32 2, %a87//~gfx9! v1: %res8_tmp1 = v_lshl_add_u32 %a, 6, %res8_tmp088//~gfx9! v1: %res8_tmp2 = v_lshl_add_u32 %a, 8, %res8_tmp189//~gfx9! v1: %res8 = v_lshl_add_u32 %a, 11, %res8_tmp290//~gfx10! v1: %res8 = v_mul_lo_u32 0x944, %a91//! p_unit_test 8, %res892writeout(8, bld.v_mul_imm(bld.def(v1), inputs[0], 4 | 64 | 256 | 2048));9394/* lshl+add optimization with inline constant */9596//~gfx8! v1: %res9_tmp0 = v_lshlrev_b32 1, %a97//~gfx8! v1: %res9_tmp1 = v_lshlrev_b32 2, %a98//~gfx8! v1: %res9, s2: %_ = v_add_co_u32 %res9_tmp1, %res9_tmp099//~gfx9! v1: %res9_tmp0 = v_lshlrev_b32 1, %a100//~gfx9! v1: %res9 = v_lshl_add_u32 %a, 2, %res9_tmp0101//~gfx10! v1: %res9 = v_mul_lo_u32 6, %a102//! p_unit_test 9, %res9103writeout(9, bld.v_mul_imm(bld.def(v1), inputs[0], 2 | 4));104105//~gfx(8|10)! v1: %res10 = v_mul_lo_u32 14, %a106//~gfx9! v1: %res10_tmp0 = v_lshlrev_b32 1, %a107//~gfx9! v1: %res10_tmp1 = v_lshl_add_u32 %a, 2, %res10_tmp0108//~gfx9! v1: %res10 = v_lshl_add_u32 %a, 3, %res10_tmp1109//! p_unit_test 10, %res10110writeout(10, bld.v_mul_imm(bld.def(v1), inputs[0], 2 | 4 | 8));111112//! v1: %res11 = v_mul_lo_u32 30, %a113//! p_unit_test 11, %res11114writeout(11, bld.v_mul_imm(bld.def(v1), inputs[0], 2 | 4 | 8 | 16));115116finish_opt_test();117}118END_TEST119120121