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 4C49C3858C83 for ; Thu, 3 Nov 2022 12:14:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4C49C3858C83 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 _____8BxLtutsGNjNDoEAA--.14701S3; Thu, 03 Nov 2022 20:14:37 +0800 (CST) Received: from 5.5.5 (unknown [10.2.5.5]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Axf+CrsGNj2+0LAA--.34667S3; Thu, 03 Nov 2022 20:14:36 +0800 (CST) From: Xiaolin Tang To: adhemerval.zanella@linaro.org, libc-alpha@sourceware.org, caiyinyu@loongson.cn, i.swmail@xen0n.name Cc: xuchenghua@loongson.cn, Xiaolin Tang Subject: [PATCH 1/1] LoongArch: Hard Float Support Of Math Functions. Date: Thu, 3 Nov 2022 20:14:33 +0800 Message-Id: <20221103121433.2909287-2-tangxiaolin@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221103121433.2909287-1-tangxiaolin@loongson.cn> References: <20221103121433.2909287-1-tangxiaolin@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8Axf+CrsGNj2+0LAA--.34667S3 X-CM-SenderInfo: pwdqw5xldrzx3q6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvAXoWDCrWrtFWkuFy7Aw48tF4xWFg_yoWxZF15to WS9FW8Jr4xGrW8ur4fCayDA3y7WF12kr47Xw47ZrZ3KFyDG34UGFy0y3ZIg3srGrn8CF4k XFyfXa93ArW2gryxn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXasCq-sGcSsGvf J3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnRJU UUvFb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2IYs7xG6rWj6s 0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1l84 ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I8E87Iv6xkF7I0E14v26F4UJVW0owAS 0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMc02F40EFcxC0V AKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAFwI0_Jr0_Gr1l Ox8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28IcxkI7VAKI48JMxC20s 026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y6r17MI8I3I0E5I8CrVAFwI0_Jr0_ Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwI xGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8 JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcV C2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxU2nYFDUUUU X-Spam-Status: No, score=-11.8 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: This patch contains hardware floating-point support of math fuctions for the LoongArch ISA. LoongArch ISA has many hardware floating-point instructions that can be used in the corresponding math functions. instructions functions fma.{s/d} __fma{f/ } f{max/min}.{s/d}, fclass.{s/d} __f{max/min}i{mum/mum_mum}{f/ } f{maxa/mina}.{s/d} __f{max,min}mag{f/ } f{maxa/mina}.{s/d}, fclass.{s/d __f{max/min}imum{_mag/_mag_num}{f/ } fcopysign.{s/d __copysign{f/ } frint.{s/d} __{ /l/ll}rint{f/ } fscaleb.{s/d}, fclass.{s/d} __scalbn{f/ }, __ieee754__scalb{f/ } flogb.{s/d}, fclass.{s/d} __logb{f/ }, __ieee754_ilogb{f/ } fclass.{s/d} __fpclassify{f/ }, __issignaling{f/ } * sysdeps/loongarch/fpu/e_ilogb.c: New file. * sysdeps/loongarch/fpu/e_ilogbf.c: Likewise. * sysdeps/loongarch/fpu/e_scalb.c: Likewise. * sysdeps/loongarch/fpu/e_scalbf.c: Likewise. * sysdeps/loongarch/fpu/math-use-builtins-fma.h: Likewise. * sysdeps/loongarch/fpu/s_copysign.c: Likewise. * sysdeps/loongarch/fpu/s_copysignf.c: Likewise. * sysdeps/loongarch/fpu/s_fmaximum.c: Likewise. * sysdeps/loongarch/fpu/s_fmaximum_mag.c: Likewise. * sysdeps/loongarch/fpu/s_fmaximum_mag_num.c: Likewise. * sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c: Likewise. * sysdeps/loongarch/fpu/s_fmaximum_magf.c: Likewise. * sysdeps/loongarch/fpu/s_fmaximum_num.c: Likewise. * sysdeps/loongarch/fpu/s_fmaximum_numf.c: Likewise. * sysdeps/loongarch/fpu/s_fmaximumf.c: Likewise. * sysdeps/loongarch/fpu/s_fmaxmag.c: Likewise. * sysdeps/loongarch/fpu/s_fmaxmagf.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum_mag.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum_mag_num.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum_mag_numf.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum_magf.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum_num.c: Likewise. * sysdeps/loongarch/fpu/s_fminimum_numf.c: Likewise. * sysdeps/loongarch/fpu/s_fminimumf.c: Likewise. * sysdeps/loongarch/fpu/s_fminmag.c: Likewise. * sysdeps/loongarch/fpu/s_fminmagf.c: Likewise. * sysdeps/loongarch/fpu/s_fpclassify.c: Likewise. * sysdeps/loongarch/fpu/s_fpclassifyf.c: Likewise. * sysdeps/loongarch/fpu/s_issignaling.c: Likewise. * sysdeps/loongarch/fpu/s_issignalingf.c: Likewise. * sysdeps/loongarch/fpu/s_llrint.c: Likewise. * sysdeps/loongarch/fpu/s_llrintf.c: Likewise. * sysdeps/loongarch/fpu/s_logb.c: Likewise. * sysdeps/loongarch/fpu/s_logbf.c: Likewise. * sysdeps/loongarch/fpu/s_lrint.c: Likewise. * sysdeps/loongarch/fpu/s_lrintf.c: Likewise. * sysdeps/loongarch/fpu/s_rint.c: Likewise. * sysdeps/loongarch/fpu/s_rintf.c: Likewise. * sysdeps/loongarch/fpu/s_scalbn.c: Likewise. * sysdeps/loongarch/fpu/s_scalbnf.c: Likewise. * sysdeps/loongarch/fpu_control.h: Add _FCLASS_* macro. --- sysdeps/loongarch/fpu/e_ilogb.c | 37 +++++++++++ sysdeps/loongarch/fpu/e_ilogbf.c | 37 +++++++++++ sysdeps/loongarch/fpu/e_scalb.c | 61 +++++++++++++++++++ sysdeps/loongarch/fpu/e_scalbf.c | 61 +++++++++++++++++++ sysdeps/loongarch/fpu/math-use-builtins-fma.h | 4 ++ sysdeps/loongarch/fpu/s_copysign.c | 29 +++++++++ sysdeps/loongarch/fpu/s_copysignf.c | 29 +++++++++ sysdeps/loongarch/fpu/s_fmaximum.c | 38 ++++++++++++ sysdeps/loongarch/fpu/s_fmaximum_mag.c | 38 ++++++++++++ sysdeps/loongarch/fpu/s_fmaximum_mag_num.c | 47 ++++++++++++++ sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c | 47 ++++++++++++++ sysdeps/loongarch/fpu/s_fmaximum_magf.c | 38 ++++++++++++ sysdeps/loongarch/fpu/s_fmaximum_num.c | 47 ++++++++++++++ sysdeps/loongarch/fpu/s_fmaximum_numf.c | 47 ++++++++++++++ sysdeps/loongarch/fpu/s_fmaximumf.c | 38 ++++++++++++ sysdeps/loongarch/fpu/s_fmaxmag.c | 29 +++++++++ sysdeps/loongarch/fpu/s_fmaxmagf.c | 29 +++++++++ sysdeps/loongarch/fpu/s_fminimum.c | 38 ++++++++++++ sysdeps/loongarch/fpu/s_fminimum_mag.c | 38 ++++++++++++ sysdeps/loongarch/fpu/s_fminimum_mag_num.c | 47 ++++++++++++++ sysdeps/loongarch/fpu/s_fminimum_mag_numf.c | 47 ++++++++++++++ sysdeps/loongarch/fpu/s_fminimum_magf.c | 38 ++++++++++++ sysdeps/loongarch/fpu/s_fminimum_num.c | 47 ++++++++++++++ sysdeps/loongarch/fpu/s_fminimum_numf.c | 47 ++++++++++++++ sysdeps/loongarch/fpu/s_fminimumf.c | 38 ++++++++++++ sysdeps/loongarch/fpu/s_fminmag.c | 29 +++++++++ sysdeps/loongarch/fpu/s_fminmagf.c | 29 +++++++++ sysdeps/loongarch/fpu/s_fpclassify.c | 38 ++++++++++++ sysdeps/loongarch/fpu/s_fpclassifyf.c | 38 ++++++++++++ sysdeps/loongarch/fpu/s_issignaling.c | 29 +++++++++ sysdeps/loongarch/fpu/s_issignalingf.c | 29 +++++++++ sysdeps/loongarch/fpu/s_llrint.c | 29 +++++++++ sysdeps/loongarch/fpu/s_llrintf.c | 29 +++++++++ sysdeps/loongarch/fpu/s_logb.c | 30 +++++++++ sysdeps/loongarch/fpu/s_logbf.c | 30 +++++++++ sysdeps/loongarch/fpu/s_lrint.c | 29 +++++++++ sysdeps/loongarch/fpu/s_lrintf.c | 29 +++++++++ sysdeps/loongarch/fpu/s_rint.c | 29 +++++++++ sysdeps/loongarch/fpu/s_rintf.c | 29 +++++++++ sysdeps/loongarch/fpu/s_scalbn.c | 29 +++++++++ sysdeps/loongarch/fpu/s_scalbnf.c | 29 +++++++++ sysdeps/loongarch/fpu_control.h | 17 ++++++ 42 files changed, 1497 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/e_scalb.c create mode 100644 sysdeps/loongarch/fpu/e_scalbf.c create mode 100644 sysdeps/loongarch/fpu/math-use-builtins-fma.h create mode 100644 sysdeps/loongarch/fpu/s_copysign.c create mode 100644 sysdeps/loongarch/fpu/s_copysignf.c create mode 100644 sysdeps/loongarch/fpu/s_fmaximum.c create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_mag.c create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_mag_num.c create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c create mode 100644 sysdeps/loongarch/fpu/s_fmaximum_magf.c 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_fmaximumf.c create mode 100644 sysdeps/loongarch/fpu/s_fmaxmag.c create mode 100644 sysdeps/loongarch/fpu/s_fmaxmagf.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum_mag.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum_mag_num.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum_mag_numf.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum_magf.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum_num.c create mode 100644 sysdeps/loongarch/fpu/s_fminimum_numf.c create mode 100644 sysdeps/loongarch/fpu/s_fminimumf.c create mode 100644 sysdeps/loongarch/fpu/s_fminmag.c create mode 100644 sysdeps/loongarch/fpu/s_fminmagf.c create mode 100644 sysdeps/loongarch/fpu/s_fpclassify.c create mode 100644 sysdeps/loongarch/fpu/s_fpclassifyf.c create mode 100644 sysdeps/loongarch/fpu/s_issignaling.c create mode 100644 sysdeps/loongarch/fpu/s_issignalingf.c create mode 100644 sysdeps/loongarch/fpu/s_llrint.c create mode 100644 sysdeps/loongarch/fpu/s_llrintf.c create mode 100644 sysdeps/loongarch/fpu/s_logb.c create mode 100644 sysdeps/loongarch/fpu/s_logbf.c create mode 100644 sysdeps/loongarch/fpu/s_lrint.c create mode 100644 sysdeps/loongarch/fpu/s_lrintf.c create mode 100644 sysdeps/loongarch/fpu/s_rint.c create mode 100644 sysdeps/loongarch/fpu/s_rintf.c create mode 100644 sysdeps/loongarch/fpu/s_scalbn.c create mode 100644 sysdeps/loongarch/fpu/s_scalbnf.c diff --git a/sysdeps/loongarch/fpu/e_ilogb.c b/sysdeps/loongarch/fpu/e_ilogb.c new file mode 100644 index 0000000000..27a7dace29 --- /dev/null +++ b/sysdeps/loongarch/fpu/e_ilogb.c @@ -0,0 +1,37 @@ +/* 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 (x_cond & _FCLASS_ZERO ) + return FP_ILOGB0; + if (x_cond & ( _FCLASS_NAN | _FCLASS_INF)) + return FP_ILOGBNAN; + + 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..ed5ac99b6b --- /dev/null +++ b/sysdeps/loongarch/fpu/e_ilogbf.c @@ -0,0 +1,37 @@ +/* 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 (x_cond & _FCLASS_ZERO ) + return FP_ILOGB0; + if (x_cond & ( _FCLASS_NAN | _FCLASS_INF)) + return FP_ILOGBNAN; + + 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/e_scalb.c b/sysdeps/loongarch/fpu/e_scalb.c new file mode 100644 index 0000000000..e7fcfe86d0 --- /dev/null +++ b/sysdeps/loongarch/fpu/e_scalb.c @@ -0,0 +1,61 @@ +/* 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 (__builtin_expect(( x_cond | fn_cond) & _FCLASS_NAN, 0)) + return x * fn; + else if (__builtin_expect(fn_cond & _FCLASS_INF, 0)) + { + if (!(fn_cond & _FCLASS_MINF)) + return x * fn; + else + return x / -fn; + } + else if (__builtin_expect(-DBL_MAX < fn && fn < DBL_MAX, 1)) + { + long y1; + double y; + + asm volatile("frint.d \t%0, %1" : "=f" (y) : "f" (fn)); + asm volatile("ftintrz.l.d \t%0, %1" : "=f" (y) : "f" (y)); + asm volatile("movfr2gr.d \t%0, %1" : "=r" (y1) : "f" (y)); + + if (y1 != fn ) + return (x - x) / (x - x); + + asm volatile("fscaleb.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + } + 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..085a5a63bc --- /dev/null +++ b/sysdeps/loongarch/fpu/e_scalbf.c @@ -0,0 +1,61 @@ +/* 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 (__builtin_expect(( x_cond | fn_cond) & _FCLASS_NAN, 0)) + return x * fn; + else if (__builtin_expect(fn_cond & _FCLASS_INF, 0)) + { + if (!(fn_cond & _FCLASS_MINF)) + return x * fn; + else + return x / -fn; + } + else if (__builtin_expect(-FLT_MAX < fn && fn < FLT_MAX, 1)) + { + int y1; + float y; + + asm volatile("frint.s \t%0, %1" : "=f" (y) : "f" (fn)); + asm volatile("ftintrz.w.s \t%0, %1" : "=f" (y) : "f" (y)); + asm volatile("movfr2gr.s \t%0, %1" : "=r" (y1) : "f" (y)); + + if (y1 != fn ) + return (x - x) / (x - x); + + asm volatile("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + } + else + asm volatile("fscaleb.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (fn)); + + return x; +} +libm_alias_finite (__ieee754_scalb, __scalb) diff --git a/sysdeps/loongarch/fpu/math-use-builtins-fma.h b/sysdeps/loongarch/fpu/math-use-builtins-fma.h new file mode 100644 index 0000000000..eede75aa41 --- /dev/null +++ b/sysdeps/loongarch/fpu/math-use-builtins-fma.h @@ -0,0 +1,4 @@ +#define USE_FMA_BUILTIN 1 +#define USE_FMAF_BUILTIN 1 +#define USE_FMAL_BUILTIN 0 +#define USE_FMAF128_BUILTIN 0 diff --git a/sysdeps/loongarch/fpu/s_copysign.c b/sysdeps/loongarch/fpu/s_copysign.c new file mode 100644 index 0000000000..e850227549 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_copysign.c @@ -0,0 +1,29 @@ +/* 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 +__copysign (double x, double y) +{ + asm volatile("fcopysign.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_double (__copysign, copysign) diff --git a/sysdeps/loongarch/fpu/s_copysignf.c b/sysdeps/loongarch/fpu/s_copysignf.c new file mode 100644 index 0000000000..2047869359 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_copysignf.c @@ -0,0 +1,29 @@ +/* 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 +__copysignf (float x, float y) +{ + asm volatile("fcopysign.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_float (__copysign, copysign) diff --git a/sysdeps/loongarch/fpu/s_fmaximum.c b/sysdeps/loongarch/fpu/s_fmaximum.c new file mode 100644 index 0000000000..381a2839da --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum.c @@ -0,0 +1,38 @@ +/* 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 ((x_cond | y_cond) & _FCLASS_NAN) + return x * y; + + 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_fmaximum_mag.c b/sysdeps/loongarch/fpu/s_fmaximum_mag.c new file mode 100644 index 0000000000..e17fc76c25 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum_mag.c @@ -0,0 +1,38 @@ +/* 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 ((x_cond | y_cond) & _FCLASS_NAN) + return x * y; + + 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_mag_num.c b/sysdeps/loongarch/fpu/s_fmaximum_mag_num.c new file mode 100644 index 0000000000..b6002aefbd --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum_mag_num.c @@ -0,0 +1,47 @@ +/* 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_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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN)) + { + asm volatile("fmaxa.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + + if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN)) + { + asm volatile("fmaxa.d \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + + asm volatile("fmaxa.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_double (__fmaximum_mag_num, fmaximum_mag_num) diff --git a/sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c b/sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c new file mode 100644 index 0000000000..7790579555 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum_mag_numf.c @@ -0,0 +1,47 @@ +/* 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_mag_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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN)) + { + asm volatile("fmaxa.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + + if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN)) + { + asm volatile("fmaxa.s \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + + asm volatile("fmaxa.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_float (__fmaximum_mag_num, fmaximum_mag_num) diff --git a/sysdeps/loongarch/fpu/s_fmaximum_magf.c b/sysdeps/loongarch/fpu/s_fmaximum_magf.c new file mode 100644 index 0000000000..54c8b5da47 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum_magf.c @@ -0,0 +1,38 @@ +/* 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 ((x_cond | y_cond) & _FCLASS_NAN) + return x * y; + + 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_fmaximum_num.c b/sysdeps/loongarch/fpu/s_fmaximum_num.c new file mode 100644 index 0000000000..4b36ae800c --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum_num.c @@ -0,0 +1,47 @@ +/* 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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN)) + { + asm volatile("fmax.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + + if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN)) + { + asm volatile("fmax.d \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + + 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..75c7b9937f --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximum_numf.c @@ -0,0 +1,47 @@ +/* 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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN)) + { + asm volatile("fmax.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + + if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN)) + { + asm volatile("fmax.s \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + + 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_fmaximumf.c b/sysdeps/loongarch/fpu/s_fmaximumf.c new file mode 100644 index 0000000000..f6c7e629b6 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaximumf.c @@ -0,0 +1,38 @@ +/* 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 ((x_cond | y_cond) & _FCLASS_NAN) + return x * y; + + 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_fmaxmag.c b/sysdeps/loongarch/fpu/s_fmaxmag.c new file mode 100644 index 0000000000..3757c981de --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaxmag.c @@ -0,0 +1,29 @@ +/* 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 +__fmaxmag (double x, double y) +{ + asm volatile("fmaxa.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_double (__fmaxmag, fmaxmag) diff --git a/sysdeps/loongarch/fpu/s_fmaxmagf.c b/sysdeps/loongarch/fpu/s_fmaxmagf.c new file mode 100644 index 0000000000..fd826c03cc --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fmaxmagf.c @@ -0,0 +1,29 @@ +/* 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 +__fmaxmagf (float x, float y) +{ + asm volatile("fmaxa.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_float (__fmaxmag, fmaxmag) diff --git a/sysdeps/loongarch/fpu/s_fminimum.c b/sysdeps/loongarch/fpu/s_fminimum.c new file mode 100644 index 0000000000..526dced320 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum.c @@ -0,0 +1,38 @@ +/* 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 ((x_cond | y_cond) & _FCLASS_NAN) + return x * y; + + 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_fminimum_mag.c b/sysdeps/loongarch/fpu/s_fminimum_mag.c new file mode 100644 index 0000000000..2de6d4d9d8 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum_mag.c @@ -0,0 +1,38 @@ +/* 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 ((x_cond | y_cond) & _FCLASS_NAN) + return x * y; + + 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_mag_num.c b/sysdeps/loongarch/fpu/s_fminimum_mag_num.c new file mode 100644 index 0000000000..3f0e6d34b2 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum_mag_num.c @@ -0,0 +1,47 @@ +/* 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_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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN)) + { + asm volatile("fmina.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + + if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN)) + { + asm volatile("fmina.d \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + + asm volatile("fmina.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_double (__fminimum_mag_num, fminimum_mag_num) diff --git a/sysdeps/loongarch/fpu/s_fminimum_mag_numf.c b/sysdeps/loongarch/fpu/s_fminimum_mag_numf.c new file mode 100644 index 0000000000..f8146b0873 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum_mag_numf.c @@ -0,0 +1,47 @@ +/* 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_mag_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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN)) + { + asm volatile("fmina.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + + if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN)) + { + asm volatile("fmina.s \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + + asm volatile("fmina.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_float (__fminimum_mag_num, fminimum_mag_num) diff --git a/sysdeps/loongarch/fpu/s_fminimum_magf.c b/sysdeps/loongarch/fpu/s_fminimum_magf.c new file mode 100644 index 0000000000..214a6168ad --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum_magf.c @@ -0,0 +1,38 @@ +/* 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 ((x_cond | y_cond) & _FCLASS_NAN) + return x * y; + + asm volatile("fmina.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_float (__fminimum_mag, fminimum_mag) diff --git a/sysdeps/loongarch/fpu/s_fminimum_num.c b/sysdeps/loongarch/fpu/s_fminimum_num.c new file mode 100644 index 0000000000..0091286d12 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum_num.c @@ -0,0 +1,47 @@ +/* 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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN)) + { + asm volatile("fmin.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + + if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN)) + { + asm volatile("fmin.d \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + + 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..16f8414293 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimum_numf.c @@ -0,0 +1,47 @@ +/* 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 ((x_cond & _FCLASS_NAN) && !(y_cond & _FCLASS_NAN)) + { + asm volatile("fmin.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return y; + } + + if (!(x_cond & _FCLASS_NAN) && (y_cond & _FCLASS_NAN)) + { + asm volatile("fmin.s \t%0, %1, %2" : "=f" (y) : "f" (x), "f" (y)); + return x; + } + + asm volatile("fmin.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_float (__fminimum_num, fminimum_num) diff --git a/sysdeps/loongarch/fpu/s_fminimumf.c b/sysdeps/loongarch/fpu/s_fminimumf.c new file mode 100644 index 0000000000..1122db177e --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminimumf.c @@ -0,0 +1,38 @@ +/* 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 ((x_cond | y_cond) & _FCLASS_NAN) + return x * y; + + asm volatile("fmin.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_float (__fminimum, fminimum) diff --git a/sysdeps/loongarch/fpu/s_fminmag.c b/sysdeps/loongarch/fpu/s_fminmag.c new file mode 100644 index 0000000000..7b6e2915fe --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminmag.c @@ -0,0 +1,29 @@ +/* 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 +__fminmag (double x, double y) +{ + asm volatile("fmina.d \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_double (__fminmag, fminmag) diff --git a/sysdeps/loongarch/fpu/s_fminmagf.c b/sysdeps/loongarch/fpu/s_fminmagf.c new file mode 100644 index 0000000000..a93cec2e2b --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fminmagf.c @@ -0,0 +1,29 @@ +/* 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 +__fminmagf (float x, float y) +{ + asm volatile("fmina.s \t%0, %1, %2" : "=f" (x) : "f" (x), "f" (y)); + return x; +} +libm_alias_float (__fminmag, fminmag) diff --git a/sysdeps/loongarch/fpu/s_fpclassify.c b/sysdeps/loongarch/fpu/s_fpclassify.c new file mode 100644 index 0000000000..865436c9a2 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fpclassify.c @@ -0,0 +1,38 @@ +/* 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 + . */ + +#include +#include + +int +__fpclassify (double x) +{ + int cls; + asm volatile ("fclass.d \t%0, %1" : "=f" (cls) : "f" (x)); + + if (__builtin_expect (cls & _FCLASS_ZERO, _FCLASS_ZERO)) + return FP_ZERO; + if (__builtin_expect (cls & _FCLASS_SUBNORM, _FCLASS_SUBNORM)) + return FP_SUBNORMAL; + if (__builtin_expect (cls & _FCLASS_NAN, _FCLASS_NAN)) + return FP_NAN; + if (__builtin_expect (cls & _FCLASS_INF, _FCLASS_INF)) + return FP_INFINITE; + return FP_NORMAL; +} +libm_hidden_def (__fpclassify) diff --git a/sysdeps/loongarch/fpu/s_fpclassifyf.c b/sysdeps/loongarch/fpu/s_fpclassifyf.c new file mode 100644 index 0000000000..ca7b1d6703 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_fpclassifyf.c @@ -0,0 +1,38 @@ +/* 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 + . */ + +#include +#include + +int +__fpclassifyf (float x) +{ + int cls; + asm volatile ("fclass.s \t%0, %1" : "=f" (cls) : "f" (x)); + + if (__builtin_expect (cls & _FCLASS_NORM, _FCLASS_NORM)) + return FP_NORMAL; + if (__builtin_expect (cls & _FCLASS_ZERO, _FCLASS_ZERO)) + return FP_ZERO; + if (__builtin_expect (cls & _FCLASS_SUBNORM, _FCLASS_SUBNORM)) + return FP_SUBNORMAL; + if (__builtin_expect (cls & _FCLASS_INF, _FCLASS_INF)) + return FP_INFINITE; + return FP_NAN; +} +libm_hidden_def (__fpclassifyf) diff --git a/sysdeps/loongarch/fpu/s_issignaling.c b/sysdeps/loongarch/fpu/s_issignaling.c new file mode 100644 index 0000000000..d6525516e1 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_issignaling.c @@ -0,0 +1,29 @@ +/* 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 + . */ + +#include +#include + +int +__issignaling (double x) +{ + int x_cond; + asm volatile("fclass.d \t%0, %1" : "=f" (x_cond) : "f" (x)); + return (x_cond & _FCLASS_SNAN) != 0; +} +libm_hidden_def (__issignaling) diff --git a/sysdeps/loongarch/fpu/s_issignalingf.c b/sysdeps/loongarch/fpu/s_issignalingf.c new file mode 100644 index 0000000000..48c287c8e7 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_issignalingf.c @@ -0,0 +1,29 @@ +/* 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 + . */ + +#include +#include + +int +__issignalingf (float x) +{ + int x_cond; + asm volatile("fclass.s \t%0, %1" : "=f" (x_cond) : "f" (x)); + return (x_cond & _FCLASS_SNAN) != 0; +} +libm_hidden_def (__issignalingf) diff --git a/sysdeps/loongarch/fpu/s_llrint.c b/sysdeps/loongarch/fpu/s_llrint.c new file mode 100644 index 0000000000..0adaacf1c1 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_llrint.c @@ -0,0 +1,29 @@ +/* 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 + +long long int +__llrint (double x) +{ + asm volatile("frint.d \t%0, %1" : "=f" (x) : "f" (x)); + return x; +} +libm_alias_double (__llrint, llrint) diff --git a/sysdeps/loongarch/fpu/s_llrintf.c b/sysdeps/loongarch/fpu/s_llrintf.c new file mode 100644 index 0000000000..c0b0adaf69 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_llrintf.c @@ -0,0 +1,29 @@ +/* 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 + +long long int +__llrintf (float x) +{ + asm volatile("frint.s \t%0, %1" : "=f" (x) : "f" (x)); + return x; +} +libm_alias_float (__llrint, llrint) diff --git a/sysdeps/loongarch/fpu/s_logb.c b/sysdeps/loongarch/fpu/s_logb.c new file mode 100644 index 0000000000..44fd5d7c40 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_logb.c @@ -0,0 +1,30 @@ +/* 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..6c1ab23b5e --- /dev/null +++ b/sysdeps/loongarch/fpu/s_logbf.c @@ -0,0 +1,30 @@ +/* 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) diff --git a/sysdeps/loongarch/fpu/s_lrint.c b/sysdeps/loongarch/fpu/s_lrint.c new file mode 100644 index 0000000000..f4185f2271 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_lrint.c @@ -0,0 +1,29 @@ +/* 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 + +long int +__lrint (double x) +{ + asm volatile("frint.d \t%0, %1" : "=f" (x) : "f" (x)); + return x; +} +libm_alias_double (__lrint, lrint) diff --git a/sysdeps/loongarch/fpu/s_lrintf.c b/sysdeps/loongarch/fpu/s_lrintf.c new file mode 100644 index 0000000000..48197b21c4 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_lrintf.c @@ -0,0 +1,29 @@ +/* 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 + +long int +__lrintf (float x) +{ + asm volatile("frint.s \t%0, %1" : "=f" (x) : "f" (x)); + return x; +} +libm_alias_float (__lrint, lrint) diff --git a/sysdeps/loongarch/fpu/s_rint.c b/sysdeps/loongarch/fpu/s_rint.c new file mode 100644 index 0000000000..28638eb9e0 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_rint.c @@ -0,0 +1,29 @@ +/* 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 +__rint (double x) +{ + asm volatile("frint.d \t%0, %1" : "=f" (x) : "f" (x)); + return x; +} +libm_alias_double (__rint, rint) diff --git a/sysdeps/loongarch/fpu/s_rintf.c b/sysdeps/loongarch/fpu/s_rintf.c new file mode 100644 index 0000000000..ce3815f5e0 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_rintf.c @@ -0,0 +1,29 @@ +/* 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 +__rintf (float x) +{ + asm volatile("frint.s \t%0, %1" : "=f" (x) : "f" (x)); + return x; +} +libm_alias_float (__rint, rint) diff --git a/sysdeps/loongarch/fpu/s_scalbn.c b/sysdeps/loongarch/fpu/s_scalbn.c new file mode 100644 index 0000000000..4c4bbf8be9 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_scalbn.c @@ -0,0 +1,29 @@ +/* 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..ff6dc6d3f8 --- /dev/null +++ b/sysdeps/loongarch/fpu/s_scalbnf.c @@ -0,0 +1,29 @@ +/* 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; +} diff --git a/sysdeps/loongarch/fpu_control.h b/sysdeps/loongarch/fpu_control.h index f482395dba..13436335fe 100644 --- a/sysdeps/loongarch/fpu_control.h +++ b/sysdeps/loongarch/fpu_control.h @@ -97,6 +97,23 @@ extern void __loongarch_fpu_setcw (fpu_control_t) __THROW; /* Default control word set at startup. */ extern fpu_control_t __fpu_control; +# define _FCLASS_SNAN (1 << 0) +# define _FCLASS_QNAN (1 << 1) +# define _FCLASS_MINF (1 << 2) +# define _FCLASS_MNORM (1 << 3) +# define _FCLASS_MSUBNORM (1 << 4) +# define _FCLASS_MZERO (1 << 5) +# define _FCLASS_PINF (1 << 6) +# define _FCLASS_PNORM (1 << 7) +# define _FCLASS_PSUBNORM (1 << 8) +# define _FCLASS_PZERO (1 << 9) + +# define _FCLASS_ZERO (_FCLASS_MZERO | _FCLASS_PZERO) +# define _FCLASS_SUBNORM (_FCLASS_MSUBNORM | _FCLASS_PSUBNORM) +# define _FCLASS_NORM (_FCLASS_MNORM | _FCLASS_PNORM) +# define _FCLASS_INF (_FCLASS_MINF | _FCLASS_PINF) +# define _FCLASS_NAN (_FCLASS_SNAN | _FCLASS_QNAN) + #endif /* __loongarch_soft_float */ #endif /* fpu_control.h */ -- 2.36.0