From patchwork Fri Nov 18 11:30:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Tang X-Patchwork-Id: 60828 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 673BA384233F for ; Fri, 18 Nov 2022 11:30:57 +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 778A13839DB2 for ; Fri, 18 Nov 2022 11:30:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 778A13839DB2 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 _____8BxnrfjbHdjMZoIAA--.19462S3; Fri, 18 Nov 2022 19:30:43 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxn+DibHdjqn4WAA--.59241S2; Fri, 18 Nov 2022 19:30:42 +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 Subject: [PATCH 1/9] LoongArch: Use __builtin_rint{,f} with GCC >= 13 Date: Fri, 18 Nov 2022 19:30:40 +0800 Message-Id: <20221118113040.2502609-1-tangxiaolin@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8Cxn+DibHdjqn4WAA--.59241S2 X-CM-SenderInfo: pwdqw5xldrzx3q6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvdXoW7GryrZF43uw13KF1rtw45Awb_yoW3Krg_XF yfAryDGFWIy3WxXwsIvr98XFW8WFZYkFy3GFZ8Kr17Wr4kJr43JFZ7Ww1DZr1agFsFgFWf ZrW0yr1fZ34j9jkaLaAFLSUrUUUU8b8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrn0 xqx4xG64xvF2IEw4CE5I8CrVC2j2Jv73VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UUUY g7kC6x804xWl14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3w AFIxvE14AKwVWUGVWUXwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK 6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j6F4UM28EF7 xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr1j6rxdM2kK e7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI 0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWrXwAv7VC2z280 aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y6r17MI8I3I0E 5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAV WUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY 1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI 0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7I U8N6pPUUUUU== X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, 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" From: Xi Ruoyao GCC 13 compiles these built-ins to frint.{d,s} instruction. Link: https://gcc.gnu.org/r13-3919 --- sysdeps/loongarch/fpu/math-use-builtins-rint.h | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-rint.h diff --git a/sysdeps/loongarch/fpu/math-use-builtins-rint.h b/sysdeps/loongarch/fpu/math-use-builtins-rint.h new file mode 100644 index 0000000000..cd91482f5f --- /dev/null +++ b/sysdeps/loongarch/fpu/math-use-builtins-rint.h @@ -0,0 +1,9 @@ +#if __GNUC_PREREQ (13, 0) +# define USE_RINT_BUILTIN 1 +# define USE_RINTF_BUILTIN 1 +#else +# define USE_RINT_BUILTIN 0 +# define USE_RINTF_BUILTIN 0 +#endif +#define USE_RINTL_BUILTIN 0 +#define USE_RINTF128_BUILTIN 0 From patchwork Fri Nov 18 11:32:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Tang X-Patchwork-Id: 60829 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 89D2F38432F5 for ; Fri, 18 Nov 2022 11:32:49 +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 C716D385781F for ; Fri, 18 Nov 2022 11:32:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C716D385781F 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 _____8Cx7NhTbXdjRZoIAA--.24400S3; Fri, 18 Nov 2022 19:32:35 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxNldSbXdjzn4WAA--.40985S2; Fri, 18 Nov 2022 19:32:34 +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 8/9] LoongArch: Add support for scalbn[f] Date: Fri, 18 Nov 2022 19:32:32 +0800 Message-Id: <20221118113232.2503753-1-tangxiaolin@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxNldSbXdjzn4WAA--.40985S2 X-CM-SenderInfo: pwdqw5xldrzx3q6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxJFy3Gw1xWr4xuw4fArykuFg_yoW5Cw4fpF W3ur45GF4xGr1fCrWfW3W5X3WrGFn5JF1YgF13Gr4UJw1Dtry0qrsF93s8Wa4rJw1xC3yj vFWY9a4DGFn7XaUanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b7AYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26F4UJVW0owAS 0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWrXwAv7VC2z280aVAFwI0_Gr0_Cr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s 026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_ JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14 v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xva j40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JV W8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU84xRDUUUUU== 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 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 scalbn functions. Passes GLIBC regression. GCC 13, LoongArch support ___builtin_scalbn{,f} with -fno-math-errno, but only "libm" can use -fno-math-errno in GLIBC, and scalbn is in libc instead of libm because __printf_fp calls it. --- sysdeps/loongarch/fpu/s_scalbn.c | 29 +++++++++++++++++++++++++++++ sysdeps/loongarch/fpu/s_scalbnf.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 sysdeps/loongarch/fpu/s_scalbn.c create mode 100644 sysdeps/loongarch/fpu/s_scalbnf.c diff --git a/sysdeps/loongarch/fpu/s_scalbn.c b/sysdeps/loongarch/fpu/s_scalbn.c new file mode 100644 index 0000000000..c03e81a31e --- /dev/null +++ b/sysdeps/loongarch/fpu/s_scalbn.c @@ -0,0 +1,29 @@ +/* scalbn(). 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 + +double +__scalbn (double x, int fn) +{ + double tmp; + asm volatile ("movgr2fr.d \t%0, %1" : "=f" (tmp) : "r" (fn)); + asm volatile ("fscaleb.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (tmp)); + return x; +} diff --git a/sysdeps/loongarch/fpu/s_scalbnf.c b/sysdeps/loongarch/fpu/s_scalbnf.c new file mode 100644 index 0000000000..15e6428044 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_scalbnf.c @@ -0,0 +1,29 @@ +/* scalbnf(). 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 + +float +__scalbnf (float x, int fn) +{ + float tmp; + asm volatile ("movgr2fr.w \t%0, %1" : "=f" (tmp) : "r" (fn)); + asm volatile ("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (tmp)); + return x; +} From patchwork Fri Nov 18 11:32:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolin Tang X-Patchwork-Id: 60830 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 A14F0383F2FD for ; Fri, 18 Nov 2022 11:33:05 +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 23EE638432FF for ; Fri, 18 Nov 2022 11:32:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 23EE638432FF 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 _____8BxXbdgbXdjSpoIAA--.15052S3; Fri, 18 Nov 2022 19:32:48 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxHuJgbXdjz34WAA--.59300S2; Fri, 18 Nov 2022 19:32:48 +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: Fri, 18 Nov 2022 19:32:46 +0800 Message-Id: <20221118113246.2503967-1-tangxiaolin@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxHuJgbXdjz34WAA--.59300S2 X-CM-SenderInfo: pwdqw5xldrzx3q6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoWxZw1fZw4kKFy8ZF4kuFWDCFg_yoWruFWrpF WruF45GF48Kr13GFWIvF1ag3WrCF1fGF15JFnxWw1xXw12qr1vgr4qkwn8Wa4xJa97ua1U ZFZ0kayUC3WxXr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b7AYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26F4UJVW0owAS 0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWrXwAv7VC2z280aVAFwI0_Gr0_Cr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s 026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_ JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14 v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xva j40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8JV W8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8QJ57UUUUU== 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 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)