From 64ba751ef174c8c40fff1c88aac96ca7d09de115 Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 25 Dec 2024 18:25:59 +0100 Subject: [PATCH] * make use of LA pseudo-instruction --- compiler/aasmtai.pas | 3 +++ compiler/riscv/aasmcpu.pas | 2 +- compiler/riscv/agrvgas.pas | 2 +- compiler/riscv/cgrv.pas | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/compiler/aasmtai.pas b/compiler/aasmtai.pas index e65d00d2ef..55e5084973 100644 --- a/compiler/aasmtai.pas +++ b/compiler/aasmtai.pas @@ -2987,6 +2987,9 @@ implementation {$ifdef aarch64} and not(r.refaddr in [addr_full,addr_gotpageoffset,addr_gotpage]) {$endif aarch64} +{$ifdef riscv} + and not(opcode=A_LA) +{$endif riscv} then internalerror(200502052); {$endif not llvm} diff --git a/compiler/riscv/aasmcpu.pas b/compiler/riscv/aasmcpu.pas index 2a5a6ce6e6..a6faf4c4d2 100644 --- a/compiler/riscv/aasmcpu.pas +++ b/compiler/riscv/aasmcpu.pas @@ -480,7 +480,7 @@ uses cutils, cclasses; // I type A_JALR, - A_LB,A_LH,A_LW,A_LBU,A_LHU, + A_LA,A_LB,A_LH,A_LW,A_LBU,A_LHU, A_ADDI,A_SLTI,A_SLTIU, A_XORI,A_ORI,A_ANDI, A_SLLI,A_SRLI,A_SRAI, diff --git a/compiler/riscv/agrvgas.pas b/compiler/riscv/agrvgas.pas index 9a3f8dfde7..0b1d7a5350 100644 --- a/compiler/riscv/agrvgas.pas +++ b/compiler/riscv/agrvgas.pas @@ -74,7 +74,7 @@ unit agrvgas; else begin s :=''; - if not(refaddr in [addr_no,addr_pic_no_got,addr_plt]) then + if not(refaddr in [addr_no,addr_pic_no_got,addr_plt,addr_full]) then s := s+'('; if assigned(symbol) then begin diff --git a/compiler/riscv/cgrv.pas b/compiler/riscv/cgrv.pas index 8847502830..cfd9b576cc 100644 --- a/compiler/riscv/cgrv.pas +++ b/compiler/riscv/cgrv.pas @@ -931,6 +931,12 @@ unit cgrv; if assigned(ref.symbol) then begin +{$ifdef unsed} + { keeping the code for reference + + we use the pseudo instruction LA below which is expanded by the assembler, doing + so results in more readable assembler and easier optimization of the assembler code + } if cs_create_pic in current_settings.moduleswitches then begin reference_reset_symbol(href,ref.symbol,0,0,[]); @@ -969,6 +975,15 @@ unit cgrv; href.refaddr:=addr_pcrel_lo12; list.concat(taicpu.op_reg_reg_ref(A_ADDI,tmpreg,tmpreg,href)); end; +{$endif unsed} + + reference_reset_symbol(href,ref.symbol,0,0,[]); + href.refaddr:=addr_full; + ref.symbol:=nil; + + tmpreg:=getintregister(list,OS_ADDR); + + list.concat(taicpu.op_reg_ref(A_LA,tmpreg,href)); if (ref.index<>NR_NO) and (ref.base<>NR_NO) then