From patchwork Wed Nov 23 02:38:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Tang X-Patchwork-Id: 61000 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D0D1E384F6F4 for ; Wed, 23 Nov 2022 02:39:22 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 8D7AE385782B for ; Wed, 23 Nov 2022 02:39:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D7AE385782B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.5]) by gateway (Coremail) with SMTP id _____8CxZPDEh31jXCcAAA--.445S3; Wed, 23 Nov 2022 10:39:00 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxoOK9h31jy3kYAA--.63733S5; Wed, 23 Nov 2022 10:38:59 +0800 (CST) From: Xiaolin Tang To: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org, caiyinyu@loongson.cn, xry111@xry111.site Cc: xuchenghua@loongson.cn, chenglulu@loongson.cn, Xiaolin Tang Subject: [PATCH 9/9] LoongArch: Add support for scalb[f] Date: Wed, 23 Nov 2022 10:38:51 +0800 Message-Id: <20221123023851.751187-4-tangxiaolin@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221123023851.751187-1-tangxiaolin@loongson.cn> References: <20221123023851.751187-1-tangxiaolin@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxoOK9h31jy3kYAA--.63733S5 X-CM-SenderInfo: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gr 0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07j8CztUUUUU= X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, 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: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Add inline assembler for the scalb functions. Passes GLIBC regression. --- sysdeps/loongarch/fpu/e_scalb.c | 60 ++++++++++++++++++++++++++++++++ sysdeps/loongarch/fpu/e_scalbf.c | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 sysdeps/loongarch/fpu/e_scalb.c create mode 100644 sysdeps/loongarch/fpu/e_scalbf.c diff --git a/sysdeps/loongarch/fpu/e_scalb.c b/sysdeps/loongarch/fpu/e_scalb.c new file mode 100644 index 0000000000..9fdf21fa3a --- /dev/null +++ b/sysdeps/loongarch/fpu/e_scalb.c @@ -0,0 +1,60 @@ +/* scalb(). LoongArch version. + Copyright (C) 2022 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 + . */ + +#define NO_MATH_REDIRECT +#include +#include +#include +#include + +double +__ieee754_scalb (double x, double fn) +{ + int x_cond; + int fn_cond; + asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x)); + asm volatile ("fclass.d \t%0, %1" : "=f" (fn_cond) : "f" (fn)); + + if (__glibc_unlikely(( x_cond | fn_cond) & _FCLASS_NAN)) + return x * fn; + else if (__glibc_unlikely(fn_cond & _FCLASS_INF)) + { + if (!(fn_cond & _FCLASS_MINF)) + return x * fn; + else + return x / -fn; + } + else if (__glibc_likely(-DBL_MAX < fn && fn < DBL_MAX)) + { + double rint_fn, tmp; + + /* rint_fn = rint(fn) */ + asm volatile ("frint.d \t%0, %1" : "=f" (rint_fn) : "f" (fn)); + + if (rint_fn != fn ) + return (x - x) / (x - x); + + asm volatile ("ftintrz.l.d \t%0, %1" : "=f" (tmp) : "f" (rint_fn)); + asm volatile ("fscaleb.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (tmp)); + } + else + asm volatile ("fscaleb.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (fn)); + + return x; +} +libm_alias_finite (__ieee754_scalb, __scalb) diff --git a/sysdeps/loongarch/fpu/e_scalbf.c b/sysdeps/loongarch/fpu/e_scalbf.c new file mode 100644 index 0000000000..fae2e92e20 --- /dev/null +++ b/sysdeps/loongarch/fpu/e_scalbf.c @@ -0,0 +1,60 @@ +/* scalbf(). LoongArch version. + Copyright (C) 2022 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 + . */ + +#define NO_MATH_REDIRECT +#include +#include +#include +#include + +float +__ieee754_scalbf (float x, float fn) +{ + int x_cond; + int fn_cond; + asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x)); + asm volatile ("fclass.s \t%0, %1" : "=f" (fn_cond) : "f" (fn)); + + if (__glibc_unlikely(( x_cond | fn_cond) & _FCLASS_NAN)) + return x * fn; + else if (__glibc_unlikely(fn_cond & _FCLASS_INF)) + { + if (!(fn_cond & _FCLASS_MINF)) + return x * fn; + else + return x / -fn; + } + else if (__glibc_likely(-FLT_MAX < fn && fn < FLT_MAX)) + { + float rintf_fn, tmp; + + /* rintf_fn = rintf(fn) */ + asm volatile ("frint.s \t%0, %1" : "=f" (rintf_fn) : "f" (fn)); + + if (rintf_fn != fn ) + return (x - x) / (x - x); + + asm volatile ("ftintrz.w.s \t%0, %1" : "=f" (tmp) : "f" (rintf_fn)); + asm volatile ("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (tmp)); + } + else + asm volatile ("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (fn)); + + return x; +} +libm_alias_finite (__ieee754_scalb, __scalb)