opcodes: LoongArch: add "ret" instruction to reduce typing
authorWANG Xuerui <git@xen0n.name>
Wed, 27 Jul 2022 11:07:57 +0000 (19:07 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Mon, 1 Aug 2022 07:57:32 +0000 (15:57 +0800)
This syntactic sugar is present in both classical and emerging
architectures, like Alpha, SPARC and RISC-V, and assembler macros
doing the same thing can already be found in the wild e.g. [1], proving
the feature's popularity. It's better to provide support directly in the
assembler so downstream users wouldn't have to re-invent this over and
over again.

[1]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/loongarch/sysdep.h;h=c586df819cd90;hb=HEAD#l28

gas/testsuite/gas/loongarch/jmp_op.d
gas/testsuite/gas/loongarch/jmp_op.s
ld/testsuite/ld-loongarch-elf/jmp_op.d
ld/testsuite/ld-loongarch-elf/jmp_op.s
opcodes/loongarch-opc.c

index b10390f640fc48f4768993681005d6a0fc6c0b81..218c13f939882d925f3d191234e28b2d181e19b3 100644 (file)
@@ -28,3 +28,4 @@ Disassembly of section .text:
 [      ]+48:[  ]+6bffb8a4[     ]+[     ]+bltu[         ]+\$a1, \$a0, -72\(0x3ffb8\)[   ]+# 0x0
 [      ]+4c:[  ]+6fffb485[     ]+[     ]+bgeu[         ]+\$a0, \$a1, -76\(0x3ffb4\)[   ]+# 0x0
 [      ]+50:[  ]+6fffb0a4[     ]+[     ]+bgeu[         ]+\$a1, \$a0, -80\(0x3ffb0\)[   ]+# 0x0
+[      ]+54:[  ]+4c000020[     ]+[     ]+jirl[         ]+\$zero, \$ra, 0
index 1deb165aebadd1a735ce38452d9459249d58949a..56f986784e27f0bba2879fdf6cc492886b7c7dbf 100644 (file)
@@ -20,3 +20,4 @@ bltu  $r4,$r5,.L1
 bgtu  $r4,$r5,.L1
 bgeu  $r4,$r5,.L1
 bleu  $r4,$r5,.L1
+ret
index b10390f640fc48f4768993681005d6a0fc6c0b81..218c13f939882d925f3d191234e28b2d181e19b3 100644 (file)
@@ -28,3 +28,4 @@ Disassembly of section .text:
 [      ]+48:[  ]+6bffb8a4[     ]+[     ]+bltu[         ]+\$a1, \$a0, -72\(0x3ffb8\)[   ]+# 0x0
 [      ]+4c:[  ]+6fffb485[     ]+[     ]+bgeu[         ]+\$a0, \$a1, -76\(0x3ffb4\)[   ]+# 0x0
 [      ]+50:[  ]+6fffb0a4[     ]+[     ]+bgeu[         ]+\$a1, \$a0, -80\(0x3ffb0\)[   ]+# 0x0
+[      ]+54:[  ]+4c000020[     ]+[     ]+jirl[         ]+\$zero, \$ra, 0
index 1deb165aebadd1a735ce38452d9459249d58949a..56f986784e27f0bba2879fdf6cc492886b7c7dbf 100644 (file)
@@ -20,3 +20,4 @@ bltu  $r4,$r5,.L1
 bgtu  $r4,$r5,.L1
 bgeu  $r4,$r5,.L1
 bleu  $r4,$r5,.L1
+ret
index 35bae8c3ed411e11e1c0ceb921bd5eb10e69a4b0..1b510048c29939d31670c305983b7604dec7f712 100644 (file)
@@ -841,6 +841,7 @@ static struct loongarch_opcode loongarch_jmp_opcodes[] =
   { 0x0,       0x0,            "bgtu",         "r,r,la",                       "bltu %2,%1,%%b16(%3)",         0, 0, 0 },
   { 0x0,       0x0,            "bleu",         "r,r,la",                       "bgeu %2,%1,%%b16(%3)",         0, 0, 0 },
   { 0x0,       0x0,            "jr",           "r",                            "jirl $r0,%1,0",                0, 0, 0 },
+  { 0x0,       0x0,            "ret",          "",                             "jirl $r0,$r1,0",               0, 0, 0 },
   { 0 } /* Terminate the list.  */
 };