[0/2] riscv: Fix gas when encoding BE floats/doubles

Message ID AM6PR03MB49843D0F7C0438ADEB19172E985BA@AM6PR03MB4984.eurprd03.prod.outlook.com
State Repeat Merge
Headers

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

Branislav Brzak June 15, 2023, 11:09 a.m. UTC
  RISCV gas currently does not take into consideration -mbig-endian
directive when encoding floats and doubles. The effect is that when
-mbig-endian is supplied floats and doubles are endian flipped only
on 2-byte boundaries, for example:

.data:
      .float 1.1

Compiled as LE will be encoded as: 0xcdcc8c3f
And BE encoded will be: 0x8c3fcdcc

The correct sequence is 0x3f8ccccd

This patch introduces a fix in float/double endian encoding and
set of tests that verify validity of LE and BE float and double
encoding.

Branislav Brzak (2):
      gas: Fix float/double BE encoding in RISCV.
      riscv: Add LE/BE float/double encoding tests.

 gas/config/tc-riscv.c
 gas/testsuite/gas/riscv/double-be.d | 18 ++++++++++++++++++
 gas/testsuite/gas/riscv/double-le.d | 18 ++++++++++++++++++
 gas/testsuite/gas/riscv/double.s    | 21 +++++++++++++++++++++
 gas/testsuite/gas/riscv/float-be.d  | 13 +++++++++++++
 gas/testsuite/gas/riscv/float-le.d  | 13 +++++++++++++
 gas/testsuite/gas/riscv/float.s     | 21 +++++++++++++++++++++
 7 files changed, 105 insertions(+), 1 deletion(-)
  

Comments

Jan Beulich June 15, 2023, 12:09 p.m. UTC | #1
On 15.06.2023 13:09, Branislav Brzak wrote:
> RISCV gas currently does not take into consideration -mbig-endian
> directive when encoding floats and doubles. The effect is that when
> -mbig-endian is supplied floats and doubles are endian flipped only
> on 2-byte boundaries, for example:
> 
> .data:
>       .float 1.1
> 
> Compiled as LE will be encoded as: 0xcdcc8c3f
> And BE encoded will be: 0x8c3fcdcc
> 
> The correct sequence is 0x3f8ccccd
> 
> This patch introduces a fix in float/double endian encoding and
> set of tests that verify validity of LE and BE float and double
> encoding.
> 
> Branislav Brzak (2):
>       gas: Fix float/double BE encoding in RISCV.
>       riscv: Add LE/BE float/double encoding tests.
> 
>  gas/config/tc-riscv.c
>  gas/testsuite/gas/riscv/double-be.d | 18 ++++++++++++++++++
>  gas/testsuite/gas/riscv/double-le.d | 18 ++++++++++++++++++
>  gas/testsuite/gas/riscv/double.s    | 21 +++++++++++++++++++++
>  gas/testsuite/gas/riscv/float-be.d  | 13 +++++++++++++
>  gas/testsuite/gas/riscv/float-le.d  | 13 +++++++++++++
>  gas/testsuite/gas/riscv/float.s     | 21 +++++++++++++++++++++
>  7 files changed, 105 insertions(+), 1 deletion(-)

Did you see
https://sourceware.org/pipermail/binutils/2023-June/127845.html
? (Only the cover letter came through so far, so I can't tell yet
whether you do anything different than Andreas does. Also, as an
aside, it typically helps if you Cc arch maintainers for arch
patches.)

Jan
  
Branislav Brzak June 15, 2023, 12:14 p.m. UTC | #2
Hi,

I wasn't aware of that patch. The only difference between
my patch and Andreas are that I have added tests to test
encoding of doubles as well as float ones.

Regards,
Branislav

________________________________
From: Jan Beulich <jbeulich@suse.com>
Sent: Thursday, June 15, 2023 2:09 PM
To: Branislav Brzak <Branislav.Brzak@Syrmia.com>
Cc: Dragoslav Sicarov <Dragoslav.Sicarov@Syrmia.com>; Djordje Todorovic <Djordje.Todorovic@syrmia.com>; binutils@sourceware.org <binutils@sourceware.org>
Subject: Re: [PATCH 0/2] riscv: Fix gas when encoding BE floats/doubles

On 15.06.2023 13:09, Branislav Brzak wrote:
> RISCV gas currently does not take into consideration -mbig-endian
> directive when encoding floats and doubles. The effect is that when
> -mbig-endian is supplied floats and doubles are endian flipped only
> on 2-byte boundaries, for example:
>
> .data:
>       .float 1.1
>
> Compiled as LE will be encoded as: 0xcdcc8c3f
> And BE encoded will be: 0x8c3fcdcc
>
> The correct sequence is 0x3f8ccccd
>
> This patch introduces a fix in float/double endian encoding and
> set of tests that verify validity of LE and BE float and double
> encoding.
>
> Branislav Brzak (2):
>       gas: Fix float/double BE encoding in RISCV.
>       riscv: Add LE/BE float/double encoding tests.
>
>  gas/config/tc-riscv.c
>  gas/testsuite/gas/riscv/double-be.d | 18 ++++++++++++++++++
>  gas/testsuite/gas/riscv/double-le.d | 18 ++++++++++++++++++
>  gas/testsuite/gas/riscv/double.s    | 21 +++++++++++++++++++++
>  gas/testsuite/gas/riscv/float-be.d  | 13 +++++++++++++
>  gas/testsuite/gas/riscv/float-le.d  | 13 +++++++++++++
>  gas/testsuite/gas/riscv/float.s     | 21 +++++++++++++++++++++
>  7 files changed, 105 insertions(+), 1 deletion(-)

