Skip to content

Commit cf45871

Browse files
pz9115artemiy-volkov
authored andcommitted
RISC-V: PR32036, Support Zcmp cm.mva01s and cm.mvsa01 instructions.
This patch supports Zcmp instruction 'cm.mva01s' and 'cm.mvsa01'. All disassemble instructions use the sreg format. Co-Authored by: Charlie Keaney <[email protected]> Co-Authored by: Mary Bennett <[email protected]> Co-Authored by: Nandni Jamnadas <[email protected]> Co-Authored by: Sinan Lin <[email protected]> Co-Authored by: Simon Cook <[email protected]> Co-Authored by: Shihua Liao <[email protected]> Co-Authored by: Yulong Shi <[email protected]> gas/ChangeLog: PR 32036 * NEWS: Updated. * config/tc-riscv.c (validate_riscv_insn): New operators. (riscv_ip): Ditto. * testsuite/gas/riscv/zcmp-mv.d: New test. * testsuite/gas/riscv/zcmp-mv.s: New test. include/ChangeLog: PR 32036 * opcode/riscv-opc.h (MATCH_CM_MVA01S): New opcode. (MASK_CM_MVA01S): New mask. (MATCH_CM_MVSA01): New opcode. (MASK_CM_MVSA01): New mask. (DECLARE_INSN): New declarations. * opcode/riscv.h (OP_MASK_SREG1): New mask. (OP_SH_SREG1): New operand code. (OP_MASK_SREG2): New mask. (OP_SH_SREG2): New operand code. (X_A0): New reg number. (X_A1): Ditto. (X_S7): Ditto. (RISCV_SREG_0_7): New macro function. opcodes/ChangeLog: PR 32036 * riscv-dis.c (riscv_zcmp_get_sregno): New function. (print_insn_args): New operators. * riscv-opc.c (match_sreg1_not_eq_sreg2): New match function.
1 parent 94cbae4 commit cf45871

File tree

8 files changed

+111
-0
lines changed

8 files changed

+111
-0
lines changed

gas/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
-*- text -*-
22

3+
* Add support for RISC-V Zcmp (cm.mva01s, cm.mvsa01) and CORE-V (XCvBitmanip)
4+
extensions with version 1.0.
5+
36
Changes in 2.43:
47

58
* Add support for LoongArch .option for fine-grained control of assembly

gas/config/tc-riscv.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,9 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
16221622
case 'c':
16231623
switch (*++oparg)
16241624
{
1625+
/* sreg operators in cm.mvsa01 and cm.mva01s. */
1626+
case '1': USE_BITS (OP_MASK_SREG1, OP_SH_SREG1); break;
1627+
case '2': USE_BITS (OP_MASK_SREG2, OP_SH_SREG2); break;
16251628
/* byte immediate operators, load/store byte insns. */
16261629
case 'h': used_bits |= ENCODE_ZCB_HALFWORD_UIMM (-1U); break;
16271630
/* halfword immediate operators, load/store halfword insns. */
@@ -3882,6 +3885,18 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
38823885
asarg = expr_parse_end;
38833886
imm_expr->X_op = O_absent;
38843887
continue;
3888+
case '1':
3889+
if (!reg_lookup (&asarg, RCLASS_GPR, &regno)
3890+
|| !RISCV_SREG_0_7 (regno))
3891+
break;
3892+
INSERT_OPERAND (SREG1, *ip, regno % 8);
3893+
continue;
3894+
case '2':
3895+
if (!reg_lookup (&asarg, RCLASS_GPR, &regno)
3896+
|| !RISCV_SREG_0_7 (regno))
3897+
break;
3898+
INSERT_OPERAND (SREG2, *ip, regno % 8);
3899+
continue;
38853900
default:
38863901
goto unknown_riscv_ip_operand;
38873902
}

