forked from Mirrors/opensbi
lib: sbi_scratch: Optimize hartid and scratch lookup
The compiler generates much better code for sbi_hartindex_to_hartid() and sbi_hartindex_to_scratch() when using a constant for the bounds check. This works out nicely because the underlying arrays are already a constant size, so the only change needed is to fill the remainder of each array with the appropriate default/out-of-bounds value. The ellipsis in the designated initializer is a GCC extension (also supported by Clang), but avoids runtime initialization of the array. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:

committed by
Anup Patel

parent
ef4ed2dda7
commit
6b97950cf5
@@ -15,8 +15,8 @@
|
||||
#include <sbi/sbi_string.h>
|
||||
|
||||
u32 last_hartindex_having_scratch = 0;
|
||||
u32 hartindex_to_hartid_table[SBI_HARTMASK_MAX_BITS] = { -1U };
|
||||
struct sbi_scratch *hartindex_to_scratch_table[SBI_HARTMASK_MAX_BITS] = { 0 };
|
||||
u32 hartindex_to_hartid_table[SBI_HARTMASK_MAX_BITS] = { [0 ... SBI_HARTMASK_MAX_BITS-1] = -1U };
|
||||
struct sbi_scratch *hartindex_to_scratch_table[SBI_HARTMASK_MAX_BITS];
|
||||
|
||||
static spinlock_t extra_lock = SPIN_LOCK_INITIALIZER;
|
||||
static unsigned long extra_offset = SBI_SCRATCH_EXTRA_SPACE_OFFSET;
|
||||
|
Reference in New Issue
Block a user