intel-xe.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: Lucas De Marchi <lucas.demarchi@intel.com>
To: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: <intel-xe@lists.freedesktop.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: Re: [PATCH] drm/xe: Rename few xe_args.h macros
Date: Tue, 7 May 2024 08:24:13 -0500	[thread overview]
Message-ID: <c5meihr4bizvba6yxyuiygwzvwzb7njqbhpblvqbl2vakoygrs@tnmfpt4i4v3j> (raw)
In-Reply-To: <20240506215618.2703-1-michal.wajdeczko@intel.com>

On Mon, May 06, 2024 at 11:56:18PM GMT, Michal Wajdeczko wrote:
>To minimize the risk of future name collisions, rename macros to
>always include the ARG or ARGS tag:
>
>  DROP_FIRST to ARGS_TAIL

this one is odd. When I read DROP_FIRST(1, 2, 3), it's immediately clear
what it means. It's not with ARGS_TAIL(1, 2, 3) as I have to read the
doc to know if tail == everything but first arg, or if the first args is
the length.

I'd rather prefer DROP_FIRST_ARG if we are trying to add _ARG suffix in
the others. It's longer, but it's also unambiguous.

>  PICK_FIRST to FIRST_ARG
>  PICK_LAST to LAST_ARG

these are clear, so ack

Lucas De Marchi

