From 6100c5287ac712fc4a9809593094a17c4da7c38b Mon Sep 17 00:00:00 2001 From: Simon Perretta Date: Tue, 19 Aug 2025 13:11:57 +0100 Subject: [PATCH] pco/usclib: add some preprocessor helper macros Signed-off-by: Simon Perretta Acked-by: Erik Faye-Lund Part-of: --- src/imagination/pco/usclib/libcl.h | 1 + src/imagination/pco/usclib/pp_macros.h | 89 ++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/imagination/pco/usclib/pp_macros.h diff --git a/src/imagination/pco/usclib/libcl.h b/src/imagination/pco/usclib/libcl.h index f70d4a9d1f3..617ff9f1049 100644 --- a/src/imagination/pco/usclib/libcl.h +++ b/src/imagination/pco/usclib/libcl.h @@ -9,6 +9,7 @@ #include "compiler/libcl/libcl.h" #include "compiler/shader_enums.h" #include "pco/pco_common.h" +#include "pp_macros.h" void nir_mutex_pco(enum pco_mutex_id mutex_id, enum pco_mutex_op mutex_op); uint32_t nir_load_instance_num_pco(void); diff --git a/src/imagination/pco/usclib/pp_macros.h b/src/imagination/pco/usclib/pp_macros.h new file mode 100644 index 00000000000..13f1a51d6b3 --- /dev/null +++ b/src/imagination/pco/usclib/pp_macros.h @@ -0,0 +1,89 @@ +/* + * Copyright © 2025 Imagination Technologies Ltd. + * SPDX-License-Identifier: MIT + */ + +#ifndef PCO_PP_MACROS_H +#define PCO_PP_MACROS_H + +#define _NUM_ARGS(_0, \ + _1, \ + _2, \ + _3, \ + _4, \ + _5, \ + _6, \ + _7, \ + _8, \ + _9, \ + _10, \ + _11, \ + _12, \ + _13, \ + _14, \ + _15, \ + _16, \ + N, \ + ...) \ + N + +/* Returns the numbers of arguments passed to the macro. */ +#define NUM_ARGS(...) \ + _NUM_ARGS(_, \ + ##__VA_ARGS__, \ + 16, \ + 15, \ + 14, \ + 13, \ + 12, \ + 11, \ + 10, \ + 9, \ + 8, \ + 7, \ + 6, \ + 5, \ + 4, \ + 3, \ + 2, \ + 1, \ + 0) + +/* Returns the numbers of arguments passed to the macro + 2. */ +#define NUM_ARGS_PLUS_2(...) \ + _NUM_ARGS(_, \ + ##__VA_ARGS__, \ + 18, \ + 17, \ + 16, \ + 15, \ + 14, \ + 13, \ + 12, \ + 11, \ + 10, \ + 9, \ + 8, \ + 7, \ + 6, \ + 5, \ + 4, \ + 3, \ + 2) + +#define _CAT2(a, b) a##b + +/* Concatenates two tokens. */ +#define CAT2(a, b) _CAT2(a, b) + +#define _CAT3(a, b, c) a##b##c + +/* Concatenates three tokens. */ +#define CAT3(a, b, c) _CAT3(a, b, c) + +/* Constructs a function name from its base name, separator, and the number of + * args passed to it. + */ +#define SELECT_NAME(f, sep, ...) CAT3(f, sep, NUM_ARGS(__VA_ARGS__)) + +#endif /* ifndef PCO_PP_MACROS_H */