| 1 |
|
| 2 |
#include "../sfn_instr_alu.h" |
| 3 |
#include "../sfn_instr_export.h" |
| 4 |
#include "../sfn_instr_fetch.h" |
| 5 |
#include "../sfn_instr_lds.h" |
| 6 |
#include "../sfn_instr_mem.h" |
| 7 |
#include "../sfn_instr_tex.h" |
| 8 |
#include "../sfn_instrfactory.h" |
| 9 |
|
| 10 |
#include "gtest/gtest.h" |
| 11 |
#include <sstream> |
| 12 |
|
| 13 |
namespace r600 { |
| 14 |
|
| 15 |
using std::istringstream; |
| 16 |
using std::ostringstream; |
| 17 |
using std::string; |
| 18 |
|
| 19 |
class TestInstrFromString : public ::testing::Test { |
| 20 |
public: |
| 21 |
TestInstrFromString(); |
| 22 |
|
| 23 |
PInst from_string(const std::string& s); |
| 24 |
|
| 25 |
protected: |
| 26 |
void add_dest_from_string(const char *init); |
| 27 |
void add_dest_vec4_from_string(const char *init); |
| 28 |
|
| 29 |
void check(const Instr& eval, const Instr& expect); |
| 30 |
void check(const string& init, const Instr& expect); |
| 31 |
|
| 32 |
void SetUp() override; |
| 33 |
void TearDown() override; |
| 34 |
|
| 35 |
InstrFactory *m_instr_factory{nullptr}; |
| 36 |
}; |
| 37 |
|
| 38 |
TEST_F(TestInstrFromString, test_alu_mov) |
| 39 |
{ |
| 40 |
add_dest_from_string("R1999.x"); |
| 41 |
|
| 42 |
AluInstr expect(op1_mov, |
| 43 |
new Register(2000, 1, pin_none), |
| 44 |
new Register(1999, 0, pin_none), |
| 45 |
{alu_write, alu_last_instr}); |
| 46 |
|
| 47 |
check("ALU MOV R2000.y : R1999.x {WL}", expect); |
| 48 |
} |
| 49 |
|
| 50 |
TEST_F(TestInstrFromString, test_alu_lds_read_ret) |
| 51 |
{ |
| 52 |
add_dest_from_string("R1999.x"); |
| 53 |
|
| 54 |
AluInstr expect(DS_OP_READ_RET, {new Register(1999, 0, pin_none)}, AluInstr::empty); |
| 55 |
|
| 56 |
check("ALU LDS READ_RET __.x : R1999.x {}", expect); |
| 57 |
} |
| 58 |
|
| 59 |
TEST_F(TestInstrFromString, test_alu_mov_literal) |
| 60 |
{ |
| 61 |
AluInstr expect(op1_mov, |
| 62 |
new Register(2000, 1, pin_none), |
| 63 |
new LiteralConstant(0x10), |
| 64 |
{alu_write, alu_last_instr}); |
| 65 |
|
| 66 |
check("ALU MOV R2000.y : L[0x10] {WL}", expect); |
| 67 |
} |
| 68 |
|
| 69 |
TEST_F(TestInstrFromString, test_alu_mov_neg) |
| 70 |
{ |
| 71 |
add_dest_from_string("R1999.x"); |
| 72 |
AluInstr expect(op1_mov, |
| 73 |
new Register(2000, 1, pin_none), |
| 74 |
new Register(1999, 0, pin_none), |
| 75 |
{alu_write, alu_last_instr}); |
| 76 |
expect.set_source_mod(0, AluInstr::mod_neg); |
| 77 |
|
| 78 |
check("ALU MOV R2000.y : -R1999.x {WL}", expect); |
| 79 |
} |
| 80 |
|
| 81 |
TEST_F(TestInstrFromString, test_alu_mov_abs) |
| 82 |
{ |
| 83 |
add_dest_from_string("R1999.x"); |
| 84 |
AluInstr expect(op1_mov, |
| 85 |
new Register(2000, 1, pin_none), |
| 86 |
new Register(1999, 0, pin_none), |
| 87 |
{alu_write, alu_last_instr}); |
| 88 |
expect.set_source_mod(0, AluInstr::mod_abs); |
| 89 |
|
| 90 |
check("ALU MOV R2000.y : |R1999.x| {WL}", expect); |
| 91 |
} |
| 92 |
|
| 93 |
TEST_F(TestInstrFromString, test_alu_mov_neg_abs) |
| 94 |
{ |
| 95 |
add_dest_from_string("R1999.x"); |
| 96 |
AluInstr expect(op1_mov, |
| 97 |
new Register(2000, 1, pin_none), |
| 98 |
new Register(1999, 0, pin_none), |
| 99 |
AluInstr::write); |
| 100 |
expect.set_source_mod(0, AluInstr::mod_abs); |
| 101 |
expect.set_source_mod(0, AluInstr::mod_neg); |
| 102 |
|
| 103 |
check("ALU MOV R2000.y : -|R1999.x| {W}", expect); |
| 104 |
} |
| 105 |
|
| 106 |
TEST_F(TestInstrFromString, test_alu_add) |
| 107 |
{ |
| 108 |
add_dest_from_string("R1998.z"); |
| 109 |
add_dest_from_string("R1999.w"); |
| 110 |
|
| 111 |
AluInstr expect(op2_add, |
| 112 |
1, |
| 113 |
{new Register(1999, 3, pin_none), new Register(1998, 2, pin_none)}, |
| 114 |
{alu_last_instr}); |
| 115 |
check("ALU ADD __.y : R1999.w R1998.z {L}", expect); |
| 116 |
} |
| 117 |
|
| 118 |
TEST_F(TestInstrFromString, test_alu_add_clmap) |
| 119 |
{ |
| 120 |
add_dest_from_string("R1998.z"); |
| 121 |
add_dest_from_string("R1999.w"); |
| 122 |
AluInstr expect(op2_add, |
| 123 |
1, |
| 124 |
{new Register(1999, 3, pin_none), new Register(1998, 2, pin_none)}, |
| 125 |
{alu_last_instr, alu_dst_clamp}); |
| 126 |
check("ALU ADD CLAMP __.y : R1999.w R1998.z {L}", expect); |
| 127 |
} |
| 128 |
|
| 129 |
TEST_F(TestInstrFromString, test_alu_add_neg2) |
| 130 |
{ |
| 131 |
add_dest_from_string("R1998.z"); |
| 132 |
add_dest_from_string("R1999.w"); |
| 133 |
AluInstr expect(op2_add, |
| 134 |
1, |
| 135 |
{new Register(1999, 3, pin_none), new Register(1998, 2, pin_none)}, |
| 136 |
{alu_last_instr}); |
| 137 |
expect.set_source_mod(1, AluInstr::mod_neg); |
| 138 |
|
| 139 |
check("ALU ADD __.y : R1999.w -R1998.z {L}", expect); |
| 140 |
} |
| 141 |
|
| 142 |
TEST_F(TestInstrFromString, test_alu_sete_update_pref) |
| 143 |
{ |
| 144 |
add_dest_from_string("R1998.z"); |
| 145 |
add_dest_from_string("R1999.w"); |
| 146 |
AluInstr expect(op2_sete, |
| 147 |
1, |
| 148 |
{new Register(1999, 3, pin_none), new Register(1998, 2, pin_none)}, |
| 149 |
{alu_last_instr, alu_update_pred}); |
| 150 |
expect.set_source_mod(1, AluInstr::mod_neg); |
| 151 |
check("ALU SETE __.y : R1999.w -R1998.z {LP}", expect); |
| 152 |
} |
| 153 |
|
| 154 |
TEST_F(TestInstrFromString, test_alu_sete_update_pref_empty_dest) |
| 155 |
{ |
| 156 |
add_dest_from_string("R1998.z"); |
| 157 |
add_dest_from_string("R1999.w"); |
| 158 |
AluInstr expect(op2_sete, |
| 159 |
0, |
| 160 |
{new Register(1999, 3, pin_none), new Register(1998, 2, pin_none)}, |
| 161 |
{alu_last_instr, alu_update_pred}); |
| 162 |
check("ALU SETE __.x : R1999.w R1998.z {LP}", expect); |
| 163 |
} |
| 164 |
|
| 165 |
TEST_F(TestInstrFromString, test_alu_setne_update_exec) |
| 166 |
{ |
| 167 |
add_dest_from_string("R1998.z"); |
| 168 |
add_dest_from_string("R1999.w"); |
| 169 |
AluInstr expect(op2_setne, |
| 170 |
1, |
| 171 |
{new Register(1999, 3, pin_none), new Register(1998, 2, pin_none)}, |
| 172 |
{alu_last_instr, alu_update_exec}); |
| 173 |
expect.set_source_mod(1, AluInstr::mod_neg); |
| 174 |
check("ALU SETNE __.y : R1999.w -R1998.z {LE}", expect); |
| 175 |
} |
| 176 |
|
| 177 |
TEST_F(TestInstrFromString, test_alu_add_abs2) |
| 178 |
{ |
| 179 |
add_dest_from_string("R1998.z"); |
| 180 |
add_dest_from_string("R1999.w"); |
| 181 |
AluInstr expect(op2_add, |
| 182 |
new Register(2000, 1, pin_none), |
| 183 |
new Register(1999, 3, pin_none), |
| 184 |
new Register(1998, 2, pin_none), |
| 185 |
{alu_write, alu_last_instr}); |
| 186 |
expect.set_source_mod(1, AluInstr::mod_abs); |
| 187 |
check("ALU ADD R2000.y : R1999.w |R1998.z| {WL}", expect); |
| 188 |
} |
| 189 |
|
| 190 |
TEST_F(TestInstrFromString, test_alu_add_abs2_neg2) |
| 191 |
{ |
| 192 |
add_dest_from_string("R1998.z"); |
| 193 |
add_dest_from_string("R1999.w"); |
| 194 |
AluInstr expect(op2_add, |
| 195 |
new Register(2000, 1, pin_none), |
| 196 |
new Register(1999, 3, pin_none), |
| 197 |
new Register(1998, 2, pin_none), |
| 198 |
{alu_write, alu_last_instr}); |
| 199 |
expect.set_source_mod(1, AluInstr::mod_neg); |
| 200 |
expect.set_source_mod(1, AluInstr::mod_abs); |
| 201 |
|
| 202 |
check("ALU ADD R2000.y : R1999.w -|R1998.z| {WL}", expect); |
| 203 |
} |
| 204 |
|
| 205 |
TEST_F(TestInstrFromString, test_alu_muladd) |
| 206 |
{ |
| 207 |
add_dest_from_string("R1998.z"); |
| 208 |
add_dest_from_string("R1999.w"); |
| 209 |
add_dest_from_string("R2000.y"); |
| 210 |
AluInstr expect(op3_muladd_ieee, |
| 211 |
new Register(2000, 1, pin_none), |
| 212 |
new Register(1999, 3, pin_none), |
| 213 |
new Register(1998, 2, pin_none), |
| 214 |
new Register(2000, 1, pin_none), |
| 215 |
{alu_write, alu_last_instr}); |
| 216 |
check("ALU MULADD_IEEE R2000.y : R1999.w R1998.z R2000.y {WL}", expect); |
| 217 |
} |
| 218 |
|
| 219 |
TEST_F(TestInstrFromString, test_alu_muladd_neg3) |
| 220 |
{ |
| 221 |
add_dest_from_string("R1998.z"); |
| 222 |
add_dest_from_string("R1999.w"); |
| 223 |
add_dest_from_string("R2000.y"); |
| 224 |
AluInstr expect(op3_muladd_ieee, |
| 225 |
new Register(g_registers_unused, 1, pin_chan), |
| 226 |
new Register(1999, 3, pin_none), |
| 227 |
new Register(1998, 2, pin_none), |
| 228 |
new Register(2000, 1, pin_none), |
| 229 |
{alu_last_instr}); |
| 230 |
check("ALU MULADD_IEEE __.y@chan : R1999.w R1998.z -R2000.y {L}", expect); |
| 231 |
} |
| 232 |
|
| 233 |
TEST_F(TestInstrFromString, test_alu_mov_bs) |
| 234 |
{ |
| 235 |
add_dest_from_string("R1999.x"); |
| 236 |
for (auto& [expect_bs, str] : AluInstr::bank_swizzle_map) { |
| 237 |
auto init = std::string("ALU MOV R2000.y : R1999.x {WL} ") + str; |
| 238 |
|
| 239 |
AluInstr expect(op1_mov, |
| 240 |
new Register(2000, 1, pin_none), |
| 241 |
new Register(1999, 0, pin_none), |
| 242 |
{alu_write, alu_last_instr}); |
| 243 |
expect.set_bank_swizzle(expect_bs); |
| 244 |
|
| 245 |
check(init, expect); |
| 246 |
} |
| 247 |
} |
| 248 |
|
| 249 |
TEST_F(TestInstrFromString, test_alu_dot4_ieee) |
| 250 |
{ |
| 251 |
add_dest_from_string("R199.x"); |
| 252 |
add_dest_from_string("R199.y"); |
| 253 |
add_dest_from_string("R199.z"); |
| 254 |
add_dest_from_string("R199.w"); |
| 255 |
add_dest_from_string("R198.x"); |
| 256 |
add_dest_from_string("R198.y"); |
| 257 |
add_dest_from_string("R198.z"); |
| 258 |
add_dest_from_string("R198.w"); |
| 259 |
auto init = std::string("ALU DOT4_IEEE R2000.y : R199.x R198.w + R199.y R198.z + " |
| 260 |
"R199.z R198.y + R199.w R198.x {WL}"); |
| 261 |
|
| 262 |
AluInstr expect(op2_dot4_ieee, |
| 263 |
new Register(2000, 1, pin_none), |
| 264 |
{new Register(199, 0, pin_none), |
| 265 |
new Register(198, 3, pin_none), |
| 266 |
new Register(199, 1, pin_none), |
| 267 |
new Register(198, 2, pin_none), |
| 268 |
new Register(199, 2, pin_none), |
| 269 |
new Register(198, 1, pin_none), |
| 270 |
new Register(199, 3, pin_none), |
| 271 |
new Register(198, 0, pin_none)}, |
| 272 |
{alu_write, alu_last_instr}, |
| 273 |
4); |
| 274 |
|
| 275 |
check(init, expect); |
| 276 |
} |
| 277 |
|
| 278 |
TEST_F(TestInstrFromString, test_alu_dot4_with_mods) |
| 279 |
{ |
| 280 |
add_dest_from_string("R199.x"); |
| 281 |
add_dest_from_string("R199.y"); |
| 282 |
add_dest_from_string("R199.z"); |
| 283 |
add_dest_from_string("R199.w"); |
| 284 |
add_dest_from_string("R198.x"); |
| 285 |
add_dest_from_string("R198.y"); |
| 286 |
add_dest_from_string("R198.z"); |
| 287 |
add_dest_from_string("R198.w"); |
| 288 |
auto init = std::string("ALU DOT4_IEEE R2000.y : -R199.x R198.w + R199.y |R198.z| + " |
| 289 |
"-|R199.z| R198.y + -R199.w R198.x {WL}"); |
| 290 |
|
| 291 |
AluInstr expect(op2_dot4_ieee, |
| 292 |
new Register(2000, 1, pin_none), |
| 293 |
{new Register(199, 0, pin_none), |
| 294 |
new Register(198, 3, pin_none), |
| 295 |
new Register(199, 1, pin_none), |
| 296 |
new Register(198, 2, pin_none), |
| 297 |
new Register(199, 2, pin_none), |
| 298 |
new Register(198, 1, pin_none), |
| 299 |
new Register(199, 3, pin_none), |
| 300 |
new Register(198, 0, pin_none)}, |
| 301 |
{alu_write, alu_last_instr}, |
| 302 |
4); |
| 303 |
|
| 304 |
expect.set_source_mod(0, AluInstr::mod_neg); |
| 305 |
expect.set_source_mod(3, AluInstr::mod_abs); |
| 306 |
expect.set_source_mod(4, AluInstr::mod_neg); |
| 307 |
expect.set_source_mod(4, AluInstr::mod_abs); |
| 308 |
expect.set_source_mod(7, AluInstr::mod_neg); |
| 309 |
|
| 310 |
check(init, expect); |
| 311 |
auto instr = from_string(init); |
| 312 |
|
| 313 |
std::ostringstream print_str; |
| 314 |
print_str << *instr; |
| 315 |
EXPECT_EQ(print_str.str(), init); |
| 316 |
|
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
TEST_F(TestInstrFromString, test_alu_mov_cf) |
| 321 |
{ |
| 322 |
add_dest_from_string("R1999.x"); |
| 323 |
for (auto& [expect_cf, str] : AluInstr::cf_map) { |
| 324 |
auto init = std::string("ALU MOV R2000.y : R1999.x {WL} ") + str; |
| 325 |
|
| 326 |
AluInstr expect(op1_mov, |
| 327 |
new Register(2000, 1, pin_none), |
| 328 |
new Register(1999, 0, pin_none), |
| 329 |
{alu_write, alu_last_instr}); |
| 330 |
expect.set_cf_type(expect_cf); |
| 331 |
|
| 332 |
check(init, expect); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
TEST_F(TestInstrFromString, test_alu_interp_xy) |
| 337 |
{ |
| 338 |
add_dest_from_string("R0.y@fully"); |
| 339 |
auto init = |
| 340 |
std::string("ALU INTERP_ZW R1024.z@chan : R0.y@fully Param0.z {W} VEC_210"); |
| 341 |
|
| 342 |
auto r0y = new Register(0, 1, pin_fully); |
| 343 |
r0y->set_flag(Register::pin_start); |
| 344 |
AluInstr expect(op2_interp_zw, |
| 345 |
new Register(1024, 2, pin_chan), |
| 346 |
r0y, |
| 347 |
new InlineConstant(ALU_SRC_PARAM_BASE, 2), |
| 348 |
AluInstr::write); |
| 349 |
expect.set_bank_swizzle(alu_vec_210); |
| 350 |
|
| 351 |
check(init, expect); |
| 352 |
} |
| 353 |
|
| 354 |
TEST_F(TestInstrFromString, test_alu_add_d2) |
| 355 |
{ |
| 356 |
add_dest_from_string("R0.y@fully"); |
| 357 |
add_dest_from_string("R0.x@fully"); |
| 358 |
auto init = std::string("ALU ADD D2 R1024.z@chan : R0.y@fully R0.x@fully {W}"); |
| 359 |
|
| 360 |
auto r0x = new Register(0, 0, pin_fully); |
| 361 |
auto r0y = new Register(0, 1, pin_fully); |
| 362 |
r0y->set_flag(Register::pin_start); |
| 363 |
r0x->set_flag(Register::pin_start); |
| 364 |
AluInstr expect(op2_add, new Register(1024, 2, pin_chan), r0y, r0x, AluInstr::write); |
| 365 |
expect.set_output_modifier(AluInstr::omod_div2); |
| 366 |
|
| 367 |
check(init, expect); |
| 368 |
} |
| 369 |
|
| 370 |
TEST_F(TestInstrFromString, test_alu_interp_xy_no_write) |
| 371 |
{ |
| 372 |
add_dest_from_string("R0.x@fully"); |
| 373 |
auto init = std::string("ALU INTERP_XY __.x : R0.x@fully Param0.z {} VEC_210"); |
| 374 |
|
| 375 |
auto r0x = new Register(0, 0, pin_fully); |
| 376 |
r0x->set_flag(Register::pin_start); |
| 377 |
|
| 378 |
AluInstr expect(op2_interp_xy, |
| 379 |
0, |
| 380 |
{r0x, new InlineConstant(ALU_SRC_PARAM_BASE, 2)}, |
| 381 |
AluInstr::empty); |
| 382 |
expect.set_bank_swizzle(alu_vec_210); |
| 383 |
|
| 384 |
check(init, expect); |
| 385 |
} |
| 386 |
|
| 387 |
TEST_F(TestInstrFromString, test_alu_mov_cf_bs) |
| 388 |
{ |
| 389 |
add_dest_from_string("R1999.x"); |
| 390 |
auto init = std::string("ALU MOV R2000.y : R1999.x {WL} VEC_210 POP_AFTER"); |
| 391 |
AluInstr expect(op1_mov, |
| 392 |
new Register(2000, 1, pin_none), |
| 393 |
new Register(1999, 0, pin_none), |
| 394 |
{alu_write, alu_last_instr}); |
| 395 |
expect.set_cf_type(cf_alu_pop_after); |
| 396 |
expect.set_bank_swizzle(alu_vec_210); |
| 397 |
check(init, expect); |
| 398 |
} |
| 399 |
|
| 400 |
TEST_F(TestInstrFromString, test_tex_sample_basic) |
| 401 |
{ |
| 402 |
add_dest_vec4_from_string("R2000.xyzw"); |
| 403 |
auto init = std::string("TEX SAMPLE R1000.xyzw : R2000.xyzw RID:10 SID:1 NNNN"); |
| 404 |
TexInstr expect( |
| 405 |
TexInstr::sample, RegisterVec4(1000), {0, 1, 2, 3}, RegisterVec4(2000), 10, nullptr, 1); |
| 406 |
check(init, expect); |
| 407 |
} |
| 408 |
|
| 409 |
TEST_F(TestInstrFromString, test_tex_ld_basic) |
| 410 |
{ |
| 411 |
add_dest_vec4_from_string("R2002.xyzw"); |
| 412 |
auto init = std::string("TEX LD R1001.xyzw : R2002.xyzw RID:27 SID:7 NNNN"); |
| 413 |
TexInstr expect( |
| 414 |
TexInstr::ld, RegisterVec4(1001), {0, 1, 2, 3}, RegisterVec4(2002), 27, nullptr, 7); |
| 415 |
check(init, expect); |
| 416 |
} |
| 417 |
|
| 418 |
TEST_F(TestInstrFromString, test_tex_sample_with_offset) |
| 419 |
{ |
| 420 |
add_dest_vec4_from_string("R2002.xyzw"); |
| 421 |
auto init = |
| 422 |
std::string("TEX SAMPLE R1001.xyzw : R2002.xyzw RID:27 SID:2 OX:1 OY:-2 OZ:5 NNNN"); |
| 423 |
|
| 424 |
TexInstr expect( |
| 425 |
TexInstr::sample, RegisterVec4(1001), {0, 1, 2, 3}, RegisterVec4(2002), 27, nullptr, 2); |
| 426 |
expect.set_offset(0, 1); |
| 427 |
expect.set_offset(1, -2); |
| 428 |
expect.set_offset(2, 5); |
| 429 |
|
| 430 |
check(init, expect); |
| 431 |
} |
| 432 |
|
| 433 |
TEST_F(TestInstrFromString, test_tex_gather4_x) |
| 434 |
{ |
| 435 |
add_dest_vec4_from_string("R2002.xyzw"); |
| 436 |
auto init = |
| 437 |
std::string("TEX GATHER4 R1001.xyzw : R2002.xyzw RID:7 SID:27 MODE:0 NNNN"); |
| 438 |
TexInstr expect( |
| 439 |
TexInstr::gather4, RegisterVec4(1001), {0, 1, 2, 3}, RegisterVec4(2002), 7, nullptr, 27); |
| 440 |
check(init, expect); |
| 441 |
} |
| 442 |
|
| 443 |
TEST_F(TestInstrFromString, test_tex_gather4_y) |
| 444 |
{ |
| 445 |
add_dest_vec4_from_string("R2002.xyzw"); |
| 446 |
auto init = |
| 447 |
std::string("TEX GATHER4 R1001.xyzw : R2002.xyzw RID:7 SID:27 MODE:1 NNNN"); |
| 448 |
TexInstr expect( |
| 449 |
TexInstr::gather4, RegisterVec4(1001), {0, 1, 2, 3}, RegisterVec4(2002), 7, nullptr, 27); |
| 450 |
expect.set_gather_comp(1); |
| 451 |
check(init, expect); |
| 452 |
} |
| 453 |
|
| 454 |
TEST_F(TestInstrFromString, test_tex_sampler_with_offset) |
| 455 |
{ |
| 456 |
add_dest_vec4_from_string("R2002.xyzw"); |
| 457 |
auto init = |
| 458 |
std::string("TEX SAMPLE R1001.xyzw : R2002.xyzw RID:7 SID:27 SO:R200.z NNNN"); |
| 459 |
TexInstr expect(TexInstr::sample, |
| 460 |
RegisterVec4(1001), |
| 461 |
{0, 1, 2, 3}, |
| 462 |
RegisterVec4(2002), |
| 463 |
7, |
| 464 |
nullptr, |
| 465 |
27, |
| 466 |
new Register(200, 2, pin_none)); |
| 467 |
check(init, expect); |
| 468 |
} |
| 469 |
|
| 470 |
TEST_F(TestInstrFromString, test_export_param_60) |
| 471 |
{ |
| 472 |
add_dest_vec4_from_string("R1001.xyzw"); |
| 473 |
|
| 474 |
ExportInstr expect(ExportInstr::param, 60, RegisterVec4(1001)); |
| 475 |
check("EXPORT PARAM 60 R1001.xyzw", expect); |
| 476 |
} |
| 477 |
|
| 478 |
TEST_F(TestInstrFromString, test_export_pos_61) |
| 479 |
{ |
| 480 |
add_dest_from_string("R1002.y@group"); |
| 481 |
|
| 482 |
ExportInstr expect(ExportInstr::pos, 61, RegisterVec4(1002, false, {1, 4, 5, 7})); |
| 483 |
check("EXPORT POS 61 R1002.y01_", expect); |
| 484 |
} |
| 485 |
|
| 486 |
TEST_F(TestInstrFromString, test_export_last_pixel_0) |
| 487 |
{ |
| 488 |
add_dest_vec4_from_string("R1002.xyzw"); |
| 489 |
|
| 490 |
ExportInstr expect(ExportInstr::pixel, 0, RegisterVec4(1002, false, {2, 3, 0, 1})); |
| 491 |
expect.set_is_last_export(true); |
| 492 |
check("EXPORT_DONE PIXEL 0 R1002.zwxy", expect); |
| 493 |
} |
| 494 |
|
| 495 |
TEST_F(TestInstrFromString, test_fetch_basic) |
| 496 |
{ |
| 497 |
add_dest_from_string("R201.z"); |
| 498 |
|
| 499 |
FetchInstr expect(vc_fetch, |
| 500 |
RegisterVec4(1002), |
| 501 |
{0, 4, 5, 1}, |
| 502 |
new Register(201, 2, pin_none), |
| 503 |
0, |
| 504 |
vertex_data, |
| 505 |
fmt_8, |
| 506 |
vtx_nf_norm, |
| 507 |
vtx_es_none, |
| 508 |
1, |
| 509 |
nullptr); |
| 510 |
expect.set_mfc(31); |
| 511 |
expect.set_element_size(3); |
| 512 |
check("VFETCH R1002.x01y : R201.z RID:1 VERTEX FMT(8,UNORM) MFC:31 ES:3", expect); |
| 513 |
} |
| 514 |
|
| 515 |
TEST_F(TestInstrFromString, test_query_buffer_size) |
| 516 |
{ |
| 517 |
QueryBufferSizeInstr expect(RegisterVec4(1002), |
| 518 |
RegisterVec4::Swizzle({0, 1, 2, 3}), |
| 519 |
1); |
| 520 |
check("GET_BUF_RESINFO R1002.xyzw : RID:1", expect); |
| 521 |
|
| 522 |
FetchInstr expect_fetch(vc_get_buf_resinfo, |
| 523 |
RegisterVec4(1002), |
| 524 |
RegisterVec4::Swizzle({0, 1, 2, 3}), |
| 525 |
new Register(0, 7, pin_fully), |
| 526 |
0, |
| 527 |
no_index_offset, |
| 528 |
fmt_32_32_32_32, |
| 529 |
vtx_nf_norm, |
| 530 |
vtx_es_none, |
| 531 |
1, |
| 532 |
nullptr); |
| 533 |
expect_fetch.set_fetch_flag(FetchInstr::format_comp_signed); |
| 534 |
check("GET_BUF_RESINFO R1002.xyzw : RID:1", expect_fetch); |
| 535 |
} |
| 536 |
|
| 537 |
TEST_F(TestInstrFromString, test_load_from_buffer) |
| 538 |
{ |
| 539 |
add_dest_from_string("R201.x"); |
| 540 |
add_dest_from_string("R202.x"); |
| 541 |
string init = "LOAD_BUF R200.xzwy : R201.x + 16b RID:10 + R202.x"; |
| 542 |
LoadFromBuffer expect(RegisterVec4(200), |
| 543 |
RegisterVec4::Swizzle({0, 2, 3, 1}), |
| 544 |
new Register(201, 0, pin_none), |
| 545 |
16, |
| 546 |
10, |
| 547 |
new Register(202, 0, pin_none), |
| 548 |
fmt_32_32_32_32_float); |
| 549 |
check(init, expect); |
| 550 |
|
| 551 |
auto instr = from_string(init); |
| 552 |
FetchInstr expect_fetch(vc_fetch, |
| 553 |
RegisterVec4(200), |
| 554 |
RegisterVec4::Swizzle({0, 2, 3, 1}), |
| 555 |
new Register(201, 0, pin_none), |
| 556 |
16, |
| 557 |
no_index_offset, |
| 558 |
fmt_32_32_32_32_float, |
| 559 |
vtx_nf_scaled, |
| 560 |
vtx_es_none, |
| 561 |
10, |
| 562 |
new Register(202, 0, pin_none)); |
| 563 |
expect_fetch.set_fetch_flag(FetchInstr::format_comp_signed); |
| 564 |
expect_fetch.set_mfc(16); |
| 565 |
check(*instr, expect_fetch); |
| 566 |
} |
| 567 |
|
| 568 |
TEST_F(TestInstrFromString, test_load_from_scratch) |
| 569 |
{ |
| 570 |
|
| 571 |
add_dest_from_string("R201.x"); |
| 572 |
string init = "READ_SCRATCH R200.xzwy : R201.x SIZE:20 ES:3"; |
| 573 |
|
| 574 |
LoadFromScratch expect(RegisterVec4(200), |
| 575 |
RegisterVec4::Swizzle({0, 2, 3, 1}), |
| 576 |
new Register(201, 0, pin_none), |
| 577 |
20); |
| 578 |
check(init, expect); |
| 579 |
|
| 580 |
FetchInstr expect_fetch(vc_read_scratch, |
| 581 |
RegisterVec4(200), |
| 582 |
RegisterVec4::Swizzle({0, 2, 3, 1}), |
| 583 |
new Register(201, 0, pin_none), |
| 584 |
0, |
| 585 |
no_index_offset, |
| 586 |
fmt_32_32_32_32, |
| 587 |
vtx_nf_int, |
| 588 |
vtx_es_none, |
| 589 |
0, |
| 590 |
nullptr); |
| 591 |
expect_fetch.set_element_size(3); |
| 592 |
expect_fetch.set_print_skip(FetchInstr::EPrintSkip::mfc); |
| 593 |
expect_fetch.set_print_skip(FetchInstr::EPrintSkip::fmt); |
| 594 |
expect_fetch.set_print_skip(FetchInstr::EPrintSkip::ftype); |
| 595 |
expect_fetch.set_fetch_flag(FetchInstr::EFlags::uncached); |
| 596 |
expect_fetch.set_fetch_flag(FetchInstr::EFlags::indexed); |
| 597 |
expect_fetch.set_array_size(19); |
| 598 |
|
| 599 |
check(init, expect_fetch); |
| 600 |
} |
| 601 |
|
| 602 |
TEST_F(TestInstrFromString, test_write_scratch_to_offset) |
| 603 |
{ |
| 604 |
add_dest_vec4_from_string("R1.xyzw"); |
| 605 |
string init = "WRITE_SCRATCH 20 R1.xyzw AL:4 ALO:16"; |
| 606 |
ScratchIOInstr expect(RegisterVec4(1), 20, 4, 16, 0xf); |
| 607 |
check(init, expect); |
| 608 |
|
| 609 |
add_dest_vec4_from_string("R2.xyzw"); |
| 610 |
string init2 = "WRITE_SCRATCH 10 R2.xy_w AL:8 ALO:8"; |
| 611 |
ScratchIOInstr expect2(RegisterVec4(2), 10, 8, 8, 0xb); |
| 612 |
check(init2, expect2); |
| 613 |
} |
| 614 |
|
| 615 |
TEST_F(TestInstrFromString, test_write_scratch_to_index) |
| 616 |
{ |
| 617 |
add_dest_vec4_from_string("R1.xyzw"); |
| 618 |
add_dest_from_string("R3.x"); |
| 619 |
string init = "WRITE_SCRATCH @R3.x[10] R1.xyzw AL:4 ALO:16"; |
| 620 |
ScratchIOInstr expect(RegisterVec4(1), new Register(3, 0, pin_none), 4, 16, 0xf, 10); |
| 621 |
check(init, expect); |
| 622 |
|
| 623 |
add_dest_vec4_from_string("R2.xyzw"); |
| 624 |
add_dest_from_string("R4.x"); |
| 625 |
string init2 = "WRITE_SCRATCH @R4.x[20] R2.xy__ AL:4 ALO:16"; |
| 626 |
ScratchIOInstr expect2(RegisterVec4(2), new Register(4, 0, pin_none), 4, 16, 0x3, 20); |
| 627 |
check(init2, expect2); |
| 628 |
} |
| 629 |
|
| 630 |
TEST_F(TestInstrFromString, test_load_from_scratch_fixed_offset) |
| 631 |
{ |
| 632 |
string init = "READ_SCRATCH R200.xzwy : L[0xA] SIZE:40 ES:3"; |
| 633 |
|
| 634 |
LoadFromScratch expect(RegisterVec4(200), |
| 635 |
RegisterVec4::Swizzle({0, 2, 3, 1}), |
| 636 |
new LiteralConstant(10), |
| 637 |
40); |
| 638 |
check(init, expect); |
| 639 |
|
| 640 |
FetchInstr expect_fetch(vc_read_scratch, |
| 641 |
RegisterVec4(200), |
| 642 |
RegisterVec4::Swizzle({0, 2, 3, 1}), |
| 643 |
new Register(0, 7, pin_none), |
| 644 |
0, |
| 645 |
no_index_offset, |
| 646 |
fmt_32_32_32_32, |
| 647 |
vtx_nf_int, |
| 648 |
vtx_es_none, |
| 649 |
0, |
| 650 |
nullptr); |
| 651 |
expect_fetch.set_element_size(3); |
| 652 |
expect_fetch.set_print_skip(FetchInstr::EPrintSkip::mfc); |
| 653 |
expect_fetch.set_print_skip(FetchInstr::EPrintSkip::fmt); |
| 654 |
expect_fetch.set_print_skip(FetchInstr::EPrintSkip::ftype); |
| 655 |
expect_fetch.set_fetch_flag(FetchInstr::EFlags::uncached); |
| 656 |
expect_fetch.set_array_base(10); |
| 657 |
expect_fetch.set_array_size(39); |
| 658 |
|
| 659 |
check(init, expect_fetch); |
| 660 |
} |
| 661 |
|
| 662 |
TEST_F(TestInstrFromString, test_lds_read_3_values) |
| 663 |
{ |
| 664 |
add_dest_from_string("R5.x@free"); |
| 665 |
add_dest_from_string("R5.y@free"); |
| 666 |
add_dest_from_string("R5.z@free"); |
| 667 |
|
| 668 |
auto init = |
| 669 |
"LDS_READ [ R10.x@free R11.x@free R12.x@free ] : [ R5.x@free R5.y@free R5.z@free ]"; |
| 670 |
|
| 671 |
std::vector<PRegister, Allocator<PRegister>> dests(3); |
| 672 |
std::vector<PVirtualValue, Allocator<PVirtualValue>> srcs(3); |
| 673 |
|
| 674 |
for (int i = 0; i < 3; ++i) { |
| 675 |
dests[i] = new Register(10 + i, 0, pin_free); |
| 676 |
srcs[i] = new Register(5, i, pin_free); |
| 677 |
} |
| 678 |
|
| 679 |
LDSReadInstr expect(dests, srcs); |
| 680 |
check(init, expect); |
| 681 |
} |
| 682 |
|
| 683 |
TEST_F(TestInstrFromString, test_lds_read_2_values) |
| 684 |
{ |
| 685 |
add_dest_from_string("R5.x@free"); |
| 686 |
add_dest_from_string("R5.y@free"); |
| 687 |
|
| 688 |
auto init = "LDS_READ [ R11.x@free R12.x@free ] : [ R5.x@free R5.y@free ]"; |
| 689 |
|
| 690 |
std::vector<PRegister, Allocator<PRegister>> dests(2); |
| 691 |
std::vector<PVirtualValue, Allocator<PVirtualValue>> srcs(2); |
| 692 |
|
| 693 |
for (int i = 0; i < 2; ++i) { |
| 694 |
dests[i] = new Register(11 + i, 0, pin_free); |
| 695 |
srcs[i] = new Register(5, i, pin_free); |
| 696 |
} |
| 697 |
|
| 698 |
LDSReadInstr expect(dests, srcs); |
| 699 |
check(init, expect); |
| 700 |
} |
| 701 |
|
| 702 |
TEST_F(TestInstrFromString, test_lds_write_1_value) |
| 703 |
{ |
| 704 |
auto init = "LDS WRITE __.x [ R1.x ] : R2.y"; |
| 705 |
add_dest_from_string("R1.x"); |
| 706 |
add_dest_from_string("R2.y"); |
| 707 |
|
| 708 |
LDSAtomicInstr expect(DS_OP_WRITE, |
| 709 |
nullptr, |
| 710 |
new Register(1, 0, pin_none), |
| 711 |
{new Register(2, 1, pin_none)}); |
| 712 |
|
| 713 |
check(init, expect); |
| 714 |
} |
| 715 |
|
| 716 |
TEST_F(TestInstrFromString, test_lds_write_2_value) |
| 717 |
{ |
| 718 |
auto init = "LDS WRITE2 __.x [ R1.x ] : R2.y KC0[1].z"; |
| 719 |
|
| 720 |
add_dest_from_string("R1.x"); |
| 721 |
add_dest_from_string("R2.y"); |
| 722 |
|
| 723 |
LDSAtomicInstr expect(DS_OP_WRITE2, |
| 724 |
nullptr, |
| 725 |
new Register(1, 0, pin_none), |
| 726 |
{new Register(2, 1, pin_none), new UniformValue(513, 2, 0)}); |
| 727 |
|
| 728 |
check(init, expect); |
| 729 |
} |
| 730 |
|
| 731 |
TEST_F(TestInstrFromString, test_lds_write_atomic_add_ret) |
| 732 |
{ |
| 733 |
auto init = "LDS ADD_RET R7.y [ R1.x ] : R2.y"; |
| 734 |
|
| 735 |
add_dest_from_string("R1.x"); |
| 736 |
add_dest_from_string("R2.y"); |
| 737 |
|
| 738 |
LDSAtomicInstr expect(DS_OP_ADD_RET, |
| 739 |
new Register(7, 1, pin_none), |
| 740 |
new Register(1, 0, pin_none), |
| 741 |
{new Register(2, 1, pin_none)}); |
| 742 |
|
| 743 |
check(init, expect); |
| 744 |
} |
| 745 |
|
| 746 |
TEST_F(TestInstrFromString, test_lds_write_atomic_add) |
| 747 |
{ |
| 748 |
auto init = "LDS ADD __.x [ R1.x ] : R2.y"; |
| 749 |
|
| 750 |
add_dest_from_string("R1.x"); |
| 751 |
add_dest_from_string("R2.y"); |
| 752 |
|
| 753 |
LDSAtomicInstr expect(DS_OP_ADD, |
| 754 |
nullptr, |
| 755 |
new Register(1, 0, pin_none), |
| 756 |
{new Register(2, 1, pin_none)}); |
| 757 |
|
| 758 |
check(init, expect); |
| 759 |
} |
| 760 |
|
| 761 |
TEST_F(TestInstrFromString, test_writeTF) |
| 762 |
{ |
| 763 |
auto init = "WRITE_TF R1.xyzw"; |
| 764 |
|
| 765 |
add_dest_vec4_from_string("R1.xyzw"); |
| 766 |
|
| 767 |
WriteTFInstr expect(RegisterVec4(1, false, {0, 1, 2, 3}, pin_group)); |
| 768 |
|
| 769 |
check(init, expect); |
| 770 |
} |
| 771 |
|
| 772 |
TestInstrFromString::TestInstrFromString() {} |
| 773 |
|
| 774 |
PInst |
| 775 |
TestInstrFromString::from_string(const std::string& s) |
| 776 |
{ |
| 777 |
return m_instr_factory->from_string(s, 0, false); |
| 778 |
} |
| 779 |
|
| 780 |
void |
| 781 |
TestInstrFromString::check(const Instr& eval, const Instr& expect) |
| 782 |
{ |
| 783 |
EXPECT_EQ(eval, expect); |
| 784 |
} |
| 785 |
|
| 786 |
void |
| 787 |
TestInstrFromString::check(const string& init, const Instr& expect) |
| 788 |
{ |
| 789 |
auto instr = from_string(init); |
| 790 |
ASSERT_TRUE(instr); |
| 791 |
EXPECT_EQ(*instr, expect); |
| 792 |
} |
| 793 |
|
| 794 |
void |
| 795 |
TestInstrFromString::add_dest_from_string(const char *init) |
| 796 |
{ |
| 797 |
m_instr_factory->value_factory().dest_from_string(init); |
| 798 |
} |
| 799 |
|
| 800 |
void |
| 801 |
TestInstrFromString::add_dest_vec4_from_string(const char *init) |
| 802 |
{ |
| 803 |
RegisterVec4::Swizzle dummy; |
| 804 |
m_instr_factory->value_factory().dest_vec4_from_string(init, dummy); |
| 805 |
} |
| 806 |
|
| 807 |
void |
| 808 |
TestInstrFromString::SetUp() |
| 809 |
{ |
| 810 |
MemoryPool::instance().initialize(); |
| 811 |
m_instr_factory = new InstrFactory; |
| 812 |
} |
| 813 |
|
| 814 |
void |
| 815 |
TestInstrFromString::TearDown() |
| 816 |
{ |
| 817 |
MemoryPool::instance().free(); |
| 818 |
} |
| 819 |
|
| 820 |
} // namespace r600 |