arch: riscv: introduce global pointer relative addressing support
Enable RISC-V GP relative addressing by linker relaxation to reduce the code size. It optimizes addressing of globals in small data section (.sdata). The gp initialization at program start needs each SoC support. Also, if RISC-V SoC has custom linker script, SoC should provide __global_pointer$ symbol in it's linker script. Signed-off-by: Jim Shu <cwshu@andestech.com>
This commit is contained in:
parent
8ed9cddbc5
commit
073cfa9cdf
2 changed files with 28 additions and 0 deletions
|
@ -20,6 +20,18 @@ config FLOAT_HARD
|
|||
help
|
||||
This option enables the hard-float calling convention.
|
||||
|
||||
config RISCV_GP
|
||||
bool "Enable RISC-V global pointer relative addressing"
|
||||
default n
|
||||
help
|
||||
Use global pointer relative addressing for small globals declared
|
||||
anywhere in the executable. It can benefit performance and reduce
|
||||
the code size.
|
||||
|
||||
Note: To support this feature, RISC-V SoC needs to initialize
|
||||
global pointer at program start or earlier than any instruction
|
||||
using GP relative addressing.
|
||||
|
||||
menu "RISCV Processor Options"
|
||||
|
||||
config CORE_E31
|
||||
|
|
|
@ -238,6 +238,22 @@ SECTIONS
|
|||
*(.data)
|
||||
*(".data.*")
|
||||
|
||||
#ifdef CONFIG_RISCV_GP
|
||||
/*
|
||||
* RISC-V architecture has 12-bit signed immediate offsets in the
|
||||
* instructions. If we can put the most commonly accessed globals
|
||||
* in a special 4K span of memory addressed by the GP register, then
|
||||
* we can access those values in a single instruction, saving both
|
||||
* codespace and runtime.
|
||||
*
|
||||
* Since these immediate offsets are signed, place gp 0x800 past the
|
||||
* beginning of .sdata so that we can use both positive and negative
|
||||
* offsets.
|
||||
*/
|
||||
. = ALIGN(8);
|
||||
PROVIDE (__global_pointer$ = . + 0x800);
|
||||
#endif
|
||||
|
||||
*(.sdata .sdata.* .gnu.linkonce.s.*)
|
||||
|
||||
/* Located in generated directory. This file is populated by the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue