All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: intel-xe@lists.freedesktop.org,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Matthew Brost" <matthew.brost@intel.com>
Cc: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Subject: Re: [PATCH v2 1/4] drm/xe: Introduce IF_ARGS macro utility
Date: Mon, 15 Dec 2025 16:50:27 +0100	[thread overview]
Message-ID: <856a11ed-7962-45ba-b88b-d24a2f6105e7@intel.com> (raw)
In-Reply-To: <20251215143739.196336-2-michal.wajdeczko@intel.com>



On 12/15/2025 3:37 PM, Michal Wajdeczko wrote:
> We want to extend our macro-based KLV list definitions with new
> information about the version from which given KLV is supported.
> Add utility IF_ARGS macro that can be used in code generators to
> emit different code based on the presence of additional arguments.
> 
> Introduce macro itself and extend our kunit tests to cover it.
> We will use this macro in next patch.
> 
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
> Reviewed-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
> ---
> v2: fix typo
> ---
>  drivers/gpu/drm/xe/tests/xe_args_test.c | 53 +++++++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_args.h            | 18 +++++++++
>  2 files changed, 71 insertions(+)
> 
> diff --git a/drivers/gpu/drm/xe/tests/xe_args_test.c b/drivers/gpu/drm/xe/tests/xe_args_test.c
> index f3fb23aa5d2e..d11ea610f67a 100644
> --- a/drivers/gpu/drm/xe/tests/xe_args_test.c
> +++ b/drivers/gpu/drm/xe/tests/xe_args_test.c
> @@ -78,6 +78,24 @@ static void pick_arg_example(struct kunit *test)
>  #undef buz
>  }
>  
> +static void if_args_example(struct kunit *test)
> +{
> +	enum { Z = 1, Q };
> +
> +#define foo	X, Y
> +#define bar	IF_ARGS(Z, Q, foo)
> +#define buz	IF_ARGS(Z, Q, DROP_FIRST_ARG(FIRST_ARG(foo)))
> +
> +	KUNIT_EXPECT_EQ(test, bar, Z);
> +	KUNIT_EXPECT_EQ(test, buz, Q);
> +	KUNIT_EXPECT_STREQ(test, __stringify(bar), "Z");
> +	KUNIT_EXPECT_STREQ(test, __stringify(buz), "Q");
> +
> +#undef foo
> +#undef bar
> +#undef buz
> +}
> +
>  static void sep_comma_example(struct kunit *test)
>  {
>  #define foo(f)	f(X) f(Y) f(Z) f(Q)
> @@ -198,6 +216,39 @@ static void last_arg_test(struct kunit *test)
>  	KUNIT_EXPECT_STREQ(test, __stringify(LAST_ARG(MAX_ARGS)), "-12");
>  }
>  
> +static void if_args_test(struct kunit *test)
> +{
> +	bool with_args = true;
> +	bool no_args = false;
> +	enum { X = 100 };
> +
> +	KUNIT_EXPECT_TRUE(test, IF_ARGS(true, false, FOO_ARGS));
> +	KUNIT_EXPECT_FALSE(test, IF_ARGS(true, false, NO_ARGS));
> +
> +	KUNIT_EXPECT_TRUE(test, CONCATENATE(IF_ARGS(with, no, FOO_ARGS), _args));
> +	KUNIT_EXPECT_FALSE(test, CONCATENATE(IF_ARGS(with, no, NO_ARGS), _args));
> +
> +	KUNIT_EXPECT_STREQ(test, __stringify(IF_ARGS(yes, no, FOO_ARGS)), "yes");
> +	KUNIT_EXPECT_STREQ(test, __stringify(IF_ARGS(no, no, NO_ARGS)), "no");
> +
> +	KUNIT_EXPECT_EQ(test, IF_ARGS(CALL_ARGS(COUNT_ARGS, FOO_ARGS), -1, FOO_ARGS), 4);
> +	KUNIT_EXPECT_EQ(test, IF_ARGS(CALL_ARGS(COUNT_ARGS, FOO_ARGS), -1, NO_ARGS), -1);
> +	KUNIT_EXPECT_EQ(test, IF_ARGS(CALL_ARGS(COUNT_ARGS, NO_ARGS), -1, FOO_ARGS), 0);
> +	KUNIT_EXPECT_EQ(test, IF_ARGS(CALL_ARGS(COUNT_ARGS, NO_ARGS), -1, NO_ARGS), -1);
> +
> +	KUNIT_EXPECT_EQ(test,
> +			FIRST_ARG(CONCATENATE(CALL_ARGS(IF_ARGS, FOO, MAX, FOO_ARGS), _ARGS)), X);
> +	KUNIT_EXPECT_EQ(test,
> +			FIRST_ARG(CONCATENATE(CALL_ARGS(IF_ARGS, FOO, MAX, NO_ARGS), _ARGS)), -1);
> +
> +	KUNIT_EXPECT_EQ(test,
> +			CALL_ARGS(COUNT_ARGS,
> +				  CONCATENATE(CALL_ARGS(IF_ARGS, FOO, MAX, FOO_ARGS), _ARGS)), 4);
> +	KUNIT_EXPECT_EQ(test,
> +			CALL_ARGS(COUNT_ARGS,
> +				  CONCATENATE(CALL_ARGS(IF_ARGS, FOO, MAX, NO_ARGS), _ARGS)), 12);
> +}
> +
>  static struct kunit_case args_tests[] = {
>  	KUNIT_CASE(count_args_test),
>  	KUNIT_CASE(call_args_example),
> @@ -209,6 +260,8 @@ static struct kunit_case args_tests[] = {
>  	KUNIT_CASE(last_arg_example),
>  	KUNIT_CASE(last_arg_test),
>  	KUNIT_CASE(pick_arg_example),
> +	KUNIT_CASE(if_args_example),
> +	KUNIT_CASE(if_args_test),
>  	KUNIT_CASE(sep_comma_example),
>  	{}
>  };
> diff --git a/drivers/gpu/drm/xe/xe_args.h b/drivers/gpu/drm/xe/xe_args.h
> index 4dbc7e53c624..657203852036 100644
> --- a/drivers/gpu/drm/xe/xe_args.h
> +++ b/drivers/gpu/drm/xe/xe_args.h
> @@ -121,6 +121,24 @@
>  #define PICK_ARG11(args...)		PICK_ARG10(DROP_FIRST_ARG(args))
>  #define PICK_ARG12(args...)		PICK_ARG11(DROP_FIRST_ARG(args))
>  
> +/**
> + * IF_ARGS() - Make selection based on optional argument list.
> + * @then: token to return if arguments are present
> + * @else: token to return if arguments are empty
> + * @...: arguments to check (optional)
> + *
> + * This macro allows to select a token based on the presence of the argument list.
> + *
> + * Example:
> + *
> + *	#define foo	X, Y
> + *	#define bar	IF_ARGS(Z, Q, foo)
> + *	#define buz	IF_ARGS(Z, Q, DROP_FIRST_ARG(FIRST_ARG(foo)))
> + *
> + *	With above definitions bar expands to Z while buz expands to Q.
> + */
> +#define IF_ARGS(then, else, ...)	FIRST_ARG(__VA_OPT__(then,) else)

for the record,

gcc supports __VA_OPT__ from version 8 (while min requirement for kernel is 8.1)
and clang supports __VA_OPT__ from version 12 (min requirement is 15.0.0)

[1] https://docs.kernel.org/process/changes.html
[2] https://gcc.gnu.org/projects/c-status.html
[3] https://clang.llvm.org/c_status.html

+ maintainers

> +
>  /**
>   * ARGS_SEP_COMMA - Definition of a comma character.
>   *


  reply	other threads:[~2025-12-15 15:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-15 14:37 [PATCH v2 0/4] PF: Add handling for new adverse event thresholds Michal Wajdeczko
2025-12-15 14:37 ` [PATCH v2 1/4] drm/xe: Introduce IF_ARGS macro utility Michal Wajdeczko
2025-12-15 15:50   ` Michal Wajdeczko [this message]
2025-12-15 14:37 ` [PATCH v2 2/4] drm/xe/guc: Introduce GUC_FIRMWARE_VER_AT_LEAST helper Michal Wajdeczko
2025-12-15 17:07   ` Michal Wajdeczko
2025-12-15 18:25   ` Daniele Ceraolo Spurio
2025-12-15 14:37 ` [PATCH v2 3/4] drm/xe/pf: Prepare for new threshold KLVs Michal Wajdeczko
2025-12-15 18:28   ` Daniele Ceraolo Spurio
2025-12-15 14:37 ` [PATCH v2 4/4] drm/xe/pf: Add handling for MLRC adverse event threshold Michal Wajdeczko
2025-12-15 14:57 ` ✗ CI.checkpatch: warning for PF: Add handling for new adverse event thresholds (rev2) Patchwork
2025-12-15 14:59 ` ✓ CI.KUnit: success " Patchwork
2025-12-15 16:03 ` ✓ Xe.CI.BAT: " Patchwork
2025-12-15 19:58 ` ✗ Xe.CI.Full: failure " Patchwork
2025-12-16  1:19 ` [PATCH v2 0/4] PF: Add handling for new adverse event thresholds Matthew Brost

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=856a11ed-7962-45ba-b88b-d24a2f6105e7@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=daniele.ceraolospurio@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=thomas.hellstrom@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.