x86-64: Implement libm IFUNC selectors in C

* sysdeps/x86_64/fpu/multiarch/Makefile (libm-sysdep_routines):
	Add s_ceil-sse4_1, s_ceilf-sse4_1, s_floor-sse4_1,
	s_floorf-sse4_1, s_nearbyint-sse4_1, s_nearbyintf-sse4_1,
	s_rint-sse4_1 and s_rintf-sse4_1.
	* sysdeps/x86_64/fpu/multiarch/ifunc-sse4_1.h: New file.
	* sysdeps/x86_64/fpu/multiarch/s_ceil.c: Likewise.
	* sysdeps/x86_64/fpu/multiarch/s_ceilf.c: Likewise.
	* sysdeps/x86_64/fpu/multiarch/s_floor.c: Likewise.
	* sysdeps/x86_64/fpu/multiarch/s_floorf.c: Likewise.
	* sysdeps/x86_64/fpu/multiarch/s_nearbyint.c: Likewise.
	* sysdeps/x86_64/fpu/multiarch/s_nearbyintf.c: Likewise.
	* sysdeps/x86_64/fpu/multiarch/s_rint.c: Likewise.
	* sysdeps/x86_64/fpu/multiarch/s_rintf.c: Likewise.
	* sysdeps/x86_64/fpu/multiarch/s_ceil.S: Renamed to ...
	* sysdeps/x86_64/fpu/multiarch/s_ceil-sse4_1.S: This.  Don't
	include <machine/asm.h> nor <init-arch.h>.  Include <sysdep.h>.
	(__ceil): Removed.
	* sysdeps/x86_64/fpu/multiarch/s_ceilf.S: Renamed to ...
	* sysdeps/x86_64/fpu/multiarch/s_ceilf-sse4_1.S: This.  Don't
	include <machine/asm.h> nor <init-arch.h>.  Include <sysdep.h>.
	(__ceilf): Removed.
	* sysdeps/x86_64/fpu/multiarch/s_floor.S: Renamed to ...
	* sysdeps/x86_64/fpu/multiarch/s_floor-sse4_1.S: This.  Don't
	include <machine/asm.h> nor <init-arch.h>.  Include <sysdep.h>.
	(__floor): Removed.
	* sysdeps/x86_64/fpu/multiarch/s_floorf.S: Renamed to ...
	* sysdeps/x86_64/fpu/multiarch/s_floorf-sse4_1.S: This.  Don't
	include <machine/asm.h> nor <init-arch.h>.  Include <sysdep.h>.
	(__floorf): Removed.
	* sysdeps/x86_64/fpu/multiarch/s_nearbyint.S: Renamed to ...
	* sysdeps/x86_64/fpu/multiarch/s_nearbyint-sse4_1.S: This.  Don't
	include <machine/asm.h> nor <init-arch.h>.  Include <sysdep.h>.
	(__nearbyint): Removed.
	* sysdeps/x86_64/fpu/multiarch/s_nearbyintf.S: Renamed to ...
	* sysdeps/x86_64/fpu/multiarch/s_nearbyintf-sse4_1.S: This.  Don't
	include <machine/asm.h> nor <init-arch.h>.  Include <sysdep.h>.
	(__nearbyintf): Removed.
	* sysdeps/x86_64/fpu/multiarch/s_rint.S: Renamed to ...
	* sysdeps/x86_64/fpu/multiarch/s_rint-sse4_1.S: This.  Don't
	include <machine/asm.h> nor <init-arch.h>.  Include <sysdep.h>.
	(__rint): Removed.
	* sysdeps/x86_64/fpu/multiarch/s_rintf.S: Renamed to ...
	* sysdeps/x86_64/fpu/multiarch/s_rintf-sse4_1.S: This.  Don't
	include <machine/asm.h> nor <init-arch.h>.  Include <sysdep.h>.
	(__rintf): Removed.
This commit is contained in:
H.J. Lu 2017-08-04 13:01:59 -07:00
parent 1e8e527dd9
commit 10a87ca476
19 changed files with 335 additions and 120 deletions

View File

@ -1,3 +1,51 @@
2017-08-04 H.J. Lu <hongjiu.lu@intel.com>
* sysdeps/x86_64/fpu/multiarch/Makefile (libm-sysdep_routines):
Add s_ceil-sse4_1, s_ceilf-sse4_1, s_floor-sse4_1,
s_floorf-sse4_1, s_nearbyint-sse4_1, s_nearbyintf-sse4_1,
s_rint-sse4_1 and s_rintf-sse4_1.
* sysdeps/x86_64/fpu/multiarch/ifunc-sse4_1.h: New file.
* sysdeps/x86_64/fpu/multiarch/s_ceil.c: Likewise.
* sysdeps/x86_64/fpu/multiarch/s_ceilf.c: Likewise.
* sysdeps/x86_64/fpu/multiarch/s_floor.c: Likewise.
* sysdeps/x86_64/fpu/multiarch/s_floorf.c: Likewise.
* sysdeps/x86_64/fpu/multiarch/s_nearbyint.c: Likewise.
* sysdeps/x86_64/fpu/multiarch/s_nearbyintf.c: Likewise.
* sysdeps/x86_64/fpu/multiarch/s_rint.c: Likewise.
* sysdeps/x86_64/fpu/multiarch/s_rintf.c: Likewise.
* sysdeps/x86_64/fpu/multiarch/s_ceil.S: Renamed to ...
* sysdeps/x86_64/fpu/multiarch/s_ceil-sse4_1.S: This. Don't
include <machine/asm.h> nor <init-arch.h>. Include <sysdep.h>.
(__ceil): Removed.
* sysdeps/x86_64/fpu/multiarch/s_ceilf.S: Renamed to ...
* sysdeps/x86_64/fpu/multiarch/s_ceilf-sse4_1.S: This. Don't
include <machine/asm.h> nor <init-arch.h>. Include <sysdep.h>.
(__ceilf): Removed.
* sysdeps/x86_64/fpu/multiarch/s_floor.S: Renamed to ...
* sysdeps/x86_64/fpu/multiarch/s_floor-sse4_1.S: This. Don't
include <machine/asm.h> nor <init-arch.h>. Include <sysdep.h>.
(__floor): Removed.
* sysdeps/x86_64/fpu/multiarch/s_floorf.S: Renamed to ...
* sysdeps/x86_64/fpu/multiarch/s_floorf-sse4_1.S: This. Don't
include <machine/asm.h> nor <init-arch.h>. Include <sysdep.h>.
(__floorf): Removed.
* sysdeps/x86_64/fpu/multiarch/s_nearbyint.S: Renamed to ...
* sysdeps/x86_64/fpu/multiarch/s_nearbyint-sse4_1.S: This. Don't
include <machine/asm.h> nor <init-arch.h>. Include <sysdep.h>.
(__nearbyint): Removed.
* sysdeps/x86_64/fpu/multiarch/s_nearbyintf.S: Renamed to ...
* sysdeps/x86_64/fpu/multiarch/s_nearbyintf-sse4_1.S: This. Don't
include <machine/asm.h> nor <init-arch.h>. Include <sysdep.h>.
(__nearbyintf): Removed.
* sysdeps/x86_64/fpu/multiarch/s_rint.S: Renamed to ...
* sysdeps/x86_64/fpu/multiarch/s_rint-sse4_1.S: This. Don't
include <machine/asm.h> nor <init-arch.h>. Include <sysdep.h>.
(__rint): Removed.
* sysdeps/x86_64/fpu/multiarch/s_rintf.S: Renamed to ...
* sysdeps/x86_64/fpu/multiarch/s_rintf-sse4_1.S: This. Don't
include <machine/asm.h> nor <init-arch.h>. Include <sysdep.h>.
(__rintf): Removed.
2017-08-04 H.J. Lu <hongjiu.lu@intel.com>
* sysdeps/i386/start.S (_start): Check Check PIC instead of

View File

@ -2,6 +2,10 @@ ifeq ($(subdir),math)
libm-sysdep_routines += s_floor-c s_ceil-c s_floorf-c s_ceilf-c \
s_rint-c s_rintf-c s_nearbyint-c s_nearbyintf-c
libm-sysdep_routines += s_ceil-sse4_1 s_ceilf-sse4_1 s_floor-sse4_1 \
s_floorf-sse4_1 s_nearbyint-sse4_1 \
s_nearbyintf-sse4_1 s_rint-sse4_1 s_rintf-sse4_1
libm-sysdep_routines += e_exp-fma4 e_log-fma4 e_pow-fma4 s_atan-fma4 \
e_asin-fma4 e_atan2-fma4 s_sin-fma4 s_tan-fma4 \
mplog-fma4 mpa-fma4 slowexp-fma4 slowpow-fma4 \

View File

