From patchwork Mon Nov 7 14:08:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Tang X-Patchwork-Id: 60103 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 397063857BA2 for ; Mon, 7 Nov 2022 14:08:42 +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 07C8B3857B83 for ; Mon, 7 Nov 2022 14:08:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 07C8B3857B83 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 _____8DxOdhYEWlj7w0FAA--.14861S3; Mon, 07 Nov 2022 22:08:24 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Dx9VZXEWljTnoOAA--.21929S3; Mon, 07 Nov 2022 22:08:23 +0800 (CST) From: Xiaolin Tang To: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org, i.swmail@xen0n.name Cc: caiyinyu@loongson.cn, xry111@xry111.site, xuchenghua@loongson.cn, chenglulu@loongson.cn, Xiaolin Tang Subject: [PATCH v2 09/10] LoongArch: Hard Float Support for fmaximum_mag{f/ }, fminimum_mag{f/ }. Date: Mon, 7 Nov 2022 22:08:20 +0800 Message-Id: <20221107140821.898615-2-tangxiaolin@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221107140821.898615-1-tangxiaolin@loongson.cn> References: <20221107140821.898615-1-tangxiaolin@loongson.cn> MIME-Version: 1.0 X-CM-TRANS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42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r 4UJbIYCTnIWIevJa73UjIFyTuYvjxUIwIDUUUUU X-Spam-Status: No, score=-13.3 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" Use hardware Floating-point instruction f{maxa/mina}.{s/d}, fclass.{s/d} to implement fmaximum_mag{f/ }, fminimum_mag{f/ }. * sysdeps/loongarch/fpu/s_fmaximum_mag.c: New file. * sysdeps/loongarch/fpu/s_fmaximum_magf.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum_mag.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum_magf.c: Likewise. --- sysdeps/loongarch/fpu/s_fmaximum_mag.c | 40 +++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_fmaximum_magf.c | 40 +++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_fminimum_mag.c | 40 +++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_fminimum_magf.c | 40 +++++++++++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_mag.c create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_magf.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum_mag.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum_magf.c diff --git a/sysdeps/loongarch/fpu/s_fmaximum_mag.c b/sysdeps/loongarch/fpu/s_fmaximum_mag.c new file mode 100644 index 0000000000..5aed0603e6 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum_mag.c @@ -0,0 +1,40 @@ +/* fmaximum_mag(). 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 + +double +__fmaximum_mag (double x, double y) +{ + int x_cond; + int y_cond; + asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x)); + asm volatile ("fclass.d \t%0, %1" : "=f" (y_cond) : "f" (y)); + + if (__glibc_unlikely((x_cond | y_cond) & _FCLASS_NAN)) + return x * y; + else + { + asm volatile ("fmaxa.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_double (__fmaximum_mag, fmaximum_mag) diff --git a/sysdeps/loongarch/fpu/s_fmaximum_magf.c b/sysdeps/loongarch/fpu/s_fmaximum_magf.c new file mode 100644 index 0000000000..29beb88c22 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum_magf.c @@ -0,0 +1,40 @@ +/* fmaximum_magf(). 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 + +float +__fmaximum_magf (float x, float y) +{ + int x_cond; + int y_cond; + asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x)); + asm volatile ("fclass.s \t%0, %1" : "=f" (y_cond) : "f" (y)); + + if (__glibc_unlikely((x_cond | y_cond) & _FCLASS_NAN)) + return x * y; + else + { + asm volatile ("fmaxa.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_float (__fmaximum_mag, fmaximum_mag) diff --git a/sysdeps/loongarch/fpu/s_fminimum_mag.c b/sysdeps/loongarch/fpu/s_fminimum_mag.c new file mode 100644 index 0000000000..f477498d6e --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum_mag.c @@ -0,0 +1,40 @@ +/* fminimum_mag(). 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 + +double +__fminimum_mag (double x, double y) +{ + int x_cond; + int y_cond; + asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x)); + asm volatile ("fclass.d \t%0, %1" : "=f" (y_cond) : "f" (y)); + + if (__glibc_unlikely((x_cond | y_cond) & _FCLASS_NAN)) + return x * y; + else + { + asm volatile ("fmina.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_double (__fminimum_mag, fminimum_mag) diff --git a/sysdeps/loongarch/fpu/s_fminimum_magf.c b/sysdeps/loongarch/fpu/s_fminimum_magf.c new file mode 100644 index 0000000000..d0563fc255 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum_magf.c @@ -0,0 +1,40 @@ +/* fminimum_magf(). 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 + +float +__fminimum_magf (float x, float y) +{ + int x_cond; + int y_cond; + asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x)); + asm volatile ("fclass.s \t%0, %1" : "=f" (y_cond) : "f" (y)); + + if (__glibc_unlikely((x_cond | y_cond) & _FCLASS_NAN)) + return x * y; + else + { + asm volatile ("fmina.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_float (__fminimum_mag, fminimum_mag)