From 3a9210c93dcf741ec77cd249cc31703b9f98ff5a Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Thu, 4 Nov 2021 14:28:01 -0700 Subject: [PATCH] pan/bi: Make some headers compilable with C++ This will allow have tests that use gtest (which is C++) for. Note the reordering of designated initializers in structs is because C++ requires them to follow the order that they were defined in the struct. The table `bifrost_reg_ctrl_lut` is not used by the tests at the moment, so bailed out trying to replace the C syntax designated initializer for arrays (that doesn't have an equivalent in C++), and simply #ifdef it out when including from C++ code. Also, use not_mod instead of not. not is a keyword in C++ and can't be used. Luckily, the naming is not determined by the XML, so we can freely rename. [Alyssa: squash in not_mod] Reviewed-by: Dylan Baker Reviewed-by: Alyssa Rosenzweig Part-of: --- src/panfrost/bifrost/bi_opcodes.h.py | 2 +- src/panfrost/bifrost/bifrost.h | 16 +++++++++++--- src/panfrost/bifrost/compiler.h | 32 +++++++++++++++++----------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/panfrost/bifrost/bi_opcodes.h.py b/src/panfrost/bifrost/bi_opcodes.h.py index 2c3f915baf9..3b8ff0b33d8 100644 --- a/src/panfrost/bifrost/bi_opcodes.h.py +++ b/src/panfrost/bifrost/bi_opcodes.h.py @@ -95,7 +95,7 @@ struct bi_op_props { bool not_result : 1; unsigned abs : 3; unsigned neg : 3; - bool not : 1; + bool not_mod : 1; }; /* Generated in bi_opcodes.c.py */ diff --git a/src/panfrost/bifrost/bifrost.h b/src/panfrost/bifrost/bifrost.h index b0b8495ed2c..d9c567fa59e 100644 --- a/src/panfrost/bifrost/bifrost.h +++ b/src/panfrost/bifrost/bifrost.h @@ -30,6 +30,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define BIFROST_DBG_MSGS 0x0001 #define BIFROST_DBG_SHADERS 0x0002 #define BIFROST_DBG_SHADERDB 0x0004 @@ -270,9 +274,9 @@ enum bi_clause_subword { BI_CLAUSE_SUBWORD_UPPER_56 = BI_CLAUSE_SUBWORD_UPPER_0 + 56, }; -#define L(x) (BI_CLAUSE_SUBWORD_LITERAL_0 + x) -#define U(x) (BI_CLAUSE_SUBWORD_UPPER_0 + x) -#define T(x) (BI_CLAUSE_SUBWORD_TUPLE_0 + x) +#define L(x) ((enum bi_clause_subword)(BI_CLAUSE_SUBWORD_LITERAL_0 + x)) +#define U(x) ((enum bi_clause_subword)(BI_CLAUSE_SUBWORD_UPPER_0 + x)) +#define T(x) ((enum bi_clause_subword)(BI_CLAUSE_SUBWORD_TUPLE_0 + x)) #define EC BI_CLAUSE_SUBWORD_CONSTANT #define M BI_CLAUSE_SUBWORD_M #define Z BI_CLAUSE_SUBWORD_Z @@ -371,6 +375,7 @@ struct bifrost_reg_ctrl_23 { bool slot3_fma; }; +#ifndef __cplusplus static const struct bifrost_reg_ctrl_23 bifrost_reg_ctrl_lut[32] = { [BIFROST_R_WL_FMA] = { BIFROST_OP_READ, BIFROST_OP_WRITE_LO, true }, [BIFROST_R_WH_FMA] = { BIFROST_OP_READ, BIFROST_OP_WRITE_HI, true }, @@ -399,6 +404,7 @@ static const struct bifrost_reg_ctrl_23 bifrost_reg_ctrl_lut[32] = { [BIFROST_WH_WL_MIX] = { BIFROST_OP_WRITE_HI, BIFROST_OP_WRITE_LO, false }, [BIFROST_IDLE] = { BIFROST_OP_IDLE, BIFROST_OP_IDLE, true }, }; +#endif /* Texture operator descriptors in various states. Usually packed in the * compiler and stored as a constant */ @@ -576,4 +582,8 @@ bi_constant_field(unsigned idx) return values[idx] << 4; } +#ifdef __cplusplus +} /* extern C */ +#endif + #endif diff --git a/src/panfrost/bifrost/compiler.h b/src/panfrost/bifrost/compiler.h index 72a878f13b8..a734c60ea28 100644 --- a/src/panfrost/bifrost/compiler.h +++ b/src/panfrost/bifrost/compiler.h @@ -34,6 +34,10 @@ #include "util/u_math.h" #include "util/half_float.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Swizzles across bytes in a 32-bit word. Expresses swz in the XML directly. * To express widen, use the correpsonding replicated form, i.e. H01 = identity * for widen = none, H00 for widen = h0, B1111 for widen = b1. For lane, also @@ -134,11 +138,11 @@ static inline bi_index bi_get_index(unsigned value, bool is_reg, unsigned offset) { return (bi_index) { - .type = BI_INDEX_NORMAL, .value = value, .swizzle = BI_SWIZZLE_H01, .offset = offset, .reg = is_reg, + .type = BI_INDEX_NORMAL, }; } @@ -148,9 +152,9 @@ bi_register(unsigned reg) assert(reg < 64); return (bi_index) { - .type = BI_INDEX_REGISTER, + .value = reg, .swizzle = BI_SWIZZLE_H01, - .value = reg + .type = BI_INDEX_REGISTER, }; } @@ -158,9 +162,9 @@ static inline bi_index bi_imm_u32(uint32_t imm) { return (bi_index) { - .type = BI_INDEX_CONSTANT, + .value = imm, .swizzle = BI_SWIZZLE_H01, - .value = imm + .type = BI_INDEX_CONSTANT, }; } @@ -186,9 +190,9 @@ static inline bi_index bi_passthrough(enum bifrost_packed_src value) { return (bi_index) { - .type = BI_INDEX_PASS, + .value = value, .swizzle = BI_SWIZZLE_H01, - .value = value + .type = BI_INDEX_PASS, }; } @@ -212,7 +216,7 @@ static inline bi_index bi_swz_16(bi_index idx, bool x, bool y) { assert(idx.swizzle == BI_SWIZZLE_H01); - idx.swizzle = BI_SWIZZLE_H00 | (x << 1) | y; + idx.swizzle = (enum bi_swizzle)(BI_SWIZZLE_H00 | (x << 1) | y); return idx; } @@ -227,7 +231,7 @@ bi_byte(bi_index idx, unsigned lane) { assert(idx.swizzle == BI_SWIZZLE_H01); assert(lane < 4); - idx.swizzle = BI_SWIZZLE_B0000 + lane; + idx.swizzle = (enum bi_swizzle)(BI_SWIZZLE_B0000 + lane); return idx; } @@ -676,10 +680,10 @@ static inline bi_index bi_fau(enum bir_fau value, bool hi) { return (bi_index) { - .type = BI_INDEX_FAU, .value = value, .swizzle = BI_SWIZZLE_H01, - .offset = hi ? 1 : 0 + .offset = hi ? 1u : 0u, + .type = BI_INDEX_FAU, }; } @@ -742,7 +746,7 @@ static inline bi_index bi_node_to_index(unsigned node, unsigned node_count) { assert(node < node_count); - assert(node_count < ~0); + assert(node_count < ~0u); return bi_get_index(node >> 1, node & PAN_IS_REG, 0); } @@ -1162,4 +1166,8 @@ bi_word_node(bi_index idx) bool bi_lower_divergent_indirects(nir_shader *shader, unsigned lanes); +#ifdef __cplusplus +} /* extern C */ +#endif + #endif