diff mbox series

[RFC,3/4] sh: define __BIG_ENDIAN for math-emu

Message ID 20210602231443.4670-3-rdunlap@infradead.org (mailing list archive)
State New
Headers show
Series sh: fixes for various build warnings | expand

Commit Message

Randy Dunlap June 2, 2021, 11:14 p.m. UTC
The headers in include/math-emu/ test for __BYTE_ORDER == __BIG_ENDIAN
without checking to see if these macros are defined, so add
a define for __BIG_ENDIAN before pulling in these headers.

This placates these build warnings:

In file included from ../arch/sh/math-emu/math.c:23:
../include/math-emu/single.h:50:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
   50 | #if __BYTE_ORDER == __BIG_ENDIAN
In file included from ../arch/sh/math-emu/math.c:24:
../include/math-emu/double.h:59:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
   59 | #if __BYTE_ORDER == __BIG_ENDIAN

Fixes: 4b565680d163 ("sh: math-emu support")
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: linux-sh@vger.kernel.org
---
 arch/sh/math-emu/sfp-util.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Geert Uytterhoeven June 3, 2021, 7:54 a.m. UTC | #1
Hi Randy,

On Thu, Jun 3, 2021 at 1:17 AM Randy Dunlap <rdunlap@infradead.org> wrote:
> The headers in include/math-emu/ test for __BYTE_ORDER == __BIG_ENDIAN
> without checking to see if these macros are defined, so add
> a define for __BIG_ENDIAN before pulling in these headers.
>
> This placates these build warnings:
>
> In file included from ../arch/sh/math-emu/math.c:23:
> ../include/math-emu/single.h:50:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
>    50 | #if __BYTE_ORDER == __BIG_ENDIAN
> In file included from ../arch/sh/math-emu/math.c:24:
> ../include/math-emu/double.h:59:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
>    59 | #if __BYTE_ORDER == __BIG_ENDIAN
>
> Fixes: 4b565680d163 ("sh: math-emu support")
> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>

Thanks for your patch!

> --- linux-next-20210528.orig/arch/sh/math-emu/sfp-util.h
> +++ linux-next-20210528/arch/sh/math-emu/sfp-util.h
> @@ -70,4 +70,4 @@
>
>  #define __BYTE_ORDER __LITTLE_ENDIAN
>
> -
> +#define __BIG_ENDIAN 0

I don't think this is the right fix.

I think the right values should be picked up from:

    include/uapi/linux/byteorder/big_endian.h:#define __BIG_ENDIAN 4321
    include/uapi/linux/byteorder/little_endian.h:#define __LITTLE_ENDIAN 1234

How is this picked up on other architectures using <math-emu/single.h>?

Gr{oetje,eeting}s,

                        Geert
Randy Dunlap June 3, 2021, 11:19 p.m. UTC | #2
On 6/3/21 12:54 AM, Geert Uytterhoeven wrote:
> Hi Randy,
> 
> On Thu, Jun 3, 2021 at 1:17 AM Randy Dunlap <rdunlap@infradead.org> wrote:
>> The headers in include/math-emu/ test for __BYTE_ORDER == __BIG_ENDIAN
>> without checking to see if these macros are defined, so add
>> a define for __BIG_ENDIAN before pulling in these headers.
>>
>> This placates these build warnings:
>>
>> In file included from ../arch/sh/math-emu/math.c:23:
>> ../include/math-emu/single.h:50:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
>>    50 | #if __BYTE_ORDER == __BIG_ENDIAN
>> In file included from ../arch/sh/math-emu/math.c:24:
>> ../include/math-emu/double.h:59:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
>>    59 | #if __BYTE_ORDER == __BIG_ENDIAN
>>
>> Fixes: 4b565680d163 ("sh: math-emu support")
>> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> 
> Thanks for your patch!
> 
>> --- linux-next-20210528.orig/arch/sh/math-emu/sfp-util.h
>> +++ linux-next-20210528/arch/sh/math-emu/sfp-util.h
>> @@ -70,4 +70,4 @@
>>
>>  #define __BYTE_ORDER __LITTLE_ENDIAN
>>
>> -
>> +#define __BIG_ENDIAN 0
> 
> I don't think this is the right fix.
> 
> I think the right values should be picked up from:
> 
>     include/uapi/linux/byteorder/big_endian.h:#define __BIG_ENDIAN 4321
>     include/uapi/linux/byteorder/little_endian.h:#define __LITTLE_ENDIAN 1234
> 
> How is this picked up on other architectures using <math-emu/single.h>?

