Patchwork PPC64: First in the series of patches implementing POWER8 vector math.

login
register
mail settings
Submitter GT
Date Feb. 18, 2019, 11:48 p.m.
Message ID <nN0kG0GXbx7wYro2oE34bwvcauTJw_WuDyP-obLhVMc-zwTK071-mQXBD8hiITyOHI6WoxiwvNezhvebbsjFnNlAk8mCi5yX6NYpge4SAas=@protonmail.com>
Download mbox | patch
Permalink /patch/31518/
State New
Headers show

Comments

GT - Feb. 18, 2019, 11:48 p.m.
Empty Message
Joseph Myers - Feb. 19, 2019, 1:42 a.m.
Please include the patch description in the body of your message, not just 
in an attachment - "Empty Message" isn't helpful.  When sending multiple 
patch versions, it's very helpful to describe what has changed since the 
previous version (after a "---" line or some other such indication, 
accepted by "git am", that the following text is not intended as part of 
the commit message).

I think you need to have explicit buy-in from powerpc toolchain 
maintainers that the ABI you have chosen is the desired one for this 
purpose, agreed for use by any toolchain that wishes to be able to use 
this functionality.  Please also confirm the GCC version that implements 
the ABI in question (when given the pragmas / attributes in the header you 
add).  To be clear, this information should be part of the commit message 
(in every version of the patch submission), not just in a one-off reply to 
this message.

Please also reference somewhere other than Google Groups for the ABI (both 
because Google Groups requires non-free JavaScript, contrary to GNU 
principles, and because Google Groups has a history of breaking URLs that 
used to work for linking to messages, so somewhere with a more reliably 
stable URL is important).  The glibc wiki has a copy of the x86_64 ABI at 
<https://sourceware.org/glibc/wiki/libmvec?action=AttachFile&do=view&target=VectorABI.txt>.

Please describe in patch submissions how the patch was tested.  In this 
case, running at least the libm tests for both powerpc64 big-endian and 
powerpc64 little-endian, and verifying there are no failures, would seem 
appropriate.  But more tests are needed that the installed header really 
does work as expected (see below).

You seem to build both VSX and AltiVec versions of the functions - is that 
correct?  But I don't see any Makefile code that actually causes the 
versions intended to be VSX versions to be built with -mvsx.

What do you intend to happen with the tests (test the VSX version, test 
the AltiVec version, return without running tests) in each of the 
following cases: running on VSX hardware, running on non-VSX hardware with 
AltiVec, running on hardware without either?  How do you ensure that?  
(x86_64 has math-tests-arch.h to define CHECK_ARCH_EXT to avoid running 
tests on unsupported hardware.)

What happens if you build for hardware without AltiVec?  It's of course 
fine for these functions to have an ABI that depends on AltiVec (so they 
never get called on such hardware) - do they need an explicit -maltivec 
option to ensure the vector types / ABI are available, or do they build OK 
for the correct ABI even without those options?

You're now testing a macro __POWERPC64__ in the header, but GCC doesn't 
predefine that macro, only __powerpc64__.  You need to test properly that 
the header you have really does work to cause appropriately built code, 
using the installed headers, to call these functions.  (glibc's own 
testsuite doesn't verify that, only that the internal functions work as 
expected by their mangled names.  So you need appropriate manual tests of 
using installed glibc with a suitable compiler to make sure calls get 
vectorized as expected and the vectorized calls work - and you should give 
details of that testing in the proposed commit message, to demonstrate 
that the patch has been sufficiently tested.)

A new feature like this needs a NEWS entry.

There are still coding style issues in the patch.  Comments inside a 
function are expected to be appropriately indented to match the code in 
the function, not have the "/*" at the left margin.  "if" blocks only 
containing a single statement should generally not use braces around it.  
C++-style "//" comments are not used.  Comments should end with ".  " 
(full stop, two spaces, end of comment), and start with a capital letter.
GT - Feb. 19, 2019, 5:43 p.m.
> Please include the patch description in the body of your message, not just
> in an attachment - "Empty Message" isn't helpful. When sending multiple
> patch versions, it's very helpful to describe what has changed since the
> previous version (after a "---" line or some other such indication,
> accepted by "git am", that the following text is not intended as part of
> the commit message).
>

