From 63a65893f2a2aaf8ece7868e5f2d3b9b2c2305b9 Mon Sep 17 00:00:00 2001 From: WANG Xuerui Date: Sun, 8 Aug 2021 12:01:09 +0800 Subject: [PATCH 1/3] opcodes: LoongArch: make all non-native jumps desugar to canonical b{gt/le}[u] forms --- opcodes/loongarch-opc.c | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/opcodes/loongarch-opc.c b/opcodes/loongarch-opc.c index eaf56b7b1764..03dc18f3adda 100644 --- a/opcodes/loongarch-opc.c +++ b/opcodes/loongarch-opc.c @@ -723,14 +723,6 @@ static struct loongarch_opcode loongarch_load_store_opcodes[] = static struct loongarch_opcode loongarch_jmp_opcodes[] = { /* match, mask, name, format, macro, include, exclude, pinfo. */ - { 0x0, 0x0, "bltz", "r,la", "bltz %1,%%pcrel(%2)", 0, 0, 0 }, - { 0x60000000, 0xfc00001f, "bltz", "r5:5,sb10:16<<2", 0, 0, 0, 0 }, - { 0x0, 0x0, "bgtz", "r,la", "bgtz %1,%%pcrel(%2)", 0, 0, 0 }, - { 0x60000000, 0xfc0003e0, "bgtz", "r0:5,sb10:16<<2", 0, 0, 0, 0 }, - { 0x0, 0x0, "bgez", "r,la", "bgez %1,%%pcrel(%2)", 0, 0, 0 }, - { 0x64000000, 0xfc00001f, "bgez", "r5:5,sb10:16<<2", 0, 0, 0, 0 }, - { 0x0, 0x0, "blez", "r,la", "blez %1,%%pcrel(%2)", 0, 0, 0 }, - { 0x64000000, 0xfc0003e0, "blez", "r0:5,sb10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "beqz", "r,la", "beqz %1,%%pcrel(%2)", 0, 0, 0 }, { 0x40000000, 0xfc000000, "beqz", "r5:5,sb0:5|10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "bnez", "r,la", "bnez %1,%%pcrel(%2)", 0, 0, 0 }, @@ -739,32 +731,35 @@ static struct loongarch_opcode loongarch_jmp_opcodes[] = { 0x48000000, 0xfc000300, "bceqz", "c5:3,sb0:5|10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "bcnez", "c,la", "bcnez %1,%%pcrel(%2)", 0, 0, 0 }, { 0x48000100, 0xfc000300, "bcnez", "c5:3,sb0:5|10:16<<2", 0, 0, 0, 0 }, - { 0x0, 0x0, "jr", "r", "jirl $r0,%1,0", 0, 0, 0 }, + { 0x4c000000, 0xfc000000, "jirl", "r0:5,r5:5,s10:16<<2", 0, 0, 0, 0 }, { 0x50000000, 0xfc000000, "b", "sb0:10|10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "b", "la", "b %%pcrel(%1)", 0, 0, 0 }, - { 0x4c000000, 0xfc000000, "jirl", "r0:5,r5:5,s10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "bl", "la", "bl %%pcrel(%1)", 0, 0, 0 }, { 0x54000000, 0xfc000000, "bl", "sb0:10|10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "beq", "r,r,la", "beq %1,%2,%%pcrel(%3)", 0, 0, 0 }, { 0x58000000, 0xfc000000, "beq", "r5:5,r0:5,sb10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "bne", "r,r,la", "bne %1,%2,%%pcrel(%3)", 0, 0, 0 }, { 0x5c000000, 0xfc000000, "bne", "r5:5,r0:5,sb10:16<<2", 0, 0, 0, 0 }, - { 0x0, 0x0, "blt", "r,r,la", "blt %1,%2,%%pcrel(%3)", 0, 0, 0 }, - { 0x60000000, 0xfc000000, "blt", "r5:5,r0:5,sb10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "bgt", "r,r,la", "bgt %1,%2,%%pcrel(%3)", 0, 0, 0 }, { 0x60000000, 0xfc000000, "bgt", "r0:5,r5:5,sb10:16<<2", 0, 0, 0, 0 }, - { 0x0, 0x0, "bge", "r,r,la", "bge %1,%2,%%pcrel(%3)", 0, 0, 0 }, - { 0x64000000, 0xfc000000, "bge", "r5:5,r0:5,sb10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "ble", "r,r,la", "ble %1,%2,%%pcrel(%3)", 0, 0, 0 }, { 0x64000000, 0xfc000000, "ble", "r0:5,r5:5,sb10:16<<2", 0, 0, 0, 0 }, - { 0x0, 0x0, "bltu", "r,r,la", "bltu %1,%2,%%pcrel(%3)", 0, 0, 0 }, - { 0x68000000, 0xfc000000, "bltu", "r5:5,r0:5,sb10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "bgtu", "r,r,la", "bgtu %1,%2,%%pcrel(%3)", 0, 0, 0 }, { 0x68000000, 0xfc000000, "bgtu", "r0:5,r5:5,sb10:16<<2", 0, 0, 0, 0 }, - { 0x0, 0x0, "bgeu", "r,r,la", "bgeu %1,%2,%%pcrel(%3)", 0, 0, 0 }, - { 0x6c000000, 0xfc000000, "bgeu", "r5:5,r0:5,sb10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "bleu", "r,r,la", "bleu %1,%2,%%pcrel(%3)", 0, 0, 0 }, { 0x6c000000, 0xfc000000, "bleu", "r0:5,r5:5,sb10:16<<2", 0, 0, 0, 0 }, + + /* Sugars. */ + { 0x0, 0x0, "bltz", "r,la", "bgt $r0,%1,%%pcrel(%2)", 0, 0, 0 }, + { 0x0, 0x0, "bgtz", "r,la", "bgt %1,$r0,%%pcrel(%2)", 0, 0, 0 }, + { 0x0, 0x0, "bgez", "r,la", "ble $r0,%1,%%pcrel(%2)", 0, 0, 0 }, + { 0x0, 0x0, "blez", "r,la", "ble %1,$r0,%%pcrel(%2)", 0, 0, 0 }, + { 0x0, 0x0, "blt", "r,r,la", "bgt %2,%1,%%pcrel(%3)", 0, 0, 0 }, + { 0x0, 0x0, "bge", "r,r,la", "ble %2,%1,%%pcrel(%3)", 0, 0, 0 }, + { 0x0, 0x0, "bltu", "r,r,la", "bgtu %2,%1,%%pcrel(%3)", 0, 0, 0 }, + { 0x0, 0x0, "bgeu", "r,r,la", "bleu %2,%1,%%pcrel(%3)", 0, 0, 0 }, + { 0x0, 0x0, "jr", "r", "jirl $r0,%1,0", 0, 0, 0 }, + { 0 } /* Terminate the list. */ }; From 6c4044c7b7b5cbbb3390807dc7a3a4bd2bf5cdb4 Mon Sep 17 00:00:00 2001 From: WANG Xuerui Date: Sun, 8 Aug 2021 12:13:16 +0800 Subject: [PATCH 2/3] opcodes: LoongArch: add "ret" instruction to reduce typing --- opcodes/loongarch-opc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/opcodes/loongarch-opc.c b/opcodes/loongarch-opc.c index 03dc18f3adda..74ea32f45523 100644 --- a/opcodes/loongarch-opc.c +++ b/opcodes/loongarch-opc.c @@ -759,6 +759,7 @@ static struct loongarch_opcode loongarch_jmp_opcodes[] = { 0x0, 0x0, "bltu", "r,r,la", "bgtu %2,%1,%%pcrel(%3)", 0, 0, 0 }, { 0x0, 0x0, "bgeu", "r,r,la", "bleu %2,%1,%%pcrel(%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. */ }; From e2c787ae0a93c3f55db2591c5fb1346c8bd1d763 Mon Sep 17 00:00:00 2001 From: WANG Xuerui Date: Fri, 13 Aug 2021 14:46:24 +0800 Subject: [PATCH 3/3] opcodes: LoongArch: make beq/bne's operand order "rd, rj" to be consistent with all others --- opcodes/loongarch-opc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opcodes/loongarch-opc.c b/opcodes/loongarch-opc.c index 74ea32f45523..20ea91efde88 100644 --- a/opcodes/loongarch-opc.c +++ b/opcodes/loongarch-opc.c @@ -737,9 +737,9 @@ static struct loongarch_opcode loongarch_jmp_opcodes[] = { 0x0, 0x0, "bl", "la", "bl %%pcrel(%1)", 0, 0, 0 }, { 0x54000000, 0xfc000000, "bl", "sb0:10|10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "beq", "r,r,la", "beq %1,%2,%%pcrel(%3)", 0, 0, 0 }, - { 0x58000000, 0xfc000000, "beq", "r5:5,r0:5,sb10:16<<2", 0, 0, 0, 0 }, + { 0x58000000, 0xfc000000, "beq", "r0:5,r5:5,sb10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "bne", "r,r,la", "bne %1,%2,%%pcrel(%3)", 0, 0, 0 }, - { 0x5c000000, 0xfc000000, "bne", "r5:5,r0:5,sb10:16<<2", 0, 0, 0, 0 }, + { 0x5c000000, 0xfc000000, "bne", "r0:5,r5:5,sb10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "bgt", "r,r,la", "bgt %1,%2,%%pcrel(%3)", 0, 0, 0 }, { 0x60000000, 0xfc000000, "bgt", "r0:5,r5:5,sb10:16<<2", 0, 0, 0, 0 }, { 0x0, 0x0, "ble", "r,r,la", "ble %1,%2,%%pcrel(%3)", 0, 0, 0 },