Hi Geert,

There isn't very much to compare to in other arch/.
I've made a v2 patch that is done like arch/nds32/ does.
What do you think about this one?

thanks.
---
From: Randy Dunlap <rdunlap@infradead.org>
Subject: [RFC PATCH 2/3 v2] sh: define __BIG_ENDIAN for math-emu

Fix this by defining both ENDIAN macros in
<asm/sfp-machine.h> so that they can be utilized in
<math-emu/soft-fp.h> according to the latter's comment:
/* Allow sfp-machine to have its own byte order definitions. */

(This is what is done in arch/nds32/include/asm/sfp-machine.h.)

This placates these build warnings:

In file included from ../arch/sh/math-emu/math.c:23:
../include/math-emu/single.h:50:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
   50 | #if __BYTE_ORDER == __BIG_ENDIAN
In file included from ../arch/sh/math-emu/math.c:24:
../include/math-emu/double.h:59:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
   59 | #if __BYTE_ORDER == __BIG_ENDIAN

Fixes: 4b565680d163 ("sh: math-emu support")
Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: linux-sh@vger.kernel.org
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
---
 arch/sh/include/asm/sfp-machine.h |    8 ++++++++
 1 file changed, 8 insertions(+)

--- linux-next-20210528.orig/arch/sh/include/asm/sfp-machine.h
+++ linux-next-20210528/arch/sh/include/asm/sfp-machine.h
@@ -13,6 +13,14 @@
 #ifndef _SFP_MACHINE_H
 #define _SFP_MACHINE_H
 
+#ifdef __BIG_ENDIAN__
+#define __BYTE_ORDER __BIG_ENDIAN
+#define __LITTLE_ENDIAN 0
+#else
+#define __BYTE_ORDER __LITTLE_ENDIAN
+#define __BIG_ENDIAN 0
+#endif
+
 #define _FP_W_TYPE_SIZE		32
 #define _FP_W_TYPE		unsigned long
 #define _FP_WS_TYPE		signed long
Geert Uytterhoeven June 4, 2021, 7:24 a.m. UTC | #3
Hi Randy,

