aco/optimizer: add extract_float helper

Reviewed-by: Daniel Schürmann <daniel@schuermann.dev>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38150>
This commit is contained in:
Georg Lehmann 2025-10-23 13:09:53 +02:00 committed by Marge Bot
parent 7eccf5c745
commit 53f5e447db

View file

@ -1504,6 +1504,20 @@ alu_opt_info_to_instr(opt_ctx& ctx, alu_opt_info& info, Instruction* old_instr)
return instr;
}
double
extract_float(uint64_t raw, unsigned bits, unsigned idx = 0)
{
raw >>= bits * idx;
if (bits == 16)
return _mesa_half_to_float(raw);
else if (bits == 32)
return uif(raw);
else if (bits == 64)
return uid(raw);
else
UNREACHABLE("unsupported float size");
}
uint64_t
operand_canonicalized_labels(opt_ctx& ctx, Operand op)
{
@ -2834,11 +2848,7 @@ label_instruction(opt_ctx& ctx, aco_ptr<Instruction>& instr)
if (!instr->operands[!i].isConstant() || !instr->operands[i].isTemp())
continue;
double constant = uif(instr->operands[!i].constantValue());
if (fp16)
constant = _mesa_half_to_float(instr->operands[!i].constantValue());
else if (fp64)
constant = uid(instr->operands[!i].constantValue64());
double constant = extract_float(instr->operands[!i].constantValue64(), bit_size);
if (!instr->isDPP() && !instr->isSDWA() && !instr->valu().opsel && fabs(constant) == 1.0) {
bool neg1 = constant == -1.0;