gas/testsuite/gas/riscv/zcmp-mv.d

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#as: -march=rv64i_zcmp
2+
#source: zcmp-mv.s
3+
#objdump: -dr -Mno-aliases
4+
5+
.*:[ ]+file format .*
6+
7+
8+
Disassembly of section .text:
9+
10+
0+000 <target>:
11+
[ ]*[0-9a-f]+:[ ]+ac7e[ ]+cm.mva01s[ ]+s0,s7
12+
[ ]*[0-9a-f]+:[ ]+ac7a[ ]+cm.mva01s[ ]+s0,s6
13+
[ ]*[0-9a-f]+:[ ]+acfe[ ]+cm.mva01s[ ]+s1,s7
14+
[ ]*[0-9a-f]+:[ ]+acfa[ ]+cm.mva01s[ ]+s1,s6
15+
[ ]*[0-9a-f]+:[ ]+afee[ ]+cm.mva01s[ ]+s7,s3
16+
[ ]*[0-9a-f]+:[ ]+ade2[ ]+cm.mva01s[ ]+s3,s0
17+
[ ]*[0-9a-f]+:[ ]+aef2[ ]+cm.mva01s[ ]+s5,s4
18+
[ ]*[0-9a-f]+:[ ]+aefa[ ]+cm.mva01s[ ]+s5,s6
19+
[ ]*[0-9a-f]+:[ ]+afa2[ ]+cm.mvsa01[ ]+s7,s0
20+
[ ]*[0-9a-f]+:[ ]+af22[ ]+cm.mvsa01[ ]+s6,s0
21+
[ ]*[0-9a-f]+:[ ]+afa6[ ]+cm.mvsa01[ ]+s7,s1
22+
[ ]*[0-9a-f]+:[ ]+af26[ ]+cm.mvsa01[ ]+s6,s1
23+
[ ]*[0-9a-f]+:[ ]+adbe[ ]+cm.mvsa01[ ]+s3,s7
24+
[ ]*[0-9a-f]+:[ ]+ada2[ ]+cm.mvsa01[ ]+s3,s0
25+
[ ]*[0-9a-f]+:[ ]+aeb2[ ]+cm.mvsa01[ ]+s5,s4
26+
[ ]*[0-9a-f]+:[ ]+aeba[ ]+cm.mvsa01[ ]+s5,s6

gas/testsuite/gas/riscv/zcmp-mv.s

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
target:
2+
3+
# cm.mva01s
4+
cm.mva01s s0,s7
5+
cm.mva01s s0,s6
6+
cm.mva01s s1,s7
7+
cm.mva01s s1,s6
8+
cm.mva01s s7,s3
9+
cm.mva01s x19,s0
10+
cm.mva01s s5,x20
11+
cm.mva01s x21,x22
12+
13+
# cm.mvsa01
14+
cm.mvsa01 s7,s0
15+
cm.mvsa01 s6,s0
16+
cm.mvsa01 s7,s1
17+
cm.mvsa01 s6,s1
18+
cm.mvsa01 s3,s7
19+
cm.mvsa01 x19,s0
20+
cm.mvsa01 s5,x20
21+
cm.mvsa01 x21,x22

include/opcode/riscv-opc.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,6 +2284,10 @@
22842284
#define MASK_CM_POPRET 0xff03
22852285
#define MATCH_CM_POPRETZ 0xbc02
22862286
#define MASK_CM_POPRETZ 0xff03
2287+
#define MATCH_CM_MVA01S 0xac62
2288+
#define MASK_CM_MVA01S 0xfc63
2289+
#define MATCH_CM_MVSA01 0xac22
2290+
#define MASK_CM_MVSA01 0xfc63
22872291
/* Svinval instruction. */
22882292
#define MATCH_SINVAL_VMA 0x16000073
22892293
#define MASK_SINVAL_VMA 0xfe007fff
@@ -4096,6 +4100,8 @@ DECLARE_INSN(cm_push, MATCH_CM_PUSH, MASK_CM_PUSH)
40964100
DECLARE_INSN(cm_pop, MATCH_CM_POP, MASK_CM_POP)
40974101
DECLARE_INSN(cm_popret, MATCH_CM_POPRET, MASK_CM_POPRET)
40984102
DECLARE_INSN(cm_popretz, MATCH_CM_POPRETZ, MASK_CM_POPRETZ)
4103+
DECLARE_INSN(cm_mvsa01, MATCH_CM_MVSA01, MASK_CM_MVSA01)
4104+
DECLARE_INSN(cm_mva01s, MATCH_CM_MVA01S, MASK_CM_MVA01S)
40994105
/* Vendor-specific (T-Head) XTheadBa instructions. */
41004106
DECLARE_INSN(th_addsl, MATCH_TH_ADDSL, MASK_TH_ADDSL)
41014107
/* Vendor-specific (T-Head) XTheadBb instructions. */

include/opcode/riscv.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ static inline unsigned int riscv_insn_length (insn_t insn)
349349
#define OP_MASK_REG_LIST 0xf
350350
#define OP_SH_REG_LIST 4
351351
#define ZCMP_SP_ALIGNMENT 16
352+
#define OP_MASK_SREG1 0x7
353+
#define OP_SH_SREG1 7
354+
#define OP_MASK_SREG2 0x7
355+
#define OP_SH_SREG2 2
352356

