From 7904a29340e151361421384d05bed0bdf4077b14 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 1 Apr 2020 09:41:20 -0400 Subject: [PATCH] pan/bit: Stub out BIR interpreter We'd like to step through a BIR program to evaluate it for testing. Let's stub out some infrastructure for modeling Bifrost. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/test/bi_interpret.c | 100 +++++++++++++++++++++++ src/panfrost/bifrost/test/bit.h | 10 +++ src/panfrost/meson.build | 3 +- 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/panfrost/bifrost/test/bi_interpret.c diff --git a/src/panfrost/bifrost/test/bi_interpret.c b/src/panfrost/bifrost/test/bi_interpret.c new file mode 100644 index 00000000000..fb68752c15d --- /dev/null +++ b/src/panfrost/bifrost/test/bi_interpret.c @@ -0,0 +1,100 @@ +/* + * 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 "bit.h" + +typedef union { + uint64_t u64; + uint32_t u32; + uint16_t u16[2]; + uint8_t u8[4]; + double f64; + float f32; + uint16_t f16; +} bit_t; + +/* Interprets a subset of Bifrost IR required for automated testing */ + +static uint64_t +bit_read(struct bit_state *s, bi_instruction *ins, unsigned index, nir_alu_type T) +{ + /* STUB */ + return 0; +} + +static void +bit_write(struct bit_state *s, unsigned index, nir_alu_type T, bit_t value) +{ + /* STUB */ +} + +void +bit_step(struct bit_state *s, bi_instruction *ins) +{ + /* First, load sources */ + bit_t srcs[BIR_SRC_COUNT] = { 0 }; + + bi_foreach_src(ins, src) + srcs[src].u64 = bit_read(s, ins, ins->src[src], ins->src_types[src]); + + /* Next, do the action of the instruction */ + bit_t dest = { 0 }; + + switch (ins->type) { + case BI_ADD: + case BI_ATEST: + case BI_BRANCH: + case BI_CMP: + case BI_BLEND: + case BI_BITWISE: + case BI_COMBINE: + case BI_CONVERT: + case BI_CSEL: + case BI_DISCARD: + case BI_FMA: + case BI_FREXP: + case BI_ISUB: + case BI_LOAD: + case BI_LOAD_UNIFORM: + case BI_LOAD_ATTR: + case BI_LOAD_VAR: + case BI_LOAD_VAR_ADDRESS: + case BI_MINMAX: + case BI_MOV: + case BI_SHIFT: + case BI_STORE: + case BI_STORE_VAR: + case BI_SPECIAL: /* _FAST, _TABLE on supported GPUs */ + case BI_SWIZZLE: + case BI_TEX: + case BI_ROUND: + default: + unreachable("Unsupported op"); + } + + /* Finally, store the result */ + bit_write(s, ins->dest, ins->dest_type, dest); +} diff --git a/src/panfrost/bifrost/test/bit.h b/src/panfrost/bifrost/test/bit.h index 6700bcb228e..a399c78393d 100644 --- a/src/panfrost/bifrost/test/bit.h +++ b/src/panfrost/bifrost/test/bit.h @@ -31,6 +31,7 @@ #include "panfrost/encoder/pan_device.h" #include "panfrost/encoder/pan_bo.h" #include "bifrost_compile.h" +#include "bifrost/compiler.h" struct panfrost_device * bit_initialize(void *memctx); @@ -49,6 +50,15 @@ bit_vertex(struct panfrost_device *dev, panfrost_program prog, uint32_t *iattr, size_t sz_attr, uint32_t *expected, size_t sz_expected, enum bit_debug); +/* BIT interpreter */ + +struct bit_state { + uint32_t r[64]; +}; + +void +bit_step(struct bit_state *s, bi_instruction *ins); + #endif diff --git a/src/panfrost/meson.build b/src/panfrost/meson.build index 44b483e98e2..eb2fb932f4f 100644 --- a/src/panfrost/meson.build +++ b/src/panfrost/meson.build @@ -36,7 +36,8 @@ subdir('encoder') files_bifrost = files( 'bifrost/cmdline.c', - 'bifrost/test/bi_submit.c' + 'bifrost/test/bi_submit.c', + 'bifrost/test/bi_interpret.c', ) bifrost_compiler = executable( -- 2.30.2