From 3fadd8234611837798311ff1ace7a39c1cc3adc4 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 14 Sep 2020 13:44:52 -0400 Subject: [PATCH] pan/bi: Move packing helpers to dedicated file We'll need to access them from the autogenerated section. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Daniel Stone Part-of: --- src/panfrost/bifrost/bi_pack.c | 52 +--------------- src/panfrost/bifrost/bi_pack_helpers.h | 84 ++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 51 deletions(-) create mode 100644 src/panfrost/bifrost/bi_pack_helpers.h diff --git a/src/panfrost/bifrost/bi_pack.c b/src/panfrost/bifrost/bi_pack.c index b16a670e582..aa0db55ab5f 100644 --- a/src/panfrost/bifrost/bi_pack.c +++ b/src/panfrost/bifrost/bi_pack.c @@ -23,6 +23,7 @@ #include "compiler.h" #include "bi_print.h" +#include "bi_pack_helpers.h" #define RETURN_PACKED(str) { \ uint64_t temp = 0; \ @@ -401,57 +402,6 @@ bi_pack_registers(bi_registers regs) return packed; } -static void -bi_set_data_register(bi_clause *clause, unsigned idx) -{ - assert(idx & BIR_INDEX_REGISTER); - unsigned reg = idx & ~BIR_INDEX_REGISTER; - assert(reg <= 63); - clause->data_register = reg; -} - -static void -bi_read_data_register(bi_clause *clause, bi_instruction *ins) -{ - bi_set_data_register(clause, ins->src[0]); -} - -static void -bi_write_data_register(bi_clause *clause, bi_instruction *ins) -{ - bi_set_data_register(clause, ins->dest); -} - -static enum bifrost_packed_src -bi_get_src_reg_port(bi_registers *regs, unsigned src) -{ - unsigned reg = src & ~BIR_INDEX_REGISTER; - - if (regs->port[0] == reg && regs->enabled[0]) - return BIFROST_SRC_PORT0; - else if (regs->port[1] == reg && regs->enabled[1]) - return BIFROST_SRC_PORT1; - else if (regs->port[3] == reg && regs->read_port3) - return BIFROST_SRC_PORT3; - else - unreachable("Tried to access register with no port"); -} - -static enum bifrost_packed_src -bi_get_src(bi_instruction *ins, bi_registers *regs, unsigned s) -{ - unsigned src = ins->src[s]; - - if (src & BIR_INDEX_REGISTER) - return bi_get_src_reg_port(regs, src); - else if (src & BIR_INDEX_PASS) - return src & ~BIR_INDEX_PASS; - else { - bi_print_instruction(ins, stderr); - unreachable("Unknown src in above instruction"); - } -} - /* Constructs a packed 2-bit swizzle for a 16-bit vec2 source. Source must be * 16-bit and written components must correspond to valid swizzles (component x * or y). */ diff --git a/src/panfrost/bifrost/bi_pack_helpers.h b/src/panfrost/bifrost/bi_pack_helpers.h new file mode 100644 index 00000000000..d806d332703 --- /dev/null +++ b/src/panfrost/bifrost/bi_pack_helpers.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2020 Collabora, Ltd. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#ifndef __BI_PACK_HELPERS_H +#define __BI_PACK_HELPERS_H + +/* Helpers used by the autogenerated packing routines */ + +#include "compiler.h" + +static inline void +bi_set_data_register(bi_clause *clause, unsigned idx) +{ + assert(idx & BIR_INDEX_REGISTER); + unsigned reg = idx & ~BIR_INDEX_REGISTER; + assert(reg <= 63); + clause->data_register = reg; +} + +static inline void +bi_read_data_register(bi_clause *clause, bi_instruction *ins) +{ + bi_set_data_register(clause, ins->src[0]); +} + +static inline void +bi_write_data_register(bi_clause *clause, bi_instruction *ins) +{ + bi_set_data_register(clause, ins->dest); +} + +static inline enum bifrost_packed_src +bi_get_src_reg_port(bi_registers *regs, unsigned src) +{ + unsigned reg = src & ~BIR_INDEX_REGISTER; + + if (regs->port[0] == reg && regs->enabled[0]) + return BIFROST_SRC_PORT0; + else if (regs->port[1] == reg && regs->enabled[1]) + return BIFROST_SRC_PORT1; + else if (regs->port[3] == reg && regs->read_port3) + return BIFROST_SRC_PORT3; + else + unreachable("Tried to access register with no port"); +} + +static inline enum bifrost_packed_src +bi_get_src(bi_instruction *ins, bi_registers *regs, unsigned s) +{ + unsigned src = ins->src[s]; + + if (src & BIR_INDEX_REGISTER) + return bi_get_src_reg_port(regs, src); + else if (src & BIR_INDEX_PASS) + return src & ~BIR_INDEX_PASS; + else { +#ifndef NDEBUG + bi_print_instruction(ins, stderr); +#endif + unreachable("Unknown src in above instruction"); + } +} + +#endif