Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Wajdeczko <michal.wajdeczko@intel.com>
To: Lucas De Marchi <lucas.demarchi@intel.com>
Cc: intel-xe@lists.freedesktop.org,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: Re: [PATCH v2 1/2] drm/xe: Add helpers for manipulating macro arguments
Date: Thu, 2 May 2024 22:43:02 +0200	[thread overview]
Message-ID: <a56d9a7b-e7b2-4ace-bd01-51454f4397c2@intel.com> (raw)
In-Reply-To: <nm74vqoumf5tvredns7nluu4m4ud6wimly4ec23ykzh45jfchr@ppjb7yxeruay>



On 02.05.2024 22:16, Lucas De Marchi wrote:
> On Thu, May 02, 2024 at 09:56:18PM GMT, Michal Wajdeczko wrote:
>> Define generic helpers that will replace private definitions used
>> by the RTP code and will allow reuse by the new code.
>>
>> Put them in new xe_args.h file (instead of infamous xe_macros.h)
>> as once we find more potential users outside of the Xe driver we
>> may want to move all of these macros as-is to linux/args.h.
>>
>> 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>
>> ---
>> v2: don't pollute linux/args.h yet (Andy)
>> ---
>> drivers/gpu/drm/xe/xe_args.h | 114 +++++++++++++++++++++++++++++++++++
>> 1 file changed, 114 insertions(+)
>> create mode 100644 drivers/gpu/drm/xe/xe_args.h
>>
>> diff --git a/drivers/gpu/drm/xe/xe_args.h b/drivers/gpu/drm/xe/xe_args.h
>> new file mode 100644
>> index 000000000000..6899fcc9405d
>> --- /dev/null
>> +++ b/drivers/gpu/drm/xe/xe_args.h
>> @@ -0,0 +1,114 @@
>> +/* SPDX-License-Identifier: MIT */
>> +/*
>> + * Copyright © 2023 Intel Corporation
>> + */
>> +
>> +#ifndef _XE_ARGS_H_
>> +#define _XE_ARGS_H_
>> +
> 
> as Andy mentioned, we could add a comment here stating this can
> eventually be moved to linux/args.h once more users show up.

added to commit message, but could repeat here as well

> 
> or... once we start conflicting with other macros since we are not using
> an XE_ prefix anymore.
> 
>> +#include <linux/args.h>
>> +
>> +/**
>> + * CALL_ARGS - Invoke a macro, but allow parameters to be expanded
>> beforehand.
>> + * @f: name of the macro to invoke
>> + * @args: arguments for the macro
>> + *
>> + * This macro allows calling macros which names might generated or we
>> want to
>> + * make sure it's arguments will be correctly expanded.
>> + *
>> + * Example:
>> + *
>> + *    #define foo    X,Y,Z,Q
>> + *    #define bar    COUNT_ARGS(foo)
>> + *    #define buz    CALL_ARGS(COUNT_ARGS, foo)
>> + *
>> + *    With above definitions bar expands to 1 while buz expands to 4.
>> + */
>> +#define CALL_ARGS(f, args...)        __CALL_ARGS(f, args)
>> +#define __CALL_ARGS(f, args...)        f(args)
>> +
>> +/**
>> + * DROP_FIRST - Returns all arguments except the first one.
>> + * @args: arguments
>> + *
>> + * This helper macro allows manipulation the argument list before
>> passing it
>> + * to the next level macro.
>> + *
>> + * Example:
>> + *
>> + *    #define foo    X,Y,Z,Q
>> + *    #define bar    CALL_ARGS(COUNT_ARGS, DROP_FIRST(foo))
>> + *
>> + *    With above definitions bar expands to 3.
>> + */
>> +#define DROP_FIRST(args...)        __DROP_FIRST(args)
>> +#define __DROP_FIRST(a, b...)        b
>> +
>> +/**
>> + * PICK_FIRST - Returns the first argument.
>> + * @args: arguments
>> + *
>> + * This helper macro allows manipulation the argument list before
>> passing it
>> + * to the next level macro.
>> + *
>> + * Example:
>> + *
>> + *    #define foo    X,Y,Z,Q
>> + *    #define bar    PICK_FIRST(foo)
>> + *
>> + *    With above definitions bar expands to X.
>> + */
>> +#define PICK_FIRST(args...)        __PICK_FIRST(args)
>> +#define __PICK_FIRST(a, b...)        a
>> +
>> +/**
>> + * PICK_LAST - Returns the last argument.
>> + * @args: arguments
>> + *
>> + * This helper macro allows manipulation the argument list before
>> passing it
>> + * to the next level macro.
>> + *
>> + * Like COUNT_ARGS() this macro works up to 12 arguments.
>> + *
>> + * Example:
>> + *
>> + *    #define foo    X,Y,Z,Q
>> + *    #define bar    PICK_LAST(foo)
>> + *
>> + *    With above definitions bar expands to Q.
>> + */
>> +#define PICK_LAST(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))
>> +
>> +/**
>> + * ARGS_SEP_COMMA - Definition of a comma character.
>> + *
>> + * This definition can be used in cases where any intermediate macro
>> expects
>> + * fixed number of arguments, but we want to pass more arguments
>> which can
>> + * be properly evaluated only by the next level macro.
>> + *
>> + * 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)))
>> + *
>> + *    With above definitions bar expands to
>> + *        "X", "Y", "Z", "Q"
>> + *    and buz expands to 4.
>> + */
>> +#define ARGS_SEP_COMMA            ,
>> +
>> +#endif    /* _LINUX_ARGS_H */
> 
>         ^ wrong one, and anyway can be removed as we don't use
> these comments in xe

oops, that's leftover from copy

> 
> 
> Eventually we may also add a kunit to make sure we don't have surprises.
> As long as the .o match on next patch, not required for now.

well, I do have simple kunit, will try to add it to v3

> 
> with those fixed:
> 
> 
> Reviewed-by: Lucas De Marchi <lucas.demarchi@intel.com>
> 
> 
> thanks
> Lucas De Marchi
> 
>> -- 
>> 2.43.0
>>

  reply	other threads:[~2024-05-02 20:43 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02 19:56 [PATCH v2 0/2] Define generic helpers for manipulating macro arguments Michal Wajdeczko
2024-05-02 19:56 ` [PATCH v2 1/2] drm/xe: Add " Michal Wajdeczko
2024-05-02 20:16   ` Lucas De Marchi
2024-05-02 20:43     ` Michal Wajdeczko [this message]
2024-05-02 19:56 ` [PATCH v2 2/2] drm/xe/rtp: Prefer helper macros from xe_args.h Michal Wajdeczko
2024-05-02 20:24   ` Lucas De Marchi
2024-05-02 20:07 ` ✓ CI.Patch_applied: success for Define generic helpers for manipulating macro arguments (rev2) Patchwork
2024-05-02 20:07 ` ✗ CI.checkpatch: warning " Patchwork
2024-05-02 20:08 ` ✓ CI.KUnit: success " Patchwork
2024-05-02 20:19 ` ✓ CI.Build: " Patchwork
2024-05-02 20:22 ` ✓ CI.Hooks: " Patchwork
2024-05-02 20:25 ` ✓ CI.checksparse: " Patchwork
2024-05-02 21:24 ` ✓ CI.BAT: " Patchwork
2024-05-02 23:18 ` ✗ CI.FULL: failure " Patchwork

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=a56d9a7b-e7b2-4ace-bd01-51454f4397c2@intel.com \
    --to=michal.wajdeczko@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=lucas.demarchi@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