This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 7/N v2] [x86_64] Vectorized math functions
- From: Andrew Senkevich <andrew dot n dot senkevich at gmail dot com>
- To: Joseph Myers <joseph at codesourcery dot com>
- Cc: libc-alpha <libc-alpha at sourceware dot org>
- Date: Fri, 17 Apr 2015 18:02:11 +0300
- Subject: Re: [PATCH 7/N v2] [x86_64] Vectorized math functions
- Authentication-results: sourceware.org; auth=none
- References: <CAMXFM3sG=Uo6pJsNn34VtU+VDd4+VO+YyoUw3hCYpFi_K1cLsg at mail dot gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1412031814130 dot 20515 at digraph dot polyomino dot org dot uk> <CAMXFM3sTwm+pFdALMg4aaBroFbDds=LK1rTH4ksouR=MK-75Wg at mail dot gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1412111756090 dot 21111 at digraph dot polyomino dot org dot uk>
> 2014-12-11 20:57 GMT+03:00 Joseph Myers <joseph@codesourcery.com>:
> On Tue, 9 Dec 2014, Andrew Senkevich wrote:
>
>> Combined and attached, it seems not passed being sent in plain text.
>>
>> ChangeLog
>>
>> * sysdeps/x86_64/fpu/svml_d_cos2_core.S: New file.
>> * sysdeps/x86_64/fpu/svml_d_cos4_core_avx.S: New file.
>> * sysdeps/x86_64/fpu/svml_d_cos4_core_avx2.S: New file.
>> * sysdeps/x86_64/fpu/svml_d_cos_data.S: New file.
>> * sysdeps/x86_64/fpu/svml_d_cos_data.h: New file.
>> * sysdeps/x86_64/fpu/Versions: New file.
>> * math/bits/mathcalls.h: Added cos declaration with __MATHCALL_VEC.
>> * sysdeps/x86/fpu/bits/math-vector.h: Added SIMD declaration for cos.
>> * sysdeps/x86_64/configure: Regenerated.
>> * sysdeps/x86_64/configure.ac: Options for libmvec build.
>> * sysdeps/unix/sysv/linux/x86_64/libmvec.abilist: New file.
>> * sysdeps/x86_64/fpu/Makefile: New file.
>
> I'll leave final review for when the ABI document explaining what the
> pragma means for function version availability on x86_64 is ready and
> agreed by compiler implementations, but apart from that this patch may be
> ready.
>
> --
> Joseph S. Myers
> joseph@codesourcery.com
Hi, Joseph,
to support ISAs older than SSE4 we need runtime ISA check and switch
to SSE2 version.
It is because mangled name of vector function is the same for all SSE* ISAs.
I mean implementation is changed like so:
diff --git a/sysdeps/x86_64/fpu/svml_d_cos2_core.S
b/sysdeps/x86_64/fpu/svml_d_cos2_core.S
index 11d9c94..ccd0969 100644
--- a/sysdeps/x86_64/fpu/svml_d_cos2_core.S
+++ b/sysdeps/x86_64/fpu/svml_d_cos2_core.S
@@ -1,4 +1,4 @@
-/* Function cos vectorized with SSE4.
+/* Function cos vectorized with SSE2 and SSE4.
Copyright (C) 2014 Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -17,22 +17,51 @@
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
+#include <init-arch.h>
#include "svml_d_cos_data.h"
.text
ENTRY(_ZGVbN2v_cos)
+ .type _ZGVbN2v_cos, @gnu_indirect_function
+ cmpl $0, KIND_OFFSET+__cpu_features(%rip)
+ jne 1f
+ call __init_cpu_features
+1: leaq _ZGVbN2v_cos_sse4(%rip), %rax
+ testl $bit_SSE4_1, __cpu_features+CPUID_OFFSET+index_SSE4_1(%rip)
+ jz 2f
+ ret
+2: leaq _ZGVbN2v_cos_sse2(%rip), %rax
+ ret
+END(_ZGVbN2v_cos)
+
+ENTRY(_ZGVbN2v_cos_sse2)
+/* SSE2 version as wrapper to scalar. */
+ subq $40, %rsp
+ movaps %xmm0, (%rsp)
+ call cos@PLT
+ movsd %xmm0, 16(%rsp)
+ movsd 8(%rsp), %xmm0
+ call cos@PLT
+ movsd 16(%rsp), %xmm1
+ movsd %xmm0, 24(%rsp)
+ unpcklpd %xmm0, %xmm1
+ movaps %xmm1, %xmm0
+ addq $40, %rsp
+ ret
+END(_ZGVbN2v_cos_sse2)
+ENTRY(_ZGVbN2v_cos_sse4)
/* ALGORITHM DESCRIPTION:
*
* ( low accuracy ( < 4ulp ) or enhanced performance ( half of correct
@@ -206,4 +235,4 @@ ENTRY(_ZGVbN2v_cos)
movsd %xmm0, 256(%rsp,%r15)
jmp .LBL_1_7
-END(_ZGVbN2v_cos)
+END(_ZGVbN2v_cos_sse4)
My question is do we need to test this new SSE2 version (which is just
simple wrapper to scalar one)?
If yes, is it ok to have according test linked against libmvec.a (in
libmvec.so this SSE2 implementation is hidden and no need to make it
visible)?
--
WBR,
Andrew