From 3a85d802ee63cce871963b28de50fd9ffd8900ac Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Mon, 27 Jan 2020 22:23:13 -0600 Subject: [PATCH] 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 Reviewed-by: Adrien Destugues --- src/system/libroot/os/arch/riscv64/Jamfile | 2 + .../libroot/os/arch/riscv64/byteorder.S | 68 ++++++++++++++----- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/system/libroot/os/arch/riscv64/Jamfile b/src/system/libroot/os/arch/riscv64/Jamfile index 64aa1a8422..e16a245868 100644 --- a/src/system/libroot/os/arch/riscv64/Jamfile +++ b/src/system/libroot/os/arch/riscv64/Jamfile @@ -13,6 +13,8 @@ for architectureObject in [ MultiArchSubDirSetup riscv64 ] { 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 9bded18ee4..06fa75ed35 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 .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_END(__swap_float) */ 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