From patchwork Thu Oct 19 17:31:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 828283 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-86115-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="Em+Nv507"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yHwx43B7Vz9t3B for ; Fri, 20 Oct 2017 04:32:40 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=SsBgjpVFo0VphVatdn6DopeGXC0vuRV 2bR+I7n7fscRknKusmHkAPgibSKOdH2F91E5h9fz3EwE8tMB3jEewvUJdpaoct/X s+zuiMiXmu20cwjYvRIIfoIrAiwPgKl9t57MhijyQeswoTzzfi9/cHcoAl9Mo2R0 G0P5Tms+UuHU= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=/iQtJ5RQDMGPFsgFPbCGd63hj6A=; b=Em+Nv 507tCP81PoOWEdR1ui7FnQUdEDL+opfSeyH51s4OTlqYQzLSzN1i2gfpc1d/snGV nac71Y3W19buRZM/1qa5EEHyM5XG5/dRD+skFxVEbYFpHcxigW3kj3Ht3knoxQgO ZMFxHbiHg50YQajkL4V9jFBhknvY9q4NG/T2/w= Received: (qmail 80646 invoked by alias); 19 Oct 2017 17:32:06 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 80584 invoked by uid 89); 19 Oct 2017 17:32:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy= X-HELO: mga09.intel.com X-ExtLoop1: 1 From: "H.J. Lu" To: libc-alpha@sourceware.org Subject: [PATCH 01/10] x86-64: Replace assembly versions of e_expf with generic e_expf.c Date: Thu, 19 Oct 2017 10:31:50 -0700 Message-Id: <20171019173159.21402-2-hjl.tools@gmail.com> In-Reply-To: <20171019173159.21402-1-hjl.tools@gmail.com> References: <20171019173159.21402-1-hjl.tools@gmail.com> This patch replaces x86-64 assembly versions of e_expf with generic e_expf.c. For workload-spec2017.wrf, on Nehalem, it improves performance by: Before After Improvement reciprocal-throughput 36.039 20.7749 73% latency 58.8096 40.8715 43% On Skylake, it improves Before After Improvement reciprocal-throughput 18.4436 11.1693 65% latency 47.5162 37.5411 26% * sysdeps/x86_64/fpu/e_expf.S: Removed. * sysdeps/x86_64/fpu/multiarch/e_expf-fma.S: Likewise. * sysdeps/x86_64/fpu/w_expf.c: Likewise. * sysdeps/x86_64/fpu/libm-test-ulps: Updated for generic e_expf.c. * sysdeps/x86_64/fpu/multiarch/Makefile (CFLAGS-e_expf-fma.c): New. * sysdeps/x86_64/fpu/multiarch/e_expf-fma.c: New file. * sysdeps/x86_64/fpu/multiarch/e_expf.c (__redirect_ieee754_expf): Renamed to ... (__redirect_expf): This. (SYMBOL_NAME): Changed to expf. (__ieee754_expf): Renamed to ... (__expf): This. (__GI___expf): This. (__ieee754_expf): Add strong_alias. (__expf_finite): Likewise. (__expf): New. Include . --- sysdeps/x86_64/fpu/e_expf.S | 339 ------------------------------ sysdeps/x86_64/fpu/libm-test-ulps | 4 + sysdeps/x86_64/fpu/multiarch/Makefile | 3 +- sysdeps/x86_64/fpu/multiarch/e_expf-fma.S | 182 ---------------- sysdeps/x86_64/fpu/multiarch/e_expf-fma.c | 3 + sysdeps/x86_64/fpu/multiarch/e_expf.c | 26 ++- sysdeps/x86_64/fpu/w_expf.c | 1 - 7 files changed, 29 insertions(+), 529 deletions(-) delete mode 100644 sysdeps/x86_64/fpu/e_expf.S delete mode 100644 sysdeps/x86_64/fpu/multiarch/e_expf-fma.S create mode 100644 sysdeps/x86_64/fpu/multiarch/e_expf-fma.c delete mode 100644 sysdeps/x86_64/fpu/w_expf.c diff --git a/sysdeps/x86_64/fpu/e_expf.S b/sysdeps/x86_64/fpu/e_expf.S deleted file mode 100644 index c3bf312c44..0000000000 --- a/sysdeps/x86_64/fpu/e_expf.S +++ /dev/null @@ -1,339 +0,0 @@ -/* Optimized __ieee754_expf function. - Copyright (C) 2012-2017 Free Software Foundation, Inc. - Contributed by Intel Corporation. - 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 - . */ - -#include - -/* Short algorithm description: - * - * Let K = 64 (table size). - * e^x = 2^(x/log(2)) = 2^n * T[j] * (1 + P(y)) - * where - * x = m*log(2)/K + y, y in [0.0..log(2)/K] - * m = n*K + j, m,n,j - signed integer, j in [0..K-1] - * values of 2^(j/K) are tabulated as T[j]. - * - * P(y) is a minimax polynomial approximation of expf(x)-1 - * on small interval [0.0..log(2)/K]. - * - * P(y) = P3*y*y*y*y + P2*y*y*y + P1*y*y + P0*y, calculated as - * z = y*y; P(y) = (P3*z + P1)*z + (P2*z + P0)*y - * - * Special cases: - * expf(NaN) = NaN - * expf(+INF) = +INF - * expf(-INF) = 0 - * expf(x) = 1 for subnormals - * for finite argument, only expf(0)=1 is exact - * expf(x) overflows if x>88.7228317260742190 - * expf(x) underflows if x<-103.972076416015620 - */ - - .text -ENTRY(__ieee754_expf) - /* Input: single precision x in %xmm0 */ - cvtss2sd %xmm0, %xmm1 /* Convert x to double precision */ - movd %xmm0, %ecx /* Copy x */ - movsd L(DP_KLN2)(%rip), %xmm2 /* DP K/log(2) */ - movsd L(DP_P2)(%rip), %xmm3 /* DP P2 */ - movl %ecx, %eax /* x */ - mulsd %xmm1, %xmm2 /* DP x*K/log(2) */ - andl $0x7fffffff, %ecx /* |x| */ - lea L(DP_T)(%rip), %rsi /* address of table T[j] */ - cmpl $0x42ad496b, %ecx /* |x|<125*log(2) ? */ - movsd L(DP_P3)(%rip), %xmm4 /* DP P3 */ - addsd L(DP_RS)(%rip), %xmm2 /* DP x*K/log(2)+RS */ - jae L(special_paths) - - /* Here if |x|<125*log(2) */ - cmpl $0x31800000, %ecx /* |x|<2^(-28) ? */ - jb L(small_arg) - - /* Main path: here if 2^(-28)<=|x|<125*log(2) */ - cvtsd2ss %xmm2, %xmm2 /* SP x*K/log(2)+RS */ - movd %xmm2, %eax /* bits of n*K+j with trash */ - subss L(SP_RS)(%rip), %xmm2 /* SP t=round(x*K/log(2)) */ - movl %eax, %edx /* n*K+j with trash */ - cvtss2sd %xmm2, %xmm2 /* DP t */ - andl $0x3f, %eax /* bits of j */ - mulsd L(DP_NLN2K)(%rip), %xmm2/* DP -t*log(2)/K */ - andl $0xffffffc0, %edx /* bits of n */ -#ifdef __AVX__ - vaddsd %xmm1, %xmm2, %xmm0 /* DP y=x-t*log(2)/K */ - vmulsd %xmm0, %xmm0, %xmm2 /* DP z=y*y */ -#else - addsd %xmm1, %xmm2 /* DP y=x-t*log(2)/K */ - movaps %xmm2, %xmm0 /* DP y */ - mulsd %xmm2, %xmm2 /* DP z=y*y */ -#endif - mulsd %xmm2, %xmm4 /* DP P3*z */ - addl $0x1fc0, %edx /* bits of n + SP exponent bias */ - mulsd %xmm2, %xmm3 /* DP P2*z */ - shll $17, %edx /* SP 2^n */ - addsd L(DP_P1)(%rip), %xmm4 /* DP P3*z+P1 */ - addsd L(DP_P0)(%rip), %xmm3 /* DP P2*z+P0 */ - movd %edx, %xmm1 /* SP 2^n */ - mulsd %xmm2, %xmm4 /* DP (P3*z+P1)*z */ - mulsd %xmm3, %xmm0 /* DP (P2*z+P0)*y */ - addsd %xmm4, %xmm0 /* DP P(y) */ - mulsd (%rsi,%rax,8), %xmm0 /* DP P(y)*T[j] */ - addsd (%rsi,%rax,8), %xmm0 /* DP T[j]*(P(y)+1) */ - cvtsd2ss %xmm0, %xmm0 /* SP T[j]*(P(y)+1) */ - mulss %xmm1, %xmm0 /* SP result=2^n*(T[j]*(P(y)+1)) */ - ret - - .p2align 4 -L(small_arg): - /* Here if 0<=|x|<2^(-28) */ - addss L(SP_ONE)(%rip), %xmm0 /* 1.0 + x */ - /* Return 1.0 with inexact raised, except for x==0 */ - ret - - .p2align 4 -L(special_paths): - /* Here if 125*log(2)<=|x| */ - shrl $31, %eax /* Get sign bit of x, and depending on it: */ - lea L(SP_RANGE)(%rip), %rdx /* load over/underflow bound */ - cmpl (%rdx,%rax,4), %ecx /* |x|under/overflow bound */ - cmpl $0x7f800000, %ecx /* |x| is finite ? */ - jae L(arg_inf_or_nan) - - /* Here if |x|>under/overflow bound, and x is finite */ - testq %rax, %rax /* sign of x nonzero ? */ - je L(res_overflow) - - /* Here if -inf0) */ - movss L(SP_LARGE)(%rip), %xmm0/* load large value 2^100 */ - mulss %xmm0, %xmm0 /* Return overflowed result (Inf or max normal) */ - ret - - .p2align 4 -L(arg_inf_or_nan): - /* Here if |x| is Inf or NAN */ - jne L(arg_nan) /* |x| is Inf ? */ - - /* Here if |x| is Inf */ - lea L(SP_INF_0)(%rip), %rdx /* depending on sign of x: */ - movss (%rdx,%rax,4), %xmm0 /* return zero or Inf */ - ret - - .p2align 4 -L(arg_nan): - /* Here if |x| is NaN */ - addss %xmm0, %xmm0 /* Return x+x (raise invalid) */ - ret - - .p2align 4 -L(near_under_or_overflow): - /* Here if 125*log(2)<=|x|this bound, then result overflows */ - .long 0x42cff1b4 /* if x. */ - -#include - -/* Short algorithm description: - - Let K = 64 (table size). - e^x = 2^(x/log(2)) = 2^n * T[j] * (1 + P(y)) - where - x = m*log(2)/K + y, y in [0.0..log(2)/K] - m = n*K + j, m,n,j - signed integer, j in [0..K-1] - values of 2^(j/K) are tabulated as T[j]. - - P(y) is a minimax polynomial approximation of expf(x)-1 - on small interval [0.0..log(2)/K]. - - P(y) = P3*y*y*y*y + P2*y*y*y + P1*y*y + P0*y, calculated as - z = y*y; P(y) = (P3*z + P1)*z + (P2*z + P0)*y - - Special cases: - expf(NaN) = NaN - expf(+INF) = +INF - expf(-INF) = 0 - expf(x) = 1 for subnormals - for finite argument, only expf(0)=1 is exact - expf(x) overflows if x>88.7228317260742190 - expf(x) underflows if x<-103.972076416015620 - */ - - .section .text.fma,"ax",@progbits -ENTRY(__ieee754_expf_fma) - /* Input: single precision x in %xmm0 */ - vcvtss2sd %xmm0, %xmm0, %xmm1 /* Convert x to double precision */ - vmovd %xmm0, %ecx /* Copy x */ - vmovsd L(DP_KLN2)(%rip), %xmm2 /* DP K/log(2) */ - vfmadd213sd L(DP_RD)(%rip), %xmm1, %xmm2 /* DP x*K/log(2)+RD */ - vmovsd L(DP_P2)(%rip), %xmm3 /* DP P2 */ - movl %ecx, %eax /* x */ - andl $0x7fffffff, %ecx /* |x| */ - lea L(DP_T)(%rip), %rsi /* address of table T[j] */ - vmovsd L(DP_P3)(%rip), %xmm4 /* DP P3 */ - - cmpl $0x42ad496b, %ecx /* |x|<125*log(2) ? */ - jae L(special_paths_fma) - - /* Here if |x|<125*log(2) */ - cmpl $0x31800000, %ecx /* |x|<2^(-28) ? */ - jb L(small_arg_fma) - - /* Main path: here if 2^(-28)<=|x|<125*log(2) */ - /* %xmm2 = SP x*K/log(2)+RS */ - vmovd %xmm2, %eax - vsubsd L(DP_RD)(%rip), %xmm2, %xmm2 /* DP t=round(x*K/log(2)) */ - movl %eax, %edx /* n*K+j with trash */ - andl $0x3f, %eax /* bits of j */ - vmovsd (%rsi,%rax,8), %xmm5 /* T[j] */ - andl $0xffffffc0, %edx /* bits of n */ - - vfmadd132sd L(DP_NLN2K)(%rip), %xmm1, %xmm2 /* DP y=x-t*log(2)/K */ - vmulsd %xmm2, %xmm2, %xmm6 /* DP z=y*y */ - - - vfmadd213sd L(DP_P1)(%rip), %xmm6, %xmm4 /* DP P3*z + P1 */ - vfmadd213sd L(DP_P0)(%rip), %xmm6, %xmm3 /* DP P2*z+P0 */ - - addl $0x1fc0, %edx /* bits of n + SP exponent bias */ - shll $17, %edx /* SP 2^n */ - vmovd %edx, %xmm1 /* SP 2^n */ - - vmulsd %xmm6, %xmm4, %xmm4 /* DP (P3*z+P1)*z */ - - vfmadd213sd %xmm4, %xmm3, %xmm2 /* DP P(Y) (P2*z+P0)*y */ - vfmadd213sd %xmm5, %xmm5, %xmm2 /* DP T[j]*(P(y)+1) */ - vcvtsd2ss %xmm2, %xmm2, %xmm0 /* SP T[j]*(P(y)+1) */ - vmulss %xmm1, %xmm0, %xmm0 /* SP result=2^n*(T[j]*(P(y)+1)) */ - ret - - .p2align 4 -L(small_arg_fma): - /* Here if 0<=|x|<2^(-28) */ - vaddss L(SP_ONE)(%rip), %xmm0, %xmm0 /* 1.0 + x */ - /* Return 1.0 with inexact raised, except for x==0 */ - ret - - .p2align 4 -L(special_paths_fma): - /* Here if 125*log(2)<=|x| */ - shrl $31, %eax /* Get sign bit of x, and depending on it: */ - lea L(SP_RANGE)(%rip), %rdx /* load over/underflow bound */ - cmpl (%rdx,%rax,4), %ecx /* |x|under/overflow bound */ - cmpl $0x7f800000, %ecx /* |x| is finite ? */ - jae L(arg_inf_or_nan_fma) - - /* Here if |x|>under/overflow bound, and x is finite */ - testl %eax, %eax /* sign of x nonzero ? */ - je L(res_overflow_fma) - - /* Here if -inf0) */ - vmovss L(SP_LARGE)(%rip), %xmm0/* load large value 2^100 */ - vmulss %xmm0, %xmm0, %xmm0 /* Return overflowed result (Inf or max normal) */ - ret - - .p2align 4 -L(arg_inf_or_nan_fma): - /* Here if |x| is Inf or NAN */ - jne L(arg_nan_fma) /* |x| is Inf ? */ - - /* Here if |x| is Inf */ - lea L(SP_INF_0)(%rip), %rdx /* depending on sign of x: */ - vmovss (%rdx,%rax,4), %xmm0 /* return zero or Inf */ - ret - - .p2align 4 -L(arg_nan_fma): - /* Here if |x| is NaN */ - vaddss %xmm0, %xmm0, %xmm0 /* Return x+x (raise invalid) */ - ret - - .p2align 4 -L(near_under_or_overflow_fma): - /* Here if 125*log(2)<=|x| diff --git a/sysdeps/x86_64/fpu/multiarch/e_expf-fma.c b/sysdeps/x86_64/fpu/multiarch/e_expf-fma.c new file mode 100644 index 0000000000..4e01cd6a82 --- /dev/null +++ b/sysdeps/x86_64/fpu/multiarch/e_expf-fma.c @@ -0,0 +1,3 @@ +#define __expf __expf_fma + +#include diff --git a/sysdeps/x86_64/fpu/multiarch/e_expf.c b/sysdeps/x86_64/fpu/multiarch/e_expf.c index 096209857e..18451a0f77 100644 --- a/sysdeps/x86_64/fpu/multiarch/e_expf.c +++ b/sysdeps/x86_64/fpu/multiarch/e_expf.c @@ -1,4 +1,4 @@ -/* Multiple versions of IEEE 754 expf. +/* Multiple versions of expf. Copyright (C) 2017 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -16,11 +16,25 @@ License along with the GNU C Library; if not, see . */ -extern float __redirect_ieee754_expf (float); +extern float __redirect_expf (float); -#define SYMBOL_NAME ieee754_expf +#define SYMBOL_NAME expf #include "ifunc-fma.h" -libc_ifunc_redirected (__redirect_ieee754_expf, __ieee754_expf, - IFUNC_SELECTOR ()); -strong_alias (__ieee754_expf, __expf_finite) +libc_ifunc_redirected (__redirect_expf, __expf, IFUNC_SELECTOR ()); + +#ifdef SHARED +__hidden_ver1 (__expf, __GI___expf, __redirect_expf) + __attribute__ ((visibility ("hidden"))); + +# include +versioned_symbol (libm, __expf, expf, GLIBC_2_27); +#else +weak_alias (__expf, expf) +#endif + +strong_alias (__expf, __ieee754_expf) +strong_alias (__expf, __expf_finite) + +#define __expf __expf_sse2 +#include diff --git a/sysdeps/x86_64/fpu/w_expf.c b/sysdeps/x86_64/fpu/w_expf.c deleted file mode 100644 index b5fe164520..0000000000 --- a/sysdeps/x86_64/fpu/w_expf.c +++ /dev/null @@ -1 +0,0 @@ -#include