pco/usclib: add some preprocessor helper macros

Signed-off-by: Simon Perretta <simon.perretta@imgtec.com>
Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37439>
This commit is contained in:
Simon Perretta
2025-08-19 13:11:57 +01:00
parent fd130c5d8b
commit 6100c5287a
2 changed files with 90 additions and 0 deletions
+1
View File
@@ -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);
+89
View File
@@ -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 */