>
>Suggested-by:: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
>Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>Cc: Lucas De Marchi <lucas.demarchi@intel.com>
>---
> drivers/gpu/drm/xe/tests/xe_args_test.c | 70 ++++++++++++-------------
> drivers/gpu/drm/xe/xe_args.h            | 50 +++++++++---------
> drivers/gpu/drm/xe/xe_rtp_helpers.h     | 12 ++---
> 3 files changed, 66 insertions(+), 66 deletions(-)
>
>diff --git a/drivers/gpu/drm/xe/tests/xe_args_test.c b/drivers/gpu/drm/xe/tests/xe_args_test.c
>index 9b44c1ab6364..3b25688e4da7 100644
>--- a/drivers/gpu/drm/xe/tests/xe_args_test.c
>+++ b/drivers/gpu/drm/xe/tests/xe_args_test.c
>@@ -21,10 +21,10 @@ static void call_args_example(struct kunit *test)
> #undef buz
> }
>
>-static void drop_first_example(struct kunit *test)
>+static void args_tail_example(struct kunit *test)
> {
> #define foo	X, Y, Z, Q
>-#define bar	CALL_ARGS(COUNT_ARGS, DROP_FIRST(foo))
>+#define bar	CALL_ARGS(COUNT_ARGS, ARGS_TAIL(foo))
>
> 	KUNIT_EXPECT_EQ(test, bar, 3);
>
>@@ -32,12 +32,12 @@ static void drop_first_example(struct kunit *test)
> #undef bar
> }
>
>-static void pick_first_example(struct kunit *test)
>+static void first_arg_example(struct kunit *test)
> {
> 	int X = 1;
>
> #define foo	X, Y, Z, Q
>-#define bar	PICK_FIRST(foo)
>+#define bar	FIRST_ARG(foo)
>
> 	KUNIT_EXPECT_EQ(test, bar, X);
> 	KUNIT_EXPECT_STREQ(test, __stringify(bar), "X");
>@@ -46,12 +46,12 @@ static void pick_first_example(struct kunit *test)
> #undef bar
> }
>
>-static void pick_last_example(struct kunit *test)
>+static void last_arg_example(struct kunit *test)
> {
> 	int Q = 1;
>
> #define foo	X, Y, Z, Q
>-#define bar	PICK_LAST(foo)
>+#define bar	LAST_ARG(foo)
>
> 	KUNIT_EXPECT_EQ(test, bar, Q);
> 	KUNIT_EXPECT_STREQ(test, __stringify(bar), "Q");
>@@ -63,8 +63,8 @@ static void pick_last_example(struct kunit *test)
> static void sep_comma_example(struct kunit *test)
> {
> #define foo(f)	f(X) f(Y) f(Z) f(Q)
>-#define bar	DROP_FIRST(foo(ARGS_SEP_COMMA __stringify))
>-#define buz	CALL_ARGS(COUNT_ARGS, DROP_FIRST(foo(ARGS_SEP_COMMA)))
>+#define bar	ARGS_TAIL(foo(ARGS_SEP_COMMA __stringify))
>+#define buz	CALL_ARGS(COUNT_ARGS, ARGS_TAIL(foo(ARGS_SEP_COMMA)))
>
> 	static const char * const a[] = { bar };
>
>@@ -123,61 +123,61 @@ static void call_args_test(struct kunit *test)
> 	KUNIT_EXPECT_EQ(test, CALL_ARGS(COUNT_ARGS, MAX_ARGS), 12);
> }
>
>-static void drop_first_test(struct kunit *test)
>+static void args_tail_test(struct kunit *test)
> {
> 	int Y = -2, Z = -3, Q = -4;
>-	int a[] = { DROP_FIRST(FOO_ARGS) };
>+	int a[] = { ARGS_TAIL(FOO_ARGS) };
>
>-	KUNIT_EXPECT_EQ(test, DROP_FIRST(0, -1), -1);
>-	KUNIT_EXPECT_EQ(test, DROP_FIRST(DROP_FIRST(0, -1, -2)), -2);
>+	KUNIT_EXPECT_EQ(test, ARGS_TAIL(0, -1), -1);
>+	KUNIT_EXPECT_EQ(test, ARGS_TAIL(ARGS_TAIL(0, -1, -2)), -2);
>
>-	KUNIT_EXPECT_EQ(test, CALL_ARGS(COUNT_ARGS, DROP_FIRST(FOO_ARGS)), 3);
>-	KUNIT_EXPECT_EQ(test, DROP_FIRST(DROP_FIRST(DROP_FIRST(FOO_ARGS))), -4);
>+	KUNIT_EXPECT_EQ(test, CALL_ARGS(COUNT_ARGS, ARGS_TAIL(FOO_ARGS)), 3);
>+	KUNIT_EXPECT_EQ(test, ARGS_TAIL(ARGS_TAIL(ARGS_TAIL(FOO_ARGS))), -4);
> 	KUNIT_EXPECT_EQ(test, a[0], -2);
> 	KUNIT_EXPECT_EQ(test, a[1], -3);
> 	KUNIT_EXPECT_EQ(test, a[2], -4);
>-	KUNIT_EXPECT_STREQ(test, __stringify(DROP_FIRST(DROP_FIRST(DROP_FIRST(FOO_ARGS)))), "Q");
>+	KUNIT_EXPECT_STREQ(test, __stringify(ARGS_TAIL(ARGS_TAIL(ARGS_TAIL(FOO_ARGS)))), "Q");
> }
>
>-static void pick_first_test(struct kunit *test)
>+static void first_arg_test(struct kunit *test)
> {
> 	int X = -1;
>-	int a[] = { PICK_FIRST(FOO_ARGS) };
>+	int a[] = { FIRST_ARG(FOO_ARGS) };
>
>-	KUNIT_EXPECT_EQ(test, PICK_FIRST(-1, -2), -1);
>+	KUNIT_EXPECT_EQ(test, FIRST_ARG(-1, -2), -1);
>
>-	KUNIT_EXPECT_EQ(test, CALL_ARGS(COUNT_ARGS, PICK_FIRST(FOO_ARGS)), 1);
>-	KUNIT_EXPECT_EQ(test, PICK_FIRST(FOO_ARGS), -1);
>+	KUNIT_EXPECT_EQ(test, CALL_ARGS(COUNT_ARGS, FIRST_ARG(FOO_ARGS)), 1);
>+	KUNIT_EXPECT_EQ(test, FIRST_ARG(FOO_ARGS), -1);
> 	KUNIT_EXPECT_EQ(test, a[0], -1);
>-	KUNIT_EXPECT_STREQ(test, __stringify(PICK_FIRST(FOO_ARGS)), "X");
>+	KUNIT_EXPECT_STREQ(test, __stringify(FIRST_ARG(FOO_ARGS)), "X");
> }
>
>-static void pick_last_test(struct kunit *test)
>+static void last_arg_test(struct kunit *test)
> {
> 	int Q = -4;
>-	int a[] = { PICK_LAST(FOO_ARGS) };
>+	int a[] = { LAST_ARG(FOO_ARGS) };
>
>-	KUNIT_EXPECT_EQ(test, PICK_LAST(-1, -2), -2);
>+	KUNIT_EXPECT_EQ(test, LAST_ARG(-1, -2), -2);
>
>-	KUNIT_EXPECT_EQ(test, CALL_ARGS(COUNT_ARGS, PICK_LAST(FOO_ARGS)), 1);
>-	KUNIT_EXPECT_EQ(test, PICK_LAST(FOO_ARGS), -4);
>+	KUNIT_EXPECT_EQ(test, CALL_ARGS(COUNT_ARGS, LAST_ARG(FOO_ARGS)), 1);
>+	KUNIT_EXPECT_EQ(test, LAST_ARG(FOO_ARGS), -4);
> 	KUNIT_EXPECT_EQ(test, a[0], -4);
>-	KUNIT_EXPECT_STREQ(test, __stringify(PICK_LAST(FOO_ARGS)), "Q");
>+	KUNIT_EXPECT_STREQ(test, __stringify(LAST_ARG(FOO_ARGS)), "Q");
>
>-	KUNIT_EXPECT_EQ(test, PICK_LAST(MAX_ARGS), -12);
>-	KUNIT_EXPECT_STREQ(test, __stringify(PICK_LAST(MAX_ARGS)), "-12");
>+	KUNIT_EXPECT_EQ(test, LAST_ARG(MAX_ARGS), -12);
>+	KUNIT_EXPECT_STREQ(test, __stringify(LAST_ARG(MAX_ARGS)), "-12");
> }
>
> static struct kunit_case args_tests[] = {
> 	KUNIT_CASE(count_args_test),
> 	KUNIT_CASE(call_args_example),
> 	KUNIT_CASE(call_args_test),
>-	KUNIT_CASE(drop_first_example),
>-	KUNIT_CASE(drop_first_test),
>-	KUNIT_CASE(pick_first_example),
>-	KUNIT_CASE(pick_first_test),
>-	KUNIT_CASE(pick_last_example),
>-	KUNIT_CASE(pick_last_test),
>+	KUNIT_CASE(args_tail_example),
>+	KUNIT_CASE(args_tail_test),
>+	KUNIT_CASE(first_arg_example),
>+	KUNIT_CASE(first_arg_test),
>+	KUNIT_CASE(last_arg_example),
>+	KUNIT_CASE(last_arg_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 40b9eb4151d8..e17a41f9da0b 100644
>--- a/drivers/gpu/drm/xe/xe_args.h
>+++ b/drivers/gpu/drm/xe/xe_args.h
>@@ -35,7 +35,7 @@
> #define __CALL_ARGS(f, args...)		f(args)
>
> /**
>- * DROP_FIRST - Returns all arguments except the first one.
>+ * ARGS_TAIL - Returns all arguments except the first one.
>  * @args: arguments
>  *
>  * This helper macro allows manipulation the argument list before passing it
>@@ -44,15 +44,15 @@
>  * Example:
>  *
>  *	#define foo	X,Y,Z,Q
>- *	#define bar	CALL_ARGS(COUNT_ARGS, DROP_FIRST(foo))
>+ *	#define bar	CALL_ARGS(COUNT_ARGS, ARGS_TAIL(foo))
>  *
>  *	With above definitions bar expands to 3.
>  */
>-#define DROP_FIRST(args...)		__DROP_FIRST(args)
>-#define __DROP_FIRST(a, b...)		b
>+#define ARGS_TAIL(args...)		__ARGS_TAIL(args)
>+#define __ARGS_TAIL(a, b...)		b
>
> /**
>- * PICK_FIRST - Returns the first argument.
>+ * FIRST_ARG - Returns the first argument.
>  * @args: arguments
>  *
>  * This helper macro allows manipulation the argument list before passing it
>@@ -61,15 +61,15 @@
>  * Example:
>  *
>  *	#define foo	X,Y,Z,Q
>- *	#define bar	PICK_FIRST(foo)
>+ *	#define bar	FIRST_ARG(foo)
>  *
>  *	With above definitions bar expands to X.
>  */
>-#define PICK_FIRST(args...)		__PICK_FIRST(args)
>-#define __PICK_FIRST(a, b...)		a
>+#define FIRST_ARG(args...)		__FIRST_ARG(args)
>+#define __FIRST_ARG(a, b...)		a
>
> /**
>- * PICK_LAST - Returns the last argument.
>+ * LAST_ARG - Returns the last argument.
>  * @args: arguments
>  *
>  * This helper macro allows manipulation the argument list before passing it
>@@ -80,24 +80,24 @@
>  * Example:
>  *
>  *	#define foo	X,Y,Z,Q
>- *	#define bar	PICK_LAST(foo)
>+ *	#define bar	LAST_ARG(foo)
>  *
>  *	With above definitions bar expands to Q.
>  */
>-#define PICK_LAST(args...)		__PICK_ARG(COUNT_ARGS(args), args)
>+#define LAST_ARG(args...)		__PICK_ARG(COUNT_ARGS(args), args)
> #define __PICK_ARG(n, args...)		CALL_ARGS(CONCATENATE(PICK_ARG, n), args)
>-#define PICK_ARG1(args...)		PICK_FIRST(args)
>-#define PICK_ARG2(args...)		PICK_ARG1(DROP_FIRST(args))
>-#define PICK_ARG3(args...)		PICK_ARG2(DROP_FIRST(args))
>-#define PICK_ARG4(args...)		PICK_ARG3(DROP_FIRST(args))
>-#define PICK_ARG5(args...)		PICK_ARG4(DROP_FIRST(args))
>-#define PICK_ARG6(args...)		PICK_ARG5(DROP_FIRST(args))
>-#define PICK_ARG7(args...)		PICK_ARG6(DROP_FIRST(args))
>-#define PICK_ARG8(args...)		PICK_ARG7(DROP_FIRST(args))
>-#define PICK_ARG9(args...)		PICK_ARG8(DROP_FIRST(args))
>-#define PICK_ARG10(args...)		PICK_ARG9(DROP_FIRST(args))
>-#define PICK_ARG11(args...)		PICK_ARG10(DROP_FIRST(args))
>-#define PICK_ARG12(args...)		PICK_ARG11(DROP_FIRST(args))
>+#define PICK_ARG1(args...)		FIRST_ARG(args)
>+#define PICK_ARG2(args...)		PICK_ARG1(ARGS_TAIL(args))
>+#define PICK_ARG3(args...)		PICK_ARG2(ARGS_TAIL(args))
>+#define PICK_ARG4(args...)		PICK_ARG3(ARGS_TAIL(args))
>+#define PICK_ARG5(args...)		PICK_ARG4(ARGS_TAIL(args))
>+#define PICK_ARG6(args...)		PICK_ARG5(ARGS_TAIL(args))
>+#define PICK_ARG7(args...)		PICK_ARG6(ARGS_TAIL(args))
>+#define PICK_ARG8(args...)		PICK_ARG7(ARGS_TAIL(args))
>+#define PICK_ARG9(args...)		PICK_ARG8(ARGS_TAIL(args))
>+#define PICK_ARG10(args...)		PICK_ARG9(ARGS_TAIL(args))
>+#define PICK_ARG11(args...)		PICK_ARG10(ARGS_TAIL(args))
>+#define PICK_ARG12(args...)		PICK_ARG11(ARGS_TAIL(args))
>
> /**
>  * ARGS_SEP_COMMA - Definition of a comma character.
>@@ -109,8 +109,8 @@
>  * Example:
>  *
>  *	#define foo(f)	f(X) f(Y) f(Z) f(Q)
>- *	#define bar	DROP_FIRST(foo(ARGS_SEP_COMMA __stringify))
>- *	#define buz	CALL_ARGS(COUNT_ARGS, DROP_FIRST(foo(ARGS_SEP_COMMA)))
>+ *	#define bar	ARGS_TAIL(foo(ARGS_SEP_COMMA __stringify))
>+ *	#define buz	CALL_ARGS(COUNT_ARGS, ARGS_TAIL(foo(ARGS_SEP_COMMA)))
>  *
>  *	With above definitions bar expands to
>  *		"X", "Y", "Z", "Q"
>diff --git a/drivers/gpu/drm/xe/xe_rtp_helpers.h b/drivers/gpu/drm/xe/xe_rtp_helpers.h
>index 8129d6d9ef37..5e699455c32f 100644
>--- a/drivers/gpu/drm/xe/xe_rtp_helpers.h
>+++ b/drivers/gpu/drm/xe/xe_rtp_helpers.h
>@@ -17,7 +17,7 @@
>  */
> #define _XE_ESC(...) __VA_ARGS__
>
>-#define _XE_TUPLE_TAIL(...) (DROP_FIRST(__VA_ARGS__))
>+#define _XE_TUPLE_TAIL(...) (ARGS_TAIL(__VA_ARGS__))
>
> #define _XE_RTP_CONCAT(a, b) CONCATENATE(XE_RTP_, CONCATENATE(a, b))
>
>@@ -54,10 +54,10 @@
>  *	XE_RTP_TEST_FOO BANANA XE_RTP_TEST_BAR
>  */
> #define XE_RTP_PASTE_FOREACH(prefix_, sep_, args_) _XE_RTP_CONCAT(PASTE_, COUNT_ARGS args_)(prefix_, sep_, args_)
>-#define XE_RTP_PASTE_1(prefix_, sep_, args_) _XE_RTP_CONCAT(prefix_, PICK_FIRST args_)
>-#define XE_RTP_PASTE_2(prefix_, sep_, args_) _XE_RTP_CONCAT(prefix_, PICK_FIRST args_) __XE_RTP_PASTE_SEP_ ## sep_ XE_RTP_PASTE_1(prefix_, sep_, _XE_TUPLE_TAIL args_)
>-#define XE_RTP_PASTE_3(prefix_, sep_, args_) _XE_RTP_CONCAT(prefix_, PICK_FIRST args_) __XE_RTP_PASTE_SEP_ ## sep_ XE_RTP_PASTE_2(prefix_, sep_, _XE_TUPLE_TAIL args_)
>-#define XE_RTP_PASTE_4(prefix_, sep_, args_) _XE_RTP_CONCAT(prefix_, PICK_FIRST args_) __XE_RTP_PASTE_SEP_ ## sep_ XE_RTP_PASTE_3(prefix_, sep_, _XE_TUPLE_TAIL args_)
>+#define XE_RTP_PASTE_1(prefix_, sep_, args_) _XE_RTP_CONCAT(prefix_, FIRST_ARG args_)
>+#define XE_RTP_PASTE_2(prefix_, sep_, args_) _XE_RTP_CONCAT(prefix_, FIRST_ARG args_) __XE_RTP_PASTE_SEP_ ## sep_ XE_RTP_PASTE_1(prefix_, sep_, _XE_TUPLE_TAIL args_)
>+#define XE_RTP_PASTE_3(prefix_, sep_, args_) _XE_RTP_CONCAT(prefix_, FIRST_ARG args_) __XE_RTP_PASTE_SEP_ ## sep_ XE_RTP_PASTE_2(prefix_, sep_, _XE_TUPLE_TAIL args_)
>+#define XE_RTP_PASTE_4(prefix_, sep_, args_) _XE_RTP_CONCAT(prefix_, FIRST_ARG args_) __XE_RTP_PASTE_SEP_ ## sep_ XE_RTP_PASTE_3(prefix_, sep_, _XE_TUPLE_TAIL args_)
>
> /*
>  * XE_RTP_DROP_CAST - Drop cast to convert a compound statement to a initializer
>@@ -70,6 +70,6 @@
>  *
>  *	{ .a = 10 }
>  */
>-#define XE_RTP_DROP_CAST(...) _XE_ESC(DROP_FIRST _XE_ESC __VA_ARGS__)
>+#define XE_RTP_DROP_CAST(...) _XE_ESC(ARGS_TAIL _XE_ESC __VA_ARGS__)
>
> #endif
>-- 
>2.43.0
>

      parent reply	other threads:[~2024-05-07 13:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-06 21:56 [PATCH] drm/xe: Rename few xe_args.h macros Michal Wajdeczko
2024-05-07  3:29 ` ✓ CI.Patch_applied: success for " Patchwork
2024-05-07  3:29 ` ✗ CI.checkpatch: warning " Patchwork
2024-05-07  3:30 ` ✓ CI.KUnit: success " Patchwork
2024-05-07  3:44 ` ✓ CI.Build: " Patchwork
2024-05-07  3:54 ` ✓ CI.Hooks: " Patchwork
2024-05-07  3:55 ` ✓ CI.checksparse: " Patchwork
2024-05-07  4:13 ` ✓ CI.BAT: " Patchwork
2024-05-07  8:28 ` ✗ CI.FULL: failure " Patchwork
2024-05-07 13:08 ` [PATCH] " Andy Shevchenko
2024-05-07 13:24 ` Lucas De Marchi [this message]

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=c5meihr4bizvba6yxyuiygwzvwzb7njqbhpblvqbl2vakoygrs@tnmfpt4i4v3j \
    --to=lucas.demarchi@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=michal.wajdeczko@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).