https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122382
Uroš Bizjak <ubizjak at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #9 from Uroš Bizjak <ubizjak at gmail dot com> ---
The compiler now vectorizes conversions to and from _Float16 with -mf16c (part
of -march=x86-64-v3). This enables vectorization of e.g.:
void
foo (_Float16 *__restrict r, const _Float16 *__restrict x,
const _Float16 *__restrict y, const _Float16 *__restrict z)
{
for (int n = 0; n < 128; ++n)
r[n] = (x[n] + y[n]) / z[n];
}
gcc -O2 -mf16c:
foo:
xorl %eax, %eax
.p2align 4
.p2align 3
.L2:
vmovdqu (%rsi,%rax), %ymm3
vmovdqu (%rdx,%rax), %ymm0
vmovdqu (%rcx,%rax), %ymm2
vcvtph2ps %xmm3, %ymm4
vcvtph2ps %xmm0, %ymm1
vextractf128 $0x1, %ymm3, %xmm3
vaddps %ymm4, %ymm1, %ymm1
vextractf128 $0x1, %ymm0, %xmm0
vcvtph2ps %xmm3, %ymm3
vcvtph2ps %xmm2, %ymm4
vextractf128 $0x1, %ymm2, %xmm2
vcvtph2ps %xmm0, %ymm0
vaddps %ymm3, %ymm0, %ymm0
vcvtph2ps %xmm2, %ymm2
vdivps %ymm4, %ymm1, %ymm1
vdivps %ymm2, %ymm0, %ymm0
vcvtps2ph $4, %ymm1, %xmm1
vcvtps2ph $4, %ymm0, %xmm0
vinsertf128 $0x1, %xmm0, %ymm1, %ymm0
vmovdqu %ymm0, (%rdi,%rax)
addq $32, %rax
cmpq $256, %rax
jne .L2
vzeroupper
ret
However, it still doesn't vectorize __builtin_sqrtf16, not even with
-ffast-math:
void
bar (_Float16 *__restrict r, const _Float16 *__restrict x,
const _Float16 *__restrict y)
{
for (int n = 0; n < 128; ++n)
r[n] = __builtin_sqrtf16 (x[n] + y[n]);
}
I'll open another PR for that.
So, implemented for gcc-17.