@ -0,0 +1,33 @@
/* Common definition for ifunc selections optimized with SSE4.1.
Copyright (C) 2017 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 <init-arch.h>
extern __typeof (REDIRECT_NAME) OPTIMIZE (c) attribute_hidden;
extern __typeof (REDIRECT_NAME) OPTIMIZE (sse41) attribute_hidden;
static inline void *
IFUNC_SELECTOR (void)
{
const struct cpu_features* cpu_features = __get_cpu_features ();
if (CPU_FEATURES_CPU_P (cpu_features, SSE4_1))
return OPTIMIZE (sse41);
return OPTIMIZE (c);
}

View File

@ -16,22 +16,9 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <machine/asm.h>
#include <init-arch.h>
ENTRY(__ceil)
.type __ceil, @gnu_indirect_function
LOAD_RTLD_GLOBAL_RO_RDX
leaq __ceil_sse41(%rip), %rax
HAS_CPU_FEATURE (SSE4_1)
jnz 2f
leaq __ceil_c(%rip), %rax
2: ret
END(__ceil)
weak_alias (__ceil, ceil)
#include <sysdep.h>
.section .text.sse4.1,"ax",@progbits
ENTRY(__ceil_sse41)
roundsd $10, %xmm0, %xmm0
ret

View File

@ -0,0 +1,29 @@
/* Multiple versions of __ceil.
Copyright (C) 2017 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/>. */
#define ceil __redirect_ceil
#define __ceil __redirect___ceil
#include <math.h>
#undef ceil
#undef __ceil
#define SYMBOL_NAME ceil
#include "ifunc-sse4_1.h"
libc_ifunc_redirected (__redirect_ceil, __ceil, IFUNC_SELECTOR ());
weak_alias (__ceil, ceil)

View File

@ -16,22 +16,9 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <machine/asm.h>
#include <init-arch.h>
ENTRY(__ceilf)
.type __ceilf, @gnu_indirect_function
LOAD_RTLD_GLOBAL_RO_RDX
leaq __ceilf_sse41(%rip), %rax
HAS_CPU_FEATURE (SSE4_1)
jnz 2f
leaq __ceilf_c(%rip), %rax
2: ret
END(__ceilf)
weak_alias (__ceilf, ceilf)
#include <sysdep.h>
.section .text.sse4.1,"ax",@progbits
ENTRY(__ceilf_sse41)
roundss $10, %xmm0, %xmm0
ret

View File

@ -0,0 +1,29 @@
/* Multiple versions of __ceilf.
Copyright (C) 2017 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/>. */
#define ceilf __redirect_ceilf
#define __ceilf __redirect___ceilf
#include <math.h>
#undef ceilf
#undef __ceilf
#define SYMBOL_NAME ceilf
#include "ifunc-sse4_1.h"
libc_ifunc_redirected (__redirect_ceilf, __ceilf, IFUNC_SELECTOR ());
weak_alias (__ceilf, ceilf)

View File

@ -16,22 +16,9 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <machine/asm.h>
#include <init-arch.h>
ENTRY(__floor)
.type __floor, @gnu_indirect_function
LOAD_RTLD_GLOBAL_RO_RDX
leaq __floor_sse41(%rip), %rax
HAS_CPU_FEATURE (SSE4_1)
jnz 2f
leaq __floor_c(%rip), %rax
2: ret
END(__floor)
weak_alias (__floor, floor)
#include <sysdep.h>
.section .text.sse4.1,"ax",@progbits
ENTRY(__floor_sse41)
roundsd $9, %xmm0, %xmm0
ret

View File

@ -0,0 +1,29 @@
/* Multiple versions of __floor.
Copyright (C) 2017 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/>. */
#define floor __redirect_floor
#define __floor __redirect___floor
#include <math.h>
#undef floor
#undef __floor
#define SYMBOL_NAME floor
#include "ifunc-sse4_1.h"
libc_ifunc_redirected (__redirect_floor, __floor, IFUNC_SELECTOR ());
weak_alias (__floor, floor)

View File

@ -16,22 +16,9 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <machine/asm.h>
#include <init-arch.h>
ENTRY(__floorf)
.type __floorf, @gnu_indirect_function
LOAD_RTLD_GLOBAL_RO_RDX
leaq __floorf_sse41(%rip), %rax
HAS_CPU_FEATURE (SSE4_1)
jnz 2f
leaq __floorf_c(%rip), %rax
2: ret
END(__floorf)
weak_alias (__floorf, floorf)
#include <sysdep.h>
.section .text.sse4.1,"ax",@progbits
ENTRY(__floorf_sse41)
roundss $9, %xmm0, %xmm0
ret

View File

@ -0,0 +1,29 @@
/* Multiple versions of __floorf.
Copyright (C) 2017 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/>. */
#define floorf __redirect_floorf
#define __floorf __redirect___floorf
#include <math.h>
#undef floorf
#undef __floorf
#define SYMBOL_NAME floorf
#include "ifunc-sse4_1.h"
libc_ifunc_redirected (__redirect_floorf, __floorf, IFUNC_SELECTOR ());
weak_alias (__floorf, floorf)

View File

