From: Ezra Sitorus <[email protected]>

Add the 8 bit floating point formats E5M2 and E4M3 to libiberty.

I am aiming to get FP8 formats displayed in AArch64 registers, and this
patch will allow me to use these FP8 formats. E5M2 follows the IEEE
convention on special values while E4M3 increases the dynamic range by
reducing the number of values. Note that this patch only adds the values
required for struct floatformat - another patch is sent in gdb to determine
the output of these values.

If this libiberty patch, and the GDB patch series are approved, then
include/floatformat.h will need to be synced with the new version.

Technical information on FP8, including the values used, can be found here:
https://arxiv.org/abs/2209.05433

libiberty/
        * floatformat.c: (floatformat_fp8_e5m2_big,
          floatformat_fp8_e5m2_little, floatformat_fp8_e4m3_big,
          floatformat_fp8_e4m3_little): New.

I've tested on aarch64-none-linux-gnu.
---
 libiberty/floatformat.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/libiberty/floatformat.c b/libiberty/floatformat.c
index fe82e019cc9..96ab956aef0 100644
--- a/libiberty/floatformat.c
+++ b/libiberty/floatformat.c
@@ -269,6 +269,38 @@ const struct floatformat 
floatformat_arm_ext_littlebyte_bigword =
   floatformat_always_valid,
   NULL
 };
+const struct floatformat floatformat_fp8_e5m2_big =
+{
+  floatformat_big, 8, 0, 1, 5, 15, 31, 6, 2,
+  floatformat_intbit_no,
+  "floatformat_fp8_e5m2_big",
+  floatformat_always_valid,
+  NULL
+};
+const struct floatformat floatformat_fp8_e5m2_little =
+{
+  floatformat_little, 8, 0, 1, 5, 15, 31, 6, 2,
+  floatformat_intbit_no,
+  "floatformat_fp8_e5m2_little",
+  floatformat_always_valid,
+  NULL
+};
+const struct floatformat floatformat_fp8_e4m3_big =
+{
+  floatformat_big, 8, 0, 1, 4, 7, 15, 5, 3,
+  floatformat_intbit_no,
+  "floatformat_fp8_e4m3_big",
+  floatformat_always_valid,
+  NULL
+};
+const struct floatformat floatformat_fp8_e4m3_little =
+{
+  floatformat_little, 8, 0, 1, 4, 7, 15, 5, 3,
+  floatformat_intbit_no,
+  "floatformat_fp8_e4m3_little",
+  floatformat_always_valid,
+  NULL
+};
 const struct floatformat floatformat_ia64_spill_big =
 {
   floatformat_big, 128, 0, 1, 17, 65535, 0x1ffff, 18, 64,
-- 
2.45.2

Reply via email to