The next patch sent will have a description of differences from the one we
are discussing.

> I think you need to have explicit buy-in from powerpc toolchain
> maintainers that the ABI you have chosen is the desired one for this
> purpose, agreed for use by any toolchain that wishes to be able to use
> this functionality.

Tulio and/or Bill:
Can you confirm that the POWER8 Vector Function ABI will match the
SSE ISA sections of x86_64 Vector Function ABI?

>Please also confirm the GCC version that implements
> the ABI in question (when given the pragmas / attributes in the header you
> add). To be clear, this information should be part of the commit message
> (in every version of the patch submission), not just in a one-off reply to
> this message.
>

Patches going foward will include information on the minimum GCC version
required for POWER8 libmvec.

However:

Tulio and/or Bill:
Please affirm my understanding that at present GCC does NOT
yet implement the Vector Function ABI for POWER8.


> Please also reference somewhere other than Google Groups for the ABI (both
> because Google Groups requires non-free JavaScript, contrary to GNU
> principles, and because Google Groups has a history of breaking URLs that
> used to work for linking to messages, so somewhere with a more reliably
> stable URL is important). The glibc wiki has a copy of the x86_64 ABI at
> https://sourceware.org/glibc/wiki/libmvec?action=AttachFile&do=view&target=VectorABI.txt.
>

Next patch will replace link to google groups with the glibc url you've
suggested.

> Please describe in patch submissions how the patch was tested. In this
> case, running at least the libm tests for both powerpc64 big-endian and
> powerpc64 little-endian, and verifying there are no failures, would seem
> appropriate.

Testing will be described all patches.

=========
Remaining issues you raised will be answered shortly.
Tulio Magno Quites Machado Filho - Feb. 19, 2019, 7:32 p.m.
GT <tnggil@protonmail.com> writes:

>> I think you need to have explicit buy-in from powerpc toolchain
>> maintainers that the ABI you have chosen is the desired one for this
>> purpose, agreed for use by any toolchain that wishes to be able to use
>> this functionality.
>
> Tulio and/or Bill:
> Can you confirm that the POWER8 Vector Function ABI will match the
> SSE ISA sections of x86_64 Vector Function ABI?

Not yet.
We need to clarify the concerns that have been raised in your previous thread:
https://www.sourceware.org/ml/libc-alpha/2019-02/msg00455.html

We can only confirm the ABI after having answers to all those questions.

>>Please also confirm the GCC version that implements
>> the ABI in question (when given the pragmas / attributes in the header you
>> add). To be clear, this information should be part of the commit message
>> (in every version of the patch submission), not just in a one-off reply to
>> this message.
>>
>
> Patches going foward will include information on the minimum GCC version
> required for POWER8 libmvec.
>
> However:
>
> Tulio and/or Bill:
> Please affirm my understanding that at present GCC does NOT
> yet implement the Vector Function ABI for POWER8.

That's correct.
GT - Feb. 24, 2019, 3:33 a.m.
> You're now testing a macro POWERPC64 in the header, but GCC doesn't
> predefine that macro, only powerpc64. You need to test properly that
> the header you have really does work to cause appropriately built code,
> using the installed headers, to call these functions. (glibc's own
> testsuite doesn't verify that, only that the internal functions work as
> expected by their mangled names. So you need appropriate manual tests of
> using installed glibc with a suitable compiler to make sure calls get
> vectorized as expected and the vectorized calls work - and you should give
> details of that testing in the proposed commit message, to demonstrate
> that the patch has been sufficiently tested.)
>

So, I'm trying to test the newly-built glibc to verify the installed
headers as asked for above. I am unable to compile against the new glibc.

The sequence of steps taken is this:

"Compile against glibc in an installed location", on this sourceware
URL: https://sourceware.org/glibc/wiki/Testing/Builds

The installation steps came from a section at the same URL with
title: "Building glibc with intent to install". Here I did everything
including the final step of obtaining gcc's helper library for
cancellation.

