public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/2] Fixes for big endian RISC-V
@ 2021-02-23 21:31 Marcus Comstedt
  2021-02-23 21:31 ` [PATCH 1/2] Set __IEEE_BIG_ENDIAN " Marcus Comstedt
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Marcus Comstedt @ 2021-02-23 21:31 UTC (permalink / raw)
  To: newlib

Hi.

These are two fixes needed for newlib to work correctly on big endian
RISC-V, support for which is currently being added to gcc.


  // Marcus


--

 newlib/libc/include/machine/ieeefp.h |  4 ++++
 newlib/libc/machine/riscv/strcmp.S   | 40 ++++++++++++++++++++++++++++++++----
 2 files changed, 40 insertions(+), 4 deletions(-)


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] Set __IEEE_BIG_ENDIAN for big endian RISC-V
  2021-02-23 21:31 [PATCH 0/2] Fixes for big endian RISC-V Marcus Comstedt
@ 2021-02-23 21:31 ` Marcus Comstedt
  2021-02-23 21:31 ` [PATCH 2/2] RISC-V: Fix optimized strcmp on big endian Marcus Comstedt
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Marcus Comstedt @ 2021-02-23 21:31 UTC (permalink / raw)
  To: newlib; +Cc: Marcus Comstedt

---
 newlib/libc/include/machine/ieeefp.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/newlib/libc/include/machine/ieeefp.h b/newlib/libc/include/machine/ieeefp.h
index 4dc13828c..3c1f41e03 100644
--- a/newlib/libc/include/machine/ieeefp.h
+++ b/newlib/libc/include/machine/ieeefp.h
@@ -199,7 +199,11 @@
 #endif
 
 #ifdef __riscv
+#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+#define __IEEE_BIG_ENDIAN
+#else
 #define __IEEE_LITTLE_ENDIAN
+#endif
 #ifdef __riscv_flen
 # define _SUPPORTS_ERREXCEPT
 #endif
-- 
2.26.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] RISC-V: Fix optimized strcmp on big endian
  2021-02-23 21:31 [PATCH 0/2] Fixes for big endian RISC-V Marcus Comstedt
  2021-02-23 21:31 ` [PATCH 1/2] Set __IEEE_BIG_ENDIAN " Marcus Comstedt