On Fri, Jun 4, 2021 at 1:19 AM Randy Dunlap <rdunlap@infradead.org> wrote:
> On 6/3/21 12:54 AM, Geert Uytterhoeven wrote:
> > On Thu, Jun 3, 2021 at 1:17 AM Randy Dunlap <rdunlap@infradead.org> wrote:
> >> The headers in include/math-emu/ test for __BYTE_ORDER == __BIG_ENDIAN
> >> without checking to see if these macros are defined, so add
> >> a define for __BIG_ENDIAN before pulling in these headers.
> >>
> >> This placates these build warnings:
> >>
> >> In file included from ../arch/sh/math-emu/math.c:23:
> >> ../include/math-emu/single.h:50:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
> >>    50 | #if __BYTE_ORDER == __BIG_ENDIAN
> >> In file included from ../arch/sh/math-emu/math.c:24:
> >> ../include/math-emu/double.h:59:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
> >>    59 | #if __BYTE_ORDER == __BIG_ENDIAN
> >>
> >> Fixes: 4b565680d163 ("sh: math-emu support")
> >> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> >
> > Thanks for your patch!
> >
> >> --- linux-next-20210528.orig/arch/sh/math-emu/sfp-util.h
> >> +++ linux-next-20210528/arch/sh/math-emu/sfp-util.h
> >> @@ -70,4 +70,4 @@
> >>
> >>  #define __BYTE_ORDER __LITTLE_ENDIAN
> >>
> >> -
> >> +#define __BIG_ENDIAN 0
> >
> > I don't think this is the right fix.
> >
> > I think the right values should be picked up from:
> >
> >     include/uapi/linux/byteorder/big_endian.h:#define __BIG_ENDIAN 4321
> >     include/uapi/linux/byteorder/little_endian.h:#define __LITTLE_ENDIAN 1234
> >
> > How is this picked up on other architectures using <math-emu/single.h>?
>
> There isn't very much to compare to in other arch/.
> I've made a v2 patch that is done like arch/nds32/ does.
> What do you think about this one?
>
> thanks.
> ---
> From: Randy Dunlap <rdunlap@infradead.org>
> Subject: [RFC PATCH 2/3 v2] sh: define __BIG_ENDIAN for math-emu
>
> Fix this by defining both ENDIAN macros in
> <asm/sfp-machine.h> so that they can be utilized in
> <math-emu/soft-fp.h> according to the latter's comment:
> /* Allow sfp-machine to have its own byte order definitions. */
>
> (This is what is done in arch/nds32/include/asm/sfp-machine.h.)
>
> This placates these build warnings:
>
> In file included from ../arch/sh/math-emu/math.c:23:
> ../include/math-emu/single.h:50:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
>    50 | #if __BYTE_ORDER == __BIG_ENDIAN
> In file included from ../arch/sh/math-emu/math.c:24:
> ../include/math-emu/double.h:59:21: warning: "__BIG_ENDIAN" is not defined, evaluates to 0 [-Wundef]
>    59 | #if __BYTE_ORDER == __BIG_ENDIAN
>
> Fixes: 4b565680d163 ("sh: math-emu support")
> Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> Cc: Rich Felker <dalias@libc.org>
> Cc: linux-sh@vger.kernel.org
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
> ---
>  arch/sh/include/asm/sfp-machine.h |    8 ++++++++
>  1 file changed, 8 insertions(+)
>
> --- linux-next-20210528.orig/arch/sh/include/asm/sfp-machine.h
> +++ linux-next-20210528/arch/sh/include/asm/sfp-machine.h
> @@ -13,6 +13,14 @@
>  #ifndef _SFP_MACHINE_H
>  #define _SFP_MACHINE_H
>
> +#ifdef __BIG_ENDIAN__
> +#define __BYTE_ORDER __BIG_ENDIAN
> +#define __LITTLE_ENDIAN 0
> +#else
> +#define __BYTE_ORDER __LITTLE_ENDIAN
> +#define __BIG_ENDIAN 0
> +#endif
> +
>  #define _FP_W_TYPE_SIZE                32
>  #define _FP_W_TYPE             unsigned long
>  #define _FP_WS_TYPE            signed long

These checks match with what is set by my sh cross-compiler (gcc
8.1.0):

diff <(sh4-linux-gcc-8.1.0 -ml -dM -E - < /dev/null | grep -E
"(BYTE_ORDER|ENDIAN)") <(sh4-linux-gcc-8.1.0 -mb -dM -E - < /dev/null
| grep -E "(BYTE_ORDER|ENDIAN)")
--- /dev/fd/63 2021-06-04 09:15:50.689928352 +0200
+++ /dev/fd/62 2021-06-04 09:15:50.689928352 +0200
@@ -1,6 +1,6 @@
 #define __ORDER_LITTLE_ENDIAN__ 1234
-#define __FLOAT_WORD_ORDER__ __ORDER_LITTLE_ENDIAN__
+#define __BIG_ENDIAN__ 1
+#define __FLOAT_WORD_ORDER__ __ORDER_BIG_ENDIAN__
 #define __ORDER_PDP_ENDIAN__ 3412
-#define __LITTLE_ENDIAN__ 1
 #define __ORDER_BIG_ENDIAN__ 4321
-#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
+#define __BYTE_ORDER__ __ORDER_BIG_ENDIAN__

So
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Note that powerpc checks on _BIG_ENDIAN, which works as my powerpc
cross-compiler (gcc 9.3.0) defines both _BIG_ENDIAN and _BIG_ENDIAN__.

Gr{oetje,eeting}s,

                        Geert
diff mbox series

Patch

--- linux-next-20210528.orig/arch/sh/math-emu/sfp-util.h
+++ linux-next-20210528/arch/sh/math-emu/sfp-util.h
@@ -70,4 +70,4 @@ 
 
 #define __BYTE_ORDER __LITTLE_ENDIAN
 
-
+#define __BIG_ENDIAN 0