1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2020 Valve Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci *
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci#include "helpers.h"
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ciusing namespace aco;
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ciBEGIN_TEST(builder.v_mul_imm)
29bf215546Sopenharmony_ci   for (unsigned i = GFX8; i <= GFX10; i++) {
30bf215546Sopenharmony_ci      //>> v1: %a, v1: %b, s1: %c, s1: %d = p_startpgm
31bf215546Sopenharmony_ci      if (!setup_cs("v1 v1 s1 s1", (amd_gfx_level)i))
32bf215546Sopenharmony_ci         continue;
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci      /* simple optimizations */
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci      //! p_unit_test 0, 0
37bf215546Sopenharmony_ci      writeout(0, bld.v_mul_imm(bld.def(v1), inputs[0], 0));
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci      //! p_unit_test 1, %a
40bf215546Sopenharmony_ci      writeout(1, bld.v_mul_imm(bld.def(v1), inputs[0], 1));
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci      //! v1: %res2 = v_lshlrev_b32 2, %a
43bf215546Sopenharmony_ci      //! p_unit_test 2, %res2
44bf215546Sopenharmony_ci      writeout(2, bld.v_mul_imm(bld.def(v1), inputs[0], 4));
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci      //! v1: %res3 = v_lshlrev_b32 31, %a
47bf215546Sopenharmony_ci      //! p_unit_test 3, %res3
48bf215546Sopenharmony_ci      writeout(3, bld.v_mul_imm(bld.def(v1), inputs[0], 2147483648u));
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci      /* single lshl+add/sub */
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ci      //~gfx8! v1: %res4_tmp = v_lshlrev_b32 3, %a
53bf215546Sopenharmony_ci      //~gfx8! v1: %res4,  s2: %_ = v_add_co_u32 %res4_tmp, %a
54bf215546Sopenharmony_ci      //~gfx(9|10)! v1: %res4 = v_lshl_add_u32 %a, 3, %a
55bf215546Sopenharmony_ci      //! p_unit_test 4, %res4
56bf215546Sopenharmony_ci      writeout(4, bld.v_mul_imm(bld.def(v1), inputs[0], 9));
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci      //~gfx[89]! v1: %res5_tmp = v_lshlrev_b32 3, %a
59bf215546Sopenharmony_ci      //~gfx8! v1: %res5,  s2: %_ = v_sub_co_u32 %res5_tmp, %a
60bf215546Sopenharmony_ci      //~gfx9! v1: %res5 = v_sub_u32 %res5_tmp, %a
61bf215546Sopenharmony_ci      //~gfx10! v1: %res5 = v_mul_lo_u32 7, %a
62bf215546Sopenharmony_ci      //! p_unit_test 5, %res5
63bf215546Sopenharmony_ci      writeout(5, bld.v_mul_imm(bld.def(v1), inputs[0], 7));
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_ci      /* lshl+add optimization with literal */
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci      //~gfx8! v1: %res6_tmp0 = v_lshlrev_b32 2, %a
68bf215546Sopenharmony_ci      //~gfx8! v1: %res6_tmp1 = v_lshlrev_b32 6, %a
69bf215546Sopenharmony_ci      //~gfx8! v1: %res6,  s2: %_ = v_add_co_u32 %res6_tmp1, %res6_tmp0
70bf215546Sopenharmony_ci      //~gfx9! v1: %res6_tmp = v_lshlrev_b32 2, %a
71bf215546Sopenharmony_ci      //~gfx9! v1: %res6 = v_lshl_add_u32 %a, 6, %res6_tmp
72bf215546Sopenharmony_ci      //~gfx10! v1: %res6 = v_mul_lo_u32 0x44, %a
73bf215546Sopenharmony_ci      //! p_unit_test 6, %res6
74bf215546Sopenharmony_ci      writeout(6, bld.v_mul_imm(bld.def(v1), inputs[0], 4 | 64));
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ci      //~gfx8! s1: %res7_tmp = p_parallelcopy 0x144
77bf215546Sopenharmony_ci      //~gfx8! v1: %res7 = v_mul_lo_u32 %res7_tmp, %a
78bf215546Sopenharmony_ci      //~gfx9! v1: %res7_tmp0 = v_lshlrev_b32 2, %a
79bf215546Sopenharmony_ci      //~gfx9! v1: %res7_tmp1 = v_lshl_add_u32 %a, 6, %res7_tmp0
80bf215546Sopenharmony_ci      //~gfx9! v1: %res7 = v_lshl_add_u32 %a, 8, %res7_tmp1
81bf215546Sopenharmony_ci      //~gfx10! v1: %res7 = v_mul_lo_u32 0x144, %a
82bf215546Sopenharmony_ci      //! p_unit_test 7, %res7
83bf215546Sopenharmony_ci      writeout(7, bld.v_mul_imm(bld.def(v1), inputs[0], 4 | 64 | 256));
84bf215546Sopenharmony_ci
85bf215546Sopenharmony_ci      //~gfx8! s1: %res8_tmp = p_parallelcopy 0x944
86bf215546Sopenharmony_ci      //~gfx8! v1: %res8 = v_mul_lo_u32 %res8_tmp, %a
87bf215546Sopenharmony_ci      //~gfx9! v1: %res8_tmp0 = v_lshlrev_b32 2, %a
88bf215546Sopenharmony_ci      //~gfx9! v1: %res8_tmp1 = v_lshl_add_u32 %a, 6, %res8_tmp0
89bf215546Sopenharmony_ci      //~gfx9! v1: %res8_tmp2 = v_lshl_add_u32 %a, 8, %res8_tmp1
90bf215546Sopenharmony_ci      //~gfx9! v1: %res8 = v_lshl_add_u32 %a, 11, %res8_tmp2
91bf215546Sopenharmony_ci      //~gfx10! v1: %res8 = v_mul_lo_u32 0x944, %a
92bf215546Sopenharmony_ci      //! p_unit_test 8, %res8
93bf215546Sopenharmony_ci      writeout(8, bld.v_mul_imm(bld.def(v1), inputs[0], 4 | 64 | 256 | 2048));
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci      /* lshl+add optimization with inline constant */
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci      //~gfx8! v1: %res9_tmp0 = v_lshlrev_b32 1, %a
98bf215546Sopenharmony_ci      //~gfx8! v1: %res9_tmp1 = v_lshlrev_b32 2, %a
99bf215546Sopenharmony_ci      //~gfx8! v1: %res9,  s2: %_ = v_add_co_u32 %res9_tmp1, %res9_tmp0
100bf215546Sopenharmony_ci      //~gfx9! v1: %res9_tmp0 = v_lshlrev_b32 1, %a
101bf215546Sopenharmony_ci      //~gfx9! v1: %res9 = v_lshl_add_u32 %a, 2, %res9_tmp0
102bf215546Sopenharmony_ci      //~gfx10! v1: %res9 = v_mul_lo_u32 6, %a
103bf215546Sopenharmony_ci      //! p_unit_test 9, %res9
104bf215546Sopenharmony_ci      writeout(9, bld.v_mul_imm(bld.def(v1), inputs[0], 2 | 4));
105bf215546Sopenharmony_ci
106bf215546Sopenharmony_ci      //~gfx(8|10)! v1: %res10 = v_mul_lo_u32 14, %a
107bf215546Sopenharmony_ci      //~gfx9! v1: %res10_tmp0 = v_lshlrev_b32 1, %a
108bf215546Sopenharmony_ci      //~gfx9! v1: %res10_tmp1 = v_lshl_add_u32 %a, 2, %res10_tmp0
109bf215546Sopenharmony_ci      //~gfx9! v1: %res10 = v_lshl_add_u32 %a, 3, %res10_tmp1
110bf215546Sopenharmony_ci      //! p_unit_test 10, %res10
111bf215546Sopenharmony_ci      writeout(10, bld.v_mul_imm(bld.def(v1), inputs[0], 2 | 4 | 8));
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ci      //! v1: %res11 = v_mul_lo_u32 30, %a
114bf215546Sopenharmony_ci      //! p_unit_test 11, %res11
115bf215546Sopenharmony_ci      writeout(11, bld.v_mul_imm(bld.def(v1), inputs[0], 2 | 4 | 8 | 16));
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci      finish_opt_test();
118bf215546Sopenharmony_ci   }
119bf215546Sopenharmony_ciEND_TEST
120