353357
#define NVECR 32
354358
#define NVECM 1
@@ -370,7 +374,10 @@ static inline unsigned int riscv_insn_length (insn_t insn)
370374
#define X_T2 7
371375
#define X_S0 8
372376
#define X_S1 9
377+
#define X_A0 10
378+
#define X_A1 11
373379
#define X_S2 18
380+
#define X_S7 23
374381
#define X_S10 26
375382
#define X_S11 27
376383
#define X_T3 28
@@ -418,6 +425,11 @@ static inline unsigned int riscv_insn_length (insn_t insn)
418425
/* The maximal number of subset can be required. */
419426
#define MAX_SUBSET_NUM 4
420427

428+
/* The range of sregs. */
429+
#define RISCV_SREG_0_7(REGNO) \
430+
((REGNO == X_S0 || REGNO == X_S1) \
431+
|| (REGNO >= X_S2 && REGNO <= X_S7))
432+
421433
/* All RISC-V instructions belong to at least one of these classes. */
422434
enum riscv_insn_class
423435
{

opcodes/riscv-dis.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ riscv_get_spimm (insn_t l)
285285
return spimm;
286286
}
287287

288+
/* Get s-register regno by using sreg number.
289+
e.g. the regno of s0 is 8, so
290+
riscv_zcmp_get_sregno (0) equals 8. */
291+
292+
static unsigned
293+
riscv_zcmp_get_sregno (unsigned sreg_idx)
294+
{
295+
return sreg_idx > 1 ?
296+
sreg_idx + 16 : sreg_idx + 8;
297+
}
298+
288299
/* Print insn arguments for 32/64-bit code. */
289300

290301
static void
@@ -698,6 +709,14 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
698709
case 'c': /* Zcb extension 16 bits length instruction fields. */
699710
switch (*++oparg)
700711
{
712+
case '1':
713+
print (info->stream, dis_style_register, "%s",
714+
riscv_gpr_names[riscv_zcmp_get_sregno (EXTRACT_OPERAND (SREG1, l))]);
715+
break;
716+
case '2':
717+
print (info->stream, dis_style_register, "%s",
718+
riscv_gpr_names[riscv_zcmp_get_sregno (EXTRACT_OPERAND (SREG2, l))]);
719+
break;
701720
case 'b':
702721
print (info->stream, dis_style_immediate, "%d",
703722
(int)EXTRACT_ZCB_BYTE_UIMM (l));

opcodes/riscv-opc.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,13 @@ match_th_load_pair(const struct riscv_opcode *op,
355355
return rd1 != rd2 && rd1 != rs && rd2 != rs && match_opcode (op, insn);
356356
}
357357

358+
static int
359+
match_sreg1_not_eq_sreg2 (const struct riscv_opcode *op, insn_t insn)
360+
{
361+
return match_opcode (op, insn)
362+
&& (EXTRACT_OPERAND (SREG1, insn) != EXTRACT_OPERAND (SREG2, insn));
363+
}
364+
358365
/* The order of overloaded instructions matters. Label arguments and
359366
register arguments look the same. Instructions that can have either
360367
for arguments must apear in the correct order in this table for the
@@ -2134,6 +2141,8 @@ const struct riscv_opcode riscv_opcodes[] =
21342141
{"cm.pop", 0, INSN_CLASS_ZCMP, "{Wcr},Wcp", MATCH_CM_POP, MASK_CM_POP, match_opcode, 0 },
21352142
{"cm.popret", 0, INSN_CLASS_ZCMP, "{Wcr},Wcp", MATCH_CM_POPRET, MASK_CM_POPRET, match_opcode, 0 },
21362143
{"cm.popretz", 0, INSN_CLASS_ZCMP, "{Wcr},Wcp", MATCH_CM_POPRETZ, MASK_CM_POPRETZ, match_opcode, 0 },
2144+
{"cm.mva01s", 0, INSN_CLASS_ZCMP, "Wc1,Wc2", MATCH_CM_MVA01S, MASK_CM_MVA01S, match_opcode, 0 },
2145+
{"cm.mvsa01", 0, INSN_CLASS_ZCMP, "Wc1,Wc2", MATCH_CM_MVSA01, MASK_CM_MVSA01, match_sreg1_not_eq_sreg2, 0 },
21372146

21382147
/* Supervisor instructions. */
21392148
{"csrr", 0, INSN_CLASS_ZICSR, "d,E", MATCH_CSRRS, MASK_CSRRS|MASK_RS1, match_opcode, INSN_ALIAS },

0 commit comments

Comments
 (0)