From ecfca8ec6fd7e282ac2f434475b1dec45e80b067 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 15 Jul 2025 16:43:50 -0400 Subject: [PATCH] util: crib SWAP macro from freedreno we have a bunch of copies across the tree, unify them. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Mel Henning Part-of: --- src/freedreno/common/freedreno_common.h | 11 +---------- src/gallium/drivers/etnaviv/etnaviv_ml.h | 11 +---------- src/intel/compiler/brw_opt_bank_conflicts.cpp | 10 +--------- src/intel/compiler/elk/elk_fs_bank_conflicts.cpp | 10 +--------- src/util/macros.h | 10 ++++++++++ 5 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/freedreno/common/freedreno_common.h b/src/freedreno/common/freedreno_common.h index 56687688343..83f9674af65 100644 --- a/src/freedreno/common/freedreno_common.h +++ b/src/freedreno/common/freedreno_common.h @@ -7,6 +7,7 @@ #define FREEDRENO_COMMON_H_ #include "util/u_atomic.h" +#include "util/macros.h" #ifdef __cplusplus @@ -137,16 +138,6 @@ struct BitmaskEnum { # define ENDC #endif -/* - * SWAP - swap value of @a and @b - */ -#define SWAP(a, b) \ - do { \ - __typeof(a) __tmp = (a); \ - (a) = (b); \ - (b) = __tmp; \ - } while (0) - /* for conditionally setting boolean flag(s): */ #define COND(bool, val) ((bool) ? (val) : 0) diff --git a/src/gallium/drivers/etnaviv/etnaviv_ml.h b/src/gallium/drivers/etnaviv/etnaviv_ml.h index db69371ad90..4baf8d7f74b 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_ml.h +++ b/src/gallium/drivers/etnaviv/etnaviv_ml.h @@ -8,20 +8,11 @@ #include "pipe/p_state.h" #include "util/u_dynarray.h" +#include "util/macros.h" #include "etnaviv_context.h" #define MAX_CONFIG_BOS 4 -/* - * SWAP - swap value of @a and @b - */ -#define SWAP(a, b) \ - do { \ - __typeof(a) __tmp = (a); \ - (a) = (b); \ - (b) = __tmp; \ - } while (0) - enum etna_job_type { ETNA_JOB_TYPE_NN, ETNA_JOB_TYPE_TP, diff --git a/src/intel/compiler/brw_opt_bank_conflicts.cpp b/src/intel/compiler/brw_opt_bank_conflicts.cpp index 8817ef9c753..7a1acbffee3 100644 --- a/src/intel/compiler/brw_opt_bank_conflicts.cpp +++ b/src/intel/compiler/brw_opt_bank_conflicts.cpp @@ -50,6 +50,7 @@ #include "brw_shader.h" #include "brw_cfg.h" +#include "util/macros.h" #ifdef __SSE2__ @@ -256,15 +257,6 @@ namespace { #endif -/** - * Swap \p x and \p y. - */ -#define SWAP(x, y) do { \ - __typeof(y) _swap_tmp = y; \ - y = x; \ - x = _swap_tmp; \ - } while (0) - namespace { /** * Variable-length vector type intended to represent cycle-count costs for diff --git a/src/intel/compiler/elk/elk_fs_bank_conflicts.cpp b/src/intel/compiler/elk/elk_fs_bank_conflicts.cpp index 45ab91e50c3..fb2c336e701 100644 --- a/src/intel/compiler/elk/elk_fs_bank_conflicts.cpp +++ b/src/intel/compiler/elk/elk_fs_bank_conflicts.cpp @@ -50,6 +50,7 @@ #include "elk_fs.h" #include "elk_cfg.h" +#include "util/macros.h" #ifdef __SSE2__ @@ -256,15 +257,6 @@ namespace { #endif -/** - * Swap \p x and \p y. - */ -#define SWAP(x, y) do { \ - __typeof(y) _swap_tmp = y; \ - y = x; \ - x = _swap_tmp; \ - } while (0) - namespace { /** * Variable-length vector type intended to represent cycle-count costs for diff --git a/src/util/macros.h b/src/util/macros.h index a16fac3a8c1..491d6970d34 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -519,4 +519,14 @@ typedef int lock_cap_t; #define PRAGMA_POISON #endif +/* + * SWAP - swap value of @a and @b + */ +#define SWAP(a, b) \ + do { \ + __typeof(a) __tmp = (a); \ + (a) = (b); \ + (b) = __tmp; \ + } while (0) + #endif /* UTIL_MACROS_H */