All of lore.kernel.org
 help / color / mirror / Atom feed
* Devise macros to encapsulate (x & -x)
@ 2023-11-17 10:17 Nicola Vetrini
  2023-11-17 11:04 ` Andrew Cooper
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Nicola Vetrini @ 2023-11-17 10:17 UTC (permalink / raw)
  To: Xen Devel
  Cc: Consulting, Stefano Stabellini, Jbeulich, Andrew Cooper3,
	George Dunlap, Julien Grall, Wei Liu, Roger Pau, Bertrand Marquis,
	Michal Orzel

Hi all,

As discussed in this thread [1], which is about complying with MISRA C 
Rule 10.1,
a macro was introduced to encapsulate a well-known construct:

/*
  * Given an unsigned integer argument, expands to a mask where just the 
least
  * significant nonzero bit of the argument is set, or 0 if no bits are 
set.
  */
#define ISOLATE_LSB(x) ((x) & -(x))

This macro has a gained some calls in the subsequent patches in that 
thread, but concerns were raised around the fact that it would be better 
to devise a macro that evaluates its argument only once. A proposed 
solution is this (thanks to Jan Beulich):

#define ISOLATE_LSB(x) ({ \
      typeof(x) x_ = (x); \
      x_ & -x_; \
})

However, it can't be used in all call sites that the previous macro 
would have once that series is committed, as can be seen in [2]. 
Therefore, while the implementation looks ok,
a case has been made to have separate macros, of which the latter form 
is preferred.

The following points require some thought:

- where the single evaluation macro should be placed?
   One proposed location is xen/include/xen/bitops.h
- is the proposed form actually the best, or maybe it could be an inline 
function?

Then testing can happen and a subsequent version of those uncommitted 
patches introducing uses of either construct will be submitted, to 
modify all the call sites only once in the commit history.

Let me know what you think of this.
Regards,

[1] 
https://lore.kernel.org/xen-devel/8a1313b3ab5ba6dd556cf37409e3b703@bugseng.com/T/#mdeb510325e1acacb6477a88de8577e9e87351ba5
[2] https://gitlab.com/xen-project/people/bugseng/xen/-/jobs/5423693947

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-17 10:17 Devise macros to encapsulate (x & -x) Nicola Vetrini
@ 2023-11-17 11:04 ` Andrew Cooper
  2023-11-17 11:15   ` Nicola Vetrini
  2023-11-18  2:46   ` Stefano Stabellini
  2023-11-17 11:39 ` Jan Beulich
  2023-11-17 16:15 ` Nicola Vetrini
  2 siblings, 2 replies; 13+ messages in thread
From: Andrew Cooper @ 2023-11-17 11:04 UTC (permalink / raw)
  To: Nicola Vetrini, Xen Devel
  Cc: Consulting, Stefano Stabellini, Jbeulich, George Dunlap,
	Julien Grall, Wei Liu, Roger Pau, Bertrand Marquis, Michal Orzel

On 17/11/2023 10:17 am, Nicola Vetrini wrote:
> Hi all,
>
> As discussed in this thread [1], which is about complying with MISRA C
> Rule 10.1,
> a macro was introduced to encapsulate a well-known construct:
>
> /*
>  * Given an unsigned integer argument, expands to a mask where just
> the least
>  * significant nonzero bit of the argument is set, or 0 if no bits are
> set.
>  */
> #define ISOLATE_LSB(x) ((x) & -(x))
>
> This macro has a gained some calls in the subsequent patches in that
> thread, but concerns were raised around the fact that it would be
> better to devise a macro that evaluates its argument only once. A
> proposed solution is this (thanks to Jan Beulich):
>
> #define ISOLATE_LSB(x) ({ \
>      typeof(x) x_ = (x); \
>      x_ & -x_; \
> })

Of course this was going to explode.

This isn't even the first time an unwise attempt to do single-evaluation
has needed to be reverted because it doesn't work with Integer Constant
Expressions.

Switch it back to the first form.  It's obviously a macro to begin with,
and not likely to be used in cases that have side effects.

