]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
AVX512FP16: Add expander for smin/maxhf3.
authorHongyu Wang <hongyu.wang@intel.com>
Sat, 18 Sep 2021 05:56:37 +0000 (13:56 +0800)
committerliuhongt <hongtao.liu@intel.com>
Thu, 23 Sep 2021 09:05:02 +0000 (17:05 +0800)
gcc/ChangeLog:

* config/i386/i386.md (<code>hf3): New expander.

gcc/testsuite/ChangeLog:

* gcc.target/i386/avx512fp16-builtin-minmax-1.c: New test.

gcc/config/i386/i386.md
gcc/testsuite/gcc.target/i386/avx512fp16-builtin-minmax-1.c [new file with mode: 0644]

index 4b13a59be8259b50705b513f987e2ace0d26085f..a087e557d7faa09a32e66f6ccc2c5213ce57b2ef 100644 (file)
    (set_attr "type" "sseadd")
    (set_attr "mode" "<MODE>")])
 
+(define_insn "<code>hf3"
+  [(set (match_operand:HF 0 "register_operand" "=v")
+       (smaxmin:HF
+         (match_operand:HF 1 "nonimmediate_operand" "%v")
+         (match_operand:HF 2 "nonimmediate_operand" "vm")))]
+  "TARGET_AVX512FP16"
+  "v<maxmin_float>sh\t{%2, %1, %0|%0, %1, %2}"
+  [(set_attr "prefix" "evex")
+   (set_attr "type" "sseadd")
+   (set_attr "mode" "HF")])
+
 ;; These versions of the min/max patterns implement exactly the operations
 ;;   min = (op1 < op2 ? op1 : op2)
 ;;   max = (!(op1 < op2) ? op1 : op2)
diff --git a/gcc/testsuite/gcc.target/i386/avx512fp16-builtin-minmax-1.c b/gcc/testsuite/gcc.target/i386/avx512fp16-builtin-minmax-1.c
new file mode 100644 (file)
index 0000000..90080e4
--- /dev/null
@@ -0,0 +1,35 @@
+/* { dg-do compile } */
+/* { dg-options "-Ofast -mavx512fp16 -mprefer-vector-width=512" } */
+
+_Float16
+minf1 (_Float16 a, _Float16 b)
+{
+  return __builtin_fminf16 (a, b);
+}
+
+void
+minf2 (_Float16* __restrict psrc1, _Float16* __restrict psrc2,
+       _Float16* __restrict pdst)
+{
+  for (int i = 0; i != 32; i++)
+    pdst[i] = __builtin_fminf16 (psrc1[i], psrc2[i]);
+}
+
+_Float16
+maxf1 (_Float16 a, _Float16 b)
+{
+  return __builtin_fmaxf16 (a, b);
+}
+
+void
+maxf2 (_Float16* __restrict psrc1, _Float16* __restrict psrc2,
+       _Float16* __restrict pdst)
+{
+  for (int i = 0; i != 32; i++)
+    pdst[i] = __builtin_fmaxf16 (psrc1[i], psrc2[i]);
+}
+
+/* { dg-final { scan-assembler-times "vmaxsh\[^\n\r\]*xmm\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "vmaxph\[^\n\r\]*zmm\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "vminsh\[^\n\r\]*xmm\[0-9\]" 1 } } */
+/* { dg-final { scan-assembler-times "vminph\[^\n\r\]*zmm\[0-9\]" 1 } } */