From 9b8cb9f5aee3428e49d80b2154718cae6c29938c Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 9 Mar 2020 20:19:29 -0400 Subject: [PATCH] panfrost: Move mir_to_bytemask to common code ...also so we can start sharing code properly between the panfrost compilers. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/compiler.h | 1 + src/panfrost/bifrost/meson.build | 1 + src/panfrost/meson.build | 1 + src/panfrost/midgard/compiler.h | 2 +- src/panfrost/midgard/meson.build | 1 + src/panfrost/midgard/midgard_compile.c | 2 +- src/panfrost/midgard/mir.c | 49 +---------------------- src/panfrost/util/meson.build | 34 ++++++++++++++++ src/panfrost/util/pan_ir.c | 72 ++++++++++++++++++++++++++++++++++ src/panfrost/util/pan_ir.h | 32 +++++++++++++++ 10 files changed, 146 insertions(+), 49 deletions(-) create mode 100644 src/panfrost/util/meson.build create mode 100644 src/panfrost/util/pan_ir.c create mode 100644 src/panfrost/util/pan_ir.h diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index 3b27940..14e0bc8 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -29,6 +29,7 @@ #include "bifrost.h" #include "compiler/nir/nir.h" +#include "panfrost/util/pan_ir.h" /* Bifrost opcodes are tricky -- the same op may exist on both FMA and * ADD with two completely different opcodes, and opcodes can be varying diff --git a/src/panfrost/bifrost/meson.build b/src/panfrost/bifrost/meson.build index 5eafb1b..acc54ee 100644 --- a/src/panfrost/bifrost/meson.build +++ b/src/panfrost/bifrost/meson.build @@ -33,6 +33,7 @@ libpanfrost_bifrost = static_library( [libpanfrost_bifrost_files], include_directories : [inc_common, inc_include, inc_src], dependencies: [idep_nir], + link_with: [libpanfrost_util], c_args : [c_vis_args, no_override_init_args], cpp_args : [cpp_vis_args], build_by_default : false, diff --git a/src/panfrost/meson.build b/src/panfrost/meson.build index aecbb70..6ea0739 100644 --- a/src/panfrost/meson.build +++ b/src/panfrost/meson.build @@ -28,6 +28,7 @@ inc_panfrost = include_directories([ ]) subdir('shared') +subdir('util') subdir('midgard') subdir('bifrost') subdir('pandecode') diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h index 8ee99ab..51ac956 100644 --- a/src/panfrost/midgard/compiler.h +++ b/src/panfrost/midgard/compiler.h @@ -38,6 +38,7 @@ #include "main/mtypes.h" #include "compiler/nir_types.h" #include "compiler/nir/nir.h" +#include "panfrost/util/pan_ir.h" /* Forward declare */ struct midgard_block; @@ -553,7 +554,6 @@ midgard_reg_mode mir_srcsize(midgard_instruction *ins, unsigned i); unsigned mir_bytes_for_mode(midgard_reg_mode mode); midgard_reg_mode mir_mode_for_destsize(unsigned size); uint16_t mir_from_bytemask(uint16_t bytemask, midgard_reg_mode mode); -uint16_t mir_to_bytemask(midgard_reg_mode mode, unsigned mask); uint16_t mir_bytemask(midgard_instruction *ins); uint16_t mir_round_bytemask_up(uint16_t mask, midgard_reg_mode mode); void mir_set_bytemask(midgard_instruction *ins, uint16_t bytemask); diff --git a/src/panfrost/midgard/meson.build b/src/panfrost/midgard/meson.build index af2c09d..ba69b3f 100644 --- a/src/panfrost/midgard/meson.build +++ b/src/panfrost/midgard/meson.build @@ -68,6 +68,7 @@ libpanfrost_midgard = static_library( dependencies: [ idep_nir ], + link_with: [libpanfrost_util], c_args : [c_vis_args, no_override_init_args], cpp_args : [cpp_vis_args], build_by_default : false, diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c index eb50e21..a312f5e 100644 --- a/src/panfrost/midgard/midgard_compile.c +++ b/src/panfrost/midgard/midgard_compile.c @@ -1216,7 +1216,7 @@ mir_set_intr_mask(nir_instr *instr, midgard_instruction *ins, bool is_read) } /* Once we have the NIR mask, we need to normalize to work in 32-bit space */ - unsigned bytemask = mir_to_bytemask(mir_mode_for_destsize(dsize), nir_mask); + unsigned bytemask = pan_to_bytemask(dsize, nir_mask); mir_set_bytemask(ins, bytemask); if (dsize == 64) diff --git a/src/panfrost/midgard/mir.c b/src/panfrost/midgard/mir.c index 2acfe44..772b695 100644 --- a/src/panfrost/midgard/mir.c +++ b/src/panfrost/midgard/mir.c @@ -310,51 +310,6 @@ mir_mode_for_destsize(unsigned size) } } - -/* Converts per-component mask to a byte mask */ - -uint16_t -mir_to_bytemask(midgard_reg_mode mode, unsigned mask) -{ - switch (mode) { - case midgard_reg_mode_8: - return mask; - - case midgard_reg_mode_16: { - unsigned space = - (mask & 0x1) | - ((mask & 0x2) << (2 - 1)) | - ((mask & 0x4) << (4 - 2)) | - ((mask & 0x8) << (6 - 3)) | - ((mask & 0x10) << (8 - 4)) | - ((mask & 0x20) << (10 - 5)) | - ((mask & 0x40) << (12 - 6)) | - ((mask & 0x80) << (14 - 7)); - - return space | (space << 1); - } - - case midgard_reg_mode_32: { - unsigned space = - (mask & 0x1) | - ((mask & 0x2) << (4 - 1)) | - ((mask & 0x4) << (8 - 2)) | - ((mask & 0x8) << (12 - 3)); - - return space | (space << 1) | (space << 2) | (space << 3); - } - - case midgard_reg_mode_64: { - unsigned A = (mask & 0x1) ? 0xFF : 0x00; - unsigned B = (mask & 0x2) ? 0xFF : 0x00; - return A | (B << 8); - } - - default: - unreachable("Invalid register mode"); - } -} - /* ...and the inverse */ unsigned @@ -417,7 +372,7 @@ mir_round_bytemask_up(uint16_t mask, midgard_reg_mode mode) uint16_t mir_bytemask(midgard_instruction *ins) { - return mir_to_bytemask(mir_typesize(ins), ins->mask); + return pan_to_bytemask(mir_bytes_for_mode(mir_typesize(ins)) * 8, ins->mask); } void @@ -473,7 +428,7 @@ mir_bytemask_of_read_components_single(unsigned *swizzle, unsigned inmask, midga cmask |= (1 << swizzle[c]); } - return mir_to_bytemask(mode, cmask); + return pan_to_bytemask(mir_bytes_for_mode(mode) * 8, cmask); } uint16_t diff --git a/src/panfrost/util/meson.build b/src/panfrost/util/meson.build new file mode 100644 index 0000000..63ca756 --- /dev/null +++ b/src/panfrost/util/meson.build @@ -0,0 +1,34 @@ +# Copyright © 2018 Rob Clark +# Copyright © 2019 Collabora + +# 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 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. + +libpanfrost_util_files = files( + 'pan_ir.c', + 'pan_ir.h', +) + +libpanfrost_util = static_library( + 'panfrost_util', + [libpanfrost_util_files], + include_directories : [inc_common], + c_args : [c_vis_args, no_override_init_args], + cpp_args : [cpp_vis_args], + build_by_default : false, +) diff --git a/src/panfrost/util/pan_ir.c b/src/panfrost/util/pan_ir.c new file mode 100644 index 0000000..95f8e6b --- /dev/null +++ b/src/panfrost/util/pan_ir.c @@ -0,0 +1,72 @@ +/* + * 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. + * + * Authors (Collabora): + * Alyssa Rosenzweig + */ + +#include "pan_ir.h" +#include "util/macros.h" + +/* Converts a per-component mask to a byte mask */ + +uint16_t +pan_to_bytemask(unsigned bytes, unsigned mask) +{ + switch (bytes) { + case 8: + return mask; + + case 16: { + unsigned space = + (mask & 0x1) | + ((mask & 0x2) << (2 - 1)) | + ((mask & 0x4) << (4 - 2)) | + ((mask & 0x8) << (6 - 3)) | + ((mask & 0x10) << (8 - 4)) | + ((mask & 0x20) << (10 - 5)) | + ((mask & 0x40) << (12 - 6)) | + ((mask & 0x80) << (14 - 7)); + + return space | (space << 1); + } + + case 32: { + unsigned space = + (mask & 0x1) | + ((mask & 0x2) << (4 - 1)) | + ((mask & 0x4) << (8 - 2)) | + ((mask & 0x8) << (12 - 3)); + + return space | (space << 1) | (space << 2) | (space << 3); + } + + case 64: { + unsigned A = (mask & 0x1) ? 0xFF : 0x00; + unsigned B = (mask & 0x2) ? 0xFF : 0x00; + return A | (B << 8); + } + + default: + unreachable("Invalid register mode"); + } +} diff --git a/src/panfrost/util/pan_ir.h b/src/panfrost/util/pan_ir.h new file mode 100644 index 0000000..e6cb7e5 --- /dev/null +++ b/src/panfrost/util/pan_ir.h @@ -0,0 +1,32 @@ +/* + * 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 __PAN_IR_H +#define __PAN_IR_H + +#include + +uint16_t +pan_to_bytemask(unsigned bytes, unsigned mask); + +#endif -- 2.7.4