~Andrew


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-17 11:04 ` Andrew Cooper
@ 2023-11-17 11:15   ` Nicola Vetrini
  2023-11-17 11:37     ` Jan Beulich
  2023-11-18  2:46   ` Stefano Stabellini
  1 sibling, 1 reply; 13+ messages in thread
From: Nicola Vetrini @ 2023-11-17 11:15 UTC (permalink / raw)
  To: Andrew Cooper
  Cc: Xen Devel, Consulting, Stefano Stabellini, Jbeulich,
	George Dunlap, Julien Grall, Wei Liu, Roger Pau, Bertrand Marquis,
	Michal Orzel

On 2023-11-17 12:04, Andrew Cooper wrote:
> On 17/11/2023 10:17 am, Nicola Vetrini wrote:
>> Hi all,
>> 
>> As discussed in this thread [1], which is about complying with MISRA C
>> Rule 10.1,
>> a macro was introduced to encapsulate a well-known construct:
>> 
>> /*
>>  * Given an unsigned integer argument, expands to a mask where just
>> the least
>>  * significant nonzero bit of the argument is set, or 0 if no bits are
>> set.
>>  */
>> #define ISOLATE_LSB(x) ((x) & -(x))
>> 
>> This macro has a gained some calls in the subsequent patches in that
>> thread, but concerns were raised around the fact that it would be
>> better to devise a macro that evaluates its argument only once. A
>> proposed solution is this (thanks to Jan Beulich):
>> 
>> #define ISOLATE_LSB(x) ({ \
>>      typeof(x) x_ = (x); \
>>      x_ & -x_; \
>> })
> 
> Of course this was going to explode.
> 
> This isn't even the first time an unwise attempt to do 
> single-evaluation
> has needed to be reverted because it doesn't work with Integer Constant
> Expressions.
> 
> Switch it back to the first form.  It's obviously a macro to begin 
> with,
> and not likely to be used in cases that have side effects.
> 
> ~Andrew

Actually no usages of either forms are yet committed, just the 
definition of the first form, so nothing needs to be reverted. I should 
have clarified that, sorry. If the other patches in the series go in 
unmodified (modulo renaming, but that's trivial), they would use the 
first form.

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-17 11:15   ` Nicola Vetrini
@ 2023-11-17 11:37     ` Jan Beulich
  0 siblings, 0 replies; 13+ messages in thread
From: Jan Beulich @ 2023-11-17 11:37 UTC (permalink / raw)
  To: Nicola Vetrini, Andrew Cooper
  Cc: Xen Devel, Consulting, Stefano Stabellini, George Dunlap,
	Julien Grall, Wei Liu, Roger Pau, Bertrand Marquis, Michal Orzel

On 17.11.2023 12:15, Nicola Vetrini wrote:
> On 2023-11-17 12:04, Andrew Cooper wrote:
>> On 17/11/2023 10:17 am, Nicola Vetrini wrote:
>>> Hi all,
>>>
>>> As discussed in this thread [1], which is about complying with MISRA C
>>> Rule 10.1,
>>> a macro was introduced to encapsulate a well-known construct:
>>>
>>> /*
>>>  * Given an unsigned integer argument, expands to a mask where just
>>> the least
>>>  * significant nonzero bit of the argument is set, or 0 if no bits are
>>> set.
>>>  */
>>> #define ISOLATE_LSB(x) ((x) & -(x))
>>>
>>> This macro has a gained some calls in the subsequent patches in that
>>> thread, but concerns were raised around the fact that it would be
>>> better to devise a macro that evaluates its argument only once. A
>>> proposed solution is this (thanks to Jan Beulich):
>>>
>>> #define ISOLATE_LSB(x) ({ \
>>>      typeof(x) x_ = (x); \
>>>      x_ & -x_; \
>>> })
>>
>> Of course this was going to explode.
>>
>> This isn't even the first time an unwise attempt to do 
>> single-evaluation
>> has needed to be reverted because it doesn't work with Integer Constant
>> Expressions.
>>
>> Switch it back to the first form.  It's obviously a macro to begin 
>> with,
>> and not likely to be used in cases that have side effects.