@ 2021-02-23 21:31 ` Marcus Comstedt
  2021-02-25  9:21 ` [PATCH 0/2] Fixes for big endian RISC-V Kito Cheng
  2021-02-25 11:15 ` Corinna Vinschen
  3 siblings, 0 replies; 5+ messages in thread
From: Marcus Comstedt @ 2021-02-23 21:31 UTC (permalink / raw)
  To: newlib; +Cc: Marcus Comstedt

---
 newlib/libc/machine/riscv/strcmp.S | 40 +++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/newlib/libc/machine/riscv/strcmp.S b/newlib/libc/machine/riscv/strcmp.S
index eaf6d4b3c..9af9ca1f3 100644
--- a/newlib/libc/machine/riscv/strcmp.S
+++ b/newlib/libc/machine/riscv/strcmp.S
@@ -11,10 +11,6 @@
 
 #include <sys/asm.h>
 
-#if BYTE_ORDER != LITTLE_ENDIAN
-# error
-#endif
-
 .text
 .globl strcmp
 .type  strcmp, @function
@@ -96,6 +92,9 @@ strcmp:
 
 .Lmismatch:
   # words don't match, but a2 has no null byte.
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+
 #if __riscv_xlen == 64
   sll   a4, a2, 48
   sll   a5, a3, 48
@@ -128,6 +127,39 @@ strcmp:
   sub   a0, a4, a5
   ret
 
+#else
+
+#if __riscv_xlen == 64
+  srl   a4, a2, 48
+  srl   a5, a3, 48
+  bne   a4, a5, .Lmismatch_lower
+  srl   a4, a2, 32
+  srl   a5, a3, 32
+  bne   a4, a5, .Lmismatch_lower
+#endif
+  srl   a4, a2, 16
+  srl   a5, a3, 16
+  bne   a4, a5, .Lmismatch_lower
+
+  srl	a4, a2, 8
+  srl   a5, a3, 8
+  bne   a4, a5, 1f
+  and   a4, a2, 0xff
+  and   a5, a3, 0xff
+1:sub	a0, a4, a5
+  ret
+
+.Lmismatch_lower:
+  srl	a2, a4, 8
+  srl   a3, a5, 8
+  bne   a2, a3, 1f
+  and   a2, a4, 0xff
+  and   a3, a5, 0xff
+1:sub	a0, a2, a3
+  ret
+
+#endif
+	
 .Lmisaligned:
   # misaligned
   lbu   a2, 0(a0)
-- 
2.26.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] Fixes for big endian RISC-V
  2021-02-23 21:31 [PATCH 0/2] Fixes for big endian RISC-V Marcus Comstedt
  2021-02-23 21:31 ` [PATCH 1/2] Set __IEEE_BIG_ENDIAN " Marcus Comstedt
  2021-02-23 21:31 ` [PATCH 2/2] RISC-V: Fix optimized strcmp on big endian Marcus Comstedt
@ 2021-02-25  9:21 ` Kito Cheng
  2021-02-25 11:15 ` Corinna Vinschen
  3 siblings, 0 replies; 5+ messages in thread
From: Kito Cheng @ 2021-02-25  9:21 UTC (permalink / raw)
  To: Marcus Comstedt; +Cc: Newlib

This patch set is LGTM, verified with RV64 big-endian,
although RV32 big-endian still has some regression yet,
and not clear is library or compiler issue,
but I am fine to accept both patches and then accept further
patches later for RV32 if needed.


On Wed, Feb 24, 2021 at 6:07 AM Marcus Comstedt <marcus@mc.pp.se> wrote:
>
> Hi.
>
> These are two fixes needed for newlib to work correctly on big endian
> RISC-V, support for which is currently being added to gcc.
>
>
>   // Marcus
>
>
> --
>
>  newlib/libc/include/machine/ieeefp.h |  4 ++++
>  newlib/libc/machine/riscv/strcmp.S   | 40 ++++++++++++++++++++++++++++++++----
>  2 files changed, 40 insertions(+), 4 deletions(-)
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] Fixes for big endian RISC-V
  2021-02-23 21:31 [PATCH 0/2] Fixes for big endian RISC-V Marcus Comstedt
                   ` (2 preceding siblings ...)
  2021-02-25  9:21 ` [PATCH 0/2] Fixes for big endian RISC-V Kito Cheng
@ 2021-02-25 11:15 ` Corinna Vinschen
  3 siblings, 0 replies; 5+ messages in thread
From: Corinna Vinschen @ 2021-02-25 11:15 UTC (permalink / raw)
  To: Marcus Comstedt; +Cc: newlib

On Feb 23 22:31, Marcus Comstedt wrote:
> Hi.
> 
> These are two fixes needed for newlib to work correctly on big endian
> RISC-V, support for which is currently being added to gcc.
> 
> 
>   // Marcus
> 
> 
> --
> 
>  newlib/libc/include/machine/ieeefp.h |  4 ++++
>  newlib/libc/machine/riscv/strcmp.S   | 40 ++++++++++++++++++++++++++++++++----
>  2 files changed, 40 insertions(+), 4 deletions(-)

Pushed.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-02-25 11:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-23 21:31 [PATCH 0/2] Fixes for big endian RISC-V Marcus Comstedt
2021-02-23 21:31 ` [PATCH 1/2] Set __IEEE_BIG_ENDIAN " Marcus Comstedt
2021-02-23 21:31 ` [PATCH 2/2] RISC-V: Fix optimized strcmp on big endian Marcus Comstedt
2021-02-25  9:21 ` [PATCH 0/2] Fixes for big endian RISC-V Kito Cheng
2021-02-25 11:15 ` Corinna Vinschen

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 read-only IMAP folder(s) and NNTP newsgroup(s).