My intention is to compare outputs of the simple test programs given
here: https://sourceware.org/glibc/wiki/libmvec as Examples 1 and 2.
For each of them, I run them as given, using the normal non-vector
cosine. Then I replace the calls to cosine with calls to the new
vector cosine. With manual, direct calls to the vector cosine since
GCC does not yet perform vectorization for PPC64.

The error I get when I try to compile against the new glibc:

/usr/bin/ld:
cannot find /usr/lib64/libmvec_nonshared.a inside /home/fedora/my-install-glibc

collect2: error: ld returned 1 exit status

The compile command used:

gcc -L${SYSROOT}/usr/lib64/ -I${SYSROOT}/include/ --sysroot=${SYSROOT} \
-Wl,-rpath=${SYSROOT}/lib64 -Wl,--dynamic-linker=${SYSROOT}/lib64/ld-2.29.9000.so \
-O1 -fopenmp -ffast-math -lm -mvsx -o testcos testcos.c

SYSROOT is set to the same directory I used for DESTDIR in the make install step.

I'm uncertain on how to proceed. I appreciate any and all assistance in solving this.

Thanks.
Bert.
GT - Feb. 24, 2019, 3:51 p.m.
>
> The error I get when I try to compile against the new glibc:
>
> /usr/bin/ld:
> cannot find /usr/lib64/libmvec_nonshared.a inside /home/fedora/my-install-glibc
>
> collect2: error: ld returned 1 exit status
>
> The compile command used:
>
> gcc -L${SYSROOT}/usr/lib64/ -I${SYSROOT}/include/ --sysroot=${SYSROOT} \
> -Wl,-rpath=${SYSROOT}/lib64 -Wl,--dynamic-linker=${SYSROOT}/lib64/ld-2.29.9000.so \
> -O1 -fopenmp -ffast-math -lm -mvsx -o testcos testcos.c
>
> SYSROOT is set to the same directory I used for DESTDIR in the make install step.
>
> I'm uncertain on how to proceed. I appreciate any and all assistance in solving this.
>

Creating a link libmvec_nonshared.a to libmvec.a which is installed by 'make install'
allows compilation of the executable. So, I'm able to continue on with the other
tasks.

If creating that link is required on every installation of libmvec, this should be
specified prominently in the documentation for libmvec.
Joseph Myers - Feb. 25, 2019, 5:21 p.m.
On Sun, 24 Feb 2019, GT wrote:

> gcc -L${SYSROOT}/usr/lib64/ -I${SYSROOT}/include/ --sysroot=${SYSROOT} \
> -Wl,-rpath=${SYSROOT}/lib64 -Wl,--dynamic-linker=${SYSROOT}/lib64/ld-2.29.9000.so \
> -O1 -fopenmp -ffast-math -lm -mvsx -o testcos testcos.c

Don't use -L (or -I) options pointing into a sysroot; ld cares about 
whether it found a given library via a sysrooted or nonsysrooted path, so 
using such a -L option can result in a linker script in the sysroot being 
misinterpreted (absolute paths therein not being interpreted as relative 
to the sysroot).