I guess Nicola's original mail was lacking some pieces. After the issue
with the statement expression form was pointed out, I never asked to
replace the existing (already committed, ...

> Actually no usages of either forms are yet committed, just the 
> definition of the first form, so nothing needs to be reverted.

... with actual uses in MASK_EXTR() and MASK_INSR()) macro. Instead I
was suggesting to have a _second_ macro for use wherever Integer Constant
Expressions aren't the limiting factor. E.g. isolate_lsb(), deliberately
lower-case to look more like a function (and thus communicating that its
argument indeed is going to be evaluated only once, as would be the case
if the whole thing was a function).

Jan


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-17 10:17 Devise macros to encapsulate (x & -x) Nicola Vetrini
  2023-11-17 11:04 ` Andrew Cooper
@ 2023-11-17 11:39 ` Jan Beulich
  2023-11-17 16:12   ` Nicola Vetrini
  2023-11-17 16:15 ` Nicola Vetrini
  2 siblings, 1 reply; 13+ messages in thread
From: Jan Beulich @ 2023-11-17 11:39 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: Consulting, Stefano Stabellini, Andrew Cooper3, George Dunlap,
	Julien Grall, Wei Liu, Roger Pau, Bertrand Marquis, Michal Orzel,
	Xen Devel

On 17.11.2023 11:17, Nicola Vetrini wrote:
> Hi all,
> 
> As discussed in this thread [1], which is about complying with MISRA C 
> Rule 10.1,
> a macro was introduced to encapsulate a well-known construct:
> 
> /*
>   * Given an unsigned integer argument, expands to a mask where just the 
> least
>   * significant nonzero bit of the argument is set, or 0 if no bits are 
> set.
>   */
> #define ISOLATE_LSB(x) ((x) & -(x))
> 
> This macro has a gained some calls in the subsequent patches in that 
> thread, but concerns were raised around the fact that it would be better 
> to devise a macro that evaluates its argument only once. A proposed 
> solution is this (thanks to Jan Beulich):
> 
> #define ISOLATE_LSB(x) ({ \
>       typeof(x) x_ = (x); \
>       x_ & -x_; \
> })
> 
> However, it can't be used in all call sites that the previous macro 
> would have once that series is committed, as can be seen in [2]. 
> Therefore, while the implementation looks ok,
> a case has been made to have separate macros, of which the latter form 
> is preferred.
> 
> The following points require some thought:
> 
> - where the single evaluation macro should be placed?
>    One proposed location is xen/include/xen/bitops.h

Or next to the existing one in macros.h. I can see pros and cons for either.

> - is the proposed form actually the best, or maybe it could be an inline 
> function?

How would you make such a function type generic?

Jan


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-17 11:39 ` Jan Beulich
@ 2023-11-17 16:12   ` Nicola Vetrini
  0 siblings, 0 replies; 13+ messages in thread
From: Nicola Vetrini @ 2023-11-17 16:12 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Consulting, Stefano Stabellini, Andrew Cooper3, George Dunlap,
	Julien Grall, Wei Liu, Roger Pau, Bertrand Marquis, Michal Orzel,
	Xen Devel

On 2023-11-17 12:39, Jan Beulich wrote:
> On 17.11.2023 11:17, Nicola Vetrini wrote:
>> Hi all,
>> 
>> As discussed in this thread [1], which is about complying with MISRA C
>> Rule 10.1,
>> a macro was introduced to encapsulate a well-known construct:
>> 
>> /*
>>   * Given an unsigned integer argument, expands to a mask where just 
>> the
>> least
>>   * significant nonzero bit of the argument is set, or 0 if no bits 
>> are
>> set.
>>   */
>> #define ISOLATE_LSB(x) ((x) & -(x))
>> 
>> This macro has a gained some calls in the subsequent patches in that
>> thread, but concerns were raised around the fact that it would be 
>> better
>> to devise a macro that evaluates its argument only once. A proposed
>> solution is this (thanks to Jan Beulich):
>> 
>> #define ISOLATE_LSB(x) ({ \
>>       typeof(x) x_ = (x); \
>>       x_ & -x_; \
>> })
>> 
>> However, it can't be used in all call sites that the previous macro
>> would have once that series is committed, as can be seen in [2].
>> Therefore, while the implementation looks ok,
>> a case has been made to have separate macros, of which the latter form
>> is preferred.
>> 
>> The following points require some thought:
>> 
>> - where the single evaluation macro should be placed?
>>    One proposed location is xen/include/xen/bitops.h
> 
> Or next to the existing one in macros.h. I can see pros and cons for 
> either.
> 
>> - is the proposed form actually the best, or maybe it could be an 
>> inline
>> function?
> 
> How would you make such a function type generic?
> 

