Path: blob/21.2-virgl/src/amd/compiler/tests/test_assembler.cpp
7097 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(assembler.s_memtime)28for (unsigned i = GFX6; i <= GFX10; i++) {29if (!setup_cs(NULL, (chip_class)i))30continue;3132//~gfx[6-7]>> c780000033//~gfx[6-7]! bf81000034//~gfx[8-9]>> s_memtime s[0:1] ; c0900000 0000000035//~gfx10>> s_memtime s[0:1] ; f4900000 fa00000036bld.smem(aco_opcode::s_memtime, bld.def(s2)).def(0).setFixed(PhysReg{0});3738finish_assembler_test();39}40END_TEST4142BEGIN_TEST(assembler.branch_3f)43if (!setup_cs(NULL, (chip_class)GFX10))44return;4546//! BB0:47//! s_branch BB1 ; bf82004048//! s_nop 0 ; bf80000049bld.sopp(aco_opcode::s_branch, Definition(PhysReg(0), s2), 1);5051for (unsigned i = 0; i < 0x3f; i++)52bld.vop1(aco_opcode::v_nop);5354bld.reset(program->create_and_insert_block());5556program->blocks[1].linear_preds.push_back(0u);5758finish_assembler_test();59END_TEST6061BEGIN_TEST(assembler.long_jump.unconditional_forwards)62if (!setup_cs(NULL, (chip_class)GFX10))63return;6465//!BB0:66//! s_getpc_b64 s[0:1] ; be801f0067//! s_addc_u32 s0, s0, 0x20018 ; 8200ff00 0002001868//! s_addc_u32 s1, s1, 0 ; 8201800169//! s_bitcmp1_b32 s0, 0 ; bf0d800070//! s_bitset0_b32 s0, 0 ; be801b8071//! s_setpc_b64 s[0:1] ; be80200072bld.sopp(aco_opcode::s_branch, Definition(PhysReg(0), s2), 2);7374bld.reset(program->create_and_insert_block());7576//! s_nop 0 ; bf80000077//!(then repeated 32767 times)78for (unsigned i = 0; i < INT16_MAX + 1; i++)79bld.sopp(aco_opcode::s_nop, -1, 0);8081//! BB2:82//! s_endpgm ; bf81000083bld.reset(program->create_and_insert_block());8485program->blocks[2].linear_preds.push_back(0u);86program->blocks[2].linear_preds.push_back(1u);8788finish_assembler_test();89END_TEST9091BEGIN_TEST(assembler.long_jump.conditional_forwards)92if (!setup_cs(NULL, (chip_class)GFX10))93return;9495//! BB0:96//! s_cbranch_scc1 BB1 ; bf85000797//! s_getpc_b64 s[0:1] ; be801f0098//! s_addc_u32 s0, s0, 0x20018 ; 8200ff00 0002001899//! s_addc_u32 s1, s1, 0 ; 82018001100//! s_bitcmp1_b32 s0, 0 ; bf0d8000101//! s_bitset0_b32 s0, 0 ; be801b80102//! s_setpc_b64 s[0:1] ; be802000103bld.sopp(aco_opcode::s_cbranch_scc0, Definition(PhysReg(0), s2), 2);104105bld.reset(program->create_and_insert_block());106107//! BB1:108//! s_nop 0 ; bf800000109//!(then repeated 32767 times)110for (unsigned i = 0; i < INT16_MAX + 1; i++)111bld.sopp(aco_opcode::s_nop, -1, 0);112113//! BB2:114//! s_endpgm ; bf810000115bld.reset(program->create_and_insert_block());116117program->blocks[1].linear_preds.push_back(0u);118program->blocks[2].linear_preds.push_back(0u);119program->blocks[2].linear_preds.push_back(1u);120121finish_assembler_test();122END_TEST123124BEGIN_TEST(assembler.long_jump.unconditional_backwards)125if (!setup_cs(NULL, (chip_class)GFX10))126return;127128//!BB0:129//! s_nop 0 ; bf800000130//!(then repeated 32767 times)131for (unsigned i = 0; i < INT16_MAX + 1; i++)132bld.sopp(aco_opcode::s_nop, -1, 0);133134//! s_getpc_b64 s[0:1] ; be801f00135//! s_addc_u32 s0, s0, 0xfffdfffc ; 8200ff00 fffdfffc136//! s_addc_u32 s1, s1, -1 ; 8201c101137//! s_bitcmp1_b32 s0, 0 ; bf0d8000138//! s_bitset0_b32 s0, 0 ; be801b80139//! s_setpc_b64 s[0:1] ; be802000140bld.sopp(aco_opcode::s_branch, Definition(PhysReg(0), s2), 0);141142//! BB1:143//! s_endpgm ; bf810000144bld.reset(program->create_and_insert_block());145146program->blocks[0].linear_preds.push_back(0u);147program->blocks[1].linear_preds.push_back(0u);148149finish_assembler_test();150END_TEST151152BEGIN_TEST(assembler.long_jump.conditional_backwards)153if (!setup_cs(NULL, (chip_class)GFX10))154return;155156//!BB0:157//! s_nop 0 ; bf800000158//!(then repeated 32767 times)159for (unsigned i = 0; i < INT16_MAX + 1; i++)160bld.sopp(aco_opcode::s_nop, -1, 0);161162//! s_cbranch_execz BB1 ; bf880007163//! s_getpc_b64 s[0:1] ; be801f00164//! s_addc_u32 s0, s0, 0xfffdfff8 ; 8200ff00 fffdfff8165//! s_addc_u32 s1, s1, -1 ; 8201c101166//! s_bitcmp1_b32 s0, 0 ; bf0d8000167//! s_bitset0_b32 s0, 0 ; be801b80168//! s_setpc_b64 s[0:1] ; be802000169bld.sopp(aco_opcode::s_cbranch_execnz, Definition(PhysReg(0), s2), 0);170171//! BB1:172//! s_endpgm ; bf810000173bld.reset(program->create_and_insert_block());174175program->blocks[0].linear_preds.push_back(0u);176program->blocks[1].linear_preds.push_back(0u);177178finish_assembler_test();179END_TEST180181BEGIN_TEST(assembler.long_jump.3f)182if (!setup_cs(NULL, (chip_class)GFX10))183return;184185//! BB0:186//! s_branch BB1 ; bf820040187//! s_nop 0 ; bf800000188bld.sopp(aco_opcode::s_branch, Definition(PhysReg(0), s2), 1);189190for (unsigned i = 0; i < 0x3f - 7; i++) // a unconditional long jump is 7 dwords191bld.vop1(aco_opcode::v_nop);192bld.sopp(aco_opcode::s_branch, Definition(PhysReg(0), s2), 2);193194bld.reset(program->create_and_insert_block());195for (unsigned i = 0; i < INT16_MAX + 1; i++)196bld.vop1(aco_opcode::v_nop);197bld.reset(program->create_and_insert_block());198199program->blocks[1].linear_preds.push_back(0u);200program->blocks[2].linear_preds.push_back(0u);201program->blocks[2].linear_preds.push_back(1u);202203finish_assembler_test();204END_TEST205206BEGIN_TEST(assembler.long_jump.constaddr)207if (!setup_cs(NULL, (chip_class)GFX10))208return;209210//>> s_getpc_b64 s[0:1] ; be801f00211bld.sopp(aco_opcode::s_branch, Definition(PhysReg(0), s2), 2);212213bld.reset(program->create_and_insert_block());214215for (unsigned i = 0; i < INT16_MAX + 1; i++)216bld.sopp(aco_opcode::s_nop, -1, 0);217218bld.reset(program->create_and_insert_block());219220//>> s_getpc_b64 s[0:1] ; be801f00221//! s_add_u32 s0, s0, 0xe0 ; 8000ff00 000000e0222bld.sop1(aco_opcode::p_constaddr_getpc, Definition(PhysReg(0), s2), Operand::zero());223bld.sop2(aco_opcode::p_constaddr_addlo, Definition(PhysReg(0), s1), bld.def(s1, scc),224Operand(PhysReg(0), s1), Operand::zero());225226program->blocks[2].linear_preds.push_back(0u);227program->blocks[2].linear_preds.push_back(1u);228229finish_assembler_test();230END_TEST231232BEGIN_TEST(assembler.v_add3)233for (unsigned i = GFX9; i <= GFX10; i++) {234if (!setup_cs(NULL, (chip_class)i))235continue;236237//~gfx9>> v_add3_u32 v0, 0, 0, 0 ; d1ff0000 02010080238//~gfx10>> v_add3_u32 v0, 0, 0, 0 ; d76d0000 02010080239aco_ptr<VOP3_instruction> add3{create_instruction<VOP3_instruction>(aco_opcode::v_add3_u32, Format::VOP3, 3, 1)};240add3->operands[0] = Operand::zero();241add3->operands[1] = Operand::zero();242add3->operands[2] = Operand::zero();243add3->definitions[0] = Definition(PhysReg(0), v1);244bld.insert(std::move(add3));245246finish_assembler_test();247}248END_TEST249250BEGIN_TEST(assembler.v_add3_clamp)251for (unsigned i = GFX9; i <= GFX10; i++) {252if (!setup_cs(NULL, (chip_class)i))253continue;254255//~gfx9>> integer addition + clamp ; d1ff8000 02010080256//~gfx10>> integer addition + clamp ; d76d8000 02010080257aco_ptr<VOP3_instruction> add3{create_instruction<VOP3_instruction>(aco_opcode::v_add3_u32, Format::VOP3, 3, 1)};258add3->operands[0] = Operand::zero();259add3->operands[1] = Operand::zero();260add3->operands[2] = Operand::zero();261add3->definitions[0] = Definition(PhysReg(0), v1);262add3->clamp = 1;263bld.insert(std::move(add3));264265finish_assembler_test();266}267END_TEST268269270