mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-24 23:41:23 +01:00
firmware: fw_base: Optimize _hartid_to_scratch() implementation
This patch optimizes _hartid_to_scratch() in following ways: 1. Use caller saved registers instead of callee saved registers so that we don't need to save/restore registers on stack 2. Remove second redundant mul instruction by re-arranging instructions Overall, we reduce 9 instructions in _hartid_to_scratch() implementation. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
@@ -409,35 +409,26 @@ _link_end:
|
|||||||
.align 3
|
.align 3
|
||||||
.globl _hartid_to_scratch
|
.globl _hartid_to_scratch
|
||||||
_hartid_to_scratch:
|
_hartid_to_scratch:
|
||||||
add sp, sp, -(3 * __SIZEOF_POINTER__)
|
|
||||||
REG_S s0, (sp)
|
|
||||||
REG_S s1, (__SIZEOF_POINTER__)(sp)
|
|
||||||
REG_S s2, (__SIZEOF_POINTER__ * 2)(sp)
|
|
||||||
/*
|
/*
|
||||||
* a0 -> HART ID (passed by caller)
|
* a0 -> HART ID (passed by caller)
|
||||||
* s0 -> HART Stack Size
|
* t0 -> HART Stack Size
|
||||||
* s1 -> HART Stack End
|
* t1 -> HART Stack End
|
||||||
* s2 -> Temporary
|
* t2 -> Temporary
|
||||||
*/
|
*/
|
||||||
la s2, platform
|
la t2, platform
|
||||||
#if __riscv_xlen == 64
|
#if __riscv_xlen == 64
|
||||||
lwu s0, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(s2)
|
lwu t0, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(t2)
|
||||||
lwu s2, SBI_PLATFORM_HART_COUNT_OFFSET(s2)
|
lwu t2, SBI_PLATFORM_HART_COUNT_OFFSET(t2)
|
||||||
#else
|
#else
|
||||||
lw s0, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(s2)
|
lw t0, SBI_PLATFORM_HART_STACK_SIZE_OFFSET(t2)
|
||||||
lw s2, SBI_PLATFORM_HART_COUNT_OFFSET(s2)
|
lw t2, SBI_PLATFORM_HART_COUNT_OFFSET(t2)
|
||||||
#endif
|
#endif
|
||||||
mul s2, s2, s0
|
sub t2, t2, a0
|
||||||
la s1, _fw_end
|
mul t2, t2, t0
|
||||||
add s1, s1, s2
|
la t1, _fw_end
|
||||||
mul s2, s0, a0
|
add t1, t1, t2
|
||||||
sub s1, s1, s2
|
li t2, SBI_SCRATCH_SIZE
|
||||||
li s2, SBI_SCRATCH_SIZE
|
sub a0, t1, t2
|
||||||
sub a0, s1, s2
|
|
||||||
REG_L s0, (sp)
|
|
||||||
REG_L s1, (__SIZEOF_POINTER__)(sp)
|
|
||||||
REG_L s2, (__SIZEOF_POINTER__ * 2)(sp)
|
|
||||||
add sp, sp, (3 * __SIZEOF_POINTER__)
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.section .entry, "ax", %progbits
|
.section .entry, "ax", %progbits
|
||||||
|
Reference in New Issue
Block a user