1/* 2 * Copyright 2018-2020, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Optimized byteswap functions from the rv8 test 6 * suite licensed under the MIT License 7 * https://github.com/rv8-io/rv8/tree/master/src/test 8 * 9 */ 10 11#include <asm_defs.h> 12 13.text 14 15/* float __swap_float(float value) 16 */ 17FUNCTION(__swap_float): 18 // Assumes single precision 19 1: auipc a4, %pcrel_hi(__bswap64_c1) 20 ld a4, %pcrel_lo(1b)(a4) 21 slli a5, a0, 8 22 and a5, a5, a4 23 srli a0, a0, 8 24 srli a4, a4, 8 25 and a0, a0, a4 26 or a5, a5, a0 27 1: auipc a4, %pcrel_hi(__bswap64_c2) 28 ld a4, %pcrel_lo(1b)(a4) 29 slli a0, a5, 16 30 and a0, a0, a4 31 srli a5, a5, 16 32 srli a4, a4, 16 33 and a5, a5, a4 34 or a5, a5, a0 35 slli a0, a5, 32 36 srli a5, a5, 32 37 or a0, a0, a5 38 ret 39FUNCTION_END(__swap_float) 40 41 42/* double __swap_double(double value) 43 */ 44FUNCTION(__swap_double): 45 // Assumes double is int64 on RV64 46 1: auipc a4, %pcrel_hi(__bswap64_c1) 47 ld a4, %pcrel_lo(1b)(a4) 48 slli a5, a0, 8 49 and a5, a5, a4 50 srli a0, a0, 8 51 srli a4, a4, 8 52 and a0, a0, a4 53 or a5, a5, a0 54 1: auipc a4, %pcrel_hi(__bswap64_c2) 55 ld a4, %pcrel_lo(1b)(a4) 56 slli a0, a5, 16 57 and a0, a0, a4 58 srli a5, a5, 16 59 srli a4, a4, 16 60 and a5, a5, a4 61 or a5, a5, a0 62 slli a0, a5, 32 63 srli a5, a5, 32 64 or a0, a0, a5 65 ret 66FUNCTION_END(__swap_double) 67 68 69.section .rodata 70__bswap32_c1: .4byte 0xFF00FF00ULL 71__bswap64_c1: .8byte 0xFF00FF00FF00FF00ULL 72__bswap64_c2: .8byte 0xFFFF0000FFFF0000ULL 73