Did you see
https://sourceware.org/pipermail/binutils/2023-June/127845.html
? (Only the cover letter came through so far, so I can't tell yet
whether you do anything different than Andreas does. Also, as an
aside, it typically helps if you Cc arch maintainers for arch
patches.)

Jan
  
Nelson Chu June 16, 2023, 12:38 a.m. UTC | #3
On Thu, Jun 15, 2023 at 8:14 PM Branislav Brzak <Branislav.Brzak@syrmia.com>
wrote:

> Hi,
>
> I wasn't aware of that patch. The only difference between
> my patch and Andreas are that I have added tests to test
> encoding of doubles as well as float ones.
>

If you are willing to, then after Andreas committing his patch, you can
send and support the double-testcase with another patch.

Did you see
> https://sourceware.org/pipermail/binutils/2023-June/127845.html
> ? (Only the cover letter came through so far, so I can't tell yet
> whether you do anything different than Andreas does. Also, as an
> aside, it typically helps if you Cc arch maintainers for arch
> patches.)
>

Yeah, cc arch maintainers for arch patches really helps, thanks for
pointing this out, Jan :-)

Thanks
Nelson
  
Andreas Schwab June 19, 2023, 7:18 a.m. UTC | #4
On Jun 15 2023, Branislav Brzak wrote:

> I wasn't aware of that patch. The only difference between
> my patch and Andreas are that I have added tests to test
> encoding of doubles as well as float ones.

There is also a double test in my patch.  It probably makes sense to
add a generic test for floating point literals, though.
  

Patch

From f6739b8abeaa054196e0b2e31807dea2d7e1ec8a Mon Sep 17 00:00:00 2001
From: Branislav Brzak <branislav.brzak@syrmia.com>
Date: Thu, 15 Jun 2023 11:42:32 +0200
Subject: [PATCH 2/2] Add LE/BE float/double encoding tests.

	* testsuite/gas/riscv/float.s: New file.
	* testsuite/gas/riscv/float-le.d: Likewise.
        * testsuite/gas/riscv/float-be.d: Likewise.
        * testsuite/gas/riscv/double.d: Likewise.
        * testsuite/gas/riscv/double-le.d: Likewise.
        * testsuite/gas/riscv/double-be.d: Likewise.
---
 gas/testsuite/gas/riscv/double-be.d | 18 ++++++++++++++++++
 gas/testsuite/gas/riscv/double-le.d | 18 ++++++++++++++++++
 gas/testsuite/gas/riscv/double.s    | 21 +++++++++++++++++++++
 gas/testsuite/gas/riscv/float-be.d  | 13 +++++++++++++
 gas/testsuite/gas/riscv/float-le.d  | 13 +++++++++++++
 gas/testsuite/gas/riscv/float.s     | 21 +++++++++++++++++++++
 6 files changed, 104 insertions(+)
 create mode 100644 gas/testsuite/gas/riscv/double-be.d
 create mode 100644 gas/testsuite/gas/riscv/double-le.d
 create mode 100755 gas/testsuite/gas/riscv/double.s
 create mode 100644 gas/testsuite/gas/riscv/float-be.d
 create mode 100644 gas/testsuite/gas/riscv/float-le.d
 create mode 100755 gas/testsuite/gas/riscv/float.s

