From patchwork Mon Nov 7 14:05:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Tang X-Patchwork-Id: 60100 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 016D638555A5 for ; Mon, 7 Nov 2022 14:06:35 +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 E10C73858403 for ; Mon, 7 Nov 2022 14:05:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E10C73858403 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 _____8Dx_7evEGljwA0FAA--.14988S3; Mon, 07 Nov 2022 22:05:35 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxb+KkEGljEHoOAA--.40708S8; Mon, 07 Nov 2022 22:05:34 +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 06/10] LoongArch: Hard Float Support for fmaximum{f/ }, fminimum{f/ }. Date: Mon, 7 Nov 2022 22:05:19 +0800 Message-Id: <20221107140523.896735-7-tangxiaolin@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221107140523.896735-1-tangxiaolin@loongson.cn> References: <20221107140523.896735-1-tangxiaolin@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cxb+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IxAIcVC2z280aVCY1x0267AKxVW8JV W8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8l38UUUUUU== X-Spam-Status: No, score=-13.2 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{max/min}.{s/d}, fclass.{s/d} to implement fmaximum{f/ }, fminimum{f/ }. * sysdeps/loongarch/fpu/s_fmaximum.c: New file. * sysdeps/loongarch/fpu/s_fmaximumf.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum.c: Likewise. * sysdeps/loongarch/fpu/s_fminimumf.c: Likewise. --- sysdeps/loongarch/fpu/s_fmaximum.c | 40 +++++++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_fmaximumf.c | 40 +++++++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_fminimum.c | 40 +++++++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_fminimumf.c | 40 +++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 sysdeps/loongarch/fpu/s_fmaximum.c create mode 100644 sysdeps/loongarch/fpu/s_fmaximumf.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum.c create mode 100644 sysdeps/loongarch/fpu/s_fminimumf.c diff --git a/sysdeps/loongarch/fpu/s_fmaximum.c b/sysdeps/loongarch/fpu/s_fmaximum.c new file mode 100644 index 0000000000..af1c2bf006 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum.c @@ -0,0 +1,40 @@ +/* fmaximum(). 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 (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 ("fmax.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_double (__fmaximum, fmaximum) diff --git a/sysdeps/loongarch/fpu/s_fmaximumf.c b/sysdeps/loongarch/fpu/s_fmaximumf.c new file mode 100644 index 0000000000..da4dcb6a3b --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximumf.c @@ -0,0 +1,40 @@ +/* fmaximumf(). 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 +__fmaximumf (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 ("fmax.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_float (__fmaximum, fmaximum) diff --git a/sysdeps/loongarch/fpu/s_fminimum.c b/sysdeps/loongarch/fpu/s_fminimum.c new file mode 100644 index 0000000000..e395ff7e62 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum.c @@ -0,0 +1,40 @@ +/* fminimum(). 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 (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 ("fmin.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_double (__fminimum, fminimum) diff --git a/sysdeps/loongarch/fpu/s_fminimumf.c b/sysdeps/loongarch/fpu/s_fminimumf.c new file mode 100644 index 0000000000..680c5e7e9a --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimumf.c @@ -0,0 +1,40 @@ +/* fminimumf(). 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 +__fminimumf (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 ("fmin.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_float (__fminimum, fminimum)