From patchwork Mon Sep 25 23:32:08 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: 23137 Received: (qmail 61294 invoked by alias); 25 Sep 2017 23:32:26 -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 61284 invoked by uid 89); 25 Sep 2017 23:32:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-it0-f45.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=aYIPL5uH6EE35hgEBNv4lMggXWaFatagAl3JzSa2uVQ=; b=OhDd1S3IWkB/DFFHmj8NPeMowKjcvEL+wiyeWk7YN7GBTdfPY/+f0ygzsVrx0cgeMl h8pR3E8E+PYcYxjKGx/yzdUvz/FdWAe2VOjjCQG1OjOfJAVbJLHH9+WaOoCsKDnWZHvz pLN902NIMwOMmSkoRDwYtX92LmiFoDfbcn0WZMirkH8CgEsPbG2dNWZR6bq2UxTdzkOR 5cvj3T4FgnZ5dhEYAYzXBHVtSKQjbFaTSUUPM6YUIenSGbFRM07Hkfi3RMRXwJoWpgtI vRNuzHef74+KHMHrMaNt5l4gdnQYcu7CMuYkP5W5X0eYQf9efbdTOLUcCPQm0e4RIB3z JokQ== X-Gm-Message-State: AHPjjUioxbY8VtY++jK3/+2Og7ezGuLh/u7moJctEz0nYOZyxdwC3mI0 QsmEre3+rz/1uKJxMz4txNY= X-Google-Smtp-Source: AOwi7QDwW3EvJ3dZmXpmyRFwHszNxbjvjDwUZPZ5/g3PH9VG3Hw5fKoxnvYSbS4wkiIzjoy2tZyR3A== X-Received: by 10.36.223.2 with SMTP id r2mr3279743itg.19.1506382338364; Mon, 25 Sep 2017 16:32:18 -0700 (PDT) Date: Mon, 25 Sep 2017 16:32:08 -0700 From: "H.J. Lu" To: GNU C Library Cc: Arjan van de Ven , Andrew Senkevich Subject: [PATCH 1/4] x86-64: Replace assembly versions of e_expf with generic e_expf.c Message-ID: <20170925233208.GA31745@gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) This patch replaces x86-64 assembly versions of e_expf with generic e_expf.c. * sysdeps/x86_64/fpu/e_expf.S: Removed. * sysdeps/x86_64/fpu/multiarch/e_expf-fma.S: 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 (strong_alias): New. (__ieee754_expf): Likewise. 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 | 6 + sysdeps/x86_64/fpu/multiarch/e_expf.c | 7 + 6 files changed, 19 insertions(+), 522 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 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..c871d43cfc --- /dev/null +++ b/sysdeps/x86_64/fpu/multiarch/e_expf-fma.c @@ -0,0 +1,6 @@ +#undef strong_alias +#define strong_alias(ignored1, ignored2) + +#define __ieee754_expf __ieee754_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..3111b43eae 100644 --- a/sysdeps/x86_64/fpu/multiarch/e_expf.c +++ b/sysdeps/x86_64/fpu/multiarch/e_expf.c @@ -24,3 +24,10 @@ extern float __redirect_ieee754_expf (float); libc_ifunc_redirected (__redirect_ieee754_expf, __ieee754_expf, IFUNC_SELECTOR ()); strong_alias (__ieee754_expf, __expf_finite) + +#undef strong_alias +#define strong_alias(ignored1, ignored2) + +#define __ieee754_expf __ieee754_expf_sse2 + +#include