2021-06-09 17:54:53 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2018 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.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2021-06-09 15:40:03 +02:00
|
|
|
|
2020-08-04 16:06:56 +01:00
|
|
|
#include "aco_builder.h"
|
2021-06-09 15:40:03 +02:00
|
|
|
#include "aco_ir.h"
|
2021-06-10 11:33:15 +02:00
|
|
|
|
|
|
|
|
#include "common/sid.h"
|
2021-06-09 15:40:03 +02:00
|
|
|
|
2020-08-04 10:58:11 -07:00
|
|
|
#include "util/memstream.h"
|
2021-06-09 15:40:03 +02:00
|
|
|
|
2023-03-03 11:52:52 -08:00
|
|
|
#include "ac_shader_util.h"
|
2021-06-09 15:40:03 +02:00
|
|
|
#include <algorithm>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <vector>
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
namespace aco {
|
|
|
|
|
|
2021-02-01 12:42:38 +00:00
|
|
|
struct constaddr_info {
|
|
|
|
|
unsigned getpc_end;
|
|
|
|
|
unsigned add_literal;
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
struct asm_context {
|
2021-06-09 10:14:54 +02:00
|
|
|
Program* program;
|
2022-05-12 02:50:17 -04:00
|
|
|
enum amd_gfx_level gfx_level;
|
2019-09-10 18:11:13 +01:00
|
|
|
std::vector<std::pair<int, SOPP_instruction*>> branches;
|
2021-02-01 12:42:38 +00:00
|
|
|
std::map<unsigned, constaddr_info> constaddrs;
|
2023-04-25 20:50:48 +08:00
|
|
|
std::vector<struct aco_symbol>* symbols;
|
2019-09-17 13:22:17 +02:00
|
|
|
const int16_t* opcode;
|
|
|
|
|
// TODO: keep track of branch instructions referring blocks
|
|
|
|
|
// and, when emitting the block, correct the offset in instr
|
2023-04-25 20:50:48 +08:00
|
|
|
asm_context(Program* program_, std::vector<struct aco_symbol>* symbols_)
|
|
|
|
|
: program(program_), gfx_level(program->gfx_level), symbols(symbols_)
|
2021-06-09 10:14:54 +02:00
|
|
|
{
|
2022-05-12 02:50:17 -04:00
|
|
|
if (gfx_level <= GFX7)
|
2019-11-04 18:02:47 +01:00
|
|
|
opcode = &instr_info.opcode_gfx7[0];
|
2022-05-12 02:50:17 -04:00
|
|
|
else if (gfx_level <= GFX9)
|
2019-09-17 13:22:17 +02:00
|
|
|
opcode = &instr_info.opcode_gfx9[0];
|
2022-06-16 18:15:16 +01:00
|
|
|
else if (gfx_level <= GFX10_3)
|
2019-09-26 17:45:13 +02:00
|
|
|
opcode = &instr_info.opcode_gfx10[0];
|
2022-06-16 18:15:16 +01:00
|
|
|
else if (gfx_level >= GFX11)
|
|
|
|
|
opcode = &instr_info.opcode_gfx11[0];
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2019-10-08 14:43:43 +02:00
|
|
|
|
|
|
|
|
int subvector_begin_pos = -1;
|
2019-09-17 13:22:17 +02:00
|
|
|
};
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
unsigned
|
|
|
|
|
get_mimg_nsa_dwords(const Instruction* instr)
|
|
|
|
|
{
|
2021-02-22 11:12:15 +00:00
|
|
|
unsigned addr_dwords = instr->operands.size() - 3;
|
|
|
|
|
for (unsigned i = 1; i < addr_dwords; i++) {
|
2022-12-17 12:32:49 +01:00
|
|
|
if (instr->operands[3 + i].physReg() !=
|
|
|
|
|
instr->operands[3 + (i - 1)].physReg().advance(instr->operands[3 + (i - 1)].bytes()))
|
2021-02-22 11:12:15 +00:00
|
|
|
return DIV_ROUND_UP(addr_dwords - 1, 4);
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-16 19:36:24 +01:00
|
|
|
uint32_t
|
|
|
|
|
reg(asm_context& ctx, PhysReg reg)
|
|
|
|
|
{
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level >= GFX11) {
|
|
|
|
|
if (reg == m0)
|
|
|
|
|
return sgpr_null.reg();
|
|
|
|
|
else if (reg == sgpr_null)
|
|
|
|
|
return m0.reg();
|
|
|
|
|
}
|
2022-06-16 19:36:24 +01:00
|
|
|
return reg.reg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ALWAYS_INLINE uint32_t
|
|
|
|
|
reg(asm_context& ctx, Operand op, unsigned width = 32)
|
|
|
|
|
{
|
|
|
|
|
return reg(ctx, op.physReg()) & BITFIELD_MASK(width);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ALWAYS_INLINE uint32_t
|
|
|
|
|
reg(asm_context& ctx, Definition def, unsigned width = 32)
|
|
|
|
|
{
|
|
|
|
|
return reg(ctx, def.physReg()) & BITFIELD_MASK(width);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-11 19:58:45 +00:00
|
|
|
bool
|
2023-02-03 13:28:32 +01:00
|
|
|
needs_vop3_gfx11(asm_context& ctx, Instruction* instr)
|
2022-11-11 19:58:45 +00:00
|
|
|
{
|
|
|
|
|
if (ctx.gfx_level <= GFX10_3)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
uint8_t mask = get_gfx11_true16_mask(instr->opcode);
|
|
|
|
|
if (!mask)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
u_foreach_bit (i, mask & 0x3) {
|
|
|
|
|
if (instr->operands[i].physReg().reg() >= (256 + 128))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if ((mask & 0x8) && instr->definitions[0].physReg().reg() >= (256 + 128))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
2023-02-03 13:28:32 +01:00
|
|
|
emit_instruction(asm_context& ctx, std::vector<uint32_t>& out, Instruction* instr)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
|
|
|
|
/* lower remaining pseudo-instructions */
|
2021-02-01 12:42:38 +00:00
|
|
|
if (instr->opcode == aco_opcode::p_constaddr_getpc) {
|
|
|
|
|
ctx.constaddrs[instr->operands[0].constantValue()].getpc_end = out.size() + 1;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2021-02-01 12:42:38 +00:00
|
|
|
instr->opcode = aco_opcode::s_getpc_b64;
|
|
|
|
|
instr->operands.pop_back();
|
|
|
|
|
} else if (instr->opcode == aco_opcode::p_constaddr_addlo) {
|
2022-05-11 19:23:00 +01:00
|
|
|
ctx.constaddrs[instr->operands[2].constantValue()].add_literal = out.size() + 1;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2021-02-01 12:42:38 +00:00
|
|
|
instr->opcode = aco_opcode::s_add_u32;
|
2022-05-11 19:23:00 +01:00
|
|
|
instr->operands.pop_back();
|
|
|
|
|
assert(instr->operands[1].isConstant());
|
|
|
|
|
/* in case it's an inline constant, make it a literal */
|
2022-05-02 14:21:21 +01:00
|
|
|
instr->operands[1] = Operand::literal32(instr->operands[1].constantValue());
|
2023-04-25 20:50:48 +08:00
|
|
|
} else if (instr->opcode == aco_opcode::p_load_symbol) {
|
|
|
|
|
assert(instr->operands[0].isConstant());
|
|
|
|
|
assert(ctx.symbols);
|
|
|
|
|
|
|
|
|
|
struct aco_symbol info;
|
|
|
|
|
info.id = (enum aco_symbol_id)instr->operands[0].constantValue();
|
|
|
|
|
info.offset = out.size() + 1;
|
|
|
|
|
ctx.symbols->push_back(info);
|
|
|
|
|
|
|
|
|
|
instr->opcode = aco_opcode::s_mov_b32;
|
|
|
|
|
/* in case it's an inline constant, make it a literal */
|
|
|
|
|
instr->operands[0] = Operand::literal32(0);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2023-02-03 13:28:32 +01:00
|
|
|
/* Promote VOP12C to VOP3 if necessary. */
|
|
|
|
|
if ((instr->isVOP1() || instr->isVOP2() || instr->isVOPC()) && !instr->isVOP3() &&
|
|
|
|
|
needs_vop3_gfx11(ctx, instr)) {
|
|
|
|
|
instr->format = asVOP3(instr->format);
|
|
|
|
|
if (instr->opcode == aco_opcode::v_fmaak_f16) {
|
|
|
|
|
instr->opcode = aco_opcode::v_fma_f16;
|
|
|
|
|
instr->format = (Format)((uint32_t)instr->format & ~(uint32_t)Format::VOP2);
|
|
|
|
|
} else if (instr->opcode == aco_opcode::v_fmamk_f16) {
|
|
|
|
|
std::swap(instr->operands[1], instr->operands[2]);
|
2023-03-21 11:54:33 +01:00
|
|
|
instr->valu().opsel[1].swap(instr->valu().opsel[2]);
|
2023-02-03 13:28:32 +01:00
|
|
|
instr->opcode = aco_opcode::v_fma_f16;
|
|
|
|
|
instr->format = (Format)((uint32_t)instr->format & ~(uint32_t)Format::VOP2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
uint32_t opcode = ctx.opcode[(int)instr->opcode];
|
|
|
|
|
if (opcode == (uint32_t)-1) {
|
2021-06-09 10:14:54 +02:00
|
|
|
char* outmem;
|
2020-08-14 10:42:27 +02:00
|
|
|
size_t outsize;
|
2020-08-04 10:58:11 -07:00
|
|
|
struct u_memstream mem;
|
2020-11-03 14:40:05 +01:00
|
|
|
u_memstream_open(&mem, &outmem, &outsize);
|
2021-06-09 10:14:54 +02:00
|
|
|
FILE* const memf = u_memstream_get(&mem);
|
2020-08-14 10:42:27 +02:00
|
|
|
|
|
|
|
|
fprintf(memf, "Unsupported opcode: ");
|
2022-07-21 15:17:24 +01:00
|
|
|
aco_print_instr(ctx.gfx_level, instr, memf);
|
2020-08-04 10:58:11 -07:00
|
|
|
u_memstream_close(&mem);
|
2020-08-14 10:42:27 +02:00
|
|
|
|
2020-11-03 14:40:05 +01:00
|
|
|
aco_err(ctx.program, outmem);
|
|
|
|
|
free(outmem);
|
2020-08-14 10:42:27 +02:00
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (instr->format) {
|
|
|
|
|
case Format::SOP2: {
|
|
|
|
|
uint32_t encoding = (0b10 << 30);
|
|
|
|
|
encoding |= opcode << 23;
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= !instr->definitions.empty() ? reg(ctx, instr->definitions[0]) << 16 : 0;
|
|
|
|
|
encoding |= instr->operands.size() >= 2 ? reg(ctx, instr->operands[1]) << 8 : 0;
|
|
|
|
|
encoding |= !instr->operands.empty() ? reg(ctx, instr->operands[0]) : 0;
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::SOPK: {
|
2021-01-21 16:13:34 +00:00
|
|
|
SOPK_instruction& sopk = instr->sopk();
|
2019-10-08 14:43:43 +02:00
|
|
|
|
|
|
|
|
if (instr->opcode == aco_opcode::s_subvector_loop_begin) {
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(ctx.gfx_level >= GFX10);
|
2019-10-08 14:43:43 +02:00
|
|
|
assert(ctx.subvector_begin_pos == -1);
|
|
|
|
|
ctx.subvector_begin_pos = out.size();
|
|
|
|
|
} else if (instr->opcode == aco_opcode::s_subvector_loop_end) {
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(ctx.gfx_level >= GFX10);
|
2019-10-08 14:43:43 +02:00
|
|
|
assert(ctx.subvector_begin_pos != -1);
|
|
|
|
|
/* Adjust s_subvector_loop_begin instruction to the address after the end */
|
|
|
|
|
out[ctx.subvector_begin_pos] |= (out.size() - ctx.subvector_begin_pos);
|
|
|
|
|
/* Adjust s_subvector_loop_end instruction to the address after the beginning */
|
2021-01-21 16:13:34 +00:00
|
|
|
sopk.imm = (uint16_t)(ctx.subvector_begin_pos - (int)out.size());
|
2019-10-08 14:43:43 +02:00
|
|
|
ctx.subvector_begin_pos = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
uint32_t encoding = (0b1011 << 28);
|
|
|
|
|
encoding |= opcode << 23;
|
2021-06-09 10:14:54 +02:00
|
|
|
encoding |= !instr->definitions.empty() && !(instr->definitions[0].physReg() == scc)
|
2022-06-16 19:36:24 +01:00
|
|
|
? reg(ctx, instr->definitions[0]) << 16
|
2021-06-09 10:14:54 +02:00
|
|
|
: !instr->operands.empty() && instr->operands[0].physReg() <= 127
|
2022-06-16 19:36:24 +01:00
|
|
|
? reg(ctx, instr->operands[0]) << 16
|
2021-06-09 10:14:54 +02:00
|
|
|
: 0;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= sopk.imm;
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::SOP1: {
|
|
|
|
|
uint32_t encoding = (0b101111101 << 23);
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= !instr->definitions.empty() ? reg(ctx, instr->definitions[0]) << 16 : 0;
|
2019-09-17 13:22:17 +02:00
|
|
|
encoding |= opcode << 8;
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= !instr->operands.empty() ? reg(ctx, instr->operands[0]) : 0;
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::SOPC: {
|
|
|
|
|
uint32_t encoding = (0b101111110 << 23);
|
|
|
|
|
encoding |= opcode << 16;
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= instr->operands.size() == 2 ? reg(ctx, instr->operands[1]) << 8 : 0;
|
|
|
|
|
encoding |= !instr->operands.empty() ? reg(ctx, instr->operands[0]) : 0;
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::SOPP: {
|
2021-01-21 16:13:34 +00:00
|
|
|
SOPP_instruction& sopp = instr->sopp();
|
2019-09-17 13:22:17 +02:00
|
|
|
uint32_t encoding = (0b101111111 << 23);
|
|
|
|
|
encoding |= opcode << 16;
|
2021-06-09 10:14:54 +02:00
|
|
|
encoding |= (uint16_t)sopp.imm;
|
2021-01-21 16:13:34 +00:00
|
|
|
if (sopp.block != -1) {
|
|
|
|
|
sopp.pass_flags = 0;
|
|
|
|
|
ctx.branches.emplace_back(out.size(), &sopp);
|
2020-08-04 16:06:56 +01:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::SMEM: {
|
2021-01-21 16:13:34 +00:00
|
|
|
SMEM_instruction& smem = instr->smem();
|
2019-09-17 13:22:17 +02:00
|
|
|
bool soe = instr->operands.size() >= (!instr->definitions.empty() ? 3 : 4);
|
2019-09-26 17:46:05 +02:00
|
|
|
bool is_load = !instr->definitions.empty();
|
|
|
|
|
uint32_t encoding = 0;
|
|
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level <= GFX7) {
|
2019-11-04 18:02:47 +01:00
|
|
|
encoding = (0b11000 << 27);
|
|
|
|
|
encoding |= opcode << 22;
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= instr->definitions.size() ? reg(ctx, instr->definitions[0]) << 15 : 0;
|
|
|
|
|
encoding |= instr->operands.size() ? (reg(ctx, instr->operands[0]) >> 1) << 9 : 0;
|
2020-01-15 13:08:17 +01:00
|
|
|
if (instr->operands.size() >= 2) {
|
2021-06-08 18:06:46 +02:00
|
|
|
if (!instr->operands[1].isConstant()) {
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[1]);
|
2021-06-08 18:06:46 +02:00
|
|
|
} else if (instr->operands[1].constantValue() >= 1024) {
|
|
|
|
|
encoding |= 255; /* SQ_SRC_LITERAL */
|
2020-01-15 13:08:17 +01:00
|
|
|
} else {
|
|
|
|
|
encoding |= instr->operands[1].constantValue() >> 2;
|
|
|
|
|
encoding |= 1 << 8;
|
|
|
|
|
}
|
2019-11-04 18:02:47 +01:00
|
|
|
}
|
|
|
|
|
out.push_back(encoding);
|
2021-06-08 18:06:46 +02:00
|
|
|
/* SMRD instructions can take a literal on GFX7 */
|
2021-06-09 10:14:54 +02:00
|
|
|
if (instr->operands.size() >= 2 && instr->operands[1].isConstant() &&
|
|
|
|
|
instr->operands[1].constantValue() >= 1024)
|
2019-11-04 18:02:47 +01:00
|
|
|
out.push_back(instr->operands[1].constantValue() >> 2);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level <= GFX9) {
|
2019-09-26 17:46:05 +02:00
|
|
|
encoding = (0b110000 << 26);
|
2021-01-21 16:13:34 +00:00
|
|
|
assert(!smem.dlc); /* Device-level coherent is not supported on GFX9 and lower */
|
|
|
|
|
encoding |= smem.nv ? 1 << 15 : 0;
|
2019-09-26 17:46:05 +02:00
|
|
|
} else {
|
|
|
|
|
encoding = (0b111101 << 26);
|
2021-01-21 16:13:34 +00:00
|
|
|
assert(!smem.nv); /* Non-volatile is not supported on GFX10 */
|
2022-06-17 11:23:00 +01:00
|
|
|
encoding |= smem.dlc ? 1 << (ctx.gfx_level >= GFX11 ? 13 : 14) : 0;
|
2019-09-26 17:46:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
encoding |= opcode << 18;
|
2022-06-17 11:23:00 +01:00
|
|
|
encoding |= smem.glc ? 1 << (ctx.gfx_level >= GFX11 ? 14 : 16) : 0;
|
2019-09-26 17:46:05 +02:00
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level <= GFX9) {
|
2019-09-26 17:46:05 +02:00
|
|
|
if (instr->operands.size() >= 2)
|
|
|
|
|
encoding |= instr->operands[1].isConstant() ? 1 << 17 : 0; /* IMM - immediate enable */
|
|
|
|
|
}
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level == GFX9) {
|
2019-09-26 17:46:05 +02:00
|
|
|
encoding |= soe ? 1 << 14 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_load || instr->operands.size() >= 3) { /* SDATA */
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= (is_load ? reg(ctx, instr->definitions[0]) : reg(ctx, instr->operands[2]))
|
2021-06-09 10:14:54 +02:00
|
|
|
<< 6;
|
2019-09-26 17:46:05 +02:00
|
|
|
}
|
|
|
|
|
if (instr->operands.size() >= 1) { /* SBASE */
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[0]) >> 1;
|
2019-09-26 17:46:05 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
encoding = 0;
|
2019-09-26 17:46:05 +02:00
|
|
|
|
|
|
|
|
int32_t offset = 0;
|
2022-06-16 19:36:24 +01:00
|
|
|
uint32_t soffset =
|
|
|
|
|
ctx.gfx_level >= GFX10
|
|
|
|
|
? reg(ctx, sgpr_null) /* On GFX10 this is disabled by specifying SGPR_NULL */
|
|
|
|
|
: 0; /* On GFX9, it is disabled by the SOE bit (and it's not present on
|
|
|
|
|
GFX8 and below) */
|
2019-09-26 17:46:05 +02:00
|
|
|
if (instr->operands.size() >= 2) {
|
2021-06-09 10:14:54 +02:00
|
|
|
const Operand& op_off1 = instr->operands[1];
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level <= GFX9) {
|
2022-06-16 19:36:24 +01:00
|
|
|
offset = op_off1.isConstant() ? op_off1.constantValue() : reg(ctx, op_off1);
|
2019-09-26 17:46:05 +02:00
|
|
|
} else {
|
2021-06-09 10:14:54 +02:00
|
|
|
/* GFX10 only supports constants in OFFSET, so put the operand in SOFFSET if it's an
|
|
|
|
|
* SGPR */
|
2019-09-26 17:46:05 +02:00
|
|
|
if (op_off1.isConstant()) {
|
|
|
|
|
offset = op_off1.constantValue();
|
|
|
|
|
} else {
|
2022-06-16 19:36:24 +01:00
|
|
|
soffset = reg(ctx, op_off1);
|
2019-09-26 17:46:05 +02:00
|
|
|
assert(!soe); /* There is no place to put the other SGPR offset, if any */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (soe) {
|
2021-06-09 10:14:54 +02:00
|
|
|
const Operand& op_off2 = instr->operands.back();
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(ctx.gfx_level >= GFX9); /* GFX8 and below don't support specifying a constant
|
2021-06-09 10:14:54 +02:00
|
|
|
and an SGPR at the same time */
|
2019-09-26 17:46:05 +02:00
|
|
|
assert(!op_off2.isConstant());
|
2022-06-16 19:36:24 +01:00
|
|
|
soffset = reg(ctx, op_off2);
|
2019-09-26 17:46:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
encoding |= offset;
|
|
|
|
|
encoding |= soffset << 25;
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
case Format::VOP2: {
|
2023-03-21 11:54:33 +01:00
|
|
|
VALU_instruction& valu = instr->valu();
|
2023-02-03 13:28:32 +01:00
|
|
|
uint32_t encoding = 0;
|
|
|
|
|
encoding |= opcode << 25;
|
|
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8) << 17;
|
2023-03-21 11:54:33 +01:00
|
|
|
encoding |= (valu.opsel[3] ? 128 : 0) << 17;
|
2023-02-03 13:28:32 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[1], 8) << 9;
|
2023-03-21 11:54:33 +01:00
|
|
|
encoding |= (valu.opsel[1] ? 128 : 0) << 9;
|
2023-02-03 13:28:32 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[0]);
|
2023-03-21 11:54:33 +01:00
|
|
|
encoding |= valu.opsel[0] ? 128 : 0;
|
2023-02-03 13:28:32 +01:00
|
|
|
out.push_back(encoding);
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::VOP1: {
|
2023-03-21 11:54:33 +01:00
|
|
|
VALU_instruction& valu = instr->valu();
|
2023-02-03 13:28:32 +01:00
|
|
|
uint32_t encoding = (0b0111111 << 25);
|
2023-03-21 11:54:33 +01:00
|
|
|
if (!instr->definitions.empty()) {
|
2023-02-03 13:28:32 +01:00
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8) << 17;
|
2023-03-21 11:54:33 +01:00
|
|
|
encoding |= (valu.opsel[3] ? 128 : 0) << 17;
|
|
|
|
|
}
|
2023-02-03 13:28:32 +01:00
|
|
|
encoding |= opcode << 9;
|
2023-03-21 11:54:33 +01:00
|
|
|
if (!instr->operands.empty()) {
|
2023-02-03 13:28:32 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[0]);
|
2023-03-21 11:54:33 +01:00
|
|
|
encoding |= valu.opsel[0] ? 128 : 0;
|
|
|
|
|
}
|
2023-02-03 13:28:32 +01:00
|
|
|
out.push_back(encoding);
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::VOPC: {
|
2023-03-21 11:54:33 +01:00
|
|
|
VALU_instruction& valu = instr->valu();
|
2023-02-03 13:28:32 +01:00
|
|
|
uint32_t encoding = (0b0111110 << 25);
|
|
|
|
|
encoding |= opcode << 17;
|
|
|
|
|
encoding |= reg(ctx, instr->operands[1], 8) << 9;
|
2023-03-21 11:54:33 +01:00
|
|
|
encoding |= (valu.opsel[1] ? 128 : 0) << 9;
|
2023-02-03 13:28:32 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[0]);
|
2023-03-21 11:54:33 +01:00
|
|
|
encoding |= valu.opsel[0] ? 128 : 0;
|
2023-02-03 13:28:32 +01:00
|
|
|
out.push_back(encoding);
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::VINTRP: {
|
2022-09-14 11:19:30 +01:00
|
|
|
VINTRP_instruction& interp = instr->vintrp();
|
2019-09-26 17:46:43 +02:00
|
|
|
uint32_t encoding = 0;
|
|
|
|
|
|
2020-05-08 16:21:07 +02:00
|
|
|
if (instr->opcode == aco_opcode::v_interp_p1ll_f16 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_interp_p1lv_f16 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_interp_p2_legacy_f16 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_interp_p2_f16) {
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level == GFX8 || ctx.gfx_level == GFX9) {
|
2020-05-08 16:21:07 +02:00
|
|
|
encoding = (0b110100 << 26);
|
2022-05-12 02:50:17 -04:00
|
|
|
} else if (ctx.gfx_level >= GFX10) {
|
2020-05-08 16:21:07 +02:00
|
|
|
encoding = (0b110101 << 26);
|
|
|
|
|
} else {
|
2022-05-12 02:50:17 -04:00
|
|
|
unreachable("Unknown gfx_level.");
|
2020-05-08 16:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
encoding |= opcode << 16;
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8);
|
2020-05-08 16:21:07 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
|
|
|
|
|
encoding = 0;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= interp.attribute;
|
|
|
|
|
encoding |= interp.component << 6;
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[0]) << 9;
|
2020-05-08 16:21:07 +02:00
|
|
|
if (instr->opcode == aco_opcode::v_interp_p2_f16 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_interp_p2_legacy_f16 ||
|
|
|
|
|
instr->opcode == aco_opcode::v_interp_p1lv_f16) {
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[2]) << 18;
|
2020-05-08 16:21:07 +02:00
|
|
|
}
|
|
|
|
|
out.push_back(encoding);
|
2019-09-26 17:46:43 +02:00
|
|
|
} else {
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level == GFX8 || ctx.gfx_level == GFX9) {
|
2020-05-08 16:21:07 +02:00
|
|
|
encoding = (0b110101 << 26); /* Vega ISA doc says 110010 but it's wrong */
|
|
|
|
|
} else {
|
|
|
|
|
encoding = (0b110010 << 26);
|
|
|
|
|
}
|
2019-09-26 17:46:43 +02:00
|
|
|
|
2020-05-08 16:21:07 +02:00
|
|
|
assert(encoding);
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8) << 18;
|
2020-05-08 16:21:07 +02:00
|
|
|
encoding |= opcode << 16;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= interp.attribute << 10;
|
|
|
|
|
encoding |= interp.component << 8;
|
2020-05-08 16:21:07 +02:00
|
|
|
if (instr->opcode == aco_opcode::v_interp_mov_f32)
|
|
|
|
|
encoding |= (0x3 & instr->operands[0].constantValue());
|
|
|
|
|
else
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[0], 8);
|
2020-05-08 16:21:07 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2022-06-17 13:53:08 +01:00
|
|
|
case Format::VINTERP_INREG: {
|
|
|
|
|
VINTERP_inreg_instruction& interp = instr->vinterp_inreg();
|
|
|
|
|
uint32_t encoding = (0b11001101 << 24);
|
|
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8);
|
|
|
|
|
encoding |= (uint32_t)interp.wait_exp << 8;
|
|
|
|
|
encoding |= (uint32_t)interp.opsel << 11;
|
|
|
|
|
encoding |= (uint32_t)interp.clamp << 15;
|
|
|
|
|
encoding |= opcode << 16;
|
|
|
|
|
out.push_back(encoding);
|
|
|
|
|
|
|
|
|
|
encoding = 0;
|
|
|
|
|
for (unsigned i = 0; i < instr->operands.size(); i++)
|
|
|
|
|
encoding |= reg(ctx, instr->operands[i]) << (i * 9);
|
|
|
|
|
for (unsigned i = 0; i < 3; i++)
|
|
|
|
|
encoding |= interp.neg[i] << (29 + i);
|
|
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
case Format::DS: {
|
2021-01-21 16:13:34 +00:00
|
|
|
DS_instruction& ds = instr->ds();
|
2019-09-17 13:22:17 +02:00
|
|
|
uint32_t encoding = (0b110110 << 26);
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level == GFX8 || ctx.gfx_level == GFX9) {
|
2019-09-26 17:47:30 +02:00
|
|
|
encoding |= opcode << 17;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (ds.gds ? 1 : 0) << 16;
|
2019-09-26 17:47:30 +02:00
|
|
|
} else {
|
|
|
|
|
encoding |= opcode << 18;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (ds.gds ? 1 : 0) << 17;
|
2019-09-26 17:47:30 +02:00
|
|
|
}
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= ((0xFF & ds.offset1) << 8);
|
|
|
|
|
encoding |= (0xFFFF & ds.offset0);
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
encoding = 0;
|
2022-06-16 19:36:24 +01:00
|
|
|
if (!instr->definitions.empty())
|
|
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8) << 24;
|
|
|
|
|
if (instr->operands.size() >= 3 && instr->operands[2].physReg() != m0)
|
|
|
|
|
encoding |= reg(ctx, instr->operands[2], 8) << 16;
|
|
|
|
|
if (instr->operands.size() >= 2 && instr->operands[1].physReg() != m0)
|
|
|
|
|
encoding |= reg(ctx, instr->operands[1], 8) << 8;
|
|
|
|
|
encoding |= reg(ctx, instr->operands[0], 8);
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-06-17 13:53:08 +01:00
|
|
|
case Format::LDSDIR: {
|
|
|
|
|
LDSDIR_instruction& dir = instr->ldsdir();
|
|
|
|
|
uint32_t encoding = (0b11001110 << 24);
|
|
|
|
|
encoding |= opcode << 20;
|
|
|
|
|
encoding |= (uint32_t)dir.wait_vdst << 16;
|
|
|
|
|
encoding |= (uint32_t)dir.attr << 10;
|
|
|
|
|
encoding |= (uint32_t)dir.attr_chan << 8;
|
|
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8);
|
|
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
case Format::MUBUF: {
|
2021-01-21 16:13:34 +00:00
|
|
|
MUBUF_instruction& mubuf = instr->mubuf();
|
2019-09-17 13:22:17 +02:00
|
|
|
uint32_t encoding = (0b111000 << 26);
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level >= GFX11 && mubuf.lds) /* GFX11 has separate opcodes for LDS loads */
|
|
|
|
|
opcode = opcode == 0 ? 0x32 : (opcode + 0x1d);
|
|
|
|
|
else
|
|
|
|
|
encoding |= (mubuf.lds ? 1 : 0) << 16;
|
2019-09-17 13:22:17 +02:00
|
|
|
encoding |= opcode << 18;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (mubuf.glc ? 1 : 0) << 14;
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level <= GFX10_3)
|
|
|
|
|
encoding |= (mubuf.idxen ? 1 : 0) << 13;
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(!mubuf.addr64 || ctx.gfx_level <= GFX7);
|
|
|
|
|
if (ctx.gfx_level == GFX6 || ctx.gfx_level == GFX7)
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (mubuf.addr64 ? 1 : 0) << 15;
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level <= GFX10_3)
|
|
|
|
|
encoding |= (mubuf.offen ? 1 : 0) << 12;
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level == GFX8 || ctx.gfx_level == GFX9) {
|
2021-01-21 16:13:34 +00:00
|
|
|
assert(!mubuf.dlc); /* Device-level coherent is not supported on GFX9 and lower */
|
|
|
|
|
encoding |= (mubuf.slc ? 1 : 0) << 17;
|
2022-06-17 11:23:00 +01:00
|
|
|
} else if (ctx.gfx_level >= GFX11) {
|
|
|
|
|
encoding |= (mubuf.slc ? 1 : 0) << 12;
|
|
|
|
|
encoding |= (mubuf.dlc ? 1 : 0) << 13;
|
2022-05-12 02:50:17 -04:00
|
|
|
} else if (ctx.gfx_level >= GFX10) {
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (mubuf.dlc ? 1 : 0) << 15;
|
2019-09-26 17:47:51 +02:00
|
|
|
}
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= 0x0FFF & mubuf.offset;
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
encoding = 0;
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level <= GFX7 || (ctx.gfx_level >= GFX10 && ctx.gfx_level <= GFX10_3)) {
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (mubuf.slc ? 1 : 0) << 22;
|
2019-09-26 17:47:51 +02:00
|
|
|
}
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[2]) << 24;
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level >= GFX11) {
|
|
|
|
|
encoding |= (mubuf.tfe ? 1 : 0) << 21;
|
|
|
|
|
encoding |= (mubuf.offen ? 1 : 0) << 22;
|
|
|
|
|
encoding |= (mubuf.idxen ? 1 : 0) << 23;
|
|
|
|
|
} else {
|
|
|
|
|
encoding |= (mubuf.tfe ? 1 : 0) << 23;
|
|
|
|
|
}
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= (reg(ctx, instr->operands[0]) >> 2) << 16;
|
2022-06-17 16:25:42 +01:00
|
|
|
if (instr->operands.size() > 3 && !mubuf.lds)
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[3], 8) << 8;
|
2022-06-17 16:25:42 +01:00
|
|
|
else if (!mubuf.lds)
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8) << 8;
|
|
|
|
|
encoding |= reg(ctx, instr->operands[1], 8);
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::MTBUF: {
|
2021-01-21 16:13:34 +00:00
|
|
|
MTBUF_instruction& mtbuf = instr->mtbuf();
|
2019-09-26 17:48:08 +02:00
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
uint32_t img_format = ac_get_tbuffer_format(ctx.gfx_level, mtbuf.dfmt, mtbuf.nfmt);
|
2019-09-17 13:22:17 +02:00
|
|
|
uint32_t encoding = (0b111010 << 26);
|
2019-11-06 13:29:26 +01:00
|
|
|
assert(img_format <= 0x7F);
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(!mtbuf.dlc || ctx.gfx_level >= GFX10);
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level >= GFX11) {
|
|
|
|
|
encoding |= (mtbuf.slc ? 1 : 0) << 12;
|
|
|
|
|
encoding |= (mtbuf.dlc ? 1 : 0) << 13;
|
|
|
|
|
} else {
|
|
|
|
|
/* DLC bit replaces one bit of the OPCODE on GFX10 */
|
|
|
|
|
encoding |= (mtbuf.dlc ? 1 : 0) << 15;
|
|
|
|
|
}
|
|
|
|
|
if (ctx.gfx_level <= GFX10_3) {
|
|
|
|
|
encoding |= (mtbuf.idxen ? 1 : 0) << 13;
|
|
|
|
|
encoding |= (mtbuf.offen ? 1 : 0) << 12;
|
|
|
|
|
}
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (mtbuf.glc ? 1 : 0) << 14;
|
|
|
|
|
encoding |= 0x0FFF & mtbuf.offset;
|
2019-09-26 17:48:08 +02:00
|
|
|
encoding |= (img_format << 19); /* Handles both the GFX10 FORMAT and the old NFMT+DFMT */
|
|
|
|
|
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level == GFX8 || ctx.gfx_level == GFX9 || ctx.gfx_level >= GFX11) {
|
2019-09-26 17:48:08 +02:00
|
|
|
encoding |= opcode << 15;
|
|
|
|
|
} else {
|
|
|
|
|
encoding |= (opcode & 0x07) << 16; /* 3 LSBs of 4-bit OPCODE */
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
encoding = 0;
|
2019-09-26 17:48:08 +02:00
|
|
|
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[2]) << 24;
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level >= GFX11) {
|
|
|
|
|
encoding |= (mtbuf.tfe ? 1 : 0) << 21;
|
|
|
|
|
encoding |= (mtbuf.offen ? 1 : 0) << 22;
|
|
|
|
|
encoding |= (mtbuf.idxen ? 1 : 0) << 23;
|
|
|
|
|
} else {
|
|
|
|
|
encoding |= (mtbuf.tfe ? 1 : 0) << 23;
|
|
|
|
|
encoding |= (mtbuf.slc ? 1 : 0) << 22;
|
|
|
|
|
}
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= (reg(ctx, instr->operands[0]) >> 2) << 16;
|
|
|
|
|
if (instr->operands.size() > 3)
|
|
|
|
|
encoding |= reg(ctx, instr->operands[3], 8) << 8;
|
|
|
|
|
else
|
|
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8) << 8;
|
|
|
|
|
encoding |= reg(ctx, instr->operands[1], 8);
|
2019-09-26 17:48:08 +02:00
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level >= GFX10) {
|
2020-05-08 18:02:12 +02:00
|
|
|
encoding |= (((opcode & 0x08) >> 3) << 21); /* MSB of 4-bit OPCODE */
|
2019-09-26 17:48:08 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::MIMG: {
|
2021-02-22 11:12:15 +00:00
|
|
|
unsigned nsa_dwords = get_mimg_nsa_dwords(instr);
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(!nsa_dwords || ctx.gfx_level >= GFX10);
|
2021-01-14 19:58:13 +00:00
|
|
|
|
2021-01-21 16:13:34 +00:00
|
|
|
MIMG_instruction& mimg = instr->mimg();
|
2019-09-17 13:22:17 +02:00
|
|
|
uint32_t encoding = (0b111100 << 26);
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level >= GFX11) { /* GFX11: rearranges most fields */
|
|
|
|
|
assert(nsa_dwords <= 1);
|
|
|
|
|
encoding |= nsa_dwords;
|
|
|
|
|
encoding |= mimg.dim << 2;
|
|
|
|
|
encoding |= mimg.unrm ? 1 << 7 : 0;
|
|
|
|
|
encoding |= (0xF & mimg.dmask) << 8;
|
|
|
|
|
encoding |= mimg.slc ? 1 << 12 : 0;
|
|
|
|
|
encoding |= mimg.dlc ? 1 << 13 : 0;
|
|
|
|
|
encoding |= mimg.glc ? 1 << 14 : 0;
|
|
|
|
|
encoding |= mimg.r128 ? 1 << 15 : 0;
|
|
|
|
|
encoding |= mimg.a16 ? 1 << 16 : 0;
|
|
|
|
|
encoding |= mimg.d16 ? 1 << 17 : 0;
|
|
|
|
|
encoding |= (opcode & 0xFF) << 18;
|
2019-09-26 17:48:55 +02:00
|
|
|
} else {
|
2022-06-17 11:23:00 +01:00
|
|
|
encoding |= mimg.slc ? 1 << 25 : 0;
|
|
|
|
|
encoding |= (opcode & 0x7f) << 18;
|
|
|
|
|
encoding |= (opcode >> 7) & 1;
|
|
|
|
|
encoding |= mimg.lwe ? 1 << 17 : 0;
|
|
|
|
|
encoding |= mimg.tfe ? 1 << 16 : 0;
|
|
|
|
|
encoding |= mimg.glc ? 1 << 13 : 0;
|
|
|
|
|
encoding |= mimg.unrm ? 1 << 12 : 0;
|
|
|
|
|
if (ctx.gfx_level <= GFX9) {
|
|
|
|
|
assert(!mimg.dlc); /* Device-level coherent is not supported on GFX9 and lower */
|
|
|
|
|
assert(!mimg.r128);
|
|
|
|
|
encoding |= mimg.a16 ? 1 << 15 : 0;
|
|
|
|
|
encoding |= mimg.da ? 1 << 14 : 0;
|
|
|
|
|
} else {
|
|
|
|
|
encoding |= mimg.r128
|
|
|
|
|
? 1 << 15
|
|
|
|
|
: 0; /* GFX10: A16 moved to 2nd word, R128 replaces it in 1st word */
|
|
|
|
|
encoding |= nsa_dwords << 1;
|
|
|
|
|
encoding |= mimg.dim << 3; /* GFX10: dimensionality instead of declare array */
|
|
|
|
|
encoding |= mimg.dlc ? 1 << 7 : 0;
|
|
|
|
|
}
|
|
|
|
|
encoding |= (0xF & mimg.dmask) << 8;
|
2019-09-26 17:48:55 +02:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
2022-06-17 11:23:00 +01:00
|
|
|
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding = reg(ctx, instr->operands[3], 8); /* VADDR */
|
2019-09-17 13:22:17 +02:00
|
|
|
if (!instr->definitions.empty()) {
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8) << 8; /* VDATA */
|
2021-01-14 17:46:50 +00:00
|
|
|
} else if (!instr->operands[2].isUndefined()) {
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[2], 8) << 8; /* VDATA */
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= (0x1F & (reg(ctx, instr->operands[0]) >> 2)) << 16; /* T# (resource) */
|
2019-09-26 17:48:55 +02:00
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(!mimg.d16 || ctx.gfx_level >= GFX9);
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level >= GFX11) {
|
|
|
|
|
if (!instr->operands[1].isUndefined())
|
|
|
|
|
encoding |= (0x1F & (reg(ctx, instr->operands[1]) >> 2)) << 26; /* sampler */
|
|
|
|
|
|
|
|
|
|
encoding |= mimg.tfe ? 1 << 21 : 0;
|
|
|
|
|
encoding |= mimg.lwe ? 1 << 22 : 0;
|
|
|
|
|
} else {
|
|
|
|
|
if (!instr->operands[1].isUndefined())
|
|
|
|
|
encoding |= (0x1F & (reg(ctx, instr->operands[1]) >> 2)) << 21; /* sampler */
|
|
|
|
|
|
|
|
|
|
encoding |= mimg.d16 ? 1 << 31 : 0;
|
|
|
|
|
if (ctx.gfx_level >= GFX10) {
|
|
|
|
|
/* GFX10: A16 still exists, but is in a different place */
|
|
|
|
|
encoding |= mimg.a16 ? 1 << 30 : 0;
|
|
|
|
|
}
|
2019-09-26 17:48:55 +02:00
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
2021-01-14 19:58:13 +00:00
|
|
|
|
|
|
|
|
if (nsa_dwords) {
|
|
|
|
|
out.resize(out.size() + nsa_dwords);
|
|
|
|
|
std::vector<uint32_t>::iterator nsa = std::prev(out.end(), nsa_dwords);
|
2021-02-22 11:12:15 +00:00
|
|
|
for (unsigned i = 0; i < instr->operands.size() - 4u; i++)
|
2022-06-16 19:36:24 +01:00
|
|
|
nsa[i / 4] |= reg(ctx, instr->operands[4 + i], 8) << (i % 4 * 8);
|
2021-01-14 19:58:13 +00:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::FLAT:
|
|
|
|
|
case Format::SCRATCH:
|
|
|
|
|
case Format::GLOBAL: {
|
2021-01-21 16:13:34 +00:00
|
|
|
FLAT_instruction& flat = instr->flatlike();
|
2019-09-17 13:22:17 +02:00
|
|
|
uint32_t encoding = (0b110111 << 26);
|
|
|
|
|
encoding |= opcode << 18;
|
2022-05-19 15:18:36 +01:00
|
|
|
if (ctx.gfx_level == GFX9 || ctx.gfx_level >= GFX11) {
|
|
|
|
|
if (instr->isFlat())
|
|
|
|
|
assert(flat.offset <= 0xfff);
|
|
|
|
|
else
|
|
|
|
|
assert(flat.offset >= -4096 && flat.offset < 4096);
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= flat.offset & 0x1fff;
|
2022-05-19 15:18:36 +01:00
|
|
|
} else if (ctx.gfx_level <= GFX8 || instr->isFlat()) {
|
2019-10-17 17:14:37 +02:00
|
|
|
/* GFX10 has a 12-bit immediate OFFSET field,
|
|
|
|
|
* but it has a hw bug: it ignores the offset, called FlatSegmentOffsetBug
|
|
|
|
|
*/
|
2021-01-21 16:13:34 +00:00
|
|
|
assert(flat.offset == 0);
|
2019-11-20 14:52:15 +00:00
|
|
|
} else {
|
2022-05-19 15:18:36 +01:00
|
|
|
assert(flat.offset >= -2048 && flat.offset <= 2047);
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= flat.offset & 0xfff;
|
2019-09-26 17:50:06 +02:00
|
|
|
}
|
2021-01-20 15:27:16 +00:00
|
|
|
if (instr->isScratch())
|
2022-06-17 11:23:00 +01:00
|
|
|
encoding |= 1 << (ctx.gfx_level >= GFX11 ? 16 : 14);
|
2021-01-20 15:27:16 +00:00
|
|
|
else if (instr->isGlobal())
|
2022-06-17 11:23:00 +01:00
|
|
|
encoding |= 2 << (ctx.gfx_level >= GFX11 ? 16 : 14);
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= flat.lds ? 1 << 13 : 0;
|
2022-06-17 11:23:00 +01:00
|
|
|
encoding |= flat.glc ? 1 << (ctx.gfx_level >= GFX11 ? 14 : 16) : 0;
|
|
|
|
|
encoding |= flat.slc ? 1 << (ctx.gfx_level >= GFX11 ? 15 : 17) : 0;
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level >= GFX10) {
|
2021-01-21 16:13:34 +00:00
|
|
|
assert(!flat.nv);
|
2022-06-17 11:23:00 +01:00
|
|
|
encoding |= flat.dlc ? 1 << (ctx.gfx_level >= GFX11 ? 13 : 12) : 0;
|
2019-09-26 17:50:06 +02:00
|
|
|
} else {
|
2021-01-21 16:13:34 +00:00
|
|
|
assert(!flat.dlc);
|
2019-09-26 17:50:06 +02:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding = reg(ctx, instr->operands[0], 8);
|
2019-09-17 13:22:17 +02:00
|
|
|
if (!instr->definitions.empty())
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8) << 24;
|
2019-11-27 17:06:10 +00:00
|
|
|
if (instr->operands.size() >= 3)
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[2], 8) << 8;
|
2019-09-17 13:22:17 +02:00
|
|
|
if (!instr->operands[1].isUndefined()) {
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(ctx.gfx_level >= GFX10 || instr->operands[1].physReg() != 0x7F);
|
2019-09-17 13:22:17 +02:00
|
|
|
assert(instr->format != Format::FLAT);
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[1], 8) << 16;
|
2021-06-09 10:14:54 +02:00
|
|
|
} else if (instr->format != Format::FLAT ||
|
2022-05-12 02:50:17 -04:00
|
|
|
ctx.gfx_level >= GFX10) { /* SADDR is actually used with FLAT on GFX10 */
|
2022-05-19 15:55:53 +01:00
|
|
|
/* For GFX10.3 scratch, 0x7F disables both ADDR and SADDR, unlike sgpr_null, which only
|
|
|
|
|
* disables SADDR.
|
|
|
|
|
*/
|
|
|
|
|
if (ctx.gfx_level <= GFX9 ||
|
|
|
|
|
(instr->format == Format::SCRATCH && instr->operands[0].isUndefined()))
|
2019-09-26 17:50:06 +02:00
|
|
|
encoding |= 0x7F << 16;
|
|
|
|
|
else
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, sgpr_null) << 16;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level >= GFX11 && instr->isScratch())
|
|
|
|
|
encoding |= !instr->operands[0].isUndefined() ? 1 << 23 : 0;
|
|
|
|
|
else
|
|
|
|
|
encoding |= flat.nv ? 1 << 23 : 0;
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::EXP: {
|
2021-01-21 16:13:34 +00:00
|
|
|
Export_instruction& exp = instr->exp();
|
2019-09-26 17:50:48 +02:00
|
|
|
uint32_t encoding;
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level == GFX8 || ctx.gfx_level == GFX9) {
|
2019-09-26 17:50:48 +02:00
|
|
|
encoding = (0b110001 << 26);
|
2019-11-04 18:02:47 +01:00
|
|
|
} else {
|
2019-09-26 17:50:48 +02:00
|
|
|
encoding = (0b111110 << 26);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 11:23:00 +01:00
|
|
|
if (ctx.gfx_level >= GFX11) {
|
|
|
|
|
encoding |= exp.row_en ? 0b1 << 13 : 0;
|
|
|
|
|
} else {
|
|
|
|
|
encoding |= exp.valid_mask ? 0b1 << 12 : 0;
|
|
|
|
|
encoding |= exp.compressed ? 0b1 << 10 : 0;
|
|
|
|
|
}
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= exp.done ? 0b1 << 11 : 0;
|
|
|
|
|
encoding |= exp.dest << 4;
|
|
|
|
|
encoding |= exp.enabled_mask;
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding = reg(ctx, exp.operands[0], 8);
|
|
|
|
|
encoding |= reg(ctx, exp.operands[1], 8) << 8;
|
|
|
|
|
encoding |= reg(ctx, exp.operands[2], 8) << 16;
|
|
|
|
|
encoding |= reg(ctx, exp.operands[3], 8) << 24;
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case Format::PSEUDO:
|
|
|
|
|
case Format::PSEUDO_BARRIER:
|
2020-01-22 19:58:27 +00:00
|
|
|
if (instr->opcode != aco_opcode::p_unit_test)
|
|
|
|
|
unreachable("Pseudo instructions should be lowered before assembly.");
|
|
|
|
|
break;
|
2019-09-17 13:22:17 +02:00
|
|
|
default:
|
2022-06-17 11:23:00 +01:00
|
|
|
/* TODO: VOP3/VOP3P can use DPP8/16 on GFX11 (encoding of src0 and DPP8/16 word seems same
|
|
|
|
|
* except abs/neg is ignored). src2 cannot be literal and src0/src1 must be VGPR.
|
|
|
|
|
*/
|
2023-02-03 13:28:32 +01:00
|
|
|
if (instr->isVOP3() && !instr->isDPP()) {
|
2023-02-21 20:08:42 +01:00
|
|
|
VALU_instruction& vop3 = instr->valu();
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2021-01-20 15:27:16 +00:00
|
|
|
if (instr->isVOP2()) {
|
2019-09-17 13:22:17 +02:00
|
|
|
opcode = opcode + 0x100;
|
2021-01-20 15:27:16 +00:00
|
|
|
} else if (instr->isVOP1()) {
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level == GFX8 || ctx.gfx_level == GFX9)
|
2019-09-26 17:51:51 +02:00
|
|
|
opcode = opcode + 0x140;
|
2019-11-04 18:02:47 +01:00
|
|
|
else
|
2019-09-26 17:51:51 +02:00
|
|
|
opcode = opcode + 0x180;
|
2021-01-20 15:27:16 +00:00
|
|
|
} else if (instr->isVOPC()) {
|
2019-09-17 13:22:17 +02:00
|
|
|
opcode = opcode + 0x0;
|
2021-01-20 15:27:16 +00:00
|
|
|
} else if (instr->isVINTRP()) {
|
2019-09-17 13:22:17 +02:00
|
|
|
opcode = opcode + 0x270;
|
2019-09-26 17:51:51 +02:00
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2019-09-26 17:51:51 +02:00
|
|
|
uint32_t encoding;
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level <= GFX9) {
|
2019-09-26 17:51:51 +02:00
|
|
|
encoding = (0b110100 << 26);
|
2022-05-12 02:50:17 -04:00
|
|
|
} else if (ctx.gfx_level >= GFX10) {
|
2019-09-26 17:51:51 +02:00
|
|
|
encoding = (0b110101 << 26);
|
2020-01-21 13:49:00 +01:00
|
|
|
} else {
|
2022-05-12 02:50:17 -04:00
|
|
|
unreachable("Unknown gfx_level.");
|
2019-09-26 17:51:51 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level <= GFX7) {
|
2019-11-04 18:02:47 +01:00
|
|
|
encoding |= opcode << 17;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (vop3.clamp ? 1 : 0) << 11;
|
2019-11-04 18:02:47 +01:00
|
|
|
} else {
|
|
|
|
|
encoding |= opcode << 16;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (vop3.clamp ? 1 : 0) << 15;
|
2019-11-04 18:02:47 +01:00
|
|
|
}
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= vop3.opsel << 11;
|
2019-09-17 13:22:17 +02:00
|
|
|
for (unsigned i = 0; i < 3; i++)
|
2021-06-09 10:14:54 +02:00
|
|
|
encoding |= vop3.abs[i] << (8 + i);
|
2022-08-15 12:10:38 +02:00
|
|
|
/* On GFX9 and older, v_cmpx implicitly writes exec besides writing an SGPR pair.
|
|
|
|
|
* On GFX10 and newer, v_cmpx always writes just exec.
|
|
|
|
|
*/
|
|
|
|
|
if (instr->definitions.size() == 2 && instr->isVOPC())
|
|
|
|
|
assert(ctx.gfx_level <= GFX9 && instr->definitions[1].physReg() == exec);
|
|
|
|
|
else if (instr->definitions.size() == 2)
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->definitions[1]) << 8;
|
|
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8);
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
encoding = 0;
|
|
|
|
|
if (instr->opcode == aco_opcode::v_interp_mov_f32) {
|
|
|
|
|
encoding = 0x3 & instr->operands[0].constantValue();
|
2022-02-02 16:42:24 +00:00
|
|
|
} else if (instr->opcode == aco_opcode::v_writelane_b32_e64) {
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[0]) << 0;
|
|
|
|
|
encoding |= reg(ctx, instr->operands[1]) << 9;
|
2022-02-02 16:42:24 +00:00
|
|
|
/* Encoding src2 works fine with hardware but breaks some disassemblers. */
|
2019-09-17 13:22:17 +02:00
|
|
|
} else {
|
|
|
|
|
for (unsigned i = 0; i < instr->operands.size(); i++)
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[i]) << (i * 9);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= vop3.omod << 27;
|
2019-09-17 13:22:17 +02:00
|
|
|
for (unsigned i = 0; i < 3; i++)
|
2021-06-09 10:14:54 +02:00
|
|
|
encoding |= vop3.neg[i] << (29 + i);
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
|
2021-01-20 15:27:16 +00:00
|
|
|
} else if (instr->isVOP3P()) {
|
2023-02-21 20:08:42 +01:00
|
|
|
VALU_instruction& vop3 = instr->valu();
|
2020-04-10 17:28:33 +01:00
|
|
|
|
|
|
|
|
uint32_t encoding;
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level == GFX9) {
|
2020-04-10 17:28:33 +01:00
|
|
|
encoding = (0b110100111 << 23);
|
2022-05-12 02:50:17 -04:00
|
|
|
} else if (ctx.gfx_level >= GFX10) {
|
2020-04-10 17:28:33 +01:00
|
|
|
encoding = (0b110011 << 26);
|
|
|
|
|
} else {
|
2022-05-12 02:50:17 -04:00
|
|
|
unreachable("Unknown gfx_level.");
|
2020-04-10 17:28:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
encoding |= opcode << 16;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (vop3.clamp ? 1 : 0) << 15;
|
|
|
|
|
encoding |= vop3.opsel_lo << 11;
|
|
|
|
|
encoding |= ((vop3.opsel_hi & 0x4) ? 1 : 0) << 14;
|
2020-04-10 17:28:33 +01:00
|
|
|
for (unsigned i = 0; i < 3; i++)
|
2021-06-09 10:14:54 +02:00
|
|
|
encoding |= vop3.neg_hi[i] << (8 + i);
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->definitions[0], 8);
|
2020-04-10 17:28:33 +01:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
encoding = 0;
|
|
|
|
|
for (unsigned i = 0; i < instr->operands.size(); i++)
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->operands[i]) << (i * 9);
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (vop3.opsel_hi & 0x3) << 27;
|
2020-04-10 17:28:33 +01:00
|
|
|
for (unsigned i = 0; i < 3; i++)
|
2021-06-09 10:14:54 +02:00
|
|
|
encoding |= vop3.neg_lo[i] << (29 + i);
|
2020-04-10 17:28:33 +01:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
|
2021-11-29 00:12:04 +09:00
|
|
|
} else if (instr->isDPP16()) {
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(ctx.gfx_level >= GFX8);
|
2021-11-29 00:12:04 +09:00
|
|
|
DPP16_instruction& dpp = instr->dpp16();
|
2021-01-20 14:49:08 +00:00
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
/* first emit the instruction without the DPP operand */
|
|
|
|
|
Operand dpp_op = instr->operands[0];
|
|
|
|
|
instr->operands[0] = Operand(PhysReg{250}, v1);
|
2021-11-29 00:12:04 +09:00
|
|
|
instr->format = (Format)((uint16_t)instr->format & ~(uint16_t)Format::DPP16);
|
2023-02-03 13:28:32 +01:00
|
|
|
emit_instruction(ctx, out, instr);
|
2021-01-21 16:13:34 +00:00
|
|
|
uint32_t encoding = (0xF & dpp.row_mask) << 28;
|
|
|
|
|
encoding |= (0xF & dpp.bank_mask) << 24;
|
|
|
|
|
encoding |= dpp.abs[1] << 23;
|
|
|
|
|
encoding |= dpp.neg[1] << 22;
|
|
|
|
|
encoding |= dpp.abs[0] << 21;
|
|
|
|
|
encoding |= dpp.neg[0] << 20;
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level >= GFX10)
|
2020-07-20 17:19:40 +01:00
|
|
|
encoding |= 1 << 18; /* set Fetch Inactive to match GFX9 behaviour */
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= dpp.bound_ctrl << 19;
|
|
|
|
|
encoding |= dpp.dpp_ctrl << 8;
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, dpp_op, 8);
|
2023-03-21 11:54:33 +01:00
|
|
|
encoding |= dpp.opsel[0] && !instr->isVOP3() ? 128 : 0;
|
2019-09-17 13:22:17 +02:00
|
|
|
out.push_back(encoding);
|
|
|
|
|
return;
|
2021-11-29 00:12:04 +09:00
|
|
|
} else if (instr->isDPP8()) {
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(ctx.gfx_level >= GFX10);
|
2021-11-29 00:12:04 +09:00
|
|
|
DPP8_instruction& dpp = instr->dpp8();
|
|
|
|
|
|
|
|
|
|
/* first emit the instruction without the DPP operand */
|
|
|
|
|
Operand dpp_op = instr->operands[0];
|
|
|
|
|
instr->operands[0] = Operand(PhysReg{234}, v1);
|
|
|
|
|
instr->format = (Format)((uint16_t)instr->format & ~(uint16_t)Format::DPP8);
|
2023-02-03 13:28:32 +01:00
|
|
|
emit_instruction(ctx, out, instr);
|
2022-06-16 19:36:24 +01:00
|
|
|
uint32_t encoding = reg(ctx, dpp_op, 8);
|
2023-03-21 11:54:33 +01:00
|
|
|
encoding |= dpp.opsel[0] && !instr->isVOP3() ? 128 : 0;
|
2021-11-29 00:12:04 +09:00
|
|
|
for (unsigned i = 0; i < 8; ++i)
|
|
|
|
|
encoding |= dpp.lane_sel[i] << (8 + i * 3);
|
|
|
|
|
out.push_back(encoding);
|
|
|
|
|
return;
|
2019-12-04 20:18:05 +00:00
|
|
|
} else if (instr->isSDWA()) {
|
2022-05-13 12:01:03 +01:00
|
|
|
assert(ctx.gfx_level >= GFX8 && ctx.gfx_level < GFX11);
|
2021-01-21 16:13:34 +00:00
|
|
|
SDWA_instruction& sdwa = instr->sdwa();
|
2021-01-20 14:49:08 +00:00
|
|
|
|
2019-12-04 20:18:05 +00:00
|
|
|
/* first emit the instruction without the SDWA operand */
|
|
|
|
|
Operand sdwa_op = instr->operands[0];
|
|
|
|
|
instr->operands[0] = Operand(PhysReg{249}, v1);
|
2021-06-09 10:14:54 +02:00
|
|
|
instr->format = (Format)((uint16_t)instr->format & ~(uint16_t)Format::SDWA);
|
2019-12-04 20:18:05 +00:00
|
|
|
emit_instruction(ctx, out, instr);
|
|
|
|
|
|
|
|
|
|
uint32_t encoding = 0;
|
|
|
|
|
|
2021-01-20 15:27:16 +00:00
|
|
|
if (instr->isVOPC()) {
|
2022-08-15 17:01:52 +01:00
|
|
|
if (instr->definitions[0].physReg() !=
|
|
|
|
|
(ctx.gfx_level >= GFX10 && is_cmpx(instr->opcode) ? exec : vcc)) {
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, instr->definitions[0]) << 8;
|
2019-12-04 20:18:05 +00:00
|
|
|
encoding |= 1 << 15;
|
|
|
|
|
}
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (sdwa.clamp ? 1 : 0) << 13;
|
2019-12-04 20:18:05 +00:00
|
|
|
} else {
|
2021-08-30 17:58:36 +02:00
|
|
|
encoding |= sdwa.dst_sel.to_sdwa_sel(instr->definitions[0].physReg().byte()) << 8;
|
|
|
|
|
uint32_t dst_u = sdwa.dst_sel.sign_extend() ? 1 : 0;
|
2021-09-01 14:19:33 +02:00
|
|
|
if (instr->definitions[0].bytes() < 4) /* dst_preserve */
|
2020-02-07 12:08:09 +00:00
|
|
|
dst_u = 2;
|
2019-12-04 20:18:05 +00:00
|
|
|
encoding |= dst_u << 11;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= (sdwa.clamp ? 1 : 0) << 13;
|
|
|
|
|
encoding |= sdwa.omod << 14;
|
2019-12-04 20:18:05 +00:00
|
|
|
}
|
|
|
|
|
|
2021-08-30 17:58:36 +02:00
|
|
|
encoding |= sdwa.sel[0].to_sdwa_sel(sdwa_op.physReg().byte()) << 16;
|
|
|
|
|
encoding |= sdwa.sel[0].sign_extend() ? 1 << 19 : 0;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= sdwa.abs[0] << 21;
|
|
|
|
|
encoding |= sdwa.neg[0] << 20;
|
2019-12-04 20:18:05 +00:00
|
|
|
|
|
|
|
|
if (instr->operands.size() >= 2) {
|
2021-08-30 17:58:36 +02:00
|
|
|
encoding |= sdwa.sel[1].to_sdwa_sel(instr->operands[1].physReg().byte()) << 24;
|
|
|
|
|
encoding |= sdwa.sel[1].sign_extend() ? 1 << 27 : 0;
|
2021-01-21 16:13:34 +00:00
|
|
|
encoding |= sdwa.abs[1] << 29;
|
|
|
|
|
encoding |= sdwa.neg[1] << 28;
|
2019-12-04 20:18:05 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-16 19:36:24 +01:00
|
|
|
encoding |= reg(ctx, sdwa_op, 8);
|
2019-12-04 20:18:05 +00:00
|
|
|
encoding |= (sdwa_op.physReg() < 256) << 23;
|
|
|
|
|
if (instr->operands.size() >= 2)
|
|
|
|
|
encoding |= (instr->operands[1].physReg() < 256) << 31;
|
|
|
|
|
out.push_back(encoding);
|
2019-09-17 13:22:17 +02:00
|
|
|
} else {
|
|
|
|
|
unreachable("unimplemented instruction format");
|
|
|
|
|
}
|
2019-09-12 19:55:36 +01:00
|
|
|
break;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* append literal dword */
|
|
|
|
|
for (const Operand& op : instr->operands) {
|
|
|
|
|
if (op.isLiteral()) {
|
|
|
|
|
out.push_back(op.constantValue());
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
|
|
|
|
emit_block(asm_context& ctx, std::vector<uint32_t>& out, Block& block)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
|
|
|
|
for (aco_ptr<Instruction>& instr : block.instructions) {
|
|
|
|
|
#if 0
|
|
|
|
|
int start_idx = out.size();
|
|
|
|
|
std::cerr << "Encoding:\t" << std::endl;
|
|
|
|
|
aco_print_instr(&*instr, stderr);
|
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
#endif
|
|
|
|
|
emit_instruction(ctx, out, instr.get());
|
|
|
|
|
#if 0
|
|
|
|
|
for (int i = start_idx; i < out.size(); i++)
|
|
|
|
|
std::cerr << "encoding: " << "0x" << std::setfill('0') << std::setw(8) << std::hex << out[i] << std::endl;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
|
|
|
|
fix_exports(asm_context& ctx, std::vector<uint32_t>& out, Program* program)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2020-03-12 17:20:16 +01:00
|
|
|
bool exported = false;
|
2019-11-15 11:43:19 +00:00
|
|
|
for (Block& block : program->blocks) {
|
|
|
|
|
if (!(block.kind & block_kind_export_end))
|
|
|
|
|
continue;
|
2019-09-17 13:22:17 +02:00
|
|
|
std::vector<aco_ptr<Instruction>>::reverse_iterator it = block.instructions.rbegin();
|
2021-06-09 10:14:54 +02:00
|
|
|
while (it != block.instructions.rend()) {
|
2021-01-20 15:27:16 +00:00
|
|
|
if ((*it)->isEXP()) {
|
2021-01-21 16:13:34 +00:00
|
|
|
Export_instruction& exp = (*it)->exp();
|
2020-10-07 18:21:48 +02:00
|
|
|
if (program->stage.hw == HWStage::VS || program->stage.hw == HWStage::NGG) {
|
2021-01-21 16:13:34 +00:00
|
|
|
if (exp.dest >= V_008DFC_SQ_EXP_POS && exp.dest <= (V_008DFC_SQ_EXP_POS + 3)) {
|
|
|
|
|
exp.done = true;
|
2019-09-17 13:22:17 +02:00
|
|
|
exported = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-06-24 14:38:59 +02:00
|
|
|
if (!program->info.ps.has_epilog) {
|
|
|
|
|
exp.done = true;
|
|
|
|
|
exp.valid_mask = true;
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
exported = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-06-24 14:39:10 +02:00
|
|
|
} else if ((*it)->definitions.size() && (*it)->definitions[0].physReg() == exec) {
|
2019-09-17 13:22:17 +02:00
|
|
|
break;
|
2022-06-24 14:39:10 +02:00
|
|
|
} else if ((*it)->opcode == aco_opcode::s_setpc_b64) {
|
|
|
|
|
/* Do not abort if the main FS has an epilog because it only
|
|
|
|
|
* exports MRTZ (if present) and the epilog exports colors.
|
|
|
|
|
*/
|
|
|
|
|
exported |= program->stage.hw == HWStage::FS && program->info.ps.has_epilog;
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
++it;
|
|
|
|
|
}
|
2020-03-12 17:20:16 +01:00
|
|
|
}
|
|
|
|
|
|
2023-04-23 16:39:11 +08:00
|
|
|
/* GFX10+ FS may not export anything if no discard is used. */
|
|
|
|
|
bool may_skip_export = program->stage.hw == HWStage::FS && program->gfx_level >= GFX10;
|
|
|
|
|
|
|
|
|
|
if (!exported && !may_skip_export) {
|
2020-03-12 17:20:16 +01:00
|
|
|
/* Abort in order to avoid a GPU hang. */
|
2021-06-09 10:14:54 +02:00
|
|
|
bool is_vertex_or_ngg =
|
|
|
|
|
(program->stage.hw == HWStage::VS || program->stage.hw == HWStage::NGG);
|
|
|
|
|
aco_err(program,
|
|
|
|
|
"Missing export in %s shader:", is_vertex_or_ngg ? "vertex or NGG" : "fragment");
|
2020-03-12 17:20:16 +01:00
|
|
|
aco_print_program(program, stderr);
|
|
|
|
|
abort();
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
static void
|
|
|
|
|
insert_code(asm_context& ctx, std::vector<uint32_t>& out, unsigned insert_before,
|
|
|
|
|
unsigned insert_count, const uint32_t* insert_data)
|
2020-08-04 16:06:56 +01:00
|
|
|
{
|
|
|
|
|
out.insert(out.begin() + insert_before, insert_data, insert_data + insert_count);
|
|
|
|
|
|
|
|
|
|
/* Update the offset of each affected block */
|
|
|
|
|
for (Block& block : ctx.program->blocks) {
|
|
|
|
|
if (block.offset >= insert_before)
|
|
|
|
|
block.offset += insert_count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Find first branch after the inserted code */
|
2021-06-09 10:14:54 +02:00
|
|
|
auto branch_it = std::find_if(ctx.branches.begin(), ctx.branches.end(),
|
|
|
|
|
[insert_before](const auto& branch) -> bool
|
|
|
|
|
{ return (unsigned)branch.first >= insert_before; });
|
2020-08-04 16:06:56 +01:00
|
|
|
|
|
|
|
|
/* Update the locations of branches */
|
|
|
|
|
for (; branch_it != ctx.branches.end(); ++branch_it)
|
|
|
|
|
branch_it->first += insert_count;
|
|
|
|
|
|
2021-02-01 12:42:38 +00:00
|
|
|
/* Update the locations of p_constaddr instructions */
|
|
|
|
|
for (auto& constaddr : ctx.constaddrs) {
|
|
|
|
|
constaddr_info& info = constaddr.second;
|
|
|
|
|
if (info.getpc_end >= insert_before)
|
|
|
|
|
info.getpc_end += insert_count;
|
|
|
|
|
if (info.add_literal >= insert_before)
|
|
|
|
|
info.add_literal += insert_count;
|
|
|
|
|
}
|
2023-04-25 20:50:48 +08:00
|
|
|
|
|
|
|
|
if (ctx.symbols) {
|
|
|
|
|
for (auto& symbol : *ctx.symbols) {
|
|
|
|
|
if (symbol.offset >= insert_before)
|
|
|
|
|
symbol.offset += insert_count;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-04 16:06:56 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
static void
|
|
|
|
|
fix_branches_gfx10(asm_context& ctx, std::vector<uint32_t>& out)
|
2019-09-10 18:11:13 +01:00
|
|
|
{
|
2021-06-09 10:14:54 +02:00
|
|
|
/* Branches with an offset of 0x3f are buggy on GFX10,
|
|
|
|
|
* we workaround by inserting NOPs if needed.
|
|
|
|
|
*/
|
2019-09-10 18:11:13 +01:00
|
|
|
bool gfx10_3f_bug = false;
|
|
|
|
|
|
|
|
|
|
do {
|
2021-06-09 10:14:54 +02:00
|
|
|
auto buggy_branch_it = std::find_if(
|
|
|
|
|
ctx.branches.begin(), ctx.branches.end(),
|
|
|
|
|
[&ctx](const auto& branch) -> bool {
|
|
|
|
|
return ((int)ctx.program->blocks[branch.second->block].offset - branch.first - 1) ==
|
|
|
|
|
0x3f;
|
|
|
|
|
});
|
2019-09-10 18:11:13 +01:00
|
|
|
|
|
|
|
|
gfx10_3f_bug = buggy_branch_it != ctx.branches.end();
|
|
|
|
|
|
|
|
|
|
if (gfx10_3f_bug) {
|
|
|
|
|
/* Insert an s_nop after the branch */
|
|
|
|
|
constexpr uint32_t s_nop_0 = 0xbf800000u;
|
2020-08-04 16:06:56 +01:00
|
|
|
insert_code(ctx, out, buggy_branch_it->first + 1, 1, &s_nop_0);
|
|
|
|
|
}
|
|
|
|
|
} while (gfx10_3f_bug);
|
|
|
|
|
}
|
2019-09-10 18:11:13 +01:00
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
|
|
|
|
emit_long_jump(asm_context& ctx, SOPP_instruction* branch, bool backwards,
|
|
|
|
|
std::vector<uint32_t>& out)
|
2020-08-04 16:06:56 +01:00
|
|
|
{
|
|
|
|
|
Builder bld(ctx.program);
|
2019-10-16 15:05:56 +02:00
|
|
|
|
2022-08-18 14:31:06 +01:00
|
|
|
Definition def;
|
|
|
|
|
if (branch->definitions.empty()) {
|
|
|
|
|
assert(ctx.program->blocks[branch->block].kind & block_kind_discard_early_exit);
|
|
|
|
|
def = Definition(PhysReg(0), s2); /* The discard early exit block doesn't use SGPRs. */
|
|
|
|
|
} else {
|
|
|
|
|
def = branch->definitions[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Definition def_tmp_lo(def.physReg(), s1);
|
|
|
|
|
Operand op_tmp_lo(def.physReg(), s1);
|
|
|
|
|
Definition def_tmp_hi(def.physReg().advance(4), s1);
|
|
|
|
|
Operand op_tmp_hi(def.physReg().advance(4), s1);
|
2019-10-16 15:05:56 +02:00
|
|
|
|
2020-08-04 16:06:56 +01:00
|
|
|
aco_ptr<Instruction> instr;
|
2019-10-16 15:05:56 +02:00
|
|
|
|
2020-08-04 16:06:56 +01:00
|
|
|
if (branch->opcode != aco_opcode::s_branch) {
|
|
|
|
|
/* for conditional branches, skip the long jump if the condition is false */
|
|
|
|
|
aco_opcode inv;
|
|
|
|
|
switch (branch->opcode) {
|
2021-06-09 10:14:54 +02:00
|
|
|
case aco_opcode::s_cbranch_scc0: inv = aco_opcode::s_cbranch_scc1; break;
|
|
|
|
|
case aco_opcode::s_cbranch_scc1: inv = aco_opcode::s_cbranch_scc0; break;
|
|
|
|
|
case aco_opcode::s_cbranch_vccz: inv = aco_opcode::s_cbranch_vccnz; break;
|
|
|
|
|
case aco_opcode::s_cbranch_vccnz: inv = aco_opcode::s_cbranch_vccz; break;
|
|
|
|
|
case aco_opcode::s_cbranch_execz: inv = aco_opcode::s_cbranch_execnz; break;
|
|
|
|
|
case aco_opcode::s_cbranch_execnz: inv = aco_opcode::s_cbranch_execz; break;
|
|
|
|
|
default: unreachable("Unhandled long jump.");
|
2019-09-10 18:11:13 +01:00
|
|
|
}
|
2022-05-11 19:33:32 +01:00
|
|
|
instr.reset(bld.sopp(inv, -1, 6));
|
2020-08-04 16:06:56 +01:00
|
|
|
emit_instruction(ctx, out, instr.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create the new PC and stash SCC in the LSB */
|
2022-08-18 14:31:06 +01:00
|
|
|
instr.reset(bld.sop1(aco_opcode::s_getpc_b64, def).instr);
|
2020-08-04 16:06:56 +01:00
|
|
|
emit_instruction(ctx, out, instr.get());
|
|
|
|
|
|
2022-05-02 14:21:21 +01:00
|
|
|
instr.reset(
|
|
|
|
|
bld.sop2(aco_opcode::s_addc_u32, def_tmp_lo, op_tmp_lo, Operand::literal32(0)).instr);
|
2020-08-04 16:06:56 +01:00
|
|
|
emit_instruction(ctx, out, instr.get());
|
|
|
|
|
branch->pass_flags = out.size();
|
|
|
|
|
|
2022-05-11 19:33:32 +01:00
|
|
|
/* s_addc_u32 for high 32 bits not needed because the program is in a 32-bit VA range */
|
2020-08-04 16:06:56 +01:00
|
|
|
|
|
|
|
|
/* restore SCC and clear the LSB of the new PC */
|
2021-07-13 11:22:46 +02:00
|
|
|
instr.reset(bld.sopc(aco_opcode::s_bitcmp1_b32, def_tmp_lo, op_tmp_lo, Operand::zero()).instr);
|
2020-08-04 16:06:56 +01:00
|
|
|
emit_instruction(ctx, out, instr.get());
|
2021-07-13 11:22:46 +02:00
|
|
|
instr.reset(bld.sop1(aco_opcode::s_bitset0_b32, def_tmp_lo, Operand::zero()).instr);
|
2020-08-04 16:06:56 +01:00
|
|
|
emit_instruction(ctx, out, instr.get());
|
|
|
|
|
|
|
|
|
|
/* create the s_setpc_b64 to jump */
|
2021-06-09 10:14:54 +02:00
|
|
|
instr.reset(
|
2022-08-18 14:31:06 +01:00
|
|
|
bld.sop1(aco_opcode::s_setpc_b64, Operand(def.physReg(), s2)).instr);
|
2020-08-04 16:06:56 +01:00
|
|
|
emit_instruction(ctx, out, instr.get());
|
2019-09-10 18:11:13 +01:00
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
|
|
|
|
fix_branches(asm_context& ctx, std::vector<uint32_t>& out)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2020-08-04 16:06:56 +01:00
|
|
|
bool repeat = false;
|
|
|
|
|
do {
|
|
|
|
|
repeat = false;
|
2019-09-10 18:11:13 +01:00
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
if (ctx.gfx_level == GFX10)
|
2020-08-04 16:06:56 +01:00
|
|
|
fix_branches_gfx10(ctx, out);
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
for (std::pair<int, SOPP_instruction*>& branch : ctx.branches) {
|
2020-08-04 16:06:56 +01:00
|
|
|
int offset = (int)ctx.program->blocks[branch.second->block].offset - branch.first - 1;
|
|
|
|
|
if ((offset < INT16_MIN || offset > INT16_MAX) && !branch.second->pass_flags) {
|
|
|
|
|
std::vector<uint32_t> long_jump;
|
2021-06-09 10:14:54 +02:00
|
|
|
bool backwards =
|
|
|
|
|
ctx.program->blocks[branch.second->block].offset < (unsigned)branch.first;
|
2020-08-04 16:06:56 +01:00
|
|
|
emit_long_jump(ctx, branch.second, backwards, long_jump);
|
|
|
|
|
|
|
|
|
|
out[branch.first] = long_jump[0];
|
|
|
|
|
insert_code(ctx, out, branch.first + 1, long_jump.size() - 1, long_jump.data() + 1);
|
|
|
|
|
|
|
|
|
|
repeat = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (branch.second->pass_flags) {
|
|
|
|
|
int after_getpc = branch.first + branch.second->pass_flags - 2;
|
|
|
|
|
offset = (int)ctx.program->blocks[branch.second->block].offset - after_getpc;
|
|
|
|
|
out[branch.first + branch.second->pass_flags - 1] = offset * 4;
|
|
|
|
|
} else {
|
|
|
|
|
out[branch.first] &= 0xffff0000u;
|
2021-06-09 10:14:54 +02:00
|
|
|
out[branch.first] |= (uint16_t)offset;
|
2020-08-04 16:06:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (repeat);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
void
|
|
|
|
|
fix_constaddrs(asm_context& ctx, std::vector<uint32_t>& out)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2021-02-01 12:42:38 +00:00
|
|
|
for (auto& constaddr : ctx.constaddrs) {
|
|
|
|
|
constaddr_info& info = constaddr.second;
|
|
|
|
|
out[info.add_literal] += (out.size() - info.getpc_end) * 4u;
|
|
|
|
|
}
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
unsigned
|
2023-04-25 20:50:48 +08:00
|
|
|
emit_program(Program* program, std::vector<uint32_t>& code,
|
|
|
|
|
std::vector<struct aco_symbol>* symbols)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2023-04-25 20:50:48 +08:00
|
|
|
asm_context ctx(program, symbols);
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
if (program->stage.hw == HWStage::VS || program->stage.hw == HWStage::FS ||
|
2020-10-07 18:21:48 +02:00
|
|
|
program->stage.hw == HWStage::NGG)
|
2019-09-17 13:22:17 +02:00
|
|
|
fix_exports(ctx, code, program);
|
|
|
|
|
|
|
|
|
|
for (Block& block : program->blocks) {
|
|
|
|
|
block.offset = code.size();
|
|
|
|
|
emit_block(ctx, code, block);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fix_branches(ctx, code);
|
2019-10-08 14:47:00 +02:00
|
|
|
|
|
|
|
|
unsigned exec_size = code.size() * sizeof(uint32_t);
|
|
|
|
|
|
2022-05-12 02:50:17 -04:00
|
|
|
if (program->gfx_level >= GFX10) {
|
2019-10-08 14:47:00 +02:00
|
|
|
/* Pad output with s_code_end so instruction prefetching doesn't cause
|
|
|
|
|
* page faults */
|
2023-01-05 15:44:09 +00:00
|
|
|
unsigned final_size = align(code.size() + 3 * 16, program->gfx_level >= GFX11 ? 32 : 16);
|
2019-10-08 14:47:00 +02:00
|
|
|
while (code.size() < final_size)
|
|
|
|
|
code.push_back(0xbf9f0000u);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
fix_constaddrs(ctx, code);
|
|
|
|
|
|
|
|
|
|
while (program->constant_data.size() % 4u)
|
|
|
|
|
program->constant_data.push_back(0);
|
|
|
|
|
/* Copy constant data */
|
|
|
|
|
code.insert(code.end(), (uint32_t*)program->constant_data.data(),
|
|
|
|
|
(uint32_t*)(program->constant_data.data() + program->constant_data.size()));
|
|
|
|
|
|
2023-01-05 14:01:21 +00:00
|
|
|
program->config->scratch_bytes_per_wave = align(
|
|
|
|
|
program->config->scratch_bytes_per_wave, program->dev.scratch_alloc_granule);
|
|
|
|
|
|
2019-10-08 14:47:00 +02:00
|
|
|
return exec_size;
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2021-06-09 10:14:54 +02:00
|
|
|
} // namespace aco
|