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 <alyssa.rosenzweig@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4139>
This commit is contained in:
committed by
Marge Bot
parent
ba03e308b6
commit
9b8cb9f5ae
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -28,6 +28,7 @@ inc_panfrost = include_directories([
|
||||
])
|
||||
|
||||
subdir('shared')
|
||||
subdir('util')
|
||||
subdir('midgard')
|
||||
subdir('bifrost')
|
||||
subdir('pandecode')
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
@@ -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 <alyssa.rosenzweig@collabora.com>
|
||||
*/
|
||||
|
||||
#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");
|
||||
}
|
||||
}
|
||||
@@ -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 <stdint.h>
|
||||
|
||||
uint16_t
|
||||
pan_to_bytemask(unsigned bytes, unsigned mask);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user