aboutsummaryrefslogtreecommitdiff
path: root/gcc/function.cc
diff options
context:
space:
mode:
authorPan Li <pan2.li@intel.com>2023-09-27 10:46:15 +0800
committerPan Li <pan2.li@intel.com>2023-09-27 11:33:58 +0800
commit1c4ca595d817ae1e1139145f86cfb58899d376bd (patch)
tree7fda26d690fb1d592ba12c3f96c27c8e5b6dbe49 /gcc/function.cc
parent12039c9f40a81605e59951f80007827bc0413573 (diff)
downloadgcc-1c4ca595d817ae1e1139145f86cfb58899d376bd.zip
gcc-1c4ca595d817ae1e1139145f86cfb58899d376bd.tar.gz
gcc-1c4ca595d817ae1e1139145f86cfb58899d376bd.tar.bz2
RISC-V: Support FP trunc auto-vectorization
This patch would like to support auto-vectorization for the trunc API in math.h. It depends on the -ffast-math option. When we would like to call trunc/truncf like v2 = trunc (v1), we will convert it into below insns (reference the implementation of llvm). * vfcvt.rtz.x.f v3, v1 * vfcvt.f.x v2, v3 However, the floating point value may not need the cvt as above if its mantissa is zero. Take single precision floating point as example: +------------+---------------+-----------------+ | raw float | binary layout | after trunc | +------------+---------------+-----------------+ | -8388607.5 | 0xcaffffff | -8388607.0 | | 8388607.5 | 0x4affffff | 8388607.0 | | 8388608.0 | 0x4b000000 | 8388608.0 | | 8388609.0 | 0x4b000001 | 8388609.0 | +------------+---------------+-----------------+ All single floating point >= 8388608.0 will have all zero mantisaa. We leverage vmflt and mask to filter them out in vector and only do the cvt on mask. Befor this patch: math-trunc-1.c:21:1: missed: couldn't vectorize loop ... .L3: flw fa0,0(s0) addi s0,s0,4 addi s1,s1,4 call trunc fsw fa0,-4(s1) bne s0,s2,.L3 After this patch: vfabs.v v2,v1 vmflt.vf v0,v2,fa5 vfcvt.rtz.x.f.v v4,v1,v0.t vfcvt.f.x.v v2,v4,v0.t vfsgnj.vv v2,v2,v1 bne .L4 Please note VLS mode is also involved in this patch and covered by the test cases. gcc/ChangeLog: * config/riscv/autovec.md (btrunc<mode>2): New pattern. * config/riscv/riscv-protos.h (expand_vec_trunc): New func decl. * config/riscv/riscv-v.cc (emit_vec_cvt_x_f_rtz): New func impl. (expand_vec_trunc): Ditto. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/unop/math-trunc-0.c: New test. * gcc.target/riscv/rvv/autovec/unop/math-trunc-1.c: New test. * gcc.target/riscv/rvv/autovec/unop/math-trunc-2.c: New test. * gcc.target/riscv/rvv/autovec/unop/math-trunc-3.c: New test. * gcc.target/riscv/rvv/autovec/unop/math-trunc-run-1.c: New test. * gcc.target/riscv/rvv/autovec/unop/math-trunc-run-2.c: New test. * gcc.target/riscv/rvv/autovec/vls/math-trunc-1.c: New test. Signed-off-by: Pan Li <pan2.li@intel.com>
Diffstat (limited to 'gcc/function.cc')
0 files changed, 0 insertions, 0 deletions