From a0a34946d8ef48223126e7ab89231f9b77e65f59 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 18 Jun 2019 15:02:44 -0700 Subject: [PATCH] panfrost/midgard: Share swizzle compose Signed-off-by: Alyssa Rosenzweig --- .../drivers/panfrost/midgard/helpers.h | 29 +++++++++++++++++++ .../drivers/panfrost/midgard/midgard_ra.c | 9 +----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/gallium/drivers/panfrost/midgard/helpers.h b/src/gallium/drivers/panfrost/midgard/helpers.h index 47672ba7c53..25def4c85b3 100644 --- a/src/gallium/drivers/panfrost/midgard/helpers.h +++ b/src/gallium/drivers/panfrost/midgard/helpers.h @@ -265,4 +265,33 @@ vector_alu_from_unsigned(unsigned u) return s; } +/* Composes two swizzles */ +static inline unsigned +pan_compose_swizzle(unsigned left, unsigned right) +{ + unsigned out = 0; + + for (unsigned c = 0; c < 4; ++c) { + unsigned s = (left >> (2*c)) & 0x3; + unsigned q = (right >> (2*s)) & 0x3; + + out |= (q << (2*c)); + } + + return out; +} + +/* Applies a swizzle to an ALU source */ + +static inline unsigned +vector_alu_apply_swizzle(unsigned src, unsigned swizzle) +{ + midgard_vector_alu_src s = + vector_alu_from_unsigned(src); + + s.swizzle = pan_compose_swizzle(s.swizzle, swizzle); + + return vector_alu_srco_unsigned(s); +} + #endif diff --git a/src/gallium/drivers/panfrost/midgard/midgard_ra.c b/src/gallium/drivers/panfrost/midgard/midgard_ra.c index 77ec65b4eae..82760aa42af 100644 --- a/src/gallium/drivers/panfrost/midgard/midgard_ra.c +++ b/src/gallium/drivers/panfrost/midgard/midgard_ra.c @@ -92,14 +92,7 @@ static unsigned compose_swizzle(unsigned swizzle, unsigned mask, struct phys_reg reg, struct phys_reg dst) { - unsigned out = 0; - - for (unsigned c = 0; c < 4; ++c) { - unsigned s = (swizzle >> (2*c)) & 0x3; - unsigned q = (reg.swizzle >> (2*s)) & 0x3; - - out |= (q << (2*c)); - } + unsigned out = pan_compose_swizzle(swizzle, reg.swizzle); /* Based on the register mask, we need to adjust over. E.g if we're * writing to yz, a base swizzle of xy__ becomes _xy_. Save the -- 2.30.2