From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by sourceware.org (Postfix) with ESMTPS id BB02C3858D1E for ; Thu, 3 Nov 2022 12:43:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB02C3858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x229.google.com with SMTP id b124so1792716oia.4 for ; Thu, 03 Nov 2022 05:43:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=9YZ/ttBs52Y270qwix6QzXPx8yIenIWw3iBsXibALD0=; b=k8x/omaDTppmbUnt1J4FJzVJnNuvqiY4ZaOG9cGkyhcyNYtzV7C0Zqzg+/va8y6DVZ 8UMb0if+M7I8hh1tkU1W0dog+c8IL2v8REhdsLvy3HRYzjoNdYxewYnuwbnKPhV3giiv 25g/zI28S3QtaG9M7HZZtHEpwYg8qaUNLNuHZQ3SHq5d8gNwdbSB0vcMI0OzVsIufgT8 AycJ6xDnXuuZh/VKTsBseM2oD4x3Mom7PLUYQFy5ZrSkMtnjWoBhg32GY3w+crYXbBtU a3bpPldfUulIlGrlgCsm9VdbVxXONwKOo1yOPPgASYb2xaZn4PcTV8wKnx+iVb7L2pOf Pm2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9YZ/ttBs52Y270qwix6QzXPx8yIenIWw3iBsXibALD0=; b=WUf+gh8WIZumOAkA62w6tH1+kARZoF3UjyliVoMH3ilfr2duW9dxRnJT4ivWUMMgTf Jbk4bEQl8pqGErQngIBdctzsuybTAqldWQBC3ODcV0oHsGF8cR/R1g3vCXze8kiAXXu8 XvBcBglgWPHSIsyQ2rDqpkiC85YY7PvJ4sz2iuKh5REbAUQmek5E1/iGfGORJL02DwnU 8NtsBddXjHRFJBgRFrzh8yxoRCVYQpuT+oYZ46h0tixs6gPpvGxAeAPkAvZz9qN8TUXY ZW1qUEkZrbO0eX0KPDyAhnbAIeXispaIUeZmhbYQlb2WjbMFzyku4eBtGXGtyCB6/qMs TepQ== X-Gm-Message-State: ACrzQf3Jbt4IpjiB65lq7Bo173JUDL48LUJhzOcLFJu8MGKzCTyUWZE+ U3qc+XZz+F5ZloueCbhO2l68OdPjEUt2wyJA X-Google-Smtp-Source: AMsMyM66hwtkQ/cvdo510wtg3w8xIks8xU7zHESPv9XxJ+jz51Js2N8BtwLeMf7JgOgvG4GderD9hQ== X-Received: by 2002:a05:6808:16a6:b0:351:7211:6192 with SMTP id bb38-20020a05680816a600b0035172116192mr15973704oib.251.1667479383809; Thu, 03 Nov 2022 05:43:03 -0700 (PDT) Received: from ?IPV6:2804:1b3:a7c0:a9f4:4405:8c19:a65e:e640? ([2804:1b3:a7c0:a9f4:4405:8c19:a65e:e640]) by smtp.gmail.com with ESMTPSA id l19-20020a9d4c13000000b0066c49ce8b77sm258250otf.77.2022.11.03.05.43.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Nov 2022 05:43:03 -0700 (PDT) Message-ID: <314832e8-4db6-ad12-b8e4-bd766cadc551@linaro.org> Date: Thu, 3 Nov 2022 09:42:59 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH 1/1] LoongArch: Hard Float Support Of Math Functions. Content-Language: en-US To: Xiaolin Tang , libc-alpha@sourceware.org, caiyinyu@loongson.cn, i.swmail@xen0n.name Cc: xuchenghua@loongson.cn References: <20221103121433.2909287-1-tangxiaolin@loongson.cn> <20221103121433.2909287-2-tangxiaolin@loongson.cn> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <20221103121433.2909287-2-tangxiaolin@loongson.cn> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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: On 03/11/22 09:14, Xiaolin Tang wrote: > 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/ } GCC already implements a generic builtin copysign that expands it without a libcall, I prefer to implement it on compiler (which I presume it will be on 13, since on gcc 12 I do see fcopysign.d). I will send a patch to remove the RISCV version as well. > 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/ } > The rest looks ok, although for the max/min/ilog/log/fpclassify/issignalling function I would expect that eventually compiler will start to provide builtins and optimize the calls without the need of libc. Specially because glibc itself uses a lot of such symbols internally, so we will need compiler support to avoid using internal hacks such math_private.h. Also please split the patch to have one for each symbol (it make sense to pack version for different floating types in one patch). Besides it, replace __builtin_expect with __glibc_likely and add a brief description on each file header. There are also minor style issues, such missing space after 'volatile' asm directive. > * 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 */