From patchwork Fri Aug 11 15:04:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1820310 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=muzHr2B+; dkim-atps=neutral Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RMnBk11Zrz1yYC for ; Sat, 12 Aug 2023 01:04:30 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0880E3857806 for ; Fri, 11 Aug 2023 15:04:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0880E3857806 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1691766268; bh=/Qe++AjvClJ4RXc0kjjN/KzP52f6wkYETt5LbAlulO4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=muzHr2B+Rt3fJshtuWZNfPf+BVeg/nskBbqEwAikaeP3NMrYjVW93hc/aGI/5gbo1 63yUdxOCiR+4C7b/H79qvL3lsvJHWFr/02UKuqs6MFnVBjFy2KwcuT30IMAR4vfA3V qK5PfzWuvf5bfe6gqNvVhmnKvFmkbmLdqcs/A+4I= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 20C513858D20 for ; Fri, 11 Aug 2023 15:04:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 20C513858D20 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6873a30d02eso1559062b3a.3 for ; Fri, 11 Aug 2023 08:04:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691766251; x=1692371051; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/Qe++AjvClJ4RXc0kjjN/KzP52f6wkYETt5LbAlulO4=; b=YAPEEsZyU+9vu9Z9gQ8Qg6vHzmi43h05UsguJfoAvfVtEUT9YFsgQLnSkgS4ORwInb mlQz4rldI7kcx05CpjvE3st0uS3fyK9LEmiFm6lwTjNxluvFXksdZVXRj9X8VrRYcndO iswBqI8iAOT7D5I+l+XYhxsFyMawVG+UOSwxfeV4d3RYoy9qKGesGtIFiQdR+5clu0Pd eYe36x++hXLEZA7ujg+37yNcTT5MmYJbM6EG04j92uJFF4Jk5yZ7Pq7Oios7IPzlqMhY R/3l0tV1bsEguLl2RBNutrE0I3nzAbZG1up+RyKaz55N8hQIX2nNCWSG2+df4nYYUeg4 mhKQ== X-Gm-Message-State: AOJu0Yy/4LRqDPRJ8igoRiDK9St4C9S04aq2YAPUw7kJpogCFO0f/j4z +TzC5ph+gCBwNqWWGceZq0oxcjD3L7s= X-Google-Smtp-Source: AGHT+IF9IqoIDtchBsn9dOJz82bdoQS+/DCeI4taLtv8uvBLWMmR09mMKxdqbZx8ruiuOSRMFPjGnQ== X-Received: by 2002:a17:902:da85:b0:1bb:a834:696 with SMTP id j5-20020a170902da8500b001bba8340696mr1992611plx.29.1691766250555; Fri, 11 Aug 2023 08:04:10 -0700 (PDT) Received: from gnu-cfl-3.localdomain ([172.59.161.42]) by smtp.gmail.com with ESMTPSA id s3-20020a170902ea0300b001a5fccab02dsm4030580plg.177.2023.08.11.08.04.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 08:04:10 -0700 (PDT) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id F3C007402EC for ; Fri, 11 Aug 2023 08:04:08 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] x86_64: Add expm1 with FMA Date: Fri, 11 Aug 2023 08:04:08 -0700 Message-ID: <20230811150408.2832625-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3024.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" On Skylake, it improves expm1 bench performance by: Before After Improvement max 70.204 68.054 3% min 20.709 16.2 22% mean 22.1221 16.7367 24% NB: Add extern long double __expm1l (long double); extern long double __expm1f128 (long double); for __typeof (__expm1l) and __typeof (__expm1f128) when __expm1 is defined since __expm1 may be expanded in their declarations which causes the build failure. --- sysdeps/ieee754/dbl-64/s_expm1.c | 7 +++++ sysdeps/x86_64/fpu/multiarch/Makefile | 2 ++ sysdeps/x86_64/fpu/multiarch/s_expm1-fma.c | 10 ++++++ sysdeps/x86_64/fpu/multiarch/s_expm1.c | 36 ++++++++++++++++++++++ 4 files changed, 55 insertions(+) create mode 100644 sysdeps/x86_64/fpu/multiarch/s_expm1-fma.c create mode 100644 sysdeps/x86_64/fpu/multiarch/s_expm1.c diff --git a/sysdeps/ieee754/dbl-64/s_expm1.c b/sysdeps/ieee754/dbl-64/s_expm1.c index 8f1c95bd04..1cafeca9c0 100644 --- a/sysdeps/ieee754/dbl-64/s_expm1.c +++ b/sysdeps/ieee754/dbl-64/s_expm1.c @@ -130,6 +130,11 @@ static const double 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */ -2.01099218183624371326e-07 }; /* BE8AFDB7 6E09C32D */ +#ifndef SECTION +# define SECTION +#endif + +SECTION double __expm1 (double x) { @@ -258,4 +263,6 @@ __expm1 (double x) } return y; } +#ifndef __expm1 libm_alias_double (__expm1, expm1) +#endif diff --git a/sysdeps/x86_64/fpu/multiarch/Makefile b/sysdeps/x86_64/fpu/multiarch/Makefile index f773255721..add339a876 100644 --- a/sysdeps/x86_64/fpu/multiarch/Makefile +++ b/sysdeps/x86_64/fpu/multiarch/Makefile @@ -37,6 +37,7 @@ libm-sysdep_routines += \ e_log2-fma \ e_pow-fma \ s_atan-fma \ + s_expm1-fma \ s_sin-fma \ s_sincos-fma \ s_tan-fma \ @@ -49,6 +50,7 @@ CFLAGS-e_log-fma.c = -mfma -mavx2 CFLAGS-e_log2-fma.c = -mfma -mavx2 CFLAGS-e_pow-fma.c = -mfma -mavx2 CFLAGS-s_atan-fma.c = -mfma -mavx2 +CFLAGS-s_expm1-fma.c = -mfma -mavx2 CFLAGS-s_sin-fma.c = -mfma -mavx2 CFLAGS-s_tan-fma.c = -mfma -mavx2 CFLAGS-s_sincos-fma.c = -mfma -mavx2 diff --git a/sysdeps/x86_64/fpu/multiarch/s_expm1-fma.c b/sysdeps/x86_64/fpu/multiarch/s_expm1-fma.c new file mode 100644 index 0000000000..3ee2bd804e --- /dev/null +++ b/sysdeps/x86_64/fpu/multiarch/s_expm1-fma.c @@ -0,0 +1,10 @@ +#define __expm1 __expm1_fma + +/* NB: __expm1 may be expanded to __expm1_fma in the following + prototypes. */ +extern long double __expm1l (long double); +extern long double __expm1f128 (long double); + +#define SECTION __attribute__ ((section (".text.fma"))) + +#include diff --git a/sysdeps/x86_64/fpu/multiarch/s_expm1.c b/sysdeps/x86_64/fpu/multiarch/s_expm1.c new file mode 100644 index 0000000000..2cae83fb7f --- /dev/null +++ b/sysdeps/x86_64/fpu/multiarch/s_expm1.c @@ -0,0 +1,36 @@ +/* Multiple versions of expm1. + Copyright (C) 2023 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 + . */ + +#include + +extern double __redirect_expm1 (double); + +#define SYMBOL_NAME expm1 +#include "ifunc-fma.h" + +libc_ifunc_redirected (__redirect_expm1, __expm1, IFUNC_SELECTOR ()); +libm_alias_double (__expm1, expm1) + +#define __expm1 __expm1_sse2 + +/* NB: __expm1 may be expanded to __expm1_sse2 in the following + prototypes. */ +extern long double __expm1l (long double); +extern long double __expm1f128 (long double); + +#include