Ah, yes indeed this wouldn't work.

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-17 10:17 Devise macros to encapsulate (x & -x) Nicola Vetrini
  2023-11-17 11:04 ` Andrew Cooper
  2023-11-17 11:39 ` Jan Beulich
@ 2023-11-17 16:15 ` Nicola Vetrini
  2 siblings, 0 replies; 13+ messages in thread
From: Nicola Vetrini @ 2023-11-17 16:15 UTC (permalink / raw)
  To: Xen Devel
  Cc: Consulting, Stefano Stabellini, Jbeulich, Andrew Cooper3,
	George Dunlap, Julien Grall, Wei Liu, Roger Pau, Bertrand Marquis,
	Michal Orzel

On 2023-11-17 11:17, Nicola Vetrini wrote:
> Hi all,
> 
> As discussed in this thread [1], which is about complying with MISRA C 
> Rule 10.1,
> a macro was introduced to encapsulate a well-known construct:
> 
> /*
>  * Given an unsigned integer argument, expands to a mask where just the 
> least
>  * significant nonzero bit of the argument is set, or 0 if no bits are 
> set.
>  */
> #define ISOLATE_LSB(x) ((x) & -(x))
> 
> This macro has a gained some calls in the subsequent patches in that 
> thread, but concerns were raised around the fact that it would be 
> better to devise a macro that evaluates its argument only once. A 
> proposed solution is this (thanks to Jan Beulich):
> 
> #define ISOLATE_LSB(x) ({ \
>      typeof(x) x_ = (x); \
>      x_ & -x_; \
> })
> 
> However, it can't be used in all call sites that the previous macro 
> would have once that series is committed, as can be seen in [2]. 
> Therefore, while the implementation looks ok,
> a case has been made to have separate macros, of which the latter form 
> is preferred.
> 
> The following points require some thought:
> 
> - where the single evaluation macro should be placed?
>   One proposed location is xen/include/xen/bitops.h
> - is the proposed form actually the best, or maybe it could be an 
> inline function?
> 
> Then testing can happen and a subsequent version of those uncommitted 
> patches introducing uses of either construct will be submitted, to 
> modify all the call sites only once in the commit history.
> 
> Let me know what you think of this.
> Regards,
> 
> [1] 
> https://lore.kernel.org/xen-devel/8a1313b3ab5ba6dd556cf37409e3b703@bugseng.com/T/#mdeb510325e1acacb6477a88de8577e9e87351ba5
> [2] https://gitlab.com/xen-project/people/bugseng/xen/-/jobs/5423693947

I did a few tests; the only places where the first form can't be 
replaced are:

- inside BUILD_BUG_ON (two instances in x86/x86_64/mm.c)
- the definition of MASK_EXTR/MASK_INSR
- the definition of PDX_GROUP_COUNT

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-17 11:04 ` Andrew Cooper
  2023-11-17 11:15   ` Nicola Vetrini
@ 2023-11-18  2:46   ` Stefano Stabellini
  2023-11-20 11:16     ` Julien Grall
  1 sibling, 1 reply; 13+ messages in thread
From: Stefano Stabellini @ 2023-11-18  2:46 UTC (permalink / raw)
  To: Andrew Cooper
  Cc: Nicola Vetrini, Xen Devel, Consulting, Stefano Stabellini,
	Jbeulich, George Dunlap, Julien Grall, Wei Liu, Roger Pau,
	Bertrand Marquis, Michal Orzel

[-- Attachment #1: Type: text/plain, Size: 1221 bytes --]

On Fri, 17 Nov 2023, Andrew Cooper wrote:
> On 17/11/2023 10:17 am, Nicola Vetrini wrote:
> > Hi all,
> >
> > As discussed in this thread [1], which is about complying with MISRA C
> > Rule 10.1,
> > a macro was introduced to encapsulate a well-known construct:
> >
> > /*
> >  * Given an unsigned integer argument, expands to a mask where just
> > the least
> >  * significant nonzero bit of the argument is set, or 0 if no bits are
> > set.
> >  */
> > #define ISOLATE_LSB(x) ((x) & -(x))
> >
> > This macro has a gained some calls in the subsequent patches in that
> > thread, but concerns were raised around the fact that it would be
> > better to devise a macro that evaluates its argument only once. A
> > proposed solution is this (thanks to Jan Beulich):
> >
> > #define ISOLATE_LSB(x) ({ \
> >      typeof(x) x_ = (x); \
> >      x_ & -x_; \
> > })
> 
> Of course this was going to explode.
> 
> This isn't even the first time an unwise attempt to do single-evaluation
> has needed to be reverted because it doesn't work with Integer Constant
> Expressions.
> 
> Switch it back to the first form.  It's obviously a macro to begin with,
> and not likely to be used in cases that have side effects.

+1

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-18  2:46   ` Stefano Stabellini
@ 2023-11-20 11:16     ` Julien Grall
  2023-11-22  1:43       ` Stefano Stabellini
  0 siblings, 1 reply; 13+ messages in thread
