From 72146051d5db1c51355d7b0fff4ad088b9ea9ccc Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Thu, 2 Jun 2022 15:10:09 -0400 Subject: [PATCH] pan/va: Try negating small constants when lowering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a constant is used with a floating point instruction with a floating-point negate modifier, we can use the modifier to negate constants in the table for free. Each floating point in the table is positive, so this is required for negative small constants. total instructions in shared programs: 2728438 -> 2716912 (-0.42%) instructions in affected programs: 1418220 -> 1406694 (-0.81%) helped: 6053 HURT: 94 helped stats (abs) min: 1.0 max: 43.0 x̄: 1.94 x̃: 1 helped stats (rel) min: 0.06% max: 18.18% x̄: 1.34% x̃: 0.84% HURT stats (abs) min: 1.0 max: 5.0 x̄: 2.34 x̃: 2 HURT stats (rel) min: 0.09% max: 21.43% x̄: 1.87% x̃: 0.91% 95% mean confidence interval for instructions value: -1.93 -1.82 95% mean confidence interval for instructions %-change: -1.34% -1.25% Instructions are helped. total cycles in shared programs: 142103 -> 141984.06 (-0.08%) cycles in affected programs: 766.70 -> 647.77 (-15.51%) helped: 97 HURT: 0 helped stats (abs) min: 0.015625 max: 40.0 x̄: 1.23 x̃: 0 helped stats (rel) min: 0.27% max: 41.24% x̄: 3.63% x̃: 2.08% 95% mean confidence interval for cycles value: -2.41 -0.04 95% mean confidence interval for cycles %-change: -4.68% -2.57% Cycles are helped. total cvt in shared programs: 13983.34 -> 13805.05 (-1.28%) cvt in affected programs: 7952.45 -> 7774.16 (-2.24%) helped: 6049 HURT: 98 helped stats (abs) min: 0.015625 max: 0.359375 x̄: 0.03 x̃: 0 helped stats (rel) min: 0.25% max: 100.00% x̄: 4.74% x̃: 2.52% HURT stats (abs) min: 0.015625 max: 0.078125 x̄: 0.04 x̃: 0 HURT stats (rel) min: 0.17% max: 100.00% x̄: 5.48% x̃: 2.54% 95% mean confidence interval for cvt value: -0.03 -0.03 95% mean confidence interval for cvt %-change: -4.83% -4.32% Cvt are helped. total ls in shared programs: 129660 -> 129545 (-0.09%) ls in affected programs: 601 -> 486 (-19.13%) helped: 7 HURT: 0 helped stats (abs) min: 3.0 max: 40.0 x̄: 16.43 x̃: 8 helped stats (rel) min: 2.88% max: 41.24% x̄: 17.41% x̃: 12.50% 95% mean confidence interval for ls value: -31.42 -1.44 95% mean confidence interval for ls %-change: -29.25% -5.58% Ls are helped. total quadwords in shared programs: 1482728 -> 1476416 (-0.43%) quadwords in affected programs: 131200 -> 124888 (-4.81%) helped: 798 HURT: 15 helped stats (abs) min: 8.0 max: 24.0 x̄: 8.06 x̃: 8 helped stats (rel) min: 0.34% max: 50.00% x̄: 10.15% x̃: 6.67% HURT stats (abs) min: 8.0 max: 8.0 x̄: 8.00 x̃: 8 HURT stats (rel) min: 1.49% max: 100.00% x̄: 11.25% x̃: 2.78% 95% mean confidence interval for quadwords value: -7.92 -7.60 95% mean confidence interval for quadwords %-change: -10.52% -8.99% Quadwords are helped. total threads in shared programs: 53585 -> 53633 (0.09%) threads in affected programs: 51 -> 99 (94.12%) helped: 49 HURT: 1 helped stats (abs) min: 1.0 max: 1.0 x̄: 1.00 x̃: 1 helped stats (rel) min: 100.00% max: 100.00% x̄: 100.00% x̃: 100.00% HURT stats (abs) min: 1.0 max: 1.0 x̄: 1.00 x̃: 1 HURT stats (rel) min: 50.00% max: 50.00% x̄: 50.00% x̃: 50.00% 95% mean confidence interval for threads value: 0.88 1.04 95% mean confidence interval for threads %-change: 90.97% 103.03% Threads are helped. total spills in shared programs: 125 -> 154 (23.20%) spills in affected programs: 75 -> 104 (38.67%) helped: 3 HURT: 4 total fills in shared programs: 800 -> 656 (-18.00%) fills in affected programs: 476 -> 332 (-30.25%) helped: 7 HURT: 0 Signed-off-by: Alyssa Rosenzweig Part-of: --- .../bifrost/valhall/va_lower_constants.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/panfrost/bifrost/valhall/va_lower_constants.c b/src/panfrost/bifrost/valhall/va_lower_constants.c index ede38e871ee..e05735f2043 100644 --- a/src/panfrost/bifrost/valhall/va_lower_constants.c +++ b/src/panfrost/bifrost/valhall/va_lower_constants.c @@ -93,6 +93,18 @@ va_resolve_constant(bi_builder *b, uint32_t value, struct va_src_info info, bool if (!staging) { bi_index lut = va_lut_index_32(value); if (!bi_is_null(lut)) return lut; + + /* ...or negated as a FP32 constant */ + if (info.absneg && info.size == VA_SIZE_32) { + lut = bi_neg(va_lut_index_32(fui(-uif(value)))); + if (!bi_is_null(lut)) return lut; + } + + /* ...or negated as a FP16 constant */ + if (info.absneg && info.size == VA_SIZE_16) { + lut = bi_neg(va_lut_index_32(value ^ 0x80008000)); + if (!bi_is_null(lut)) return lut; + } } /* Try using a single half of a FP16 constant */ @@ -100,6 +112,12 @@ va_resolve_constant(bi_builder *b, uint32_t value, struct va_src_info info, bool if (!staging && info.swizzle && info.size == VA_SIZE_16 && replicated_halves) { bi_index lut = va_lut_index_16(value & 0xFFFF); if (!bi_is_null(lut)) return lut; + + /* ...possibly negated */ + if (info.absneg) { + lut = bi_neg(va_lut_index_16((value & 0xFFFF) ^ 0x8000)); + if (!bi_is_null(lut)) return lut; + } } /* TODO: Distinguish sign extend from zero extend */ @@ -121,6 +139,11 @@ va_resolve_constant(bi_builder *b, uint32_t value, struct va_src_info info, bool if (!staging && info.swizzle && info.size == VA_SIZE_32) { bi_index lut = va_demote_constant_fp16(value); if (!bi_is_null(lut)) return lut; + + if (info.absneg) { + bi_index lut = bi_neg(va_demote_constant_fp16(fui(-uif(value)))); + if (!bi_is_null(lut)) return lut; + } } /* TODO: Optimize to uniform */