public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* HELP: MIPS PC Relative Addressing
@ 2021-02-24 14:18 Jiaxun Yang
  2021-02-24 17:30 ` Maciej W. Rozycki
  2021-02-24 21:40 ` Jim Wilson
  0 siblings, 2 replies; 15+ messages in thread
From: Jiaxun Yang @ 2021-02-24 14:18 UTC (permalink / raw)
  To: open list:MIPS, binutils, gcc; +Cc: syq, macro, mfortune

Hi all,

I'm trying to implement PC Relative addressing for toolchain (GCC, LLVM).

MIPS Release6 had introduced pcrel instructions (e.g. auipc) that made
PC relative addressing for local data possible. It can help us reduce GOT
overhead and implement position independent kernel easier.

Just as RISC-V, MIPS R6 can load address by a pair of %pcrel_hi and 
%pcrel_lo
modifier. However, the usage is slightly different.

For RISC-V, %pcrel_lo shall point to the label of corresponding 
%pcrel_hi, like

.LA0:
     auipc    a0, %pcrel_hi(sym)
     addi      a0, a0, %pcrel_lo(.LA0)

However, for MIPS %pcrel_lo simply calculate LO16 of the symbol to current
PC, thus PC relative addressing will look like:

.LA0:
     auipc  a0, %pcrel_hi(sym)
.LA1:
     addi    a0, %pcrel_lo(sym + (.LA1 - .LA0))

I found it's very difficult for GCC to generate this kind of pcrel_lo 
expression,
RTX label_ref can't be lower into such LOW_SUM expression.

Could you please give me some hints about how to implement it?

If it looks infeasible for GCC side, another option would be adding 
RISC-V style
%pcrel_{hi,lo} modifier at assembler side. We can add another pair of 
modifier
like %pcrel_paired_{hi,lo} to implement the behavior. Would it be a good 
idea?

Thanks.

-Jiaxun


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-03-04 16:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 14:18 HELP: MIPS PC Relative Addressing Jiaxun Yang
2021-02-24 17:30 ` Maciej W. Rozycki
2021-02-24 21:46   ` Jim Wilson
2021-02-24 22:00     ` Maciej W. Rozycki
2021-02-25  0:55   ` Jiaxun Yang
2021-02-27 16:45     ` Maciej W. Rozycki
2021-02-24 21:40 ` Jim Wilson
2021-02-25  0:48   ` Jiaxun Yang
2021-02-25  2:57     ` Maciej W. Rozycki
2021-02-25  3:09       ` Jiaxun Yang
2021-02-25 22:30         ` Maciej W. Rozycki
2021-03-02  7:23   ` Jiaxun Yang
2021-03-02 15:30     ` Maciej W. Rozycki
2021-03-04  3:33       ` Jiaxun Yang
2021-03-04 16:54         ` Maciej W. Rozycki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).