-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LoongArch: gas: add support using variable for li.w/d #215
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,23 @@ my_getExpression (expressionS *ep, const char *str) | |
return ret; | ||
} | ||
|
||
/* op is var name? */ | ||
static void | ||
emit_const_var (const char *op) | ||
{ | ||
expressionS ep; | ||
if (end <= top) | ||
as_fatal (_("expr too huge")); | ||
my_getExpression(&ep, op); | ||
if (ep.X_op != O_constant) | ||
as_bad("illegal operand: %s", op); | ||
top->value.X_op = O_constant; | ||
top->value.X_add_number = ep.X_add_number; | ||
top->type = BFD_RELOC_LARCH_SOP_PUSH_ABSOLUTE; | ||
top++; | ||
} | ||
|
||
|
||
static void | ||
reloc (const char *op_c_str, const char *id_c_str, offsetT addend) | ||
{ | ||
|
@@ -318,6 +335,7 @@ offsetT imm; | |
|
||
primary_expression | ||
: INTEGER {emit_const ($1);} | ||
| IDENTIFIER {emit_const_var ($1);} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Judging from this, isn't the change applicable to more insns than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're exactly right. Let me fix this again to only works for li.w./d There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No no no. In its current form it's way more ergonomic. I for example would be very surprised to find out that variable substitution only works for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean you'd simply write more test cases to showcase the usage with a wide variety of insns, and reword the commit message. Just don't restrict to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we know, the li.[wd] is a macro instruction used to load immediate. li.w can load 32 bits immediate, and li.d can load 64 bits immediate. If a programmer need to load immediate, li.[wd] is completely competent. If other instructions also support, for programmer who don't know instructions immediate bits width, It is easy to make mistakes . For eaxmple, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in that case you may want to improve the error message so the user is hinted towards There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I got you, you're right. I will add more testcases for other instructions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've tested this feature of other ARCHs like x86, their behavior is really the same as you said!!!That's cool! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Told you. ;-) |
||
| '(' expression ')' | ||
| '%' IDENTIFIER '(' IDENTIFIER addend ')' {reloc ($2, $4, $5); free ($2); free ($4);} | ||
| '%' IDENTIFIER '(' INTEGER addend ')' {reloc ($2, NULL, $4 + $5); free ($2);} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#as: | ||
#objdump: -dr | ||
|
||
.*:[ ]+file format .* | ||
|
||
|
||
Disassembly of section .text: | ||
|
||
00000000.* <.text>: | ||
[ ]+0:[ ]+03848c0c[ ]+ori[ ]+\$t0,[ ]+\$zero,[ ]+0x123 | ||
[ ]+4:[ ]+15ffe00d[ ]+lu12i.w[ ]+\$t1,[ ]+-256\(0xfff00\) | ||
[ ]+8:[ ]+16001fed[ ]+lu32i.d[ ]+\$t1,[ ]+255\(0xff\) | ||
[ ]+c:[ ]+02bffc0e[ ]+addi.w[ ]+\$t2,[ ]+\$zero,[ ]+-1\(0xfff\) | ||
[ ]+10:[ ]+1601ffee[ ]+lu32i.d[ ]+\$t2,[ ]+4095\(0xfff\) | ||
[ ]+14:[ ]+0004b58b[ ]+alsl.w[ ]+\$a7,[ ]+\$t0,[ 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+e4:[ ]+290401ac[ ]+st.b[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\) | ||
[ ]+e8:[ ]+294401ac[ ]+st.h[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\) | ||
[ ]+ec:[ ]+298401ac[ ]+st.w[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\) | ||
[ ]+f0:[ ]+29c401ac[ ]+st.d[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\) | ||
[ ]+f4:[ ]+2a0401ac[ ]+ld.bu[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\) | ||
[ ]+f8:[ ]+2a4401ac[ ]+ld.hu[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\) | ||
[ ]+fc:[ ]+2a8401ac[ ]+ld.wu[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\) | ||
[ ]+100:[ ]+2ac401a2[ ]+preld[ ]+0x2,[ ]+\$t1,[ ]+256\(0x100\) | ||
[ ]+104:[ ]+382c39a2[ ]+preldx[ ]+0x2,[ ]+\$t1,[ ]+\$t2 | ||
[ ]+108:[ ]+2b048d8a[ ]+fld.s[ ]+\$ft2,[ ]+\$t0,[ ]+291\(0x123\) | ||
[ ]+10c:[ ]+2b448d8a[ ]+fst.s[ ]+\$ft2,[ ]+\$t0,[ ]+291\(0x123\) | ||
[ ]+110:[ ]+2b848d8a[ ]+fld.d[ ]+\$ft2,[ ]+\$t0,[ ]+291\(0x123\) | ||
[ ]+114:[ ]+2bc48d8a[ ]+fst.d[ ]+\$ft2,[ ]+\$t0,[ ]+291\(0x123\) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
.equ a, 0x123 | ||
.equ b, 0xfffff00000 | ||
.equ c, 0xfffffffffff | ||
.equ d, 2 | ||
.equ e,0x100 | ||
|
||
li.w $r12, a | ||
li.d $r13, b | ||
li.d $r14, c | ||
|
||
alsl.w $r11,$r12,$r13,d | ||
alsl.wu $r11,$r12,$r13,d | ||
bytepick.w $r11,$r12,$r13,d | ||
bytepick.d $r11,$r12,$r13,d | ||
|
||
break d | ||
dbcl d | ||
syscall d | ||
|
||
alsl.d $r11,$r12, $r13,d | ||
slli.w $r11,$r12,d | ||
slli.d $r11,$r12,d | ||
srli.w $r11,$r12,d | ||
srli.d $r12,$r13,d | ||
srai.w $r12,$r13,d | ||
srai.d $r12,$r13,d | ||
|
||
bstrins.w $r12,$r13,d,d | ||
bstrins.d $r12,$r13,d,d | ||
bstrpick.d $r12,$r13,d,d | ||
bstrpick.d $r12,$r13,d,d | ||
|
||
slti $r12,$r13,a | ||
sltui $r12,$r13,a | ||
addi.w $r12,$r13,a | ||
addi.d $r12,$r13,a | ||
lu52i.d $r12,$r13,a | ||
andi $r12,$r13,d | ||
ori $r12,$r13,d | ||
xori $r12,$r13,d | ||
addu16i.d $r12,$r13,d | ||
lu12i.w $r12,a | ||
lu32i.d $r12,a | ||
pcaddi $r12,a | ||
pcalau12i $r12,a | ||
pcaddu12i $r12,a | ||
pcaddu18i $r12,a | ||
|
||
csrrd $r12,a | ||
csrwr $r12,a | ||
csrxchg $r12,$r13,d | ||
cacop d,$r13,d | ||
lddir $r12,$r13,d | ||
ldpte $r12,d | ||
|
||
invtlb d,$r13,$r14 | ||
|
||
ll.w $r12,$r13,e | ||
sc.w $r12,$r13,e | ||
ll.d $r12,$r13,e | ||
sc.d $r12,$r13,e | ||
ldptr.w $r12,$r13,e | ||
stptr.w $r12,$r13,e | ||
ldptr.d $r12,$r13,e | ||
stptr.d $r12,$r13,e | ||
ld.b $r12,$r13,e | ||
ld.h $r12,$r13,e | ||
ld.w $r12,$r13,e | ||
ld.d $r12,$r13,e | ||
st.b $r12,$r13,e | ||
st.h $r12,$r13,e | ||
st.w $r12,$r13,e | ||
st.d $r12,$r13,e | ||
ld.bu $r12,$r13,e | ||
ld.hu $r12,$r13,e | ||
ld.wu $r12,$r13,e | ||
preld d,$r13,e | ||
preldx d,$r13,$r14 | ||
|
||
fld.s $f10,$r12,a | ||
fst.s $f10,$r12,a | ||
fld.d $f10,$r12,a | ||
fst.d $f10,$r12,a | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#as: | ||
#objdump: -dr | ||
|
||
.*:[ ]+file format .* | ||
|
||
|
||
Disassembly of section .text: | ||
|
||
00000000.* <_start>: | ||
[ ]+0:[ ]+03803c06[ ]+ori[ ]+\$a2,[ ]+\$zero,[ ]+0xf | ||
[ ]+4:[ ]+1a000005[ ]+pcalau12i[ ]+\$a1,[ ]+0 | ||
[ ]+4:[ ]+R_LARCH_PCALA_HI20[ ]+.rodata | ||
[ ]+8:[ ]+02c000a5[ ]+addi.d[ ]+\$a1,[ ]+\$a1,[ ]+0 | ||
[ ]+8:[ ]+R_LARCH_PCALA_LO12[ ]+.rodata | ||
[ ]+c:[ ]+03800404[ ]+ori[ ]+\$a0,[ ]+\$zero,[ ]+0x1 | ||
[ ]+10:[ ]+0381000b[ ]+ori[ ]+\$a7,[ ]+\$zero,[ ]+0x40 | ||
[ ]+14:[ ]+002b0000[ ]+syscall[ ]+0x0 | ||
[ ]+18:[ ]+00150004[ ]+move[ ]+\$a0,[ ]+\$zero | ||
[ ]+1c:[ ]+0381740b[ ]+ori[ ]+\$a7,[ ]+\$zero,[ ]+0x5d | ||
[ ]+20:[ ]+002b0000[ ]+syscall[ ]+0x0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.equ EXIT_SUCCESS, 0 | ||
.equ STDOUT, 1 | ||
.equ SYS_exit, 93 | ||
.equ SYS_write, 64 | ||
|
||
.section .rodata | ||
msg: | ||
.string "hello, world!\n" | ||
len = . - msg | ||
|
||
.text | ||
.globl _start | ||
_start: | ||
li.w $a2, len | ||
la.local $a1, msg | ||
li.w $a0, STDOUT | ||
li.w $a7, SYS_write | ||
syscall 0x0 | ||
|
||
li.w $a0, EXIT_SUCCESS | ||
li.w $a7, SYS_exit | ||
syscall 0x0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean the resulting object file will have this reloc record? Because we may be working with lld/mold that cannot process stack-based relocations, in which case we actually want to substitute the value in, as if the user had written the concrete value in the respective slot. Otherwise the approach is mostly okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once it is recognized as a constant, it will discarded this reloc in subsequent processing, and obviously object file will have not this reloc record.