public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] riscv: Fix gas when encoding BE floats/doubles
@ 2023-06-15 11:09 Branislav Brzak
  2023-06-15 12:09 ` Jan Beulich
  0 siblings, 1 reply; 5+ messages in thread
From: Branislav Brzak @ 2023-06-15 11:09 UTC (permalink / raw)
  To: binutils; +Cc: Dragoslav Sicarov, Djordje Todorovic


[-- Attachment #1.1: Type: text/plain, Size: 1149 bytes --]

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(-)



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-tc-riscv.c-md_atof-Use-target_big_endian-instead-of-.patch --]
[-- Type: text/x-patch; name="0001-tc-riscv.c-md_atof-Use-target_big_endian-instead-of-.patch", Size: 747 bytes --]

From 199f5871ca8d16d7f2e24cbc7a1b4d103a2eedef Mon Sep 17 00:00:00 2001
From: Branislav Brzak <branislav.brzak@syrmia.com>
Date: Thu, 15 Jun 2023 11:35:09 +0200
Subject: [PATCH 1/2] 	* tc-riscv.c (md_atof): Use target_big_endian instead
 of constant

---
 gas/config/tc-riscv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 7684fa7e06d..e915b82eafa 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -3693,7 +3693,7 @@ md_assemble (char *str)
 const char *
 md_atof (int type, char *litP, int *sizeP)
 {
-  return ieee_md_atof (type, litP, sizeP, TARGET_BYTES_BIG_ENDIAN);
+  return ieee_md_atof (type, litP, sizeP, target_big_endian);
 }
 
 void
-- 
2.34.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Add-LE-BE-float-double-encoding-tests.patch --]
[-- Type: text/x-patch; name="0002-Add-LE-BE-float-double-encoding-tests.patch", Size: 5211 bytes --]

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


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

* Re: [PATCH 0/2] riscv: Fix gas when encoding BE floats/doubles
  2023-06-15 11:09 [PATCH 0/2] riscv: Fix gas when encoding BE floats/doubles Branislav Brzak
@ 2023-06-15 12:09 ` Jan Beulich
  2023-06-15 12:14   ` Branislav Brzak
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Beulich @ 2023-06-15 12:09 UTC (permalink / raw)
  To: Branislav Brzak; +Cc: Dragoslav Sicarov, Djordje Todorovic, binutils

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

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

* Re: [PATCH 0/2] riscv: Fix gas when encoding BE floats/doubles
  2023-06-15 12:09 ` Jan Beulich
@ 2023-06-15 12:14   ` Branislav Brzak
  2023-06-16  0:38     ` Nelson Chu
  2023-06-19  7:18     ` Andreas Schwab
  0 siblings, 2 replies; 5+ messages in thread
From: Branislav Brzak @ 2023-06-15 12:14 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Dragoslav Sicarov, Djordje Todorovic, binutils

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

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

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

* Re: [PATCH 0/2] riscv: Fix gas when encoding BE floats/doubles
  2023-06-15 12:14   ` Branislav Brzak
@ 2023-06-16  0:38     ` Nelson Chu
  2023-06-19  7:18     ` Andreas Schwab
  1 sibling, 0 replies; 5+ messages in thread
From: Nelson Chu @ 2023-06-16  0:38 UTC (permalink / raw)
  To: Branislav Brzak
  Cc: Jan Beulich, Dragoslav Sicarov, Djordje Todorovic, binutils

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

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

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

* Re: [PATCH 0/2] riscv: Fix gas when encoding BE floats/doubles
  2023-06-15 12:14   ` Branislav Brzak
  2023-06-16  0:38     ` Nelson Chu
@ 2023-06-19  7:18     ` Andreas Schwab
  1 sibling, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2023-06-19  7:18 UTC (permalink / raw)
  To: Branislav Brzak
  Cc: Jan Beulich, Dragoslav Sicarov, Djordje Todorovic, binutils

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.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

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

end of thread, other threads:[~2023-06-19  7:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-15 11:09 [PATCH 0/2] riscv: Fix gas when encoding BE floats/doubles Branislav Brzak
2023-06-15 12:09 ` Jan Beulich
2023-06-15 12:14   ` Branislav Brzak
2023-06-16  0:38     ` Nelson Chu
2023-06-19  7:18     ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).