From Alex von Gluck IV <kallisti5@xxxxxxxxxxx>:
Alex von Gluck IV has uploaded this change for review. (
https://review.haiku-os.org/c/haiku/+/2166 ;)
Change subject: libroot/riscv64: Fix build. Add MIT optimized bswap from rv8
......................................................................
libroot/riscv64: Fix build. Add MIT optimized bswap from rv8
Change-Id: I4d0e1ec34d1568594cac0f7378f87852c997ab81
---
M src/system/libroot/os/arch/riscv64/Jamfile
M src/system/libroot/os/arch/riscv64/byteorder.S
2 files changed, 53 insertions(+), 17 deletions(-)
git pull ssh://git.haiku-os.org:22/haiku refs/changes/66/2166/1
diff --git a/src/system/libroot/os/arch/riscv64/Jamfile
b/src/system/libroot/os/arch/riscv64/Jamfile
index 64aa1a8..e16a245 100644
--- a/src/system/libroot/os/arch/riscv64/Jamfile
+++ b/src/system/libroot/os/arch/riscv64/Jamfile
@@ -13,6 +13,8 @@
SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;
MergeObject <$(architecture)>os_arch_$(TARGET_ARCH).o :
+ byteorder.S
+
stack_frame.c
system_time.c
diff --git a/src/system/libroot/os/arch/riscv64/byteorder.S
b/src/system/libroot/os/arch/riscv64/byteorder.S
index 9bded18..06fa75e 100644
--- a/src/system/libroot/os/arch/riscv64/byteorder.S
+++ b/src/system/libroot/os/arch/riscv64/byteorder.S
@@ -1,30 +1,41 @@
/*
- * Copyright 2009, Johannes Wischert. All rights reserved.
+ * Copyright 2018-2020, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
+ *
+ * Optimized byteswap functions from the rv8 test
+ * suite licensed under the MIT License
+ * https://github.com/rv8-io/rv8/tree/master/src/test
+ *
*/
#include <asm_defs.h>
.text
-/*
- * These aren't needed on gcc4+
- * uint16 __swap_int16(uint16 value)
- * uint32 __swap_int32(uint32 value)
- * uint64 __swap_int64(uint64 value)
- */
-
-/* TODO: The following functions can surely be optimized. A simple optimization
- * would be to define macros with the contents of the __swap_int{32,64}
- * functions and use those instead of calling the functions.
- */
-
/* float __swap_float(float value)
*/
FUNCTION(__swap_float):
// Assumes single precision
- b __swap_int32
- //rts
+ 1: auipc a4, %pcrel_hi(__bswap64_c1)
+ ld a4, %pcrel_lo(1b)(a4)
+ slli a5, a0, 8
+ and a5, a5, a4
+ srli a0, a0, 8
+ srli a4, a4, 8
+ and a0, a0, a4
+ or a5, a5, a0
+ 1: auipc a4, %pcrel_hi(__bswap64_c2)
+ ld a4, %pcrel_lo(1b)(a4)
+ slli a0, a5, 16
+ and a0, a0, a4
+ srli a5, a5, 16
+ srli a4, a4, 16
+ and a5, a5, a4
+ or a5, a5, a0
+ slli a0, a5, 32
+ srli a5, a5, 32
+ or a0, a0, a5
+ ret
FUNCTION_END(__swap_float)
@@ -32,7 +43,30 @@
*/
FUNCTION(__swap_double):
// Assumes double is int64 on RV64
- b __swap_int64
- //rts
+ 1: auipc a4, %pcrel_hi(__bswap64_c1)
+ ld a4, %pcrel_lo(1b)(a4)
+ slli a5, a0, 8
+ and a5, a5, a4
+ srli a0, a0, 8
+ srli a4, a4, 8
+ and a0, a0, a4
+ or a5, a5, a0
+ 1: auipc a4, %pcrel_hi(__bswap64_c2)
+ ld a4, %pcrel_lo(1b)(a4)
+ slli a0, a5, 16
+ and a0, a0, a4
+ srli a5, a5, 16
+ srli a4, a4, 16
+ and a5, a5, a4
+ or a5, a5, a0
+ slli a0, a5, 32
+ srli a5, a5, 32
+ or a0, a0, a5
+ ret
FUNCTION_END(__swap_double)
+
+.section .rodata
+__bswap32_c1: .4byte 0xFF00FF00ULL
+__bswap64_c1: .8byte 0xFF00FF00FF00FF00ULL
+__bswap64_c2: .8byte 0xFFFF0000FFFF0000ULL
--
To view, visit https://review.haiku-os.org/c/haiku/+/2166
To unsubscribe, or for help writing mail filters, visit
https://review.haiku-os.org/settings
Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I4d0e1ec34d1568594cac0f7378f87852c997ab81
Gerrit-Change-Number: 2166
Gerrit-PatchSet: 1
Gerrit-Owner: Alex von Gluck IV <kallisti5@xxxxxxxxxxx>
Gerrit-MessageType: newchange