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 0CBA53858401 for ; Mon, 7 Nov 2022 14:05:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0CBA53858401 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 _____8Dxu9iuEGljtw0FAA--.16510S3; Mon, 07 Nov 2022 22:05:34 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxb+KkEGljEHoOAA--.40708S6; Mon, 07 Nov 2022 22:05:33 +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 04/10] LoongArch: Hard Float Support for functions logb{f/ }, __ieee754_ilogb{f/ }. Date: Mon, 7 Nov 2022 22:05:17 +0800 Message-Id: <20221107140523.896735-5-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 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8Cxb+KkEGljEHoOAA--.40708S6 X-CM-SenderInfo: pwdqw5xldrzx3q6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxuw1Uur47uF4xGFyrGFy3urg_yoWxAr1DpF Z5uF45GF4xGFWfGrWfur13ZF1rAFn3JF1Yg3W3G3y8uw1jqr18ursFy3sxW3W8J34xCw15 ZFW3Ca4UCFn5XaUanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b7AYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW8JVW5JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26F4UJVW0owAS 0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWrXwAv7VC2z280aVAFwI0_Gr0_Cr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s 026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_ JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14 v26r4j6ryUMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xva j40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JV W8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8l38UUUUUU== X-Spam-Status: No, score=-13.0 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 flogb.{s/d}, fclass.{s/d} to implement functions logb{f/ }, __ieee754_ilogb{f/ }. * sysdeps/loongarch/fpu/e_ilogb.c: New file. * sysdeps/loongarch/fpu/e_ilogbf.c: Likewise. * sysdeps/loongarch/fpu/s_logb.c: Likewise. * sysdeps/loongarch/fpu/s_logbf.c: Likewise. --- sysdeps/loongarch/fpu/e_ilogb.c | 39 ++++++++++++++++++++++++++++++++ sysdeps/loongarch/fpu/e_ilogbf.c | 39 ++++++++++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_logb.c | 30 ++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_logbf.c | 30 ++++++++++++++++++++++++ 4 files changed, 138 insertions(+) create mode 100644 sysdeps/loongarch/fpu/e_ilogb.c create mode 100644 sysdeps/loongarch/fpu/e_ilogbf.c create mode 100644 sysdeps/loongarch/fpu/s_logb.c create mode 100644 sysdeps/loongarch/fpu/s_logbf.c diff --git a/sysdeps/loongarch/fpu/e_ilogb.c b/sysdeps/loongarch/fpu/e_ilogb.c new file mode 100644 index 0000000000..f9ada6921a --- /dev/null +++ b/sysdeps/loongarch/fpu/e_ilogb.c @@ -0,0 +1,39 @@ +/* __ieee754_ilogb(). 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 + +int +__ieee754_ilogb (double x) +{ + int x_cond; + asm volatile ("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x)); + + if (__glibc_unlikely (x_cond & _FCLASS_ZERO)) + return FP_ILOGB0; + else if (__glibc_unlikely (x_cond & ( _FCLASS_NAN | _FCLASS_INF))) + return FP_ILOGBNAN; + else + { + asm volatile ("fabs.d \t%0, %1" : "=f" (x) : "f" (x)); + asm volatile ("flogb.d \t%0, %1" : "=f" (x) : "f" (x)); + return x; + } +} diff --git a/sysdeps/loongarch/fpu/e_ilogbf.c b/sysdeps/loongarch/fpu/e_ilogbf.c new file mode 100644 index 0000000000..e1da48ecfc --- /dev/null +++ b/sysdeps/loongarch/fpu/e_ilogbf.c @@ -0,0 +1,39 @@ +/* __ieee754_ilogbf(). 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 + +int +__ieee754_ilogbf (float x) +{ + int x_cond; + asm volatile ("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x)); + + if (__glibc_unlikely (x_cond & _FCLASS_ZERO)) + return FP_ILOGB0; + else if (__glibc_unlikely (x_cond & ( _FCLASS_NAN | _FCLASS_INF))) + return FP_ILOGBNAN; + else + { + asm volatile ("fabs.s \t%0, %1" : "=f" (x) : "f" (x)); + asm volatile ("flogb.s \t%0, %1" : "=f" (x) : "f" (x)); + return x; + } +} diff --git a/sysdeps/loongarch/fpu/s_logb.c b/sysdeps/loongarch/fpu/s_logb.c new file mode 100644 index 0000000000..31bb3be5c9 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_logb.c @@ -0,0 +1,30 @@ +/* logb(). 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 + +double +__logb (double x) +{ + asm volatile ("fabs.d \t%0, %1" : "=f" (x) : "f" (x)); + asm volatile ("flogb.d \t%0, %1" : "=f" (x) : "f" (x)); + return x; +} +libm_alias_double (__logb, logb) diff --git a/sysdeps/loongarch/fpu/s_logbf.c b/sysdeps/loongarch/fpu/s_logbf.c new file mode 100644 index 0000000000..f5166bcabd --- /dev/null +++ b/sysdeps/loongarch/fpu/s_logbf.c @@ -0,0 +1,30 @@ +/* logbf(). 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 + +float +__logbf (float x) +{ + asm volatile ("fabs.s \t%0, %1" : "=f" (x) : "f" (x)); + asm volatile ("flogb.s \t%0, %1" : "=f" (x) : "f" (x)); + return x; +} +libm_alias_float (__logb, logb) -- 2.36.0