]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
i386: Support complex fma/conj_fma for _Float16.
authorkonglin1 <lingling.kong@intel.com>
Wed, 27 Oct 2021 09:15:05 +0000 (17:15 +0800)
committerliuhongt <hongtao.liu@intel.com>
Wed, 10 Nov 2021 07:10:23 +0000 (15:10 +0800)
Support cmla_optab, cmul_optab, cmla_conj_optab, cmul_conj_optab for vector _Float16.

gcc/ChangeLog:

* config/i386/sse.md (cmul<conj_op><mode>3): add new define_expand.
(cmla<conj_op><mode>4): Likewise

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx512fp16-vector-complex-float.c: New test.

gcc/config/i386/sse.md
gcc/testsuite/gcc.target/i386/avx512fp16-vector-complex-float.c [new file with mode: 0644]

index a58d8e82a6aa8045516fdf8db09a9134e4601704..190841211a56cd775595ffbebd4abceec2e86f34 100644 (file)
        [(UNSPEC_COMPLEX_FMA_PAIR "fmaddc")
         (UNSPEC_COMPLEX_FCMA_PAIR "fcmaddc")])
 
+(define_int_attr conj_op
+       [(UNSPEC_COMPLEX_FMA "")
+        (UNSPEC_COMPLEX_FCMA "_conj")
+        (UNSPEC_COMPLEX_FMUL "")
+        (UNSPEC_COMPLEX_FCMUL "_conj")])
+
 (define_mode_attr complexmove
   [(V32HF "avx512f_loadv16sf")
    (V16HF "avx512vl_loadv8sf")
   DONE;
 })
 
+(define_expand "cmla<conj_op><mode>4"
+  [(set (match_operand:VF_AVX512FP16VL 0 "register_operand")
+       (unspec:VF_AVX512FP16VL
+           [(match_operand:VF_AVX512FP16VL 1 "vector_operand")
+            (match_operand:VF_AVX512FP16VL 2 "vector_operand")
+            (match_operand:VF_AVX512FP16VL 3 "vector_operand")]
+            UNSPEC_COMPLEX_F_C_MA))]
+  "TARGET_AVX512FP16")
+
 (define_insn "fma_<complexopname>_<mode><sdc_maskz_name><round_name>"
   [(set (match_operand:VF_AVX512FP16VL 0 "register_operand" "=&v")
        (unspec:VF_AVX512FP16VL
   [(set_attr "type" "ssemuladd")
    (set_attr "mode" "<MODE>")])
 
+(define_expand "cmul<conj_op><mode>3"
+  [(set (match_operand:VF_AVX512FP16VL 0 "register_operand")
+       (unspec:VF_AVX512FP16VL
+         [(match_operand:VF_AVX512FP16VL 1 "vector_operand")
+          (match_operand:VF_AVX512FP16VL 2 "vector_operand")]
+          UNSPEC_COMPLEX_F_C_MUL))]
+  "TARGET_AVX512FP16")
+
 (define_insn "<avx512>_<complexopname>_<mode><maskc_name><round_name>"
   [(set (match_operand:VF_AVX512FP16VL 0 "register_operand" "=&v")
          (unspec:VF_AVX512FP16VL
diff --git a/gcc/testsuite/gcc.target/i386/avx512fp16-vector-complex-float.c b/gcc/testsuite/gcc.target/i386/avx512fp16-vector-complex-float.c
new file mode 100644 (file)
index 0000000..7c579cb
--- /dev/null
@@ -0,0 +1,40 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -ffast-math -mavx512fp16 -mavx512vl -mprefer-vector-width=512" } */
+/* { dg-final { scan-assembler-times "vfmaddcph\[ \\t\]" 1 } } */
+/* { dg-final { scan-assembler-not "vfmadd\[123]*ph\[ \\t\]"} } */
+/* { dg-final { scan-assembler-not "vfmadd\[123]*sh\[ \\t\]"} } */
+/* { dg-final { scan-assembler-times "vfcmaddcph\[ \\t\]" 1 } } */
+/* { dg-final { scan-assembler-times "vfmulcph\[ \\t\]" 1 } } */
+/* { dg-final { scan-assembler-times "vfcmulcph\[ \\t\]" 1 } } */
+
+#include<complex.h>
+#define TYPE _Float16
+#define N 16
+
+void fma0 (_Complex TYPE *a, _Complex TYPE *b,
+           _Complex TYPE * __restrict c)
+{
+  for (int i = 0; i < N; i++)
+    c[i] += a[i] * b[i];
+}
+
+void fmaconj (_Complex TYPE a[restrict N], _Complex TYPE b[restrict N],
+             _Complex TYPE c[restrict N])
+{
+  for (int i = 0; i < N; i++)
+    c[i] += a[i] * ~b[i];
+}
+
+void fmul (_Complex TYPE a[restrict N], _Complex TYPE b[restrict N],
+          _Complex TYPE c[restrict N])
+{
+  for (int i = 0; i < N; i++)
+    c[i] = a[i] * b[i];
+}
+
+void fmulconj (_Complex TYPE a[restrict N], _Complex TYPE b[restrict N],
+              _Complex TYPE c[restrict N])
+{
+  for (int i = 0; i < N; i++)
+    c[i] = a[i] * ~b[i];
+}