However, I don't think that's your issue.  You should have 
libmvec_nonshared.a; it's needed to deal with cases when the compiler 
generates calls to _Z*___*_finite because of bits/math-finite.h being in 
effect together with bits/math-vector.h (see 
sysdeps/x86_64/fpu/svml_finite_alias.S and 
<https://gcc.gnu.org/ml/gcc/2015-06/msg00173.html>).
GT - Feb. 25, 2019, 10:03 p.m.
> However, I don't think that's your issue. You should have
> libmvec_nonshared.a; it's needed to deal with cases when the compiler
> generates calls to Z*__*_finite because of bits/math-finite.h being in
> effect together with bits/math-vector.h (see
> sysdeps/x86_64/fpu/svml_finite_alias.S and
> https://gcc.gnu.org/ml/gcc/2015-06/msg00173.html).
>

1. svml_finite_alias.S deals only with log/logf, exp/expf and pow/powf.
So does the discussion linked at the given url. At this time only the
cos function has been implemented. Do we then still require
libmvec_nonshared.a to be created?

2. I find a single reference in the entire source tree where
libmvec_nonshared.a doesn't appear in the dependency section of
a rule. That's in math/Makefile. Does this mean libmvec_nonshared.a
is created with 'make install'? I rather expected it would be built
by the initial 'make' which generates most other objects.
Joseph Myers - Feb. 25, 2019, 11:46 p.m.
On Mon, 25 Feb 2019, GT wrote:

> 1. svml_finite_alias.S deals only with log/logf, exp/expf and pow/powf.
> So does the discussion linked at the given url. At this time only the
> cos function has been implemented. Do we then still require
> libmvec_nonshared.a to be created?

The alternative would be to have some kind of conditional in 
math/Makefile, where it creates the linker script for libm.so, based on 
whatever logic determines whether there is libmvec_nonshared.a (i.e. 
whether there are any objects that go in it).  If you're adding new 
architecture support for libmvec that doesn't start off with any functions 
that bits/math-finite.h does anything with, you get to deal with adapting 
the generic code to handle that previously unsupported case.

> 2. I find a single reference in the entire source tree where
> libmvec_nonshared.a doesn't appear in the dependency section of
> a rule. That's in math/Makefile. Does this mean libmvec_nonshared.a
> is created with 'make install'? I rather expected it would be built

The linker scripts that are only usable in a glibc installation, not in a 
build context, are created at install time, yes.  (So is the manual, hence 
the build of the manual breaking from time to time when someone had a 
broken change to the manual and didn't run "make install" in testing.)

Patch

From 65fda4d67a61d7ae19e53001855cd4482e2bf59e Mon Sep 17 00:00:00 2001
From: Bert Tenjy <bert.tenjy@gmail.com>
Date: Mon, 18 Feb 2019 23:24:46 +0000
Subject: [PATCH] PPC64: First in the series of patches implementing POWER8
 vector math.

Implements double-precision cosine using VSX vector capability. Algorithm for
cosine is from x86_64 [commit #2193311288] adapted to PPC64.

Name-mangling exactly duplicates SSE ISA of the x86_64 ABI. The details are
at <https://groups.google.com/forum/#!topic/x86-64-abi/LmppCfN1rZ4>.

Adds tests of the new double-precision vector cosine.

[BZ #24205]
---
 ChangeLog                                     | 16 ++++
 sysdeps/powerpc/bits/math-vector.h            | 41 ++++++++
 sysdeps/powerpc/fpu/libm-test-ulps            |  3 +
 sysdeps/powerpc/powerpc64/fpu/Versions        |  5 +
 .../powerpc/powerpc64/fpu/multiarch/Makefile  | 17 ++++
 .../multiarch/test-double-vlen2-wrappers.c    | 24 +++++
 .../powerpc64/fpu/multiarch/vec_d_cos2_core.c | 30 ++++++
 .../fpu/multiarch/vec_d_cos2_power8.c         | 93 +++++++++++++++++++
 .../powerpc64/fpu/multiarch/vec_d_cos2_vmx.c  | 35 +++++++
 .../powerpc64/fpu/multiarch/vec_d_trig_data.h | 61 ++++++++++++
 .../linux/powerpc/powerpc64/libmvec.abilist   |  1 +
 11 files changed, 326 insertions(+)
 create mode 100644 sysdeps/powerpc/bits/math-vector.h
 create mode 100644 sysdeps/powerpc/powerpc64/fpu/Versions
 create mode 100644 sysdeps/powerpc/powerpc64/fpu/multiarch/test-double-vlen2-wrappers.c
 create mode 100644 sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_core.c
 create mode 100644 sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_power8.c
 create mode 100644 sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_vmx.c
 create mode 100644 sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_trig_data.h
 create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc64/libmvec.abilist

diff --git a/ChangeLog b/ChangeLog
index 312ef3bd8f..ccdd855136 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@ 
+2019-02-18    <bert.tenjy@gmail.com>
+
+	* sysdeps/powerpc/bits/math-vector.h: New file.
+	* sysdeps/powerpc/fpu/libm-test-ulps (cos_vlen2): Regenerated.
+	* sysdeps/powerpc/powerpc64/fpu/Versions: New file.
+	* sysdeps/powerpc/powerpc64/multiarch/Makefile (libmvec-sysdep_routines)
+            (double-vlen-funcs,double-vlen-arch-ext-flags): Added build of VSX
+            vector cos function and its tests.
+	* sysdeps/powerpc/powerpc64/multiarch/test-double-vlen2-wrappers.c: New file.
+	* sysdeps/powerpc/powerpc64/multiarch/vec_d_cos2_core.c: New file.
+	* sysdeps/powerpc/powerpc64/multiarch/vec_d_cos2_power8.c: New file.
+	* sysdeps/powerpc/powerpc64/multiarch/vec_d_cos2_vmx.c: New file.
+	* sysdeps/powerpc/powerpc64/multiarch/vec_d_trig_data.h: New file.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/libmvec.abilist: New file.
+
+
 2019-02-18  Florian Weimer  <fweimer@redhat.com>
 
 	* resolv/compat-gethnamaddr.c (Dprintf): Remove definition.
diff --git a/sysdeps/powerpc/bits/math-vector.h b/sysdeps/powerpc/bits/math-vector.h
new file mode 100644
index 0000000000..a569b19e7a
--- /dev/null
+++ b/sysdeps/powerpc/bits/math-vector.h
@@ -0,0 +1,41 @@ 
+/* Platform-specific SIMD declarations of math functions.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _MATH_H
+# error "Never include <bits/math-vector.h> directly;\
+ include <math.h> instead."
+#endif
+
+/* Get default empty definitions for simd declarations.  */
+#include <bits/libm-simd-decl-stubs.h>
+
+#if defined __POWERPC64__ && defined __FAST_MATH__
+# if defined _OPENMP && _OPENMP >= 201307
+/* OpenMP case.  */
+#  define __DECL_SIMD_ARCH_PPC64 _Pragma ("omp declare simd notinbranch")
+# elif __GNUC_PREREQ (6,0)
+/* W/o OpenMP use GCC 6.* __attribute__ ((__simd__)).  */
+#  define __DECL_SIMD_ARCH_PPC64 __attribute__ ((__simd__ ("notinbranch")))
+# endif
+
+# ifdef __DECL_SIMD_ARCH_PPC64
+#  undef __DECL_SIMD_cos
+#  define __DECL_SIMD_cos __DECL_SIMD_ARCH_PPC64
+
+# endif
+#endif
diff --git a/sysdeps/powerpc/fpu/libm-test-ulps b/sysdeps/powerpc/fpu/libm-test-ulps
index 1eec27c1dc..d392b135a7 100644
--- a/sysdeps/powerpc/fpu/libm-test-ulps
+++ b/sysdeps/powerpc/fpu/libm-test-ulps
@@ -1311,6 +1311,9 @@  ifloat128: 2
 ildouble: 5
 ldouble: 5
 
+Function: "cos_vlen2":
+double: 2
+
 Function: "cosh":
 double: 1
 float: 1
diff --git a/sysdeps/powerpc/powerpc64/fpu/Versions b/sysdeps/powerpc/powerpc64/fpu/Versions
new file mode 100644
index 0000000000..9a3e1211cc
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/fpu/Versions
@@ -0,0 +1,5 @@ 
+libmvec {
+  GLIBC_2.30 {
+    _ZGVbN2v_cos;
+  }
+}
diff --git a/sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile b/sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile
index 39b557604c..51e89a2532 100644
--- a/sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile
+++ b/sysdeps/powerpc/powerpc64/fpu/multiarch/Makefile
@@ -42,3 +42,20 @@  CFLAGS-e_hypotf-power7.c = -mcpu=power7
 CFLAGS-s_modf-ppc64.c += -fsignaling-nans
 CFLAGS-s_modff-ppc64.c += -fsignaling-nans
 endif
+
+ifeq ($(subdir),mathvec)
+libmvec-sysdep_routines += vec_d_cos2_core vec_d_cos2_power8 \
+                          vec_d_cos2_vmx
+endif
+
+# Variables for libmvec tests.
+ifeq ($(subdir),math)
+ifeq ($(build-mathvec),yes)
+libmvec-tests += double-vlen2
+
+double-vlen2-funcs = cos
+
+double-vlen2-arch-ext-cflags = -mvsx
+
+endif
+endif
diff --git a/sysdeps/powerpc/powerpc64/fpu/multiarch/test-double-vlen2-wrappers.c b/sysdeps/powerpc/powerpc64/fpu/multiarch/test-double-vlen2-wrappers.c
new file mode 100644
index 0000000000..17e2cc0724
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/fpu/multiarch/test-double-vlen2-wrappers.c
@@ -0,0 +1,24 @@ 
+/* Wrapper part of tests for VSX ISA versions of vector math functions.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include "test-double-vlen2.h"
+#include <altivec.h>
+
+#define VEC_TYPE vector double
+
+VECTOR_WRAPPER (WRAPPER_NAME (cos), _ZGVbN2v_cos)
diff --git a/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_core.c b/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_core.c
new file mode 100644
index 0000000000..e089a8d844
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_core.c
@@ -0,0 +1,30 @@ 
+/* Multiple versions of vectorized cos function.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <shlib-compat.h>
+#include "init-arch.h"
+
+vector double _ZGVbN2v_cos (vector double x);
+
+extern __typeof (_ZGVbN2v_cos) _ZGVbN2v_cos_vmx attribute_hidden;
+extern __typeof (_ZGVbN2v_cos) _ZGVbN2v_cos_vsx attribute_hidden;
+
+libc_ifunc (_ZGVbN2v_cos,
+	    (hwcap2 & PPC_FEATURE2_ARCH_2_07)
+	    ? _ZGVbN2v_cos_vsx : _ZGVbN2v_cos_vmx);
diff --git a/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_power8.c b/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_power8.c
new file mode 100644
index 0000000000..4f6c9cce6b
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_power8.c
@@ -0,0 +1,93 @@ 
+/* Function cos vectorized with VSX.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include "vec_d_trig_data.h"
+
+vector double
+_ZGVbN2v_cos_vsx (vector double x)
+{
+
+/*
+   ARGUMENT RANGE REDUCTION:
+   Add Pi/2 to argument: X' = X+Pi/2
+ */
+  vector double x_prime = (vector double) d_half_pi + x;
+
+/* Get absolute argument value: X' = |X'| */
+  vector double abs_x_prime = vec_abs (x_prime);
+
+/* Y = X'*InvPi + RS : right shifter add */
+  vector double y = (x_prime * d_inv_pi) + d_rshifter;
+
+/* Check for large arguments path */
+  vector bool long long large_in = vec_cmpgt (abs_x_prime, d_rangeval);
+
+/* N = Y - RS : right shifter sub */
+  vector double n = y - d_rshifter;
+
+/* SignRes = Y<<63 : shift LSB to MSB place for result sign */
+  vector double sign_res = (vector double) vec_sl ((vector long long) y,
+						   (vector unsigned long long)
+						   vec_splats (63));
+
+/* N = N - 0.5 */
+  n = n - d_one_half;
+
+/* R = X - N*Pi1 */
+  vector double r = x - (n * d_pi1_fma);
+
+/* R = R - N*Pi2 */
+  r = r - (n * d_pi2_fma);
+
+/* R = R - N*Pi3 */
+  r = r - (n * d_pi3_fma);
+
+/* R2 = R*R */
+  vector double r2 = r * r;
+
+/* Poly = C3+R2*(C4+R2*(C5+R2*(C6+R2*C7))) */
+  vector double poly = r2 * d_coeff7 + d_coeff6;
+  poly = poly * r2 + d_coeff5;
+  poly = poly * r2 + d_coeff4;
+  poly = poly * r2 + d_coeff3;
+
+/* Poly = R+R*(R2*(C1+R2*(C2+R2*Poly))) */
+  poly = poly * r2 + d_coeff2;
+  poly = poly * r2 + d_coeff1;
+  poly = poly * r2 * r + r;
+
+/*
+   RECONSTRUCTION:
+   Final sign setting: Res = Poly^SignRes */
+  vector double out
+    = (vector double) ((vector long long) poly ^ (vector long long) sign_res);
+
+  if (large_in[0] != 0)
+    {
+      out[0] = cos (x[0]);
+    }
+
+  if (large_in[1] != 0)
+    {
+      out[1] = cos (x[1]);
+    }
+
+  return out;
+
+}				/* _ZGVbN2v_cos_vsx */
diff --git a/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_vmx.c b/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_vmx.c
new file mode 100644
index 0000000000..e32fd77b6c
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_cos2_vmx.c
@@ -0,0 +1,35 @@ 
+/* PowerPC64 default version of vectorized cos function.
+   Calls scalar cos version twice.
+
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <math.h>
+#include <altivec.h>
+
+vector double
+_ZGVbN2v_cos_vmx (vector double x)
+{
+
+  vector double out;
+
+  out[0] = cos (x[0]);
+  out[1] = cos (x[1]);
+
+  return out;
+
+}				// _ZGVbN2v_cos_vmx
diff --git a/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_trig_data.h b/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_trig_data.h
new file mode 100644
index 0000000000..ae33017324
--- /dev/null
+++ b/sysdeps/powerpc/powerpc64/fpu/multiarch/vec_d_trig_data.h
@@ -0,0 +1,61 @@ 
+/* Constants used in polynomail approximations for vectorized sin, cos,
+   and sincos functions.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef D_TRIG_DATA_H
+#define D_TRIG_DATA_H
+
+#include <altivec.h>
+
+/* PI/2 */
+const vector double d_half_pi  = {0x1.921fb54442d18p+0, 0x1.921fb54442d18p+0};
+
+/* 1/PI */
+const vector double d_inv_pi   = {0x1.45f306dc9c883p-2, 0x1.45f306dc9c883p-2};
+
+/* right-shifter constant */
+const vector double d_rshifter = {0x1.8p+52, 0x1.8p+52};
+
+/* working range threshold */
+const vector double d_rangeval = {0x1p+23, 0x1p+23};
+
+/* 0.5 */
+const vector double d_one_half = {0x1p-1, 0x1p-1};
+
+/* Range reduction PI-based constants if FMA available:
+   PI high part (FMA available)
+ */
+const vector double d_pi1_fma = {0x1.921fb54442d18p+1, 0x1.921fb54442d18p+1};
+
+/* PI mid part  (FMA available) */
+const vector double d_pi2_fma = {0x1.1a62633145c06p-53, 0x1.1a62633145c06p-53};
+
+/* PI low part  (FMA available) */
+const vector double d_pi3_fma
+= {0x1.c1cd129024e09p-106,0x1.c1cd129024e09p-106};
+
+/* Polynomial coefficients (relative error 2^(-52.115)): */
+const vector double d_coeff7 = {-0x1.9f0d60811aac8p-41,-0x1.9f0d60811aac8p-41};
+const vector double d_coeff6 = {0x1.60e6857a2f22p-33,0x1.60e6857a2f22p-33};
+const vector double d_coeff5 = {-0x1.ae63546002231p-26,-0x1.ae63546002231p-26};
+const vector double d_coeff4 = {0x1.71de38030feap-19,0x1.71de38030feap-19};
+const vector double d_coeff3 = {-0x1.a01a019a5b86dp-13,-0x1.a01a019a5b86dp-13};
+const vector double d_coeff2 = {0x1.111111110a4a8p-7,0x1.111111110a4a8p-7};
+const vector double d_coeff1 = {-0x1.55555555554a7p-3,-0x1.55555555554a7p-3};
+
+#endif // D_TRIG_DATA_H
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/libmvec.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libmvec.abilist
new file mode 100644
index 0000000000..656ce0541f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/libmvec.abilist
@@ -0,0 +1 @@ 
+GLIBC_2.30 _ZGVbN2v_cos F
-- 
2.20.1