Mesa (main): pan/bi: Teach meson about Bifrost packing test

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jul 28 22:36:05 UTC 2021


Module: Mesa
Branch: main
Commit: 8a6c214b6a55b4ca538b2b33f1258b474fd70595
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8a6c214b6a55b4ca538b2b33f1258b474fd70595

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Wed Jul 28 12:33:00 2021 -0400

pan/bi: Teach meson about Bifrost packing test

Signed-off-by: Alyssa Rosenzweig <alyssa at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12109>

---

 src/panfrost/bifrost/bi_pack.c           | 101 +++-------------------------
 src/panfrost/bifrost/cmdline.c           |   1 -
 src/panfrost/bifrost/compiler.h          |  21 +++++-
 src/panfrost/bifrost/meson.build         |  14 ++++
 src/panfrost/bifrost/test/test-packing.c | 109 +++++++++++++++++++++++++++++++
 5 files changed, 152 insertions(+), 94 deletions(-)

diff --git a/src/panfrost/bifrost/bi_pack.c b/src/panfrost/bifrost/bi_pack.c
index 01b7ea5d20f..e326a1f7e06 100644
--- a/src/panfrost/bifrost/bi_pack.c
+++ b/src/panfrost/bifrost/bi_pack.c
@@ -430,7 +430,7 @@ bi_pack_constants(unsigned tuple_count, uint64_t *constants,
         util_dynarray_append(emission, struct bifrost_fmt_constant, quad);
 }
 
-static inline uint8_t
+uint8_t
 bi_pack_literal(enum bi_clause_subword literal)
 {
         assert(literal >= BI_CLAUSE_SUBWORD_LITERAL_0);
@@ -451,7 +451,7 @@ bi_clause_upper(unsigned val,
         return (tuple.hi >> 11);
 }
 
-static inline uint8_t
+uint8_t
 bi_pack_upper(enum bi_clause_subword upper,
                 struct bi_packed_tuple *tuples,
                 ASSERTED unsigned tuple_count)
@@ -463,7 +463,7 @@ bi_pack_upper(enum bi_clause_subword upper,
                         tuple_count);
 }
 
-static inline uint64_t
+uint64_t
 bi_pack_tuple_bits(enum bi_clause_subword idx,
                 struct bi_packed_tuple *tuples,
                 ASSERTED unsigned tuple_count,
@@ -510,13 +510,13 @@ bi_pack_lu(enum bi_clause_subword word,
                 bi_pack_literal(word);
 }
 
-static uint8_t
+uint8_t
 bi_pack_sync(enum bi_clause_subword t1,
-                enum bi_clause_subword t2,
-                enum bi_clause_subword t3,
-                struct bi_packed_tuple *tuples,
-                ASSERTED unsigned tuple_count,
-                bool z)
+             enum bi_clause_subword t2,
+             enum bi_clause_subword t3,
+             struct bi_packed_tuple *tuples,
+             ASSERTED unsigned tuple_count,
+             bool z)
 {
         uint8_t sync =
                 (bi_pack_lu(t3, tuples, tuple_count) << 0) |
@@ -745,86 +745,3 @@ bi_pack(bi_context *ctx, struct util_dynarray *emission)
 
         return emission->size - previous_size;
 }
