diff options
author | liuhongt <hongtao.liu@intel.com> | 2023-10-10 14:52:33 +0800 |
---|---|---|
committer | liuhongt <hongtao.liu@intel.com> | 2023-10-16 09:08:06 +0800 |
commit | 96f12b9f9b9646deb0f7678a3f8d544e8d48cb91 (patch) | |
tree | efa3cd1e2274ccb834c746c26fc0ba3c1fc1dab1 /gcc/config | |
parent | d5cfabc677b08f38ea5d5f85deeda746b4fabb88 (diff) | |
download | gcc-96f12b9f9b9646deb0f7678a3f8d544e8d48cb91.zip gcc-96f12b9f9b9646deb0f7678a3f8d544e8d48cb91.tar.gz gcc-96f12b9f9b9646deb0f7678a3f8d544e8d48cb91.tar.bz2 |
Enable vectorization for V2HF/V4HF rounding operations and sqrt.
gcc/ChangeLog:
* config/i386/i386-expand.cc (ix86_sse_copysign_to_positive):
Handle HFmode.
(ix86_expand_round_sse4): Ditto.
* config/i386/i386.md (roundhf2): New expander.
(lroundhf<mode>2): Ditto.
(lrinthf<mode>2): Ditto.
(l<rounding_insn>hf<mode>2): Ditto.
* config/i386/mmx.md (sqrt<mode>2): Ditto.
(btrunc<mode>2): Ditto.
(nearbyint<mode>2): Ditto.
(rint<mode>2): Ditto.
(lrint<mode><mmxintvecmodelower>2): Ditto.
(floor<mode>2): Ditto.
(lfloor<mode><mmxintvecmodelower>2): Ditto.
(ceil<mode>2): Ditto.
(lceil<mode><mmxintvecmodelower>2): Ditto.
(round<mode>2): Ditto.
(lround<mode><mmxintvecmodelower>2): Ditto.
* config/i386/sse.md (lrint<mode><sseintvecmodelower>2): Ditto.
(lfloor<mode><sseintvecmodelower>2): Ditto.
(lceil<mode><sseintvecmodelower>2): Ditto.
(lround<mode><sseintvecmodelower>2): Ditto.
(sse4_1_round<ssescalarmodesuffix>): Extend to V8HF.
(round<mode>2): Extend to V8HF/V16HF/V32HF.
gcc/testsuite/ChangeLog:
* gcc.target/i386/part-vect-roundhf.c: New test.
* gcc.target/i386/part-vect-sqrtph-1.c: New test.
Diffstat (limited to 'gcc/config')
-rw-r--r-- | gcc/config/i386/i386-expand.cc | 6 | ||||
-rw-r--r-- | gcc/config/i386/i386.md | 38 | ||||
-rw-r--r-- | gcc/config/i386/mmx.md | 191 | ||||
-rw-r--r-- | gcc/config/i386/sse.md | 60 |
4 files changed, 284 insertions, 11 deletions
diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index 4ef8557..1eae9d7 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -18506,6 +18506,8 @@ ix86_sse_copysign_to_positive (rtx result, rtx abs_value, rtx sign, rtx mask) vmode = V4SFmode; else if (mode == DFmode) vmode = V2DFmode; + else if (mode == HFmode) + vmode = V8HFmode; else vmode = mode; @@ -19042,6 +19044,10 @@ ix86_expand_round_sse4 (rtx op0, rtx op1) switch (mode) { + case E_HFmode: + gen_copysign = gen_copysignhf3; + gen_round = gen_sse4_1_roundhf2; + break; case E_SFmode: gen_copysign = gen_copysignsf3; gen_round = gen_sse4_1_roundsf2; diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 2a60df5..f90cf1c 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -21840,6 +21840,15 @@ DONE; }) +(define_expand "roundhf2" + [(match_operand:HF 0 "register_operand") + (match_operand:HF 1 "register_operand")] + "TARGET_AVX512FP16 && !flag_trapping_math && !flag_rounding_math" +{ + ix86_expand_round_sse4 (operands[0], operands[1]); + DONE; +}) + (define_expand "round<mode>2" [(match_operand:X87MODEF 0 "register_operand") (match_operand:X87MODEF 1 "nonimmediate_operand")] @@ -21891,6 +21900,22 @@ [(set_attr "type" "fpspc") (set_attr "mode" "<MODE>")]) +(define_expand "lroundhf<mode>2" + [(set (match_operand:SWI248 0 "register_operand") + (unspec:SWI248 [(match_operand:HF 1 "nonimmediate_operand")] + UNSPEC_FIX_NOTRUNC))] + "TARGET_AVX512FP16 && !flag_trapping_math && !flag_rounding_math" +{ + ix86_expand_lround (operands[0], operands[1]); + DONE; +}) + +(define_expand "lrinthf<mode>2" + [(set (match_operand:SWI48 0 "register_operand") + (unspec:SWI48 [(match_operand:HF 1 "nonimmediate_operand")] + UNSPEC_FIX_NOTRUNC))] + "TARGET_AVX512FP16") + (define_expand "lrint<MODEF:mode><SWI48:mode>2" [(set (match_operand:SWI48 0 "register_operand") (unspec:SWI48 [(match_operand:MODEF 1 "nonimmediate_operand")] @@ -22133,6 +22158,19 @@ && (!TARGET_SSE_MATH || TARGET_MIX_SSE_I387) && flag_unsafe_math_optimizations") +(define_expand "l<rounding_insn>hf<mode>2" + [(set (match_operand:SWI48 0 "nonimmediate_operand") + (unspec:SWI48 [(match_operand:HF 1 "register_operand")] + FIST_ROUNDING))] + "TARGET_AVX512FP16" +{ + rtx tmp = gen_reg_rtx (HFmode); + emit_insn (gen_sse4_1_roundhf2 (tmp, operands[1], + GEN_INT (ROUND_<ROUNDING> | ROUND_NO_EXC))); + emit_insn (gen_fix_trunchf<mode>2 (operands[0], tmp)); + DONE; +}) + (define_expand "l<rounding_insn><MODEF:mode><SWI48:mode>2" [(parallel [(set (match_operand:SWI48 0 "nonimmediate_operand") (unspec:SWI48 [(match_operand:MODEF 1 "register_operand")] diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md index 4707cfa..91674b4 100644 --- a/gcc/config/i386/mmx.md +++ b/gcc/config/i386/mmx.md @@ -103,7 +103,8 @@ (V4HF "V4HF") (V2HF "V2HI")]) (define_mode_attr mmxintvecmodelower - [(V2SF "v2si") (V2SI "v2si") (V4HI "v4hi") (V8QI "v8qi")]) + [(V2SF "v2si") (V2SI "v2si") (V4HI "v4hi") (V8QI "v8qi") + (V4HF "v4hi") (V2HF "v2hi")]) ;; Mapping of vector modes to a vector mode of double size (define_mode_attr mmxdoublevecmode @@ -2053,6 +2054,21 @@ DONE; }) +(define_expand "sqrt<mode>2" + [(set (match_operand:VHF_32_64 0 "register_operand") + (sqrt:VHF_32_64 + (match_operand:VHF_32_64 1 "nonimmediate_operand")))] + "TARGET_AVX512FP16 && TARGET_AVX512VL && ix86_partial_vec_fp_math" +{ + rtx op1 = gen_reg_rtx (V8HFmode); + rtx op0 = gen_reg_rtx (V8HFmode); + + emit_insn (gen_mov<mov_to_sse_suffix>_<mode>_to_sse (op1, operands[1])); + emit_insn (gen_sqrtv8hf2 (op0, op1)); + emit_move_insn (operands[0], lowpart_subreg (<MODE>mode, op0, V8HFmode)); + DONE; +}) + (define_expand "<code><mode>2" [(set (match_operand:VHF_32_64 0 "register_operand") (absneg:VHF_32_64 @@ -2090,6 +2106,179 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; +;; Parallel half-precision floating point rounding operations. +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(define_expand "btrunc<mode>2" + [(match_operand:VHF_32_64 0 "register_operand") + (match_operand:VHF_32_64 1 "nonimmediate_operand")] + "TARGET_AVX512FP16 && TARGET_AVX512VL + && ix86_partial_vec_fp_math + && !flag_trapping_math" +{ + rtx op1 = gen_reg_rtx (V8HFmode); + rtx op0 = gen_reg_rtx (V8HFmode); + + emit_insn (gen_mov<mov_to_sse_suffix>_<mode>_to_sse (op1, operands[1])); + emit_insn (gen_btruncv8hf2 (op0, op1)); + emit_move_insn (operands[0], lowpart_subreg (<MODE>mode, op0, V8HFmode)); + + DONE; +}) + +(define_expand "nearbyint<mode>2" + [(match_operand:VHF_32_64 0 "register_operand") + (match_operand:VHF_32_64 1 "nonimmediate_operand")] + "TARGET_AVX512FP16 && TARGET_AVX512VL + && ix86_partial_vec_fp_math" +{ + rtx op1 = gen_reg_rtx (V8HFmode); + rtx op0 = gen_reg_rtx (V8HFmode); + + emit_insn (gen_mov<mov_to_sse_suffix>_<mode>_to_sse (op1, operands[1])); + emit_insn (gen_nearbyintv8hf2 (op0, op1)); + emit_move_insn (operands[0], lowpart_subreg (<MODE>mode, op0, V8HFmode)); + + DONE; +}) + +(define_expand "rint<mode>2" + [(match_operand:VHF_32_64 0 "register_operand") + (match_operand:VHF_32_64 1 "nonimmediate_operand")] + "TARGET_AVX512FP16 && TARGET_AVX512VL + && ix86_partial_vec_fp_math" +{ + rtx op1 = gen_reg_rtx (V8HFmode); + rtx op0 = gen_reg_rtx (V8HFmode); + + emit_insn (gen_mov<mov_to_sse_suffix>_<mode>_to_sse (op1, operands[1])); + emit_insn (gen_rintv8hf2 (op0, op1)); + emit_move_insn (operands[0], lowpart_subreg (<MODE>mode, op0, V8HFmode)); + + DONE; +}) + +(define_expand "lrint<mode><mmxintvecmodelower>2" + [(match_operand:<mmxintvecmode> 0 "register_operand") + (match_operand:VHF_32_64 1 "nonimmediate_operand")] + "TARGET_AVX512FP16 && TARGET_AVX512VL + && ix86_partial_vec_fp_math" +{ + rtx op1 = gen_reg_rtx (V8HFmode); + rtx op0 = gen_reg_rtx (V8HFmode); + + emit_insn (gen_mov<mov_to_sse_suffix>_<mode>_to_sse (op1, operands[1])); + emit_insn (gen_lrintv8hfv8hi2 (op0, op1)); + emit_move_insn (operands[0], lowpart_subreg (<MODE>mode, op0, V8HFmode)); + + DONE; +}) + +(define_expand "floor<mode>2" + [(match_operand:VHF_32_64 0 "register_operand") + (match_operand:VHF_32_64 1 "nonimmediate_operand")] + "TARGET_AVX512FP16 && TARGET_AVX512VL + && ix86_partial_vec_fp_math + && !flag_trapping_math" +{ + rtx op1 = gen_reg_rtx (V8HFmode); + rtx op0 = gen_reg_rtx (V8HFmode); + + emit_insn (gen_mov<mov_to_sse_suffix>_<mode>_to_sse (op1, operands[1])); + emit_insn (gen_floorv8hf2 (op0, op1)); + emit_move_insn (operands[0], lowpart_subreg (<MODE>mode, op0, V8HFmode)); + + DONE; +}) + +(define_expand "lfloor<mode><mmxintvecmodelower>2" + [(match_operand:<mmxintvecmode> 0 "register_operand") + (match_operand:VHF_32_64 1 "nonimmediate_operand")] + "TARGET_AVX512FP16 && TARGET_AVX512VL + && ix86_partial_vec_fp_math + && !flag_trapping_math" +{ + rtx op1 = gen_reg_rtx (V8HFmode); + rtx op0 = gen_reg_rtx (V8HFmode); + + emit_insn (gen_mov<mov_to_sse_suffix>_<mode>_to_sse (op1, operands[1])); + emit_insn (gen_lfloorv8hfv8hi2 (op0, op1)); + emit_move_insn (operands[0], lowpart_subreg (<MODE>mode, op0, V8HFmode)); + + DONE; +}) + +(define_expand "ceil<mode>2" + [(match_operand:VHF_32_64 0 "register_operand") + (match_operand:VHF_32_64 1 "nonimmediate_operand")] + "TARGET_AVX512FP16 && TARGET_AVX512VL + && ix86_partial_vec_fp_math + && !flag_trapping_math" +{ + rtx op1 = gen_reg_rtx (V8HFmode); + rtx op0 = gen_reg_rtx (V8HFmode); + + emit_insn (gen_mov<mov_to_sse_suffix>_<mode>_to_sse (op1, operands[1])); + emit_insn (gen_ceilv8hf2 (op0, op1)); + emit_move_insn (operands[0], lowpart_subreg (<MODE>mode, op0, V8HFmode)); + + DONE; +}) + +(define_expand "lceil<mode><mmxintvecmodelower>2" + [(match_operand:<mmxintvecmode> 0 "register_operand") + (match_operand:VHF_32_64 1 "nonimmediate_operand")] + "TARGET_AVX512FP16 && TARGET_AVX512VL + && ix86_partial_vec_fp_math + && !flag_trapping_math" +{ + rtx op1 = gen_reg_rtx (V8HFmode); + rtx op0 = gen_reg_rtx (V8HFmode); + + emit_insn (gen_mov<mov_to_sse_suffix>_<mode>_to_sse (op1, operands[1])); + emit_insn (gen_lceilv8hfv8hi2 (op0, op1)); + emit_move_insn (operands[0], lowpart_subreg (<MODE>mode, op0, V8HFmode)); + + DONE; +}) + +(define_expand "round<mode>2" + [(match_operand:VHF_32_64 0 "register_operand") + (match_operand:VHF_32_64 1 "nonimmediate_operand")] + "TARGET_AVX512FP16 && TARGET_AVX512VL + && ix86_partial_vec_fp_math + && !flag_trapping_math" +{ + rtx op1 = gen_reg_rtx (V8HFmode); + rtx op0 = gen_reg_rtx (V8HFmode); + + emit_insn (gen_mov<mov_to_sse_suffix>_<mode>_to_sse (op1, operands[1])); + emit_insn (gen_roundv8hf2 (op0, op1)); + emit_move_insn (operands[0], lowpart_subreg (<MODE>mode, op0, V8HFmode)); + + DONE; +}) + +(define_expand "lround<mode><mmxintvecmodelower>2" + [(match_operand:<mmxintvecmode> 0 "register_operand") + (match_operand:VHF_32_64 1 "nonimmediate_operand")] + "TARGET_AVX512FP16 && TARGET_AVX512VL + && ix86_partial_vec_fp_math + && !flag_trapping_math" +{ + rtx op1 = gen_reg_rtx (V8HFmode); + rtx op0 = gen_reg_rtx (V8HFmode); + + emit_insn (gen_mov<mov_to_sse_suffix>_<mode>_to_sse (op1, operands[1])); + emit_insn (gen_lroundv8hfv8hi2 (op0, op1)); + emit_move_insn (operands[0], lowpart_subreg (<MODE>mode, op0, V8HFmode)); + + DONE; +}) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; Parallel half-precision floating point logical operations ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md index 98eb79e..9feb637 100644 --- a/gcc/config/i386/sse.md +++ b/gcc/config/i386/sse.md @@ -7136,6 +7136,13 @@ DONE; }) +(define_expand "lrint<mode><sseintvecmodelower>2" + [(set (match_operand:<sseintvecmode> 0 "register_operand") + (unspec:<sseintvecmode> + [(match_operand:VHF_AVX512VL 1 "register_operand")] + UNSPEC_FIX_NOTRUNC))] + "TARGET_AVX512FP16") + (define_insn "avx512fp16_vcvtph2<sseintconvertsignprefix><sseintconvert>_<mode><mask_name><round_name>" [(set (match_operand:VI248_AVX512VL 0 "register_operand" "=v") (unspec:VI248_AVX512VL @@ -24246,13 +24253,13 @@ }) (define_insn "sse4_1_round<ssescalarmodesuffix>" - [(set (match_operand:VF_128 0 "register_operand" "=Yr,*x,x,v") - (vec_merge:VF_128 - (unspec:VF_128 - [(match_operand:VF_128 2 "nonimmediate_operand" "Yrjm,*xjm,xjm,vm") + [(set (match_operand:VFH_128 0 "register_operand" "=Yr,*x,x,v") + (vec_merge:VFH_128 + (unspec:VFH_128 + [(match_operand:VFH_128 2 "nonimmediate_operand" "Yrjm,*xjm,xjm,vm") (match_operand:SI 3 "const_0_to_15_operand")] UNSPEC_ROUND) - (match_operand:VF_128 1 "register_operand" "0,0,x,v") + (match_operand:VFH_128 1 "register_operand" "0,0,x,v") (const_int 1)))] "TARGET_SSE4_1" { @@ -24264,7 +24271,7 @@ case 2: return "vround<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %<iptr>2, %3}"; case 3: - if (x86_evex_reg_mentioned_p (operands, 3)) + if (x86_evex_reg_mentioned_p (operands, 3) || <MODE>mode == V8HFmode) return "vrndscale<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %<iptr>2, %3}"; else return "vround<ssescalarmodesuffix>\t{%3, %2, %1, %0|%0, %1, %<iptr>2, %3}"; @@ -24329,6 +24336,17 @@ (define_expand "lfloor<mode><sseintvecmodelower>2" [(match_operand:<sseintvecmode> 0 "register_operand") + (match_operand:VHF_AVX512VL 1 "nonimmediate_operand")] + "TARGET_AVX512FP16 && !flag_trapping_math" +{ + rtx tmp = gen_reg_rtx (<MODE>mode); + emit_insn (gen_floor<mode>2 (tmp, operands[1])); + emit_insn (gen_fix_trunc<mode><sseintvecmodelower>2 (operands[0], tmp)); + DONE; +}) + +(define_expand "lfloor<mode><sseintvecmodelower>2" + [(match_operand:<sseintvecmode> 0 "register_operand") (match_operand:VF1_VF2_AVX512DQ 1 "register_operand")] "TARGET_SSE4_1 && !flag_trapping_math" { @@ -24349,6 +24367,17 @@ (define_expand "lceil<mode><sseintvecmodelower>2" [(match_operand:<sseintvecmode> 0 "register_operand") + (match_operand:VHF_AVX512VL 1 "register_operand")] + "TARGET_AVX512FP16 && !flag_trapping_math" +{ + rtx tmp = gen_reg_rtx (<MODE>mode); + emit_insn (gen_ceil<mode>2 (tmp, operands[1])); + emit_insn (gen_fix_trunc<mode><sseintvecmodelower>2 (operands[0], tmp)); + DONE; +}) + +(define_expand "lceil<mode><sseintvecmodelower>2" + [(match_operand:<sseintvecmode> 0 "register_operand") (match_operand:VF1_VF2_AVX512DQ 1 "register_operand")] "TARGET_SSE4_1 && !flag_trapping_math" { @@ -24369,11 +24398,11 @@ (define_expand "round<mode>2" [(set (match_dup 3) - (plus:VF - (match_operand:VF 1 "register_operand") + (plus:VFH + (match_operand:VFH 1 "register_operand") (match_dup 2))) - (set (match_operand:VF 0 "register_operand") - (unspec:VF + (set (match_operand:VFH 0 "register_operand") + (unspec:VFH [(match_dup 3) (match_dup 4)] UNSPEC_ROUND))] "TARGET_SSE4_1 && !flag_trapping_math" @@ -24403,6 +24432,17 @@ (define_expand "lround<mode><sseintvecmodelower>2" [(match_operand:<sseintvecmode> 0 "register_operand") + (match_operand:VHF_AVX512VL 1 "register_operand")] + "TARGET_AVX512FP16 && !flag_trapping_math" +{ + rtx tmp = gen_reg_rtx (<MODE>mode); + emit_insn (gen_round<mode>2 (tmp, operands[1])); + emit_insn (gen_fix_trunc<mode><sseintvecmodelower>2 (operands[0], tmp)); + DONE; +}) + +(define_expand "lround<mode><sseintvecmodelower>2" + [(match_operand:<sseintvecmode> 0 "register_operand") (match_operand:VF1_VF2_AVX512DQ 1 "register_operand")] "TARGET_SSE4_1 && !flag_trapping_math" { |