@ -16,22 +16,9 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <machine/asm.h>
#include <init-arch.h>
ENTRY(__nearbyint)
.type __nearbyint, @gnu_indirect_function
LOAD_RTLD_GLOBAL_RO_RDX
leaq __nearbyint_sse41(%rip), %rax
HAS_CPU_FEATURE (SSE4_1)
jnz 2f
leaq __nearbyint_c(%rip), %rax
2: ret
END(__nearbyint)
weak_alias (__nearbyint, nearbyint)
#include <sysdep.h>
.section .text.sse4.1,"ax",@progbits
ENTRY(__nearbyint_sse41)
roundsd $0xc, %xmm0, %xmm0
ret

View File

@ -0,0 +1,30 @@
/* Multiple versions of __nearbyint.
Copyright (C) 2017 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/>. */
#define nearbyint __redirect_nearbyint
#define __nearbyint __redirect___nearbyint
#include <math.h>
#undef nearbyint
#undef __nearbyint
#define SYMBOL_NAME nearbyint
#include "ifunc-sse4_1.h"
libc_ifunc_redirected (__redirect_nearbyint, __nearbyint,
IFUNC_SELECTOR ());
weak_alias (__nearbyint, nearbyint)

View File

@ -16,22 +16,9 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <machine/asm.h>
#include <init-arch.h>
ENTRY(__nearbyintf)
.type __nearbyintf, @gnu_indirect_function
LOAD_RTLD_GLOBAL_RO_RDX
leaq __nearbyintf_sse41(%rip), %rax
HAS_CPU_FEATURE (SSE4_1)
jnz 2f
leaq __nearbyintf_c(%rip), %rax
2: ret
END(__nearbyintf)
weak_alias (__nearbyintf, nearbyintf)
#include <sysdep.h>
.section .text.sse4.1,"ax",@progbits
ENTRY(__nearbyintf_sse41)
roundss $0xc, %xmm0, %xmm0
ret

View File

@ -0,0 +1,30 @@
/* Multiple versions of __nearbyintf.
Copyright (C) 2017 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/>. */
#define nearbyintf __redirect_nearbyintf
#define __nearbyintf __redirect___nearbyintf
#include <math.h>
#undef nearbyintf
#undef __nearbyintf
#define SYMBOL_NAME nearbyintf
#include "ifunc-sse4_1.h"
libc_ifunc_redirected (__redirect_nearbyintf, __nearbyintf,
IFUNC_SELECTOR ());
weak_alias (__nearbyintf, nearbyintf)

View File

@ -16,22 +16,9 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <machine/asm.h>
#include <init-arch.h>
ENTRY(__rint)
.type __rint, @gnu_indirect_function
LOAD_RTLD_GLOBAL_RO_RDX
leaq __rint_sse41(%rip), %rax
HAS_CPU_FEATURE (SSE4_1)
jnz 2f
leaq __rint_c(%rip), %rax
2: ret
END(__rint)
weak_alias (__rint, rint)
#include <sysdep.h>
.section .text.sse4.1,"ax",@progbits
ENTRY(__rint_sse41)
roundsd $4, %xmm0, %xmm0
ret

View File

@ -0,0 +1,29 @@
/* Multiple versions of __rint.
Copyright (C) 2017 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/>. */
#define rint __redirect_rint
#define __rint __redirect___rint
#include <math.h>
#undef rint
#undef __rint
#define SYMBOL_NAME rint
#include "ifunc-sse4_1.h"
libc_ifunc_redirected (__redirect_rint, __rint, IFUNC_SELECTOR ());
weak_alias (__rint, rint)

View File

@ -16,22 +16,9 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <machine/asm.h>
#include <init-arch.h>
ENTRY(__rintf)
.type __rintf, @gnu_indirect_function
LOAD_RTLD_GLOBAL_RO_RDX
leaq __rintf_sse41(%rip), %rax
HAS_CPU_FEATURE (SSE4_1)
jnz 2f
leaq __rintf_c(%rip), %rax
2: ret
END(__rintf)
weak_alias (__rintf, rintf)
#include <sysdep.h>
.section .text.sse4.1,"ax",@progbits
ENTRY(__rintf_sse41)
roundss $4, %xmm0, %xmm0
ret

View File

@ -0,0 +1,29 @@
/* Multiple versions of __rintf.
Copyright (C) 2017 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/>. */
#define rintf __redirect_rintf
#define __rintf __redirect___rintf
#include <math.h>
#undef rintf
#undef __rintf
#define SYMBOL_NAME rintf
#include "ifunc-sse4_1.h"
libc_ifunc_redirected (__redirect_rintf, __rintf, IFUNC_SELECTOR ());
weak_alias (__rintf, rintf)