From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 29937 invoked from network); 28 Jul 2023 18:50:47 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 28 Jul 2023 18:50:47 -0000 Received: (qmail 1598 invoked by uid 550); 28 Jul 2023 18:50:44 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 1566 invoked from network); 28 Jul 2023 18:50:43 -0000 Date: Fri, 28 Jul 2023 14:50:34 -0400 From: Rich Felker To: zhangfei Cc: musl@lists.openwall.com, zhangfei Message-ID: <20230728185031.GR4163@brightrain.aerifal.cx> References: <20230728061955.20156-1-zhang_fei_0403@163.com> <20230728061955.20156-2-zhang_fei_0403@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230728061955.20156-2-zhang_fei_0403@163.com> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] [PATCH 1/1] RISC-V: Add some mathematical functions to riscv64 On Fri, Jul 28, 2023 at 02:19:55PM +0800, zhangfei wrote: > From: zhangfei > > Add a series of function implementations such as lrint and lround. > > Signed-off-by: Zhang Fei > --- > src/math/riscv64/llrint.c | 16 ++++++++++++++++ > src/math/riscv64/llrintf.c | 16 ++++++++++++++++ > src/math/riscv64/llround.c | 16 ++++++++++++++++ > src/math/riscv64/llroundf.c | 16 ++++++++++++++++ > src/math/riscv64/lrint.c | 16 ++++++++++++++++ > src/math/riscv64/lrintf.c | 16 ++++++++++++++++ > src/math/riscv64/lround.c | 16 ++++++++++++++++ > src/math/riscv64/lroundf.c | 16 ++++++++++++++++ > 8 files changed, 128 insertions(+) > create mode 100644 src/math/riscv64/llrint.c > create mode 100644 src/math/riscv64/llrintf.c > create mode 100644 src/math/riscv64/llround.c > create mode 100644 src/math/riscv64/llroundf.c > create mode 100644 src/math/riscv64/lrint.c > create mode 100644 src/math/riscv64/lrintf.c > create mode 100644 src/math/riscv64/lround.c > create mode 100644 src/math/riscv64/lroundf.c > > diff --git a/src/math/riscv64/llrint.c b/src/math/riscv64/llrint.c > new file mode 100644 > index 0000000..2b5ea25 > --- /dev/null > +++ b/src/math/riscv64/llrint.c > @@ -0,0 +1,16 @@ > +#include > + > +#if __riscv_flen >= 64 > + > +long long llrint (double x) > +{ > + long long res; > + __asm__ ("fcvt.l.d %0, %1" : "=r" (res) : "f" (x)); > + return res; > +} > + > +#else > + > +#include "../llrint.c" > + > +#endif > diff --git a/src/math/riscv64/llrintf.c b/src/math/riscv64/llrintf.c > new file mode 100644 > index 0000000..d69566b > --- /dev/null > +++ b/src/math/riscv64/llrintf.c > @@ -0,0 +1,16 @@ > +#include > + > +#if __riscv_flen >= 32 > + > +long long llrintf (float x) > +{ > + long long res; > + __asm__ ("fcvt.l.s %0, %1" : "=r" (res) : "f" (x)); > + return res; > +} > + > +#else > + > +#include "../llrintf.c" > + > +#endif > diff --git a/src/math/riscv64/llround.c b/src/math/riscv64/llround.c > new file mode 100644 > index 0000000..d6d2619 > --- /dev/null > +++ b/src/math/riscv64/llround.c > @@ -0,0 +1,16 @@ > +#include > + > +#if __riscv_flen >= 64 > + > +long long llround (double x) > +{ > + long long res; > + __asm__ ("fcvt.l.d %0, %1, rmm" : "=r" (res) : "f" (x)); > + return res; > +} > + > +#else > + > +#include "../llround.c" > + > +#endif This and all of the other lround() variants are almost surely wrong. AFAICT, as you've written them, they behave identically to the corresponding lrint variants. However they have very different rounding semantics. Please check that these instructions are right for what you're trying to use them for (for the lrint variants as well, tho I suspect they're right for that). Rich