Patchwork x86_64: memcpy/memmove family optimized with AVX512

login
register
mail settings
Submitter Andrew Senkevich
Date Jan. 16, 2016, 11:48 a.m.
Message ID <CAMXFM3u969ef7GtbFGaozg+mGTLCiYLo2WYUEFRq4jmBWVPw3w@mail.gmail.com>
Download mbox | patch
Permalink /patch/10403/
State New
Headers show

Comments

Andrew Senkevich - Jan. 16, 2016, 11:48 a.m.
2016-01-16 1:24 GMT+03:00 Florian Weimer <fweimer@redhat.com>:
> On 01/15/2016 10:47 PM, Andrew Senkevich wrote:
>> diff --git a/sysdeps/x86_64/multiarch/memcpy_chk.S b/sysdeps/x86_64/multiarch/memcpy_chk.S
>> index 6476c62..a0d56d4 100644
>> --- a/sysdeps/x86_64/multiarch/memcpy_chk.S
>> +++ b/sysdeps/x86_64/multiarch/memcpy_chk.S
>> @@ -30,7 +30,15 @@
>>  ENTRY(__memcpy_chk)
>>       .type   __memcpy_chk, @gnu_indirect_function
>>       LOAD_RTLD_GLOBAL_RO_RDX
>> -     leaq    __memcpy_chk_sse2(%rip), %rax
>> +#ifdef HAVE_AVX512_ASM_SUPPORT
>> +     HAS_ARCH_FEATURE (AVX512F_Usable)
>> +     jz      1f
>> +#    HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
>> +#    jz      1f
>
> The two lines starting with “#” look somewhat out of place.  Is this
> really intended?

Florian, thank you, I have fixed it:



--
WBR,
Andrew
Paul Pluzhnikov - Jan. 18, 2016, 6:50 p.m.
This patch appears to break my build:

On Ubuntu 14.04 LTS, using system gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4:


make[3]: Leaving directory '/Archive/glibc-git/elf'
gcc   -shared -static-libgcc -Wl,-O1  -Wl,-z,defs
-Wl,-dynamic-linker=/lib64/ld-linux-x86-64.so.2
-B/Archive/glibc-git/build-system-gcc/csu/
-Wl,--version-script=/Archive/glibc-git/build-system-gcc/libc.map
-Wl,-soname=libc.so.6 -Wl,-z,combreloc -Wl,-z,relro
-Wl,--hash-style=both -nostdlib -nostartfiles -e __libc_main
-L/Archive/glibc-git/build-system-gcc
-L/Archive/glibc-git/build-system-gcc/math
-L/Archive/glibc-git/build-system-gcc/elf
-L/Archive/glibc-git/build-system-gcc/dlfcn
-L/Archive/glibc-git/build-system-gcc/nss
-L/Archive/glibc-git/build-system-gcc/nis
-L/Archive/glibc-git/build-system-gcc/rt
-L/Archive/glibc-git/build-system-gcc/resolv
-L/Archive/glibc-git/build-system-gcc/crypt
-L/Archive/glibc-git/build-system-gcc/mathvec
-L/Archive/glibc-git/build-system-gcc/nptl
-Wl,-rpath-link=/Archive/glibc-git/build-system-gcc:/Archive/glibc-git/build-system-gcc/math:/Archive/glibc-git/build-system-gcc/elf:/Archive/glibc-git/build-system-gcc/dlfcn:/Archive/glibc-git/build-system-gcc/nss:/Archive/glibc-git/build-system-gcc/nis:/Archive/glibc-git/build-system-gcc/rt:/Archive/glibc-git/build-system-gcc/resolv:/Archive/glibc-git/build-system-gcc/crypt:/Archive/glibc-git/build-system-gcc/mathvec:/Archive/glibc-git/build-system-gcc/nptl
-o /Archive/glibc-git/build-system-gcc/libc.so -T
/Archive/glibc-git/build-system-gcc/shlib.lds
/Archive/glibc-git/build-system-gcc/csu/abi-note.o
/Archive/glibc-git/build-system-gcc/elf/soinit.os
/Archive/glibc-git/build-system-gcc/libc_pic.os
/Archive/glibc-git/build-system-gcc/elf/sofini.os
/Archive/glibc-git/build-system-gcc/elf/interp.os
/Archive/glibc-git/build-system-gcc/elf/ld.so -lgcc
/Archive/glibc-git/build-system-gcc/libc_pic.os: In function
`__libc_ifunc_impl_list':
/Archive/glibc-git/misc/../sysdeps/x86_64/multiarch/ifunc-impl-list.c:50:
undefined reference to `__memmove_chk_avx512_no_vzeroupper'
/usr/bin/ld: /Archive/glibc-git/build-system-gcc/libc_pic.os:
relocation R_X86_64_PC32 against undefined hidden symbol
`__memmove_chk_avx512_no_vzeroupper' can not be used when making a
shared object
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
../Makerules:681: recipe for target
'/Archive/glibc-git/build-system-gcc/libc.so' failed
make[2]: *** [/Archive/glibc-git/build-system-gcc/libc.so] Error 1
make[2]: Leaving directory '/Archive/glibc-git/elf'
Makefile:214: recipe for target 'elf/subdir_lib' failed
make[1]: *** [elf/subdir_lib] Error 2
make[1]: Leaving directory '/Archive/glibc-git'
Makefile:9: recipe for target 'all' failed
make: *** [all] Error 2


On Sat, Jan 16, 2016 at 3:48 AM, Andrew Senkevich
<andrew.n.senkevich@gmail.com> wrote:
> 2016-01-16 1:24 GMT+03:00 Florian Weimer <fweimer@redhat.com>:
>> On 01/15/2016 10:47 PM, Andrew Senkevich wrote:
>>> diff --git a/sysdeps/x86_64/multiarch/memcpy_chk.S b/sysdeps/x86_64/multiarch/memcpy_chk.S
>>> index 6476c62..a0d56d4 100644
>>> --- a/sysdeps/x86_64/multiarch/memcpy_chk.S
>>> +++ b/sysdeps/x86_64/multiarch/memcpy_chk.S
>>> @@ -30,7 +30,15 @@
>>>  ENTRY(__memcpy_chk)
>>>       .type   __memcpy_chk, @gnu_indirect_function
>>>       LOAD_RTLD_GLOBAL_RO_RDX
>>> -     leaq    __memcpy_chk_sse2(%rip), %rax
>>> +#ifdef HAVE_AVX512_ASM_SUPPORT
>>> +     HAS_ARCH_FEATURE (AVX512F_Usable)
>>> +     jz      1f
>>> +#    HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
>>> +#    jz      1f
>>
>> The two lines starting with “#” look somewhat out of place.  Is this
>> really intended?
>
> Florian, thank you, I have fixed it:
>
> diff --git a/sysdeps/x86_64/multiarch/memcpy_chk.S
> b/sysdeps/x86_64/multiarch/memcpy_chk.S
> index a0d56d4..648217e 100644
> --- a/sysdeps/x86_64/multiarch/memcpy_chk.S
> +++ b/sysdeps/x86_64/multiarch/memcpy_chk.S
> @@ -33,9 +33,9 @@ ENTRY(__memcpy_chk)
>  #ifdef HAVE_AVX512_ASM_SUPPORT
>         HAS_ARCH_FEATURE (AVX512F_Usable)
>         jz      1f
> -#      HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
> -#      jz      1f
> -       leaq    __memcpy_avx512_no_vzeroupper(%rip), %rax
> +       HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
> +       jz      1f
> +       leaq    __memcpy_chk_avx512_no_vzeroupper(%rip), %rax
>         ret
>  #endif
>  1:     leaq    __memcpy_chk_sse2(%rip), %rax
>
>
> --
> WBR,
> Andrew
H.J. Lu - Jan. 18, 2016, 10:29 p.m.
On Mon, Jan 18, 2016 at 10:50 AM, Paul Pluzhnikov
<ppluzhnikov@google.com> wrote:
> This patch appears to break my build:
>
> On Ubuntu 14.04 LTS, using system gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4:
>
>
> make[3]: Leaving directory '/Archive/glibc-git/elf'
> gcc   -shared -static-libgcc -Wl,-O1  -Wl,-z,defs
> -Wl,-dynamic-linker=/lib64/ld-linux-x86-64.so.2
> -B/Archive/glibc-git/build-system-gcc/csu/
> -Wl,--version-script=/Archive/glibc-git/build-system-gcc/libc.map
> -Wl,-soname=libc.so.6 -Wl,-z,combreloc -Wl,-z,relro
> -Wl,--hash-style=both -nostdlib -nostartfiles -e __libc_main
> -L/Archive/glibc-git/build-system-gcc
> -L/Archive/glibc-git/build-system-gcc/math
> -L/Archive/glibc-git/build-system-gcc/elf
> -L/Archive/glibc-git/build-system-gcc/dlfcn
> -L/Archive/glibc-git/build-system-gcc/nss
> -L/Archive/glibc-git/build-system-gcc/nis
> -L/Archive/glibc-git/build-system-gcc/rt
> -L/Archive/glibc-git/build-system-gcc/resolv
> -L/Archive/glibc-git/build-system-gcc/crypt
> -L/Archive/glibc-git/build-system-gcc/mathvec
> -L/Archive/glibc-git/build-system-gcc/nptl
> -Wl,-rpath-link=/Archive/glibc-git/build-system-gcc:/Archive/glibc-git/build-system-gcc/math:/Archive/glibc-git/build-system-gcc/elf:/Archive/glibc-git/build-system-gcc/dlfcn:/Archive/glibc-git/build-system-gcc/nss:/Archive/glibc-git/build-system-gcc/nis:/Archive/glibc-git/build-system-gcc/rt:/Archive/glibc-git/build-system-gcc/resolv:/Archive/glibc-git/build-system-gcc/crypt:/Archive/glibc-git/build-system-gcc/mathvec:/Archive/glibc-git/build-system-gcc/nptl
> -o /Archive/glibc-git/build-system-gcc/libc.so -T
> /Archive/glibc-git/build-system-gcc/shlib.lds
> /Archive/glibc-git/build-system-gcc/csu/abi-note.o
> /Archive/glibc-git/build-system-gcc/elf/soinit.os
> /Archive/glibc-git/build-system-gcc/libc_pic.os
> /Archive/glibc-git/build-system-gcc/elf/sofini.os
> /Archive/glibc-git/build-system-gcc/elf/interp.os
> /Archive/glibc-git/build-system-gcc/elf/ld.so -lgcc
> /Archive/glibc-git/build-system-gcc/libc_pic.os: In function
> `__libc_ifunc_impl_list':
> /Archive/glibc-git/misc/../sysdeps/x86_64/multiarch/ifunc-impl-list.c:50:
> undefined reference to `__memmove_chk_avx512_no_vzeroupper'
> /usr/bin/ld: /Archive/glibc-git/build-system-gcc/libc_pic.os:
> relocation R_X86_64_PC32 against undefined hidden symbol
> `__memmove_chk_avx512_no_vzeroupper' can not be used when making a
> shared object
> /usr/bin/ld: final link failed: Bad value
> collect2: error: ld returned 1 exit status
> ../Makerules:681: recipe for target
> '/Archive/glibc-git/build-system-gcc/libc.so' failed
> make[2]: *** [/Archive/glibc-git/build-system-gcc/libc.so] Error 1
> make[2]: Leaving directory '/Archive/glibc-git/elf'
> Makefile:214: recipe for target 'elf/subdir_lib' failed
> make[1]: *** [elf/subdir_lib] Error 2
> make[1]: Leaving directory '/Archive/glibc-git'
> Makefile:9: recipe for target 'all' failed
> make: *** [all] Error 2
>
>

Please try this.

Patch

diff --git a/sysdeps/x86_64/multiarch/memcpy_chk.S
b/sysdeps/x86_64/multiarch/memcpy_chk.S
index a0d56d4..648217e 100644
--- a/sysdeps/x86_64/multiarch/memcpy_chk.S
+++ b/sysdeps/x86_64/multiarch/memcpy_chk.S
@@ -33,9 +33,9 @@  ENTRY(__memcpy_chk)
 #ifdef HAVE_AVX512_ASM_SUPPORT
        HAS_ARCH_FEATURE (AVX512F_Usable)
        jz      1f
-#      HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
-#      jz      1f
-       leaq    __memcpy_avx512_no_vzeroupper(%rip), %rax
+       HAS_ARCH_FEATURE (Prefer_No_VZEROUPPER)
+       jz      1f
+       leaq    __memcpy_chk_avx512_no_vzeroupper(%rip), %rax
        ret
 #endif
 1:     leaq    __memcpy_chk_sse2(%rip), %rax