libroot/riscv64: Fix build. Add MIT optimized bswap from rv8
Change-Id: I4d0e1ec34d1568594cac0f7378f87852c997ab81 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2166 Reviewed-by: Alex von Gluck IV <[email protected]> Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
15fb7d88e9
commit
3a85d802ee
@@ -13,6 +13,8 @@ for architectureObject in [ MultiArchSubDirSetup riscv64 ] {
|
|||||||
SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;
|
SEARCH_SOURCE += [ FDirName $(SUBDIR) $(DOTDOT) generic ] ;
|
||||||
|
|
||||||
MergeObject <$(architecture)>os_arch_$(TARGET_ARCH).o :
|
MergeObject <$(architecture)>os_arch_$(TARGET_ARCH).o :
|
||||||
|
byteorder.S
|
||||||
|
|
||||||
stack_frame.c
|
stack_frame.c
|
||||||
system_time.c
|
system_time.c
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
* 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>
|
#include <asm_defs.h>
|
||||||
|
|
||||||
.text
|
.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)
|
/* float __swap_float(float value)
|
||||||
*/
|
*/
|
||||||
FUNCTION(__swap_float):
|
FUNCTION(__swap_float):
|
||||||
// Assumes single precision
|
// Assumes single precision
|
||||||
b __swap_int32
|
1: auipc a4, %pcrel_hi(__bswap64_c1)
|
||||||
//rts
|
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)
|
FUNCTION_END(__swap_float)
|
||||||
|
|
||||||
|
|
||||||
@@ -32,7 +43,30 @@ FUNCTION_END(__swap_float)
|
|||||||
*/
|
*/
|
||||||
FUNCTION(__swap_double):
|
FUNCTION(__swap_double):
|
||||||
// Assumes double is int64 on RV64
|
// Assumes double is int64 on RV64
|
||||||
b __swap_int64
|
1: auipc a4, %pcrel_hi(__bswap64_c1)
|
||||||
//rts
|
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)
|
FUNCTION_END(__swap_double)
|
||||||
|
|
||||||
|
|
||||||
|
.section .rodata
|
||||||
|
__bswap32_c1: .4byte 0xFF00FF00ULL
|
||||||
|
__bswap64_c1: .8byte 0xFF00FF00FF00FF00ULL
|
||||||
|
__bswap64_c2: .8byte 0xFFFF0000FFFF0000ULL
|
||||||
|
|||||||
Reference in New Issue
Block a user