* [musl] [PATCH 0/1] RISC-V: Add math functions
@ 2023-07-28 6:19 zhangfei
2023-07-28 6:19 ` [musl] [PATCH 1/1] RISC-V: Add some mathematical functions to riscv64 zhangfei
0 siblings, 1 reply; 4+ messages in thread
From: zhangfei @ 2023-07-28 6:19 UTC (permalink / raw)
To: musl; +Cc: dalias, zhangfei
From: zhangfei <zhangfei@nj.iscas.ac.cn>
Hi,
I added 8 math function implementations for riscv64.These functions
are implemented using riscv floating-point instructions instead of C
implementations.There is a similar implementation in glibc:
[1] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/riscv/rv64/rvd/s_llrint.c;h=0fbe8e2d68977f05e2f37a2dc52e00ce005c37b8;hb=HEAD
[2] https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/riscv/rv64/rvd/s_llround.c;h=f3c6275c9f9b81e9c4ce626be0d379c005eee986;hb=HEAD
...
I used libc-test on the RISC-V SiFive U74 to do the test,and there was
no error in lrint and other test items.
Thanks,
Zhang Fei
zhangfei (1):
RISC-V: Add some mathematical functions to riscv64
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [musl] [PATCH 1/1] RISC-V: Add some mathematical functions to riscv64
2023-07-28 6:19 [musl] [PATCH 0/1] RISC-V: Add math functions zhangfei
@ 2023-07-28 6:19 ` zhangfei
2023-07-28 16:46 ` Khem Raj
2023-07-28 18:50 ` Rich Felker
0 siblings, 2 replies; 4+ messages in thread
From: zhangfei @ 2023-07-28 6:19 UTC (permalink / raw)
To: musl; +Cc: dalias, zhangfei
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
diff --git a/src/math/riscv64/llroundf.c b/src/math/riscv64/llroundf.c
new file mode 100644
index 0000000..72b343a
--- /dev/null
+++ b/src/math/riscv64/llroundf.c
@@ -0,0 +1,16 @@
+#include <math.h>
+
+#if __riscv_flen >= 32
+
+long long llroundf (float x)
+{
+ long long res;
+ __asm__ ("fcvt.l.s %0, %1, rmm" : "=r" (res) : "f" (x));
+ return res;
+}
+
+#else
+
+#include "../llroundf.c"
+
+#endif
diff --git a/src/math/riscv64/lrint.c b/src/math/riscv64/lrint.c
new file mode 100644
index 0000000..c62e306
--- /dev/null
+++ b/src/math/riscv64/lrint.c
@@ -0,0 +1,16 @@
+#include <math.h>
+
+#if __riscv_flen >= 64
+
+long lrint (double x)
+{
+ long res;
+ __asm__ ("fcvt.l.d %0, %1" : "=r" (res) : "f" (x));
+ return res;
+}
+
+#else
+
+#include "../lrint.c"
+
+#endif
diff --git a/src/math/riscv64/lrintf.c b/src/math/riscv64/lrintf.c
new file mode 100644
index 0000000..6f3b120
--- /dev/null
+++ b/src/math/riscv64/lrintf.c
@@ -0,0 +1,16 @@
+#include <math.h>
+
+#if __riscv_flen >= 32
+
+long lrintf (float x)
+{
+ long res;
+ __asm__ ("fcvt.l.s %0, %1" : "=r" (res) : "f" (x));
+ return res;
+}
+
+#else
+
+#include "../lrintf.c"
+
+#endif
diff --git a/src/math/riscv64/lround.c b/src/math/riscv64/lround.c
new file mode 100644
index 0000000..7d061e8
--- /dev/null
+++ b/src/math/riscv64/lround.c
@@ -0,0 +1,16 @@
+#include <math.h>
+
+#if __riscv_flen >= 64
+
+long lround (double x)
+{
+ long res;
+ __asm__ ("fcvt.l.d %0, %1, rmm" : "=r" (res) : "f" (x));
+ return res;
+}
+
+#else
+
+#include "../lround.c"
+
+#endif
diff --git a/src/math/riscv64/lroundf.c b/src/math/riscv64/lroundf.c
new file mode 100644
index 0000000..34d978b
--- /dev/null
+++ b/src/math/riscv64/lroundf.c
@@ -0,0 +1,16 @@
+#include <math.h>
+
+#if __riscv_flen >= 32
+
+long lroundf (float x)
+{
+ long res;
+ __asm__ ("fcvt.l.s %0, %1, rmm" : "=r" (res) : "f" (x));
+ return res;
+}
+
+#else
+
+#include "../lroundf.c"
+
+#endif
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [musl] [PATCH 1/1] RISC-V: Add some mathematical functions to riscv64
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
1 sibling, 0 replies; 4+ messages in thread
From: Khem Raj @ 2023-07-28 16:46 UTC (permalink / raw)
To: musl; +Cc: dalias, zhangfei
On Thu, Jul 27, 2023 at 11:21 PM zhangfei <zhang_fei_0403@163.com> wrote:
>
> From: zhangfei <zhangfei@nj.iscas.ac.cn>
>
> Add a series of function implementations such as lrint and lround.
>
Do you have some performance numbers with these implementations to share ?
> 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
> diff --git a/src/math/riscv64/llroundf.c b/src/math/riscv64/llroundf.c
> new file mode 100644
> index 0000000..72b343a
> --- /dev/null
> +++ b/src/math/riscv64/llroundf.c
> @@ -0,0 +1,16 @@
> +#include <math.h>
> +
> +#if __riscv_flen >= 32
> +
> +long long llroundf (float x)
> +{
> + long long res;
> + __asm__ ("fcvt.l.s %0, %1, rmm" : "=r" (res) : "f" (x));
> + return res;
> +}
> +
> +#else
> +
> +#include "../llroundf.c"
> +
> +#endif
> diff --git a/src/math/riscv64/lrint.c b/src/math/riscv64/lrint.c
> new file mode 100644
> index 0000000..c62e306
> --- /dev/null
> +++ b/src/math/riscv64/lrint.c
> @@ -0,0 +1,16 @@
> +#include <math.h>
> +
> +#if __riscv_flen >= 64
> +
> +long lrint (double x)
> +{
> + long res;
> + __asm__ ("fcvt.l.d %0, %1" : "=r" (res) : "f" (x));
> + return res;
> +}
> +
> +#else
> +
> +#include "../lrint.c"
> +
> +#endif
> diff --git a/src/math/riscv64/lrintf.c b/src/math/riscv64/lrintf.c
> new file mode 100644
> index 0000000..6f3b120
> --- /dev/null
> +++ b/src/math/riscv64/lrintf.c
> @@ -0,0 +1,16 @@
> +#include <math.h>
> +
> +#if __riscv_flen >= 32
> +
> +long lrintf (float x)
> +{
> + long res;
> + __asm__ ("fcvt.l.s %0, %1" : "=r" (res) : "f" (x));
> + return res;
> +}
> +
> +#else
> +
> +#include "../lrintf.c"
> +
> +#endif
> diff --git a/src/math/riscv64/lround.c b/src/math/riscv64/lround.c
> new file mode 100644
> index 0000000..7d061e8
> --- /dev/null
> +++ b/src/math/riscv64/lround.c
> @@ -0,0 +1,16 @@
> +#include <math.h>
> +
> +#if __riscv_flen >= 64
> +
> +long lround (double x)
> +{
> + long res;
> + __asm__ ("fcvt.l.d %0, %1, rmm" : "=r" (res) : "f" (x));
> + return res;
> +}
> +
> +#else
> +
> +#include "../lround.c"
> +
> +#endif
> diff --git a/src/math/riscv64/lroundf.c b/src/math/riscv64/lroundf.c
> new file mode 100644
> index 0000000..34d978b
> --- /dev/null
> +++ b/src/math/riscv64/lroundf.c
> @@ -0,0 +1,16 @@
> +#include <math.h>
> +
> +#if __riscv_flen >= 32
> +
> +long lroundf (float x)
> +{
> + long res;
> + __asm__ ("fcvt.l.s %0, %1, rmm" : "=r" (res) : "f" (x));
> + return res;
> +}
> +
> +#else
> +
> +#include "../lroundf.c"
> +
> +#endif
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [musl] [PATCH 1/1] RISC-V: Add some mathematical functions to riscv64
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
1 sibling, 0 replies; 4+ messages in thread
From: Rich Felker @ 2023-07-28 18:50 UTC (permalink / raw)
To: zhangfei; +Cc: musl, zhangfei
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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-07-28 18:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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).