From 297ac6e4530d7c839e320fc04cf10ba5ea9ec1a2 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 25 Jun 2021 18:31:50 -0400 Subject: [PATCH] pan/bi: Simplify cube map descriptor generation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit We don't need to do the bitwise manipulation ourselves, we can just use a bitwise MUX instead. total instructions in shared programs: 146840 -> 146614 (-0.15%) instructions in affected programs: 15037 -> 14811 (-1.50%) helped: 109 HURT: 0 helped stats (abs) min: 2.0 max: 4.0 x̄: 2.07 x̃: 2 helped stats (rel) min: 0.86% max: 4.00% x̄: 1.70% x̃: 1.77% 95% mean confidence interval for instructions value: -2.15 -2.00 95% mean confidence interval for instructions %-change: -1.81% -1.59% Instructions are helped. total tuples in shared programs: 128149 -> 128116 (-0.03%) tuples in affected programs: 2896 -> 2863 (-1.14%) helped: 16 HURT: 0 helped stats (abs) min: 1.0 max: 5.0 x̄: 2.06 x̃: 1 helped stats (rel) min: 0.65% max: 2.33% x̄: 1.16% x̃: 0.70% 95% mean confidence interval for tuples value: -3.01 -1.12 95% mean confidence interval for tuples %-change: -1.50% -0.83% Tuples are helped. total cycles in shared programs: 12257.10 -> 12250.81 (-0.05%) cycles in affected programs: 449.87 -> 443.58 (-1.40%) helped: 92 HURT: 0 helped stats (abs) min: 0.0416660000000002 max: 0.20833400000000069 x̄: 0.07 x̃: 0 helped stats (rel) min: 0.93% max: 2.53% x̄: 1.40% x̃: 1.26% 95% mean confidence interval for cycles value: -0.08 -0.06 95% mean confidence interval for cycles %-change: -1.48% -1.32% Cycles are helped. total arith in shared programs: 4847.33 -> 4840.25 (-0.15%) arith in affected programs: 490.37 -> 483.29 (-1.44%) helped: 109 HURT: 0 helped stats (abs) min: 0.0416660000000002 max: 0.20833400000000069 x̄: 0.06 x̃: 0 helped stats (rel) min: 0.93% max: 5.56% x̄: 1.51% x̃: 1.26% 95% mean confidence interval for arith value: -0.07 -0.06 95% mean confidence interval for arith %-change: -1.64% -1.39% Arith are helped. total quadwords in shared programs: 116775 -> 116758 (-0.01%) quadwords in affected programs: 1331 -> 1314 (-1.28%) helped: 7 HURT: 0 helped stats (abs) min: 1.0 max: 4.0 x̄: 2.43 x̃: 3 helped stats (rel) min: 0.91% max: 2.38% x̄: 1.65% x̃: 1.39% 95% mean confidence interval for quadwords value: -3.48 -1.38 95% mean confidence interval for quadwords %-change: -2.27% -1.04% Quadwords are helped. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bifrost_compile.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/panfrost/bifrost/bifrost_compile.c b/src/panfrost/bifrost/bifrost_compile.c index 6457f6b..f247715 100644 --- a/src/panfrost/bifrost/bifrost_compile.c +++ b/src/panfrost/bifrost/bifrost_compile.c @@ -2333,29 +2333,33 @@ bi_emit_cube_coord(bi_builder *b, bi_index coord, S->clamp = BI_CLAMP_CLAMP_0_1; T->clamp = BI_CLAMP_CLAMP_0_1; - /* Cube face is stored in bit[29:31], we don't apply the shift here - * because the TEXS_CUBE and TEXC instructions expect the face index to - * be at this position. - */ + /* Face index at bit[29:31], matching the cube map descriptor */ *face = cubeface->dest[1]; } /* Emits a cube map descriptor, returning lower 32-bits and putting upper - * 32-bits in passed pointer t */ + * 32-bits in passed pointer t. The packing of the face with the S coordinate + * exploits the redundancy of floating points with the range restriction of + * CUBEFACE output. + * + * struct cube_map_descriptor { + * float s : 29; + * unsigned face : 3; + * float t : 32; + * } + * + * Since the cube face index is preshifted, this is easy to pack with a bitwise + * MUX.i32 and a fixed mask, selecting the lower bits 29 from s and the upper 3 + * bits from face. + */ static bi_index bi_emit_texc_cube_coord(bi_builder *b, bi_index coord, bi_index *t) { bi_index face, s; bi_emit_cube_coord(b, coord, &face, &s, t); - - bi_index and1 = bi_lshift_and_i32(b, face, bi_imm_u32(0xe0000000), - bi_imm_u8(0)); - - bi_index and2 = bi_lshift_and_i32(b, s, bi_imm_u32(0x1fffffff), - bi_imm_u8(0)); - - return bi_lshift_or_i32(b, and1, and2, bi_imm_u8(0)); + bi_index mask = bi_imm_u32(BITFIELD_MASK(29)); + return bi_mux_i32(b, s, face, mask, BI_MUX_BIT); } /* Map to the main texture op used. Some of these (txd in particular) will -- 2.7.4