mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: + include-uapi-linux-swabh-move-explicit-cast-outside-ternary.patch added to mm-nonmm-unstable branch
       [not found] <20220609172933.D8187C34114@smtp.kernel.org>
@ 2022-06-09 20:42 ` Alexey Dobriyan
  2022-06-09 21:01   ` Nick Desaulniers
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Dobriyan @ 2022-06-09 20:42 UTC (permalink / raw)
  To: linux-kernel; +Cc: viro, ndesaulniers, nathan, jstitt007, akpm

On Thu, Jun 09, 2022 at 10:29:33AM -0700, Andrew Morton wrote:
> A cast inside __builtin_constant_p doesn't do anything since it should
> evaluate as constant at compile time irrespective of this cast.  Instead,
> I moved this cast outside the ternary to ensure the return type is as
> expected.

> --- a/include/uapi/linux/swab.h~include-uapi-linux-swabh-move-explicit-cast-outside-ternary
> +++ a/include/uapi/linux/swab.h
> @@ -102,7 +102,7 @@ static inline __attribute_const__ __u32
>  #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
>  #else
>  #define __swab16(x)				\
> -	(__builtin_constant_p((__u16)(x)) ?	\
> +	(__u16)(__builtin_constant_p(x) ?	\

This cast is necessary.

>  	___constant_swab16(x) :			\
>  	__fswab16(x))
>  #endif
> @@ -115,7 +115,7 @@ static inline __attribute_const__ __u32
>  #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
>  #else
>  #define __swab32(x)				\
> -	(__builtin_constant_p((__u32)(x)) ?	\
> +	(__u32)(__builtin_constant_p(x) ?	\
>  	___constant_swab32(x) :			\
>  	__fswab32(x))
>  #endif
> @@ -128,7 +128,7 @@ static inline __attribute_const__ __u32
>  #define __swab64(x) (__u64)__builtin_bswap64((__u64)(x))
>  #else
>  #define __swab64(x)				\
> -	(__builtin_constant_p((__u64)(x)) ?	\
> +	(__u64)(__builtin_constant_p(x) ?	\
>  	___constant_swab64(x) :			\
>  	__fswab64(x))

These two aren't? typeof(c ? u32 : u32) is u32.

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

* Re: + include-uapi-linux-swabh-move-explicit-cast-outside-ternary.patch added to mm-nonmm-unstable branch
  2022-06-09 20:42 ` + include-uapi-linux-swabh-move-explicit-cast-outside-ternary.patch added to mm-nonmm-unstable branch Alexey Dobriyan
@ 2022-06-09 21:01   ` Nick Desaulniers
  2022-06-09 21:08     ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Nick Desaulniers @ 2022-06-09 21:01 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: linux-kernel, viro, nathan, jstitt007, akpm

On Thu, Jun 9, 2022 at 1:42 PM Alexey Dobriyan <adobriyan@gmail.com> wrote:
>
> On Thu, Jun 09, 2022 at 10:29:33AM -0700, Andrew Morton wrote:
> > A cast inside __builtin_constant_p doesn't do anything since it should
> > evaluate as constant at compile time irrespective of this cast.  Instead,
> > I moved this cast outside the ternary to ensure the return type is as
> > expected.
>
> > --- a/include/uapi/linux/swab.h~include-uapi-linux-swabh-move-explicit-cast-outside-ternary
> > +++ a/include/uapi/linux/swab.h
> > @@ -102,7 +102,7 @@ static inline __attribute_const__ __u32
> >  #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
> >  #else
> >  #define __swab16(x)                          \
> > -     (__builtin_constant_p((__u16)(x)) ?     \
> > +     (__u16)(__builtin_constant_p(x) ?       \
>
> This cast is necessary.
>
> >       ___constant_swab16(x) :                 \
> >       __fswab16(x))
> >  #endif
> > @@ -115,7 +115,7 @@ static inline __attribute_const__ __u32
> >  #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
> >  #else
> >  #define __swab32(x)                          \
> > -     (__builtin_constant_p((__u32)(x)) ?     \
> > +     (__u32)(__builtin_constant_p(x) ?       \
> >       ___constant_swab32(x) :                 \
> >       __fswab32(x))
> >  #endif
> > @@ -128,7 +128,7 @@ static inline __attribute_const__ __u32
> >  #define __swab64(x) (__u64)__builtin_bswap64((__u64)(x))
> >  #else
> >  #define __swab64(x)                          \
> > -     (__builtin_constant_p((__u64)(x)) ?     \
> > +     (__u64)(__builtin_constant_p(x) ?       \
> >       ___constant_swab64(x) :                 \
> >       __fswab64(x))
>
> These two aren't? typeof(c ? u32 : u32) is u32.

Correct.

Neither are the casts on the return values of the calls to
__builtin_bswap* in the cases where __HAVE_BUILTIN_BSWAP*__ are
defined. If you want to send a patch on top of Justin's/on top of
mm-nonmm-unstable, I'll ack it.  Or Andrew, you can drop v3 and Justin
can send a v4 with Alexey's suggestions?
-- 
Thanks,
~Nick Desaulniers

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

* Re: + include-uapi-linux-swabh-move-explicit-cast-outside-ternary.patch added to mm-nonmm-unstable branch
  2022-06-09 21:01   ` Nick Desaulniers
@ 2022-06-09 21:08     ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2022-06-09 21:08 UTC (permalink / raw)
  To: Nick Desaulniers; +Cc: Alexey Dobriyan, linux-kernel, viro, nathan, jstitt007

On Thu, 9 Jun 2022 14:01:17 -0700 Nick Desaulniers <ndesaulniers@google.com> wrote:

> On Thu, Jun 9, 2022 at 1:42 PM Alexey Dobriyan <adobriyan@gmail.com> wrote:
> >
> > On Thu, Jun 09, 2022 at 10:29:33AM -0700, Andrew Morton wrote:
> > > A cast inside __builtin_constant_p doesn't do anything since it should
> > > evaluate as constant at compile time irrespective of this cast.  Instead,
> > > I moved this cast outside the ternary to ensure the return type is as
> > > expected.
> >
> > > --- a/include/uapi/linux/swab.h~include-uapi-linux-swabh-move-explicit-cast-outside-ternary
> > > +++ a/include/uapi/linux/swab.h
> > > @@ -102,7 +102,7 @@ static inline __attribute_const__ __u32
> > >  #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
> > >  #else
> > >  #define __swab16(x)                          \
> > > -     (__builtin_constant_p((__u16)(x)) ?     \
> > > +     (__u16)(__builtin_constant_p(x) ?       \
> >
> > This cast is necessary.
> >
> > >       ___constant_swab16(x) :                 \
> > >       __fswab16(x))
> > >  #endif
> > > @@ -115,7 +115,7 @@ static inline __attribute_const__ __u32
> > >  #define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
> > >  #else
> > >  #define __swab32(x)                          \
> > > -     (__builtin_constant_p((__u32)(x)) ?     \
> > > +     (__u32)(__builtin_constant_p(x) ?       \
> > >       ___constant_swab32(x) :                 \
> > >       __fswab32(x))
> > >  #endif
> > > @@ -128,7 +128,7 @@ static inline __attribute_const__ __u32
> > >  #define __swab64(x) (__u64)__builtin_bswap64((__u64)(x))
> > >  #else
> > >  #define __swab64(x)                          \
> > > -     (__builtin_constant_p((__u64)(x)) ?     \
> > > +     (__u64)(__builtin_constant_p(x) ?       \
> > >       ___constant_swab64(x) :                 \
> > >       __fswab64(x))
> >
> > These two aren't? typeof(c ? u32 : u32) is u32.
> 
> Correct.
> 
> Neither are the casts on the return values of the calls to
> __builtin_bswap* in the cases where __HAVE_BUILTIN_BSWAP*__ are
> defined. If you want to send a patch on top of Justin's/on top of
> mm-nonmm-unstable, I'll ack it.  Or Andrew, you can drop v3 and Justin
> can send a v4 with Alexey's suggestions?

I figured we'd leave it as-is for simple symmetry.

If we're going to have one implementation different from the others
then it would be good to have a code comment explaining why.


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

end of thread, other threads:[~2022-06-09 21:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20220609172933.D8187C34114@smtp.kernel.org>
2022-06-09 20:42 ` + include-uapi-linux-swabh-move-explicit-cast-outside-ternary.patch added to mm-nonmm-unstable branch Alexey Dobriyan
2022-06-09 21:01   ` Nick Desaulniers
2022-06-09 21:08     ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®