From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id DA8903856952 for ; Mon, 7 Nov 2022 14:07:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DA8903856952 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 _____8DxTts7EWlj3Q0FAA--.16754S3; Mon, 07 Nov 2022 22:07:55 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxmFc6EWljRXoOAA--.22226S2; Mon, 07 Nov 2022 22:07:54 +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 07/10] LoongArch: Hard Float Support for fmaximum_num{f/ }, fminimum_num{f/ }. Date: Mon, 7 Nov 2022 22:07:48 +0800 Message-Id: <20221107140748.897997-1-tangxiaolin@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8BxmFc6EWljRXoOAA--.22226S2 X-CM-SenderInfo: pwdqw5xldrzx3q6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW3Xw17CF45Cr4xuF1DuryrXrb_yoW3KrW7pF W8urs8GF4xWrWfGF4S9ry2qF1FyFn7JFn8JasagFykuw10qr18XrZ2yasYq3W8J3s7uw1Y 9FWYkay3WF1xXr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b7kYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26F4UJVW0owA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr1j6rxdM2AI xVAIcxkEcVAq07x20xvEncxIr21l57IF6xkI12xvs2x26I8E6xACxx1l5I8CrVACY4xI64 kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1q6rW5McIj6I8E87Iv67AKxVW8JVWxJwAm 72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I 0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWU GVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI 0_Xr0_Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0 rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JVWxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r 4UJbIYCTnIWIevJa73UjIFyTuYvjxUcHUqUUUUU 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 List-Id: Use hardware Floating-point instruction f{max/min}.{s/d}, fclass.{s/d} to implement fmaximum_num{f/ }, fminimum_num{f/ }. * sysdeps/loongarch/fpu/s_fmaximum_num.c: New file. * sysdeps/loongarch/fpu/s_fmaximum_numf.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum_num.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum_numf.c: Likewise. --- sysdeps/loongarch/fpu/s_fmaximum_num.c | 48 ++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_fmaximum_numf.c | 49 +++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_fminimum_num.c | 48 ++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_fminimum_numf.c | 48 ++++++++++++++++++++++++ 4 files changed, 193 insertions(+) create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_num.c create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_numf.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum_num.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum_numf.c diff --git a/sysdeps/loongarch/fpu/s_fmaximum_num.c b/sysdeps/loongarch/fpu/s_fmaximum_num.c new file mode 100644 index 0000000000..142c65334c --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum_num.c @@ -0,0 +1,48 @@ +/* fmaximum_num(). 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_num (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 & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))) + { + asm volatile ("fmax.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + else if (__glibc_unlikely(!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))) + { + asm volatile ("fmax.d \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + else + { + asm volatile ("fmax.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_double (__fmaximum_num, fmaximum_num) diff --git a/sysdeps/loongarch/fpu/s_fmaximum_numf.c b/sysdeps/loongarch/fpu/s_fmaximum_numf.c new file mode 100644 index 0000000000..badf8f7e99 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum_numf.c @@ -0,0 +1,49 @@ +/* fmaximum_numf(). 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_numf (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 & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))) + { + asm volatile ("fmax.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + else if (__glibc_unlikely(!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))) + { + asm volatile ("fmax.s \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + else + { + asm volatile ("fmax.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_float (__fmaximum_num, fmaximum_num) diff --git a/sysdeps/loongarch/fpu/s_fminimum_num.c b/sysdeps/loongarch/fpu/s_fminimum_num.c new file mode 100644 index 0000000000..5d9680bea6 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum_num.c @@ -0,0 +1,48 @@ +/* fminimum_num(). 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_num (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 & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))) + { + asm volatile ("fmin.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + else if (__glibc_unlikely(!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))) + { + asm volatile ("fmin.d \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + else + { + asm volatile ("fmin.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_double (__fminimum_num, fminimum_num) diff --git a/sysdeps/loongarch/fpu/s_fminimum_numf.c b/sysdeps/loongarch/fpu/s_fminimum_numf.c new file mode 100644 index 0000000000..1610fe3263 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum_numf.c @@ -0,0 +1,48 @@ +/* fminimum_numf(). 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_numf (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 & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN))) + { + asm volatile ("fmin.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + else if (__glibc_unlikely(!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN))) + { + asm volatile ("fmin.s \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + else + { + asm volatile ("fmin.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; + } +} +libm_alias_float (__fminimum_num, fminimum_num) -- 2.36.0