-
-#ifndef NDEBUG
-
-static void
-bi_test_pack_literal(void)
-{
-        for (unsigned x = 0; x <= 7; ++x)
-                assert(bi_pack_literal(BI_CLAUSE_SUBWORD_LITERAL_0 + x) == x);
-}
-
-static void
-bi_test_pack_upper(void)
-{
-        struct bi_packed_tuple tuples[] = {
-                { 0, 0x3 << (75 - 64) },
-                { 0, 0x1 << (75 - 64) },
-                { 0, 0x7 << (75 - 64) },
-                { 0, 0x0 << (75 - 64) },
-                { 0, 0x2 << (75 - 64) },
-                { 0, 0x6 << (75 - 64) },
-                { 0, 0x5 << (75 - 64) },
-                { 0, 0x4 << (75 - 64) },
-        };
-
-        assert(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 0, tuples, 8) == 3);
-        assert(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 1, tuples, 8) == 1);
-        assert(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 2, tuples, 8) == 7);
-        assert(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 3, tuples, 8) == 0);
-        assert(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 4, tuples, 8) == 2);
-        assert(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 5, tuples, 8) == 6);
-        assert(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 6, tuples, 8) == 5);
-        assert(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 7, tuples, 8) == 4);
-}
-
-static void
-bi_test_pack_tuple_bits(void)
-{
-        struct bi_packed_tuple tuples[] = {
-                { 0x1234567801234567, 0x3A },
-                { 0x9876543299999999, 0x1B },
-                { 0xABCDEF0101234567, 0x7C },
-        };
-
-        assert(bi_pack_tuple_bits(BI_CLAUSE_SUBWORD_TUPLE_0 + 0, tuples, 8, 0, 30) == 0x01234567);
-        assert(bi_pack_tuple_bits(BI_CLAUSE_SUBWORD_TUPLE_0 + 1, tuples, 8, 10, 30) == 0xca66666);
-        assert(bi_pack_tuple_bits(BI_CLAUSE_SUBWORD_TUPLE_0 + 2, tuples, 8, 40, 15) == 0x4def);
-}
-
-#define L(x) (BI_CLAUSE_SUBWORD_LITERAL_0 + x)
-#define U(x) (BI_CLAUSE_SUBWORD_UPPER_0 + x)
-#define Z    BI_CLAUSE_SUBWORD_Z
-
-static void
-bi_test_pack_sync(void)
-{
-        struct bi_packed_tuple tuples[] = {
-                { 0, 0x3 << (75 - 64) },
-                { 0, 0x5 << (75 - 64) },
-                { 0, 0x7 << (75 - 64) },
-                { 0, 0x0 << (75 - 64) },
-                { 0, 0x2 << (75 - 64) },
-                { 0, 0x6 << (75 - 64) },
-                { 0, 0x5 << (75 - 64) },
-                { 0, 0x4 << (75 - 64) },
-        };
-
-        assert(bi_pack_sync(L(3), L(1), L(7), tuples, 8, false) == 0xCF);
-        assert(bi_pack_sync(L(3), L(1), U(7), tuples, 8, false) == 0xCC);
-        assert(bi_pack_sync(L(3), U(1), U(7), tuples, 8, false) == 0xEC);
-        assert(bi_pack_sync(Z,    U(1), U(7), tuples, 8, false) == 0x2C);
-        assert(bi_pack_sync(Z,    U(1), U(7), tuples, 8, true)  == 0x6C);
-}
-
-int bi_test_packing(void)
-{
-        bi_test_pack_literal();
-        bi_test_pack_upper();
-        bi_test_pack_tuple_bits();
-        bi_test_pack_sync();
-
-        return 0;
-}
-#endif
diff --git a/src/panfrost/bifrost/cmdline.c b/src/panfrost/bifrost/cmdline.c
index de51548e472..7539fbcaf96 100644
--- a/src/panfrost/bifrost/cmdline.c
+++ b/src/panfrost/bifrost/cmdline.c
@@ -248,7 +248,6 @@ static int
 bi_tests()
 {
 #ifndef NDEBUG
-        bi_test_packing();
         bi_test_packing_formats();
         printf("Pass.\n");
         return 0;
diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h
index e66e8afe8cc..9319ded3b9d 100644
--- a/src/panfrost/bifrost/compiler.h
+++ b/src/panfrost/bifrost/compiler.h
@@ -908,7 +908,6 @@ uint32_t bi_fold_constant(bi_instr *I, bool *unsupported);
 void bi_opt_constant_fold(bi_context *ctx);
 
 /* Test suite */
-int bi_test_packing(void);
 int bi_test_packing_formats(void);
 
 /* Liveness */
@@ -947,6 +946,26 @@ struct bi_packed_tuple {
         uint64_t hi;
 };
 
+uint8_t bi_pack_literal(enum bi_clause_subword literal);
+
+uint8_t
+bi_pack_upper(enum bi_clause_subword upper,
+                struct bi_packed_tuple *tuples,
+                ASSERTED unsigned tuple_count);
+uint64_t
+bi_pack_tuple_bits(enum bi_clause_subword idx,
+                struct bi_packed_tuple *tuples,
+                ASSERTED unsigned tuple_count,
+                unsigned offset, unsigned nbits);
+
+uint8_t
+bi_pack_sync(enum bi_clause_subword t1,
+             enum bi_clause_subword t2,
+             enum bi_clause_subword t3,
+             struct bi_packed_tuple *tuples,
+             ASSERTED unsigned tuple_count,
+             bool z);
+
 void
 bi_pack_format(struct util_dynarray *emission,
                 unsigned index,
diff --git a/src/panfrost/bifrost/meson.build b/src/panfrost/bifrost/meson.build
index 0bcf9832956..186a87a02fe 100644
--- a/src/panfrost/bifrost/meson.build
+++ b/src/panfrost/bifrost/meson.build
@@ -156,6 +156,20 @@ if with_tests
     suite : ['panfrost'],
   )
 
+  test(
+    'bifrost_packing',
+    executable(
+      'bifrost_packing_test',
+      files('test/test-packing.c'),
+      c_args : [c_msvc_compat_args, no_override_init_args],
+      gnu_symbol_visibility : 'hidden',
+      include_directories : [inc_include, inc_src, inc_mesa],
+      dependencies: [idep_nir, idep_bi_opcodes_h, idep_bi_builder_h],
+      link_with : [libpanfrost_bifrost],
+    ),
+    suite : ['panfrost'],
+  )
+
   test(
     'bifrost_constant_fold',
     executable(
diff --git a/src/panfrost/bifrost/test/test-packing.c b/src/panfrost/bifrost/test/test-packing.c
new file mode 100644
index 00000000000..5c8c8df9229
--- /dev/null
+++ b/src/panfrost/bifrost/test/test-packing.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2021 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"
+
+unsigned nr_pass = 0;
+unsigned nr_fail = 0;
+
+static void
+bi_test_pack_literal(void)
+{
+   for (unsigned x = 0; x <= 7; ++x)
+      BIT_ASSERT(bi_pack_literal(BI_CLAUSE_SUBWORD_LITERAL_0 + x) == x);
+}
+
+static void
+bi_test_pack_upper(void)
+{
+   struct bi_packed_tuple tuples[] = {
+      { 0, 0x3 << (75 - 64) },
+      { 0, 0x1 << (75 - 64) },
+      { 0, 0x7 << (75 - 64) },
+      { 0, 0x0 << (75 - 64) },
+      { 0, 0x2 << (75 - 64) },
+      { 0, 0x6 << (75 - 64) },
+      { 0, 0x5 << (75 - 64) },
+      { 0, 0x4 << (75 - 64) },
+   };
+
+   BIT_ASSERT(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 0, tuples, 8) == 3);
+   BIT_ASSERT(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 1, tuples, 8) == 1);
+   BIT_ASSERT(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 2, tuples, 8) == 7);
+   BIT_ASSERT(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 3, tuples, 8) == 0);
+   BIT_ASSERT(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 4, tuples, 8) == 2);
+   BIT_ASSERT(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 5, tuples, 8) == 6);
+   BIT_ASSERT(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 6, tuples, 8) == 5);
+   BIT_ASSERT(bi_pack_upper(BI_CLAUSE_SUBWORD_UPPER_0 + 7, tuples, 8) == 4);
+}
+
+static void
+bi_test_pack_tuple_bits(void)
+{
+   struct bi_packed_tuple tuples[] = {
+      { 0x1234567801234567, 0x3A },
+      { 0x9876543299999999, 0x1B },
+      { 0xABCDEF0101234567, 0x7C },
+   };
+
+   BIT_ASSERT(bi_pack_tuple_bits(BI_CLAUSE_SUBWORD_TUPLE_0 + 0, tuples, 8, 0, 30) == 0x01234567);
+   BIT_ASSERT(bi_pack_tuple_bits(BI_CLAUSE_SUBWORD_TUPLE_0 + 1, tuples, 8, 10, 30) == 0xca66666);
+   BIT_ASSERT(bi_pack_tuple_bits(BI_CLAUSE_SUBWORD_TUPLE_0 + 2, tuples, 8, 40, 15) == 0x4def);
+}
+
+#define L(x) (BI_CLAUSE_SUBWORD_LITERAL_0 + x)
+#define U(x) (BI_CLAUSE_SUBWORD_UPPER_0 + x)
+#define Z    BI_CLAUSE_SUBWORD_Z
+
+static void
+bi_test_pack_sync(void)
+{
+   struct bi_packed_tuple tuples[] = {
+      { 0, 0x3 << (75 - 64) },
+      { 0, 0x5 << (75 - 64) },
+      { 0, 0x7 << (75 - 64) },
+      { 0, 0x0 << (75 - 64) },
+      { 0, 0x2 << (75 - 64) },
+      { 0, 0x6 << (75 - 64) },
+      { 0, 0x5 << (75 - 64) },
+      { 0, 0x4 << (75 - 64) },
+   };
+
+   BIT_ASSERT(bi_pack_sync(L(3), L(1), L(7), tuples, 8, false) == 0xCF);
+   BIT_ASSERT(bi_pack_sync(L(3), L(1), U(7), tuples, 8, false) == 0xCC);
+   BIT_ASSERT(bi_pack_sync(L(3), U(1), U(7), tuples, 8, false) == 0xEC);
+   BIT_ASSERT(bi_pack_sync(Z,    U(1), U(7), tuples, 8, false) == 0x2C);
+   BIT_ASSERT(bi_pack_sync(Z,    U(1), U(7), tuples, 8, true)  == 0x6C);
+}
+
+int
+main(int argc, const char **argv)
+{
+   bi_test_pack_literal();
+   bi_test_pack_upper();
+   bi_test_pack_tuple_bits();
+   bi_test_pack_sync();
+
+   TEST_END(nr_pass, nr_fail);
+}



More information about the mesa-commit mailing list