gcc/testsuite/ChangeLog:

        * gcc.target/i386/avx10v2aux-packed-narrow-2.h: New test.
        * gcc.target/i386/avx10v2aux-packed-wide-2.h: New test.
        * gcc.target/i386/avx10v2aux-packed-wide6-2.h: New test.
        * gcc.target/i386/avx10v2aux-vcvtbf42hf8-2.c: New test.
        * gcc.target/i386/avx10v2aux-vcvtbf42hf8-2.h: New test.
        * gcc.target/i386/avx10v2aux-vcvtbf62hf8-2.c: New test.
        * gcc.target/i386/avx10v2aux-vcvtbf62hf8-2.h: New test.
        * gcc.target/i386/avx10v2aux-vcvtbf82bf4s-2.c: New test.
        * gcc.target/i386/avx10v2aux-vcvtbf82bf4s-2.h: New test.
        * gcc.target/i386/avx10v2aux-vcvtbf82bf6s-2.c: New test.
        * gcc.target/i386/avx10v2aux-vcvtbf82bf6s-2.h: New test.
        * gcc.target/i386/avx10v2aux-vcvthf62hf8-2.c: New test.
        * gcc.target/i386/avx10v2aux-vcvthf62hf8-2.h: New test.
        * gcc.target/i386/avx10v2aux-vcvthf82bf4s-2.c: New test.
        * gcc.target/i386/avx10v2aux-vcvthf82bf4s-2.h: New test.
        * gcc.target/i386/avx10v2aux-vcvthf82hf6s-2.c: New test.
        * gcc.target/i386/avx10v2aux-vcvthf82hf6s-2.h: New test.
        * gcc.target/i386/fp4-fp6-helper.h: Add convert helpers
        between fp4, fp6 and fp8 data types.
---
 .../i386/avx10v2aux-packed-narrow-2.h         |  62 ++++
 .../i386/avx10v2aux-packed-wide-2.h           |  58 ++++
 .../i386/avx10v2aux-packed-wide6-2.h          |  68 ++++
 .../i386/avx10v2aux-vcvtbf42hf8-2.c           |  20 ++
 .../i386/avx10v2aux-vcvtbf42hf8-2.h           |   5 +
 .../i386/avx10v2aux-vcvtbf62hf8-2.c           |  20 ++
 .../i386/avx10v2aux-vcvtbf62hf8-2.h           |   5 +
 .../i386/avx10v2aux-vcvtbf82bf4s-2.c          |  20 ++
 .../i386/avx10v2aux-vcvtbf82bf4s-2.h          |   4 +
 .../i386/avx10v2aux-vcvtbf82bf6s-2.c          |  20 ++
 .../i386/avx10v2aux-vcvtbf82bf6s-2.h          |   3 +
 .../i386/avx10v2aux-vcvthf62hf8-2.c           |  20 ++
 .../i386/avx10v2aux-vcvthf62hf8-2.h           |   5 +
 .../i386/avx10v2aux-vcvthf82bf4s-2.c          |  20 ++
 .../i386/avx10v2aux-vcvthf82bf4s-2.h          |   4 +
 .../i386/avx10v2aux-vcvthf82hf6s-2.c          |  20 ++
 .../i386/avx10v2aux-vcvthf82hf6s-2.h          |   3 +
 .../gcc.target/i386/fp4-fp6-helper.h          | 314 ++++++++++++++++++
 18 files changed, 671 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-packed-narrow-2.h
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-packed-wide-2.h
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-packed-wide6-2.h
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf42hf8-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf42hf8-2.h
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf62hf8-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf62hf8-2.h
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf4s-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf4s-2.h
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf6s-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf6s-2.h
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf62hf8-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf62hf8-2.h
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82bf4s-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82bf4s-2.h
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82hf6s-2.c
 create mode 100644 gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82hf6s-2.h
 create mode 100644 gcc/testsuite/gcc.target/i386/fp4-fp6-helper.h

diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-packed-narrow-2.h 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-packed-narrow-2.h
new file mode 100644
index 000000000000..f511ba79bd9d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-packed-narrow-2.h
@@ -0,0 +1,62 @@
+#define AVX10V2AUX
+#include "avx10-helper.h"
+#include "fp4-fp6-helper.h"
+
+#define SRC_SIZE (AVX512F_LEN / 8)
+
+#undef DST_LEN
+#ifdef PACKED_NARROW_HALF_DST
+#define DST_LEN AVX512F_LEN_HALF
+#else
+#define DST_LEN AVX512F_LEN
+#endif
+
+static void
+CALC (unsigned char *r, unsigned char *s)
+{
+  int j;
+
+  for (j = 0; j < DST_LEN / 8; j++)
+    r[j] = 0;
+
+  for (j = 0; j < SRC_SIZE; j++)
+    {
+#ifdef PACKED_NARROW_HALF_DST
+      unsigned char n = PACKED_NARROW_CVT (s[j]);
+      if (j & 1)
+       r[j / 2] = (unsigned char) (r[j / 2] | (n << 4));
+      else
+       r[j / 2] = n;
+#else
+      unsigned char fp6 = PACKED_NARROW_CVT (s[j]);
+      int bit_offset = j * 6;
+      int byte_idx = bit_offset / 8;
+      int bit_idx = bit_offset % 8;
+
+      r[byte_idx] |= (unsigned char) (fp6 << bit_idx);
+      if (bit_idx + 6 > 8)
+       r[byte_idx + 1] |= (unsigned char) (fp6 >> (8 - bit_idx));
+#endif
+    }
+}
+
+void
+TEST (void)
+{
+  int i, n;
+  UNION_TYPE (AVX512F_LEN, i_ub) src;
+  UNION_TYPE (DST_LEN, i_ub) res;
+  unsigned char res_ref[DST_LEN / 8];
+
+  for (n = 0; n < 256; n++)
+    {
+      for (i = 0; i < SRC_SIZE; i++)
+       src.a[i] = n + i;
+
+      CALC (res_ref, src.a);
+
+      res.x = V2AUX_I (PACKED_NARROW_I) (src.x);
+      if (UNION_CHECK (DST_LEN, i_ub) (res, res_ref))
+       abort ();
+    }
+}
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-packed-wide-2.h 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-packed-wide-2.h
new file mode 100644
index 000000000000..0e386f5f38f4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-packed-wide-2.h
@@ -0,0 +1,58 @@
+#define AVX10V2AUX
+#include "avx10-helper.h"
+#include "fp4-fp6-helper.h"
+
+#define SIZE (AVX512F_LEN / 8)
+#define SRC_SIZE (SIZE / 2)
+#include "avx512f-mask-type.h"
+
+static void
+CALC (unsigned char *r, unsigned char *s)
+{
+  int j;
+
+  for (j = 0; j < SIZE; j++)
+    {
+      unsigned char nibble;
+      if (j & 1)
+       nibble = (unsigned char) ((s[j / 2] >> 4) & 0xF);
+      else
+       nibble = (unsigned char) (s[j / 2] & 0xF);
+      r[j] = PACKED_WIDE_CVT (nibble);
+    }
+}
+
+void
+TEST (void)
+{
+  int i, n;
+  UNION_TYPE (AVX512F_LEN_HALF, i_ub) src;
+  UNION_TYPE (AVX512F_LEN, i_ub) res1, res2, res3;
+  MASK_TYPE mask = MASK_VALUE;
+  unsigned char res_ref[SIZE];
+
+  for (n = 0; n < 256; n += SRC_SIZE)
+    {
+      for (i = 0; i < AVX512F_LEN_HALF / 8; i++)
+       src.a[i] = i < SRC_SIZE ? n + i : v2aux_rand ();
+
+      for (i = 0; i < SIZE; i++)
+       res2.a[i] = DEFAULT_VALUE;
+
+      CALC (res_ref, src.a);
+
+      res1.x = V2AUX_I (PACKED_WIDE_I) (src.x);
+      if (UNION_CHECK (AVX512F_LEN, i_ub) (res1, res_ref))
+       abort ();
+
+      res2.x = V2AUX_I (PACKED_WIDE_MASK_I) (res2.x, mask, src.x);
+      MASK_MERGE (i_ub) (res_ref, mask, SIZE);
+      if (UNION_CHECK (AVX512F_LEN, i_ub) (res2, res_ref))
+       abort ();
+
+      res3.x = V2AUX_I (PACKED_WIDE_MASKZ_I) (mask, src.x);
+      MASK_ZERO (i_ub) (res_ref, mask, SIZE);
+      if (UNION_CHECK (AVX512F_LEN, i_ub) (res3, res_ref))
+       abort ();
+    }
+}
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-packed-wide6-2.h 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-packed-wide6-2.h
new file mode 100644
index 000000000000..0a77b06456c2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-packed-wide6-2.h
@@ -0,0 +1,68 @@
+#define AVX10V2AUX
+#include "avx10-helper.h"
+#include "fp4-fp6-helper.h"
+
+#define SIZE (AVX512F_LEN / 8)
+#include "avx512f-mask-type.h"
+
+static void
+CALC (unsigned char *r, unsigned char *s)
+{
+  int j;
+
+  for (j = 0; j < SIZE; j++)
+    {
+      int bit_offset = j * 6;
+      int byte_idx = bit_offset / 8;
+      int bit_idx = bit_offset % 8;
+      unsigned char fp6 = (unsigned char) ((s[byte_idx] >> bit_idx) & 0x3F);
+      if (bit_idx + 6 > 8)
+       fp6 = (unsigned char) (fp6 | ((s[byte_idx + 1] << (8 - bit_idx))
+                                     & 0x3F));
+      r[j] = PACKED_WIDE6_CVT (fp6);
+    }
+}
+
+void
+TEST (void)
+{
+  int i, j, n;
+  UNION_TYPE (AVX512F_LEN, i_ub) src;
+  UNION_TYPE (AVX512F_LEN, i_ub) res1, res2, res3;
+  MASK_TYPE mask = MASK_VALUE;
+  unsigned char res_ref[SIZE];
+
+  for (n = 0; n < 64; n++)
+    {
+      for (i = 0; i < SIZE; i++)
+       src.a[i] = i < SIZE * 6 / 8 ? 0 : v2aux_rand ();
+      for (j = 0; j < SIZE; j++)
+       {
+         unsigned int fp6 = (n + j) & 0x3F;
+         int bit_offset = j * 6;
+
+         src.a[bit_offset / 8] |= fp6 << (bit_offset % 8);
+         if (bit_offset % 8 > 2)
+           src.a[bit_offset / 8 + 1] |= fp6 >> (8 - bit_offset % 8);
+       }
+
+      for (i = 0; i < SIZE; i++)
+       res2.a[i] = DEFAULT_VALUE;
+
+      CALC (res_ref, src.a);
+
+      res1.x = V2AUX_I (PACKED_WIDE6_I) (src.x);
+      if (UNION_CHECK (AVX512F_LEN, i_ub) (res1, res_ref))
+       abort ();
+
+      res2.x = V2AUX_I (PACKED_WIDE6_MASK_I) (res2.x, mask, src.x);
+      MASK_MERGE (i_ub) (res_ref, mask, SIZE);
+      if (UNION_CHECK (AVX512F_LEN, i_ub) (res2, res_ref))
+       abort ();
+
+      res3.x = V2AUX_I (PACKED_WIDE6_MASKZ_I) (mask, src.x);
+      MASK_ZERO (i_ub) (res_ref, mask, SIZE);
+      if (UNION_CHECK (AVX512F_LEN, i_ub) (res3, res_ref))
+       abort ();
+    }
+}
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf42hf8-2.c 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf42hf8-2.c
new file mode 100644
index 000000000000..4a40c6da3552
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf42hf8-2.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -march=x86-64-v3 -mavx10v2aux" } */
+/* { dg-require-effective-target avx10v2aux } */
+
+#include "avx10v2aux-vcvtbf42hf8-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512VL
+#define AVX512F_LEN 256
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvtbf42hf8-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512F_LEN 128
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvtbf42hf8-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf42hf8-2.h 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf42hf8-2.h
new file mode 100644
index 000000000000..f078c3bf33d3
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf42hf8-2.h
@@ -0,0 +1,5 @@
+#define PACKED_WIDE_I _cvtbf4_hf8
+#define PACKED_WIDE_MASK_I _mask_cvtbf4_hf8
+#define PACKED_WIDE_MASKZ_I _maskz_cvtbf4_hf8
+#define PACKED_WIDE_CVT fp4_e2m1_to_fp8_e4m3
+#include "avx10v2aux-packed-wide-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf62hf8-2.c 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf62hf8-2.c
new file mode 100644
index 000000000000..a8434e05aa92
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf62hf8-2.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -march=x86-64-v3 -mavx10v2aux" } */
+/* { dg-require-effective-target avx10v2aux } */
+
+#include "avx10v2aux-vcvtbf62hf8-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512VL
+#define AVX512F_LEN 256
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvtbf62hf8-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512F_LEN 128
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvtbf62hf8-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf62hf8-2.h 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf62hf8-2.h
new file mode 100644
index 000000000000..3af37c4c50ba
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf62hf8-2.h
@@ -0,0 +1,5 @@
+#define PACKED_WIDE6_I _cvtbf6_hf8
+#define PACKED_WIDE6_MASK_I _mask_cvtbf6_hf8
+#define PACKED_WIDE6_MASKZ_I _maskz_cvtbf6_hf8
+#define PACKED_WIDE6_CVT fp6_e3m2_to_fp8_e4m3
+#include "avx10v2aux-packed-wide6-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf4s-2.c 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf4s-2.c
new file mode 100644
index 000000000000..49c511d76ff4
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf4s-2.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -march=x86-64-v3 -mavx10v2aux" } */
+/* { dg-require-effective-target avx10v2aux } */
+
+#include "avx10v2aux-vcvtbf82bf4s-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512VL
+#define AVX512F_LEN 256
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvtbf82bf4s-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512F_LEN 128
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvtbf82bf4s-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf4s-2.h 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf4s-2.h
new file mode 100644
index 000000000000..1bffe0d1330a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf4s-2.h
@@ -0,0 +1,4 @@
+#define PACKED_NARROW_HALF_DST
+#define PACKED_NARROW_I _cvts_bf8_bf4
+#define PACKED_NARROW_CVT fp8_e5m2_to_fp4_e2m1
+#include "avx10v2aux-packed-narrow-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf6s-2.c 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf6s-2.c
new file mode 100644
index 000000000000..01e8bb32cdb8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf6s-2.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -march=x86-64-v3 -mavx10v2aux" } */
+/* { dg-require-effective-target avx10v2aux } */
+
+#include "avx10v2aux-vcvtbf82bf6s-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512VL
+#define AVX512F_LEN 256
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvtbf82bf6s-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512F_LEN 128
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvtbf82bf6s-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf6s-2.h 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf6s-2.h
new file mode 100644
index 000000000000..85931a28d202
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvtbf82bf6s-2.h
@@ -0,0 +1,3 @@
+#define PACKED_NARROW_I _cvts_bf8_bf6
+#define PACKED_NARROW_CVT fp8_e5m2_to_fp6_e3m2
+#include "avx10v2aux-packed-narrow-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf62hf8-2.c 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf62hf8-2.c
new file mode 100644
index 000000000000..4d61ba664d4e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf62hf8-2.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -march=x86-64-v3 -mavx10v2aux" } */
+/* { dg-require-effective-target avx10v2aux } */
+
+#include "avx10v2aux-vcvthf62hf8-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512VL
+#define AVX512F_LEN 256
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvthf62hf8-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512F_LEN 128
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvthf62hf8-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf62hf8-2.h 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf62hf8-2.h
new file mode 100644
index 000000000000..471f5f851037
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf62hf8-2.h
@@ -0,0 +1,5 @@
+#define PACKED_WIDE6_I _cvthf6_hf8
+#define PACKED_WIDE6_MASK_I _mask_cvthf6_hf8
+#define PACKED_WIDE6_MASKZ_I _maskz_cvthf6_hf8
+#define PACKED_WIDE6_CVT fp6_e2m3_to_fp8_e4m3
+#include "avx10v2aux-packed-wide6-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82bf4s-2.c 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82bf4s-2.c
new file mode 100644
index 000000000000..527975fb386f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82bf4s-2.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -march=x86-64-v3 -mavx10v2aux" } */
+/* { dg-require-effective-target avx10v2aux } */
+
+#include "avx10v2aux-vcvthf82bf4s-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512VL
+#define AVX512F_LEN 256
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvthf82bf4s-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512F_LEN 128
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvthf82bf4s-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82bf4s-2.h 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82bf4s-2.h
new file mode 100644
index 000000000000..fe887857c1ae
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82bf4s-2.h
@@ -0,0 +1,4 @@
+#define PACKED_NARROW_HALF_DST
+#define PACKED_NARROW_I _cvts_hf8_bf4
+#define PACKED_NARROW_CVT fp8_e4m3_to_fp4_e2m1
+#include "avx10v2aux-packed-narrow-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82hf6s-2.c 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82hf6s-2.c
new file mode 100644
index 000000000000..3872dd68f74a
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82hf6s-2.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -march=x86-64-v3 -mavx10v2aux" } */
+/* { dg-require-effective-target avx10v2aux } */
+
+#include "avx10v2aux-vcvthf82hf6s-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512VL
+#define AVX512F_LEN 256
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvthf82hf6s-2.h"
+
+#undef AVX512F_LEN
+#undef AVX512F_LEN_HALF
+
+#define AVX512F_LEN 128
+#define AVX512F_LEN_HALF 128
+#include "avx10v2aux-vcvthf82hf6s-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82hf6s-2.h 
b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82hf6s-2.h
new file mode 100644
index 000000000000..6456329d7fa2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/avx10v2aux-vcvthf82hf6s-2.h
@@ -0,0 +1,3 @@
+#define PACKED_NARROW_I _cvts_hf8_hf6
+#define PACKED_NARROW_CVT fp8_e4m3_to_fp6_e2m3
+#include "avx10v2aux-packed-narrow-2.h"
diff --git a/gcc/testsuite/gcc.target/i386/fp4-fp6-helper.h 
b/gcc/testsuite/gcc.target/i386/fp4-fp6-helper.h
new file mode 100644
index 000000000000..d78c17a27cc2
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/fp4-fp6-helper.h
@@ -0,0 +1,314 @@
+#ifndef FP4_FP6_HELPER_INCLUDED
+#define FP4_FP6_HELPER_INCLUDED
+
+#include <stdint.h>
+#include <inttypes.h>
+
+static unsigned char
+mask_u8 (int bits)
+{
+  if (bits <= 0)
+    return 0;
+  if (bits >= 8)
+    return 0xff;
+  return (unsigned char) ((1u << bits) - 1u);
+}
+
+static unsigned char
+fp4_e2m1_to_fp8_e4m3 (unsigned char nibble)
+{
+  static const unsigned char lut[8] = {
+    0x00, 0x30, 0x38, 0x3C, 0x40, 0x44, 0x48, 0x4C
+  };
+  return (unsigned char) (lut[nibble & 0x7] | ((nibble & 0x8) << 4));
+}
+
+static unsigned char
+fp8_e4m3_to_fp4_e2m1 (unsigned char v)
+{
+  const unsigned int sign = (v >> 7) & 1;
+  const unsigned int exp = (v >> 3) & 0xF;
+  const unsigned int mant = v & 0x7;
+  const int exp_rebias = 7 - 1;
+  const int new_exp = (int) exp - exp_rebias;
+  int e_o = 0;
+  int m_o = 0;
+
+  if (exp == 0xF && mant == 0x7)
+    {
+      e_o = 0x3;
+      m_o = 0x1;
+    }
+  else if (exp > exp_rebias + 3 || (exp == exp_rebias + 3 && mant > 0x4))
+    {
+      e_o = 0x3;
+      m_o = 0x1;
+    }
+  else if (exp == 0)
+    {
+      e_o = 0;
+      m_o = 0;
+    }
+  else if (new_exp <= 0)
+    {
+      const int shift = 3 - new_exp;
+      if (shift <= 4)
+       {
+         const unsigned char mant_full = (unsigned char) (mant | 0x8);
+         m_o = mant_full >> shift;
+         const unsigned char low = mant_full & mask_u8 (shift);
+         const unsigned char half = (unsigned char) (1u << (shift - 1));
+         if (low > half || (low == half && (m_o & 1)))
+           {
+             m_o++;
+             if ((m_o & 0x1) == 0)
+               e_o++;
+           }
+       }
+    }
+  else
+    {
+      const unsigned char rnex
+       = (unsigned char) (v + 0x01 + ((mant >> 2) & 0x1));
+      e_o = (int) ((rnex & 0x78) >> 3) - exp_rebias;
+      m_o = (rnex & 0x07) >> 2;
+    }
+
+  return (unsigned char) ((sign << 3) | ((e_o & 0x3) << 1) | (m_o & 0x1));
+}
+
+static unsigned char
+fp8_e5m2_to_fp4_e2m1 (unsigned char v)
+{
+  const unsigned int sign = (v >> 7) & 1;
+  const unsigned int exp = (v >> 2) & 0x1F;
+  const unsigned int mant = v & 0x3;
+  const int exp_rebias = 15 - 1;
+  const int new_exp = (int) exp - exp_rebias;
+  int e_o = 0;
+  int m_o = 0;
+
+  if (exp == 0x1F)
+    {
+      e_o = 0x3;
+      m_o = 0x1;
+    }
+  else if (exp > exp_rebias + 3 || (exp == exp_rebias + 3 && mant > 0x2))
+    {
+      e_o = 0x3;
+      m_o = 0x1;
+    }
+  else if (exp == 0)
+    {
+      e_o = 0;
+      m_o = 0;
+    }
+  else if (new_exp <= 0)
+    {
+      const int shift = 2 - new_exp;
+      if (shift <= 3)
+       {
+         const unsigned char mant_full = (unsigned char) (mant | 0x4);
+         m_o = mant_full >> shift;
+         const unsigned char low = mant_full & mask_u8 (shift);
+         const unsigned char half = (unsigned char) (1u << (shift - 1));
+         if (low > half || (low == half && (m_o & 1)))
+           {
+             m_o++;
+             if ((m_o & 0x1) == 0)
+               e_o++;
+           }
+       }
+    }
+  else
+    {
+      const unsigned char rnex = (unsigned char) (v + ((mant >> 1) & 0x1));
+      e_o = (int) ((rnex & 0x7C) >> 2) - exp_rebias;
+      m_o = (rnex & 0x03) >> 1;
+    }
+
+  return (unsigned char) ((sign << 3) | ((e_o & 0x3) << 1) | (m_o & 0x1));
+}
+
+static unsigned char
+fp8_e5m2_to_fp6_e3m2 (unsigned char v)
+{
+  const unsigned int sign = (v >> 7) & 1;
+  const unsigned int exp = (v >> 2) & 0x1F;
+  const unsigned int mant = v & 0x3;
+  const int exp_rebias = 15 - 3;
+  const int new_exp = (int) exp - exp_rebias;
+  int e_o = 0;
+  int m_o = 0;
+
+  if (exp == 0x1F)
+    {
+      e_o = 0x7;
+      m_o = 0x3;
+    }
+  else if (exp > exp_rebias + 7 || (exp == exp_rebias + 7 && mant > 0x3))
+    {
+      e_o = 0x7;
+      m_o = 0x3;
+    }
+  else if (exp == 0)
+    {
+      e_o = 0;
+      m_o = 0;
+    }
+  else if (new_exp <= 0)
+    {
+      const int shift = 1 - new_exp;
+      if (shift <= 3)
+       {
+         const unsigned char mant_full = (unsigned char) (mant | 0x4);
+         m_o = mant_full >> shift;
+         const unsigned char low = mant_full & mask_u8 (shift);
+         const unsigned char half = (unsigned char) (1u << (shift - 1));
+         if (low > half || (low == half && (m_o & 1)))
+           {
+             m_o++;
+             if ((m_o & 0x3) == 0)
+               e_o++;
+           }
+       }
+    }
+  else
+    {
+      e_o = (int) exp - exp_rebias;
+      m_o = (int) mant;
+    }
+
+  return (unsigned char) ((sign << 5) | ((e_o & 0x7) << 2) | (m_o & 0x3));
+}
+
+static unsigned char
+fp8_e4m3_to_fp6_e2m3 (unsigned char v)
+{
+  const unsigned int sign = (v >> 7) & 1;
+  const unsigned int exp = (v >> 3) & 0xF;
+  const unsigned int mant = v & 0x7;
+  const int exp_rebias = 7 - 1;
+  const int new_exp = (int) exp - exp_rebias;
+  int e_o = 0;
+  int m_o = 0;
+
+  if (exp == 0xF)
+    {
+      e_o = 0x3;
+      m_o = 0x7;
+    }
+  else if (exp > exp_rebias + 3 || (exp == exp_rebias + 3 && mant > 0x7))
+    {
+      e_o = 0x3;
+      m_o = 0x7;
+    }
+  else if (exp == 0 && mant == 0)
+    {
+      e_o = 0;
+      m_o = 0;
+    }
+  else if (new_exp <= 0)
+    {
+      const int shift = 1 - new_exp;
+      if (shift <= 4)
+       {
+         const unsigned char mant_full = (unsigned char) (mant | 0x8);
+         m_o = mant_full >> shift;
+         const unsigned char low = mant_full & mask_u8 (shift);
+         const unsigned char half = (unsigned char) (1u << (shift - 1));
+         if (low > half || (low == half && (m_o & 1)))
+           {
+             m_o++;
+             if ((m_o & 0x7) == 0)
+               e_o++;
+           }
+       }
+    }
+  else
+    {
+      e_o = (int) exp - exp_rebias;
+      m_o = (int) mant;
+    }
+
+  return (unsigned char) ((sign << 5) | ((e_o & 0x3) << 3) | (m_o & 0x7));
+}
+
+static unsigned char
+fp6_e3m2_to_fp8_e4m3 (unsigned char fp6)
+{
+  const int sign = (fp6 >> 5) & 1;
+  const int exp = (fp6 >> 2) & 0x7;
+  const int mant = fp6 & 0x3;
+  int e_o = 0;
+  int m_o = 0;
+
+  if (exp == 0)
+    {
+      if (mant == 0)
+       {
+         e_o = 0;
+         m_o = 0;
+       }
+      else if (mant == 1)
+       {
+         e_o = 3;
+         m_o = 0;
+       }
+      else
+       {
+         e_o = 4;
+         m_o = (mant & 0x1) << 2;
+       }
+    }
+  else
+    {
+      e_o = exp + (7 - 3);
+      m_o = mant << 1;
+    }
+
+  return (unsigned char) ((sign << 7) | ((e_o & 0xF) << 3) | (m_o & 0x7));
+}
+
+static unsigned char
+fp6_e2m3_to_fp8_e4m3 (unsigned char fp6)
+{
+  const int sign = (fp6 >> 5) & 1;
+  const int exp = (fp6 >> 3) & 0x3;
+  const int mant = fp6 & 0x7;
+  int e_o = 0;
+  int m_o = 0;
+
+  if (exp == 0)
+    {
+      if (mant == 0)
+       {
+         e_o = 0;
+         m_o = 0;
+       }
+      else if (mant == 1)
+       {
+         e_o = 4;
+         m_o = 0;
+       }
+      else if (mant <= 3)
+       {
+         e_o = 5;
+         m_o = (mant & 0x1) << 2;
+       }
+      else
+       {
+         e_o = 6;
+         m_o = (mant & 0x3) << 1;
+       }
+    }
+  else
+    {
+      e_o = exp + (7 - 1);
+      m_o = mant;
+    }
+
+  return (unsigned char) ((sign << 7) | ((e_o & 0xF) << 3) | (m_o & 0x7));
+}
+
+#endif
-- 
2.34.1

Reply via email to