diff --git a/gas/testsuite/gas/riscv/double-be.d b/gas/testsuite/gas/riscv/double-be.d
new file mode 100644
index 00000000000..5f106e3b34f
--- /dev/null
+++ b/gas/testsuite/gas/riscv/double-be.d
@@ -0,0 +1,18 @@ 
+# source: double.s
+# objdump: -sj .data
+# as: -mbig-endian
+
+.*:[ 	]+file format .*bigriscv
+
+Contents of section \.data:
+ 0000 40280000 00000000 3fbf7ced 916872b0.*
+ 0010 3f70624d d2f1a9fc 40effc00 00000000.*
+ 0020 3e700006 3fca1753 3f0ff80f 681f458d.*
+ 0030 3f0ffffa a19c4774 3ff00000 00000000.*
+ 0040 3ff00418 9374bc6a 7fffffff ffffffff.*
+ 0050 7ff00000 00000000 fff00000 00000000.*
+ 0060 00000000 00000000 80000000 00000000.*
+ 0070 bff00000 00000000 bfef9ad4 2c3c9eed.*
+ 0080 c0effc00 00000000 40080000 00000000.*
+ 0090 40280000 00000000 4080f8fb e76c8b44.*
+ 00a0 7e000000 00000000 7c010000 00000000.*
diff --git a/gas/testsuite/gas/riscv/double-le.d b/gas/testsuite/gas/riscv/double-le.d
new file mode 100644
index 00000000000..848b76d06ed
--- /dev/null
+++ b/gas/testsuite/gas/riscv/double-le.d
@@ -0,0 +1,18 @@ 
+# source: double.s
+# objdump: -sj .data
+# as: -mlittle-endian
+
+.*:[ 	]+file format .*littleriscv
+
+Contents of section \.data:
+ 0000 00000000 00002840 b0726891 ed7cbf3f.*
+ 0010 fca9f1d2 4d62703f 00000000 00fcef40.*
+ 0020 5317ca3f 0600703e 8d451f68 0ff80f3f.*
+ 0030 74479ca1 faff0f3f 00000000 0000f03f.*
+ 0040 6abc7493 1804f03f ffffffff ffffff7f.*
+ 0050 00000000 0000f07f 00000000 0000f0ff.*
+ 0060 00000000 00000000 00000000 00000080.*
+ 0070 00000000 0000f0bf ed9e3c2c d49aefbf.*
+ 0080 00000000 00fcefc0 00000000 00000840.*
+ 0090 00000000 00002840 448b6ce7 fbf88040.*
+ 00a0 00000000 0000007e 00000000 0000017c.*
diff --git a/gas/testsuite/gas/riscv/double.s b/gas/testsuite/gas/riscv/double.s
new file mode 100755
index 00000000000..86d1f2f41e7
--- /dev/null
+++ b/gas/testsuite/gas/riscv/double.s
@@ -0,0 +1,21 @@ 
+.data
+	.double 12.0
+	.double 0.123
+	.double 0.004
+	.double 65504
+	.double 5.9605e-8
+	.double 6.0976e-5
+	.double 6.1035e-5
+	.double 1
+	.double 1.001
+	.double NaN
+	.double +Inf
+	.double -Inf
+	.double +0
+	.double -0
+	.double -1
+	.double -0.98765
+	.double -65504
+	.double 3.0, 12.0, 543.123
+	.double 0h:7e00	# qNaNh
+	.double 0h:7c01	# sNaNh
diff --git a/gas/testsuite/gas/riscv/float-be.d b/gas/testsuite/gas/riscv/float-be.d
new file mode 100644
index 00000000000..c7f3dcf39d1
--- /dev/null
+++ b/gas/testsuite/gas/riscv/float-be.d
@@ -0,0 +1,13 @@ 
+# source: float.s
+# objdump: -sj .data
+# as: -mbig-endian
+
+.*:[ 	]+file format .*bigriscv
+
+Contents of section \.data:
+ 0000 41400000 3dfbe76d 3b83126f 477fe000.*
+ 0010 33800032 387fc07b 387fffd5 3f800000.*
+ 0020 3f8020c5 7fffffff 7f800000 ff800000.*
+ 0030 00000000 80000000 bf800000 bf7cd6a1.*
+ 0040 c77fe000 40400000 41400000 4407c7df.*
+ 0050 7e000000 7c010000.*
diff --git a/gas/testsuite/gas/riscv/float-le.d b/gas/testsuite/gas/riscv/float-le.d
new file mode 100644
index 00000000000..3aa2d45d017
--- /dev/null
+++ b/gas/testsuite/gas/riscv/float-le.d
@@ -0,0 +1,13 @@ 
+# source: float.s
+# objdump: -sj .data
+# as: -mlittle-endian
+
+.*:[ 	]+file format .*littleriscv
+
+Contents of section \.data:
+ 0000 00004041 6de7fb3d 6f12833b 00e07f47.*
+ 0010 32008033 7bc07f38 d5ff7f38 0000803f.*
+ 0020 c520803f ffffff7f 0000807f 000080ff.*
+ 0030 00000000 00000080 000080bf a1d67cbf.*
+ 0040 00e07fc7 00004040 00004041 dfc70744.*
+ 0050 0000007e 0000017c.*
diff --git a/gas/testsuite/gas/riscv/float.s b/gas/testsuite/gas/riscv/float.s
new file mode 100755
index 00000000000..47c79c5b7e8
--- /dev/null
+++ b/gas/testsuite/gas/riscv/float.s
@@ -0,0 +1,21 @@ 
+.data
+	.float 12.0
+	.float 0.123
+	.float 0.004
+	.float 65504
+	.float 5.9605e-8
+	.float 6.0976e-5
+	.float 6.1035e-5
+	.float 1
+	.float 1.001
+	.float NaN
+	.float +Inf
+	.float -Inf
+	.float +0
+	.float -0
+	.float -1
+	.float -0.98765
+	.float -65504
+	.float 3.0, 12.0, 543.123
+	.float 0h:7e00	# qNaNh
+	.float 0h:7c01	# sNaNh
-- 
2.34.1