From e8b673a10939d45c8184e6d3380eabbb6a624d7a Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 9 Jul 2024 17:07:41 -0400 Subject: [PATCH] agx: do not flush denorms for fp16 fmin/fmax total instructions in shared programs: 2164639 -> 2158940 (-0.26%) instructions in affected programs: 319475 -> 313776 (-1.78%) helped: 1200 HURT: 6 Instructions are helped. total alu in shared programs: 1690198 -> 1684653 (-0.33%) alu in affected programs: 272173 -> 266628 (-2.04%) helped: 1181 HURT: 6 Alu are helped. total fscib in shared programs: 1686497 -> 1680797 (-0.34%) fscib in affected programs: 272922 -> 267222 (-2.09%) helped: 1200 HURT: 6 Fscib are helped. total bytes in shared programs: 14334550 -> 14300314 (-0.24%) bytes in affected programs: 2075546 -> 2041310 (-1.65%) helped: 1200 HURT: 6 Bytes are helped. total regs in shared programs: 662332 -> 662302 (<.01%) regs in affected programs: 1103 -> 1073 (-2.72%) helped: 14 HURT: 15 Inconclusive result (value mean confidence interval includes 0). Signed-off-by: Alyssa Rosenzweig Reviewed-by: Konstantin Seurer Part-of: --- src/asahi/compiler/agx_compile.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index c2ad1c805d1..0cf5bfde604 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -1680,8 +1680,14 @@ agx_fminmax_to(agx_builder *b, agx_index dst, agx_index s0, agx_index s1, /* Calculate min/max with the appropriate hardware instruction */ agx_index tmp = agx_fcmpsel(b, s0, s1, s0, s1, fcond); - /* Flush denorms, as cmpsel will not. */ - return agx_fadd_to(b, dst, tmp, agx_negzero()); + /* G13 flushes fp32 denorms and preserves fp16 denorms. Since cmpsel + * preserves denorms, we need to canonicalize for fp32. Canonicalizing fp16 + * would be harmless but wastes an instruction. + */ + if (alu->def.bit_size == 32) + return agx_fadd_to(b, dst, tmp, agx_negzero()); + else + return agx_mov_to(b, dst, tmp); } static agx_instr *