aco: use s_round_mode/s_denorm_mode

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5773>
This commit is contained in:
Rhys Perry 2020-07-02 13:33:55 +01:00 committed by Marge Bot
parent ca44c009b5
commit 305cffa22b
2 changed files with 34 additions and 15 deletions

View File

@ -142,6 +142,10 @@ struct float_mode {
unsigned denorm32:2;
unsigned denorm16_64:2;
};
struct {
uint8_t round:4;
uint8_t denorm:4;
};
uint8_t val = 0;
};
/* if false, optimizations which may remove infs/nan/-0.0 can be done */

View File

@ -1637,6 +1637,21 @@ void handle_operands(std::map<PhysReg, copy_operation>& copy_map, lower_context*
ctx->program->statistics[statistic_copies] += ctx->instructions.size() - num_instructions_before;
}
void emit_set_mode(Builder& bld, float_mode new_mode, bool set_round, bool set_denorm)
{
if (bld.program->chip_class >= GFX10) {
if (set_round)
bld.sopp(aco_opcode::s_round_mode, -1, new_mode.round);
if (set_denorm)
bld.sopp(aco_opcode::s_denorm_mode, -1, new_mode.denorm);
} else if (set_round || set_denorm) {
/* "((size - 1) << 11) | register" (MODE is encoded as register 1) */
Instruction *instr = bld.sopk(aco_opcode::s_setreg_imm32_b32, Operand(new_mode.val), (7 << 11) | 1).instr;
/* has to be a literal */
instr->operands[0].setFixed(PhysReg{255});
}
}
void lower_to_hw_instr(Program* program)
{
Block *discard_block = NULL;
@ -1648,23 +1663,23 @@ void lower_to_hw_instr(Program* program)
ctx.program = program;
Builder bld(program, &ctx.instructions);
bool set_mode = i == 0 && block->fp_mode.val != program->config->float_mode;
for (unsigned pred : block->linear_preds) {
if (program->blocks[pred].fp_mode.val != block->fp_mode.val) {
set_mode = true;
break;
float_mode config_mode;
config_mode.val = program->config->float_mode;
bool set_round = i == 0 && block->fp_mode.round != config_mode.round;
bool set_denorm = i == 0 && block->fp_mode.denorm != config_mode.denorm;
if (block->kind & block_kind_top_level) {
for (unsigned pred : block->linear_preds) {
if (program->blocks[pred].fp_mode.round != block->fp_mode.round)
set_round = true;
if (program->blocks[pred].fp_mode.denorm != block->fp_mode.denorm)
set_denorm = true;
}
}
if (set_mode) {
/* only allow changing modes at top-level blocks so this doesn't break
* the "jump over empty blocks" optimization */
assert(block->kind & block_kind_top_level);
uint32_t mode = block->fp_mode.val;
/* "((size - 1) << 11) | register" (MODE is encoded as register 1) */
Instruction *instr = bld.sopk(aco_opcode::s_setreg_imm32_b32, Operand(mode), (7 << 11) | 1).instr;
/* has to be a literal */
instr->operands[0].setFixed(PhysReg{255});
}
/* only allow changing modes at top-level blocks so this doesn't break
* the "jump over empty blocks" optimization */
assert((!set_round && !set_denorm) || (block->kind & block_kind_top_level));
emit_set_mode(bld, block->fp_mode, set_round, set_denorm);
for (size_t j = 0; j < block->instructions.size(); j++) {
aco_ptr<Instruction>& instr = block->instructions[j];