* [PATCH v3] RISC-V: Add .bfloat16 directive
@ 2025-01-20 11:24 Kito Cheng
2025-02-04 13:35 ` Kito Cheng
0 siblings, 1 reply; 3+ messages in thread
From: Kito Cheng @ 2025-01-20 11:24 UTC (permalink / raw)
To: binutils, kito.cheng, nelson, palmer, jbeulich; +Cc: Kito Cheng
RISC-V already support bfloat16 instruciton like Zfbfmin, Zvfbfmin and
Zvfbfwma, so I think it's reasonable to add .bfloat16 directive to
support bfloat16 data type.
And the code logic mostly support by common code already.
Changes from v2:
- Add 'B' to FLT_CHARS this time...
- Use 'B' in the testcase.
Changes from v1:
- Add big endian and little endian testcase.
- Add 'B' to FLT_CHARS.
- Drop wrong comment in testcase.
---
gas/config/tc-riscv.c | 3 ++-
gas/doc/c-riscv.texi | 10 ++++++++++
gas/testsuite/gas/riscv/bfloat16-be.d | 10 ++++++++++
gas/testsuite/gas/riscv/bfloat16-le.d | 10 ++++++++++
gas/testsuite/gas/riscv/bfloat16.s | 21 +++++++++++++++++++++
5 files changed, 53 insertions(+), 1 deletion(-)
create mode 100644 gas/testsuite/gas/riscv/bfloat16-be.d
create mode 100644 gas/testsuite/gas/riscv/bfloat16-le.d
create mode 100644 gas/testsuite/gas/riscv/bfloat16.s
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 1a32f4ee57f..344339d87c1 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -473,7 +473,7 @@ const char EXP_CHARS[] = "eE";
/* Chars that mean this number is a floating point constant.
As in 0f12.456 or 0d1.2345e12. */
-const char FLT_CHARS[] = "rRsSfFdDxXpPhH";
+const char FLT_CHARS[] = "rRsSfFdDxXpPhHbB";
/* Indicate ELF attributes are explicitly set. */
static bool explicit_attr = false;
@@ -5890,6 +5890,7 @@ static const pseudo_typeS riscv_pseudo_table[] =
{"attribute", s_riscv_attribute, 0},
{"variant_cc", s_variant_cc, 0},
{"float16", float_cons, 'h'},
+ {"bfloat16", float_cons, 'b'},
{ NULL, NULL, 0 },
};
diff --git a/gas/doc/c-riscv.texi b/gas/doc/c-riscv.texi
index d2e47455e7c..be3a09487f1 100644
--- a/gas/doc/c-riscv.texi
+++ b/gas/doc/c-riscv.texi
@@ -255,6 +255,16 @@ The @var{tag} is either an attribute number, or one of the following:
@code{Tag_RISCV_unaligned_access}, @code{Tag_RISCV_priv_spec},
@code{Tag_RISCV_priv_spec_minor}, @code{Tag_RISCV_priv_spec_revision}.
+@cindex @code{.bfloat16} directive, RISC-V
+@item .bfloat16 @var{value}
+Floating point constructors for the bfloat16 type, example usage:
+
+@smallexample
+ .bfloat16 12.0
+ .bfloat16 NaN
+ .bfloat16 0b:ffc1
+@end smallexample
+
@end table
@node RISC-V-Modifiers
diff --git a/gas/testsuite/gas/riscv/bfloat16-be.d b/gas/testsuite/gas/riscv/bfloat16-be.d
new file mode 100644
index 00000000000..21408d0befb
--- /dev/null
+++ b/gas/testsuite/gas/riscv/bfloat16-be.d
@@ -0,0 +1,10 @@
+# source: bfloat16.s
+# objdump: -sj .data
+# as: -mbig-endian
+
+.*:[ ]+file format .*
+
+Contents of section \.data:
+ 0000 41403dfc 000042f7 8000c2f7 7fff7f80.*
+ 0010 ff807f7f ff7f0080 80800001 8001007f.*
+ 0020 807f3f80 bf804000 c000ffc1 ff81.*
diff --git a/gas/testsuite/gas/riscv/bfloat16-le.d b/gas/testsuite/gas/riscv/bfloat16-le.d
new file mode 100644
index 00000000000..2043a9c161e
--- /dev/null
+++ b/gas/testsuite/gas/riscv/bfloat16-le.d
@@ -0,0 +1,10 @@
+# source: bfloat16.s
+# objdump: -sj .data
+# as: -mlittle-endian
+
+.*:[ ]+file format .*
+
+Contents of section \.data:
+ 0000 4041fc3d 0000f742 0080f7c2 ff7f807f.*
+ 0010 80ff7f7f 7fff8000 80800100 01807f00.*
+ 0020 7f80803f 80bf0040 00c0c1ff 81ff.*
diff --git a/gas/testsuite/gas/riscv/bfloat16.s b/gas/testsuite/gas/riscv/bfloat16.s
new file mode 100644
index 00000000000..ed92856ff4b
--- /dev/null
+++ b/gas/testsuite/gas/riscv/bfloat16.s
@@ -0,0 +1,21 @@
+ .data
+ .bfloat16 12.0
+ .bfloat16 0.123
+ .bfloat16 +0.0
+ .bfloat16 123.4
+ .bfloat16 -0.0
+ .bfloat16 -123.4
+ .bfloat16 NaN
+ .bfloat16 Inf
+ .bfloat16 -Inf
+ .bfloat16 3.390e+38
+ .bfloat16 -3.390e+38
+ .bfloat16 1.175e-38
+ .bfloat16 -1.175e-38
+ .bfloat16 9.194e-41
+ .bfloat16 -9.194e-41
+ .bfloat16 1.167e-38
+ .bfloat16 -1.167e-38
+ .bfloat16 1.0, -1, 2.0, -2
+ .bfloat16 0b:ffc1
+ .bfloat16 0B:ff81
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] RISC-V: Add .bfloat16 directive
2025-01-20 11:24 [PATCH v3] RISC-V: Add .bfloat16 directive Kito Cheng
@ 2025-02-04 13:35 ` Kito Cheng
2025-02-11 6:48 ` Nelson Chu
0 siblings, 1 reply; 3+ messages in thread
From: Kito Cheng @ 2025-02-04 13:35 UTC (permalink / raw)
To: Binutils, Kito Cheng, Nelson Chu, Palmer Dabbelt, Jan Beulich
ping
On Mon, Jan 20, 2025 at 7:25 PM Kito Cheng <kito.cheng@sifive.com> wrote:
>
> RISC-V already support bfloat16 instruciton like Zfbfmin, Zvfbfmin and
> Zvfbfwma, so I think it's reasonable to add .bfloat16 directive to
> support bfloat16 data type.
>
> And the code logic mostly support by common code already.
>
> Changes from v2:
> - Add 'B' to FLT_CHARS this time...
> - Use 'B' in the testcase.
>
> Changes from v1:
> - Add big endian and little endian testcase.
> - Add 'B' to FLT_CHARS.
> - Drop wrong comment in testcase.
> ---
> gas/config/tc-riscv.c | 3 ++-
> gas/doc/c-riscv.texi | 10 ++++++++++
> gas/testsuite/gas/riscv/bfloat16-be.d | 10 ++++++++++
> gas/testsuite/gas/riscv/bfloat16-le.d | 10 ++++++++++
> gas/testsuite/gas/riscv/bfloat16.s | 21 +++++++++++++++++++++
> 5 files changed, 53 insertions(+), 1 deletion(-)
> create mode 100644 gas/testsuite/gas/riscv/bfloat16-be.d
> create mode 100644 gas/testsuite/gas/riscv/bfloat16-le.d
> create mode 100644 gas/testsuite/gas/riscv/bfloat16.s
>
> diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
> index 1a32f4ee57f..344339d87c1 100644
> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -473,7 +473,7 @@ const char EXP_CHARS[] = "eE";
>
> /* Chars that mean this number is a floating point constant.
> As in 0f12.456 or 0d1.2345e12. */
> -const char FLT_CHARS[] = "rRsSfFdDxXpPhH";
> +const char FLT_CHARS[] = "rRsSfFdDxXpPhHbB";
>
> /* Indicate ELF attributes are explicitly set. */
> static bool explicit_attr = false;
> @@ -5890,6 +5890,7 @@ static const pseudo_typeS riscv_pseudo_table[] =
> {"attribute", s_riscv_attribute, 0},
> {"variant_cc", s_variant_cc, 0},
> {"float16", float_cons, 'h'},
> + {"bfloat16", float_cons, 'b'},
>
> { NULL, NULL, 0 },
> };
> diff --git a/gas/doc/c-riscv.texi b/gas/doc/c-riscv.texi
> index d2e47455e7c..be3a09487f1 100644
> --- a/gas/doc/c-riscv.texi
> +++ b/gas/doc/c-riscv.texi
> @@ -255,6 +255,16 @@ The @var{tag} is either an attribute number, or one of the following:
> @code{Tag_RISCV_unaligned_access}, @code{Tag_RISCV_priv_spec},
> @code{Tag_RISCV_priv_spec_minor}, @code{Tag_RISCV_priv_spec_revision}.
>
> +@cindex @code{.bfloat16} directive, RISC-V
> +@item .bfloat16 @var{value}
> +Floating point constructors for the bfloat16 type, example usage:
> +
> +@smallexample
> + .bfloat16 12.0
> + .bfloat16 NaN
> + .bfloat16 0b:ffc1
> +@end smallexample
> +
> @end table
>
> @node RISC-V-Modifiers
> diff --git a/gas/testsuite/gas/riscv/bfloat16-be.d b/gas/testsuite/gas/riscv/bfloat16-be.d
> new file mode 100644
> index 00000000000..21408d0befb
> --- /dev/null
> +++ b/gas/testsuite/gas/riscv/bfloat16-be.d
> @@ -0,0 +1,10 @@
> +# source: bfloat16.s
> +# objdump: -sj .data
> +# as: -mbig-endian
> +
> +.*:[ ]+file format .*
> +
> +Contents of section \.data:
> + 0000 41403dfc 000042f7 8000c2f7 7fff7f80.*
> + 0010 ff807f7f ff7f0080 80800001 8001007f.*
> + 0020 807f3f80 bf804000 c000ffc1 ff81.*
> diff --git a/gas/testsuite/gas/riscv/bfloat16-le.d b/gas/testsuite/gas/riscv/bfloat16-le.d
> new file mode 100644
> index 00000000000..2043a9c161e
> --- /dev/null
> +++ b/gas/testsuite/gas/riscv/bfloat16-le.d
> @@ -0,0 +1,10 @@
> +# source: bfloat16.s
> +# objdump: -sj .data
> +# as: -mlittle-endian
> +
> +.*:[ ]+file format .*
> +
> +Contents of section \.data:
> + 0000 4041fc3d 0000f742 0080f7c2 ff7f807f.*
> + 0010 80ff7f7f 7fff8000 80800100 01807f00.*
> + 0020 7f80803f 80bf0040 00c0c1ff 81ff.*
> diff --git a/gas/testsuite/gas/riscv/bfloat16.s b/gas/testsuite/gas/riscv/bfloat16.s
> new file mode 100644
> index 00000000000..ed92856ff4b
> --- /dev/null
> +++ b/gas/testsuite/gas/riscv/bfloat16.s
> @@ -0,0 +1,21 @@
> + .data
> + .bfloat16 12.0
> + .bfloat16 0.123
> + .bfloat16 +0.0
> + .bfloat16 123.4
> + .bfloat16 -0.0
> + .bfloat16 -123.4
> + .bfloat16 NaN
> + .bfloat16 Inf
> + .bfloat16 -Inf
> + .bfloat16 3.390e+38
> + .bfloat16 -3.390e+38
> + .bfloat16 1.175e-38
> + .bfloat16 -1.175e-38
> + .bfloat16 9.194e-41
> + .bfloat16 -9.194e-41
> + .bfloat16 1.167e-38
> + .bfloat16 -1.167e-38
> + .bfloat16 1.0, -1, 2.0, -2
> + .bfloat16 0b:ffc1
> + .bfloat16 0B:ff81
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] RISC-V: Add .bfloat16 directive
2025-02-04 13:35 ` Kito Cheng
@ 2025-02-11 6:48 ` Nelson Chu
0 siblings, 0 replies; 3+ messages in thread
From: Nelson Chu @ 2025-02-11 6:48 UTC (permalink / raw)
To: Kito Cheng; +Cc: Binutils, Kito Cheng, Palmer Dabbelt, Jan Beulich
[-- Attachment #1: Type: text/plain, Size: 1282 bytes --]
Sorry for the late reply, committed.
Thanks
Nelson
On Tue, Feb 4, 2025 at 9:35 PM Kito Cheng <kito.cheng@sifive.com> wrote:
> ping
>
> On Mon, Jan 20, 2025 at 7:25 PM Kito Cheng <kito.cheng@sifive.com> wrote:
> >
> > RISC-V already support bfloat16 instruciton like Zfbfmin, Zvfbfmin and
> > Zvfbfwma, so I think it's reasonable to add .bfloat16 directive to
> > support bfloat16 data type.
> >
> > And the code logic mostly support by common code already.
> >
> > Changes from v2:
> > - Add 'B' to FLT_CHARS this time...
> > - Use 'B' in the testcase.
> >
> > Changes from v1:
> > - Add big endian and little endian testcase.
> > - Add 'B' to FLT_CHARS.
> > - Drop wrong comment in testcase.
> > ---
> > gas/config/tc-riscv.c | 3 ++-
> > gas/doc/c-riscv.texi | 10 ++++++++++
> > gas/testsuite/gas/riscv/bfloat16-be.d | 10 ++++++++++
> > gas/testsuite/gas/riscv/bfloat16-le.d | 10 ++++++++++
> > gas/testsuite/gas/riscv/bfloat16.s | 21 +++++++++++++++++++++
> > 5 files changed, 53 insertions(+), 1 deletion(-)
> > create mode 100644 gas/testsuite/gas/riscv/bfloat16-be.d
> > create mode 100644 gas/testsuite/gas/riscv/bfloat16-le.d
> > create mode 100644 gas/testsuite/gas/riscv/bfloat16.s
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-02-11 6:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-20 11:24 [PATCH v3] RISC-V: Add .bfloat16 directive Kito Cheng
2025-02-04 13:35 ` Kito Cheng
2025-02-11 6:48 ` Nelson Chu
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).