From: Rich Felker <dalias@libc.org>
To: zhangfei <zhang_fei_0403@163.com>
Cc: musl@lists.openwall.com, zhangfei <zhangfei@nj.iscas.ac.cn>
Subject: Re: [musl] [PATCH 1/1] RISC-V: Add some mathematical functions to riscv64
Date: Fri, 28 Jul 2023 14:50:34 -0400 [thread overview]
Message-ID: <20230728185031.GR4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <20230728061955.20156-2-zhang_fei_0403@163.com>
On Fri, Jul 28, 2023 at 02:19:55PM +0800, zhangfei wrote:
> From: zhangfei <zhangfei@nj.iscas.ac.cn>
>
> Add a series of function implementations such as lrint and lround.
>
> Signed-off-by: Zhang Fei<zhangfei@nj.iscas.ac.cn>
> ---
> 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 <math.h>
> +
> +#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 <math.h>
> +
> +#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 <math.h>
> +
> +#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
prev parent reply other threads:[~2023-07-28 18:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-28 6:19 [musl] [PATCH 0/1] RISC-V: Add math functions zhangfei
2023-07-28 6:19 ` [musl] [PATCH 1/1] RISC-V: Add some mathematical functions to riscv64 zhangfei
2023-07-28 16:46 ` Khem Raj
2023-07-28 18:50 ` Rich Felker [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230728185031.GR4163@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=musl@lists.openwall.com \
--cc=zhang_fei_0403@163.com \
--cc=zhangfei@nj.iscas.ac.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).