From: Julien Grall @ 2023-11-20 11:16 UTC (permalink / raw)
  To: Stefano Stabellini, Andrew Cooper
  Cc: Nicola Vetrini, Xen Devel, Consulting, Jbeulich, George Dunlap,
	Wei Liu, Roger Pau, Bertrand Marquis, Michal Orzel



On 18/11/2023 02:46, Stefano Stabellini wrote:
> On Fri, 17 Nov 2023, Andrew Cooper wrote:
>> On 17/11/2023 10:17 am, Nicola Vetrini wrote:
>>> Hi all,
>>>
>>> As discussed in this thread [1], which is about complying with MISRA C
>>> Rule 10.1,
>>> a macro was introduced to encapsulate a well-known construct:
>>>
>>> /*
>>>   * Given an unsigned integer argument, expands to a mask where just
>>> the least
>>>   * significant nonzero bit of the argument is set, or 0 if no bits are
>>> set.
>>>   */
>>> #define ISOLATE_LSB(x) ((x) & -(x))
>>>
>>> This macro has a gained some calls in the subsequent patches in that
>>> thread, but concerns were raised around the fact that it would be
>>> better to devise a macro that evaluates its argument only once. A
>>> proposed solution is this (thanks to Jan Beulich):
>>>
>>> #define ISOLATE_LSB(x) ({ \
>>>       typeof(x) x_ = (x); \
>>>       x_ & -x_; \
>>> })
>>
>> Of course this was going to explode.
>>
>> This isn't even the first time an unwise attempt to do single-evaluation
>> has needed to be reverted because it doesn't work with Integer Constant
>> Expressions.
>>
>> Switch it back to the first form.  It's obviously a macro to begin with,
>> and not likely to be used in cases that have side effects.
> 
> +1

FWIW +1. I don't much like the idea to have two different versions of 
the helper if there is no real need for it.

Cheers,

