From d471b386c19e68e5c17ac9a3a6205b016a2cbe6b Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 22 Jun 2022 16:36:11 -0400 Subject: [PATCH] pan/bi: Unit test swizzle lowering We're about to extend this pass to support 8-bit swizzles. That will be a nontrivial change, so let's get some testing for what's already in the pass. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/meson.build | 1 + .../bifrost/test/test-lower-swizzle.cpp | 66 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 src/panfrost/bifrost/test/test-lower-swizzle.cpp diff --git a/src/panfrost/bifrost/meson.build b/src/panfrost/bifrost/meson.build index f316c1ba3ac..e6f79ac963a 100644 --- a/src/panfrost/bifrost/meson.build +++ b/src/panfrost/bifrost/meson.build @@ -164,6 +164,7 @@ if with_tests files( 'test/test-constant-fold.cpp', 'test/test-dual-texture.cpp', + 'test/test-lower-swizzle.cpp', 'test/test-message-preload.cpp', 'test/test-optimizer.cpp', 'test/test-pack-formats.cpp', diff --git a/src/panfrost/bifrost/test/test-lower-swizzle.cpp b/src/panfrost/bifrost/test/test-lower-swizzle.cpp new file mode 100644 index 00000000000..20dcde5a192 --- /dev/null +++ b/src/panfrost/bifrost/test/test-lower-swizzle.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2022 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. + */ + +#include "compiler.h" +#include "bi_test.h" +#include "bi_builder.h" + +#include + +#define CASE(instr, expected) INSTRUCTION_CASE(instr, expected, bi_lower_swizzle) +#define NEGCASE(instr) CASE(instr, instr) + +class LowerSwizzle : public testing::Test { +protected: + LowerSwizzle() { + mem_ctx = ralloc_context(NULL); + + reg = bi_register(0); + x = bi_register(1); + y = bi_register(2); + z = bi_register(3); + w = bi_register(4); + } + + ~LowerSwizzle() { + ralloc_free(mem_ctx); + } + + void *mem_ctx; + + bi_index reg, x, y, z, w; +}; + +TEST_F(LowerSwizzle, Csel16) +{ + CASE(bi_csel_v2f16_to(b, reg, bi_half(x, 0), y, z, w, BI_CMPF_NE), + bi_csel_v2f16_to(b, reg, bi_swz_v2i16(b, bi_half(x, 0)), y, z, w, BI_CMPF_NE)); +} + +TEST_F(LowerSwizzle, Fma16) +{ + NEGCASE(bi_fadd_v2f16_to(b, reg, bi_half(x, 0), y)); + NEGCASE(bi_fma_v2f16_to(b, reg, bi_half(x, 0), y, z)); +} + +