-- 
Julien Grall


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-20 11:16     ` Julien Grall
@ 2023-11-22  1:43       ` Stefano Stabellini
  2023-11-22  8:07         ` Jan Beulich
  0 siblings, 1 reply; 13+ messages in thread
From: Stefano Stabellini @ 2023-11-22  1:43 UTC (permalink / raw)
  To: Julien Grall
  Cc: Stefano Stabellini, Andrew Cooper, Nicola Vetrini, Xen Devel,
	Consulting, Jbeulich, George Dunlap, Wei Liu, Roger Pau,
	Bertrand Marquis, Michal Orzel

[-- Attachment #1: Type: text/plain, Size: 1766 bytes --]

On Mon, 20 Nov 2023, Julien Grall wrote:
> On 18/11/2023 02:46, Stefano Stabellini wrote:
> > On Fri, 17 Nov 2023, Andrew Cooper wrote:
> > > On 17/11/2023 10:17 am, Nicola Vetrini wrote:
> > > > Hi all,
> > > > 
> > > > As discussed in this thread [1], which is about complying with MISRA C
> > > > Rule 10.1,
> > > > a macro was introduced to encapsulate a well-known construct:
> > > > 
> > > > /*
> > > >   * Given an unsigned integer argument, expands to a mask where just
> > > > the least
> > > >   * significant nonzero bit of the argument is set, or 0 if no bits are
> > > > set.
> > > >   */
> > > > #define ISOLATE_LSB(x) ((x) & -(x))
> > > > 
> > > > This macro has a gained some calls in the subsequent patches in that
> > > > thread, but concerns were raised around the fact that it would be
> > > > better to devise a macro that evaluates its argument only once. A
> > > > proposed solution is this (thanks to Jan Beulich):
> > > > 
> > > > #define ISOLATE_LSB(x) ({ \
> > > >       typeof(x) x_ = (x); \
> > > >       x_ & -x_; \
> > > > })
> > > 
> > > Of course this was going to explode.
> > > 
> > > This isn't even the first time an unwise attempt to do single-evaluation
> > > has needed to be reverted because it doesn't work with Integer Constant
> > > Expressions.
> > > 
> > > Switch it back to the first form.  It's obviously a macro to begin with,
> > > and not likely to be used in cases that have side effects.
> > 
> > +1
> 
> FWIW +1. I don't much like the idea to have two different versions of the
> helper if there is no real need for it.

Jan, would you be willing to accept that other maintainers have a
preference for having a single MACRO even if suboptimal?

If so, can we go ahead and commit the original patches?

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-22  1:43       ` Stefano Stabellini
@ 2023-11-22  8:07         ` Jan Beulich
  2023-11-22  9:27           ` Nicola Vetrini
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Beulich @ 2023-11-22  8:07 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Andrew Cooper, Nicola Vetrini, Xen Devel, Consulting,
	George Dunlap, Wei Liu, Roger Pau, Bertrand Marquis, Michal Orzel,
	Julien Grall

On 22.11.2023 02:43, Stefano Stabellini wrote:
> On Mon, 20 Nov 2023, Julien Grall wrote:
>> On 18/11/2023 02:46, Stefano Stabellini wrote:
>>> On Fri, 17 Nov 2023, Andrew Cooper wrote:
>>>> On 17/11/2023 10:17 am, Nicola Vetrini wrote:
>>>>> Hi all,
>>>>>
>>>>> As discussed in this thread [1], which is about complying with MISRA C
>>>>> Rule 10.1,
>>>>> a macro was introduced to encapsulate a well-known construct:
>>>>>
>>>>> /*
>>>>>   * Given an unsigned integer argument, expands to a mask where just
>>>>> the least
>>>>>   * significant nonzero bit of the argument is set, or 0 if no bits are
>>>>> set.
>>>>>   */
>>>>> #define ISOLATE_LSB(x) ((x) & -(x))
>>>>>
>>>>> This macro has a gained some calls in the subsequent patches in that
>>>>> thread, but concerns were raised around the fact that it would be
>>>>> better to devise a macro that evaluates its argument only once. A
>>>>> proposed solution is this (thanks to Jan Beulich):
>>>>>
>>>>> #define ISOLATE_LSB(x) ({ \
>>>>>       typeof(x) x_ = (x); \
>>>>>       x_ & -x_; \
>>>>> })
>>>>
>>>> Of course this was going to explode.
>>>>
>>>> This isn't even the first time an unwise attempt to do single-evaluation
>>>> has needed to be reverted because it doesn't work with Integer Constant
>>>> Expressions.
>>>>
>>>> Switch it back to the first form.  It's obviously a macro to begin with,
>>>> and not likely to be used in cases that have side effects.
>>>
>>> +1
>>
>> FWIW +1. I don't much like the idea to have two different versions of the
>> helper if there is no real need for it.
> 
> Jan, would you be willing to accept that other maintainers have a
> preference for having a single MACRO even if suboptimal?

I can live with that, even if I'm surprised by this perspective that others
take. How can we, in reviews, tell people to make sure arguments are
evaluated only once, when then we deliberately do otherwise in a case like
the one here? The criteria of "not likely to be used in cases that have
side effects" is an extremely fuzzy and sufficiently weak one, imo. I for
one am even worried about the uses in MASK_EXTR() / MASK_INSR(), and would
have considered introducing single-evaluation forms there as well.

> If so, can we go ahead and commit the original patches?

Well, the renaming needs to be done there anyway.

Jan


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-22  8:07         ` Jan Beulich
@ 2023-11-22  9:27           ` Nicola Vetrini
  2023-11-22 21:22             ` Stefano Stabellini
  0 siblings, 1 reply; 13+ messages in thread
From: Nicola Vetrini @ 2023-11-22  9:27 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Stefano Stabellini, Andrew Cooper, Xen Devel, Consulting,
	George Dunlap, Wei Liu, Roger Pau, Bertrand Marquis, Michal Orzel,
	Julien Grall


>> 
>> Jan, would you be willing to accept that other maintainers have a
>> preference for having a single MACRO even if suboptimal?
> 
> I can live with that, even if I'm surprised by this perspective that 
> others
> take. How can we, in reviews, tell people to make sure arguments are
> evaluated only once, when then we deliberately do otherwise in a case 
> like
> the one here? The criteria of "not likely to be used in cases that have
> side effects" is an extremely fuzzy and sufficiently weak one, imo. I 
> for
> one am even worried about the uses in MASK_EXTR() / MASK_INSR(), and 
> would
> have considered introducing single-evaluation forms there as well.
> 
>> If so, can we go ahead and commit the original patches?
> 
> Well, the renaming needs to be done there anyway.
> 

I can do the renaming if you don't feel particularly safe doing it on 
commit. I already modified my local version to do experiments with 
single evaluation anyway.

-- 
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Devise macros to encapsulate (x & -x)
  2023-11-22  9:27           ` Nicola Vetrini
@ 2023-11-22 21:22             ` Stefano Stabellini
  0 siblings, 0 replies; 13+ messages in thread
From: Stefano Stabellini @ 2023-11-22 21:22 UTC (permalink / raw)
  To: Nicola Vetrini
  Cc: Jan Beulich, Stefano Stabellini, Andrew Cooper, Xen Devel,
	Consulting, George Dunlap, Wei Liu, Roger Pau, Bertrand Marquis,
	Michal Orzel, Julien Grall

On Wed, 22 Nov 2023, Nicola Vetrini wrote:
> > > 
> > > Jan, would you be willing to accept that other maintainers have a
> > > preference for having a single MACRO even if suboptimal?
> > 
> > I can live with that, even if I'm surprised by this perspective that others
> > take. How can we, in reviews, tell people to make sure arguments are
> > evaluated only once, when then we deliberately do otherwise in a case like
> > the one here? The criteria of "not likely to be used in cases that have
> > side effects" is an extremely fuzzy and sufficiently weak one, imo. I for
> > one am even worried about the uses in MASK_EXTR() / MASK_INSR(), and would
> > have considered introducing single-evaluation forms there as well.
> > 
> > > If so, can we go ahead and commit the original patches?
> > 
> > Well, the renaming needs to be done there anyway.
> > 
> 
> I can do the renaming if you don't feel particularly safe doing it on commit

Please resend


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-11-22 21:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-17 10:17 Devise macros to encapsulate (x & -x) Nicola Vetrini
2023-11-17 11:04 ` Andrew Cooper
2023-11-17 11:15   ` Nicola Vetrini
2023-11-17 11:37     ` Jan Beulich
2023-11-18  2:46   ` Stefano Stabellini
2023-11-20 11:16     ` Julien Grall
2023-11-22  1:43       ` Stefano Stabellini
2023-11-22  8:07         ` Jan Beulich
2023-11-22  9:27           ` Nicola Vetrini
2023-11-22 21:22             ` Stefano Stabellini
2023-11-17 11:39 ` Jan Beulich
2023-11-17 16:12   ` Nicola Vetrini
2023-11-17 16:15 ` Nicola Vetrini

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.