Skip to content

Commit d26cfc8

Browse files
committed
RISC-V: Add support for 'Zacas' atomic CAS
This commit adds support for the 'Zacas' extension, adding atomic CAS instructions. Beware that this extension also introduces the concept of register pairs and it checks the validity of rs1 and rs2 if applicable. This is based on the latest (frozen) draft: <https://github.com/riscv/riscv-zacas/releases/tag/v1.0-rc5> bfd/ChangeLog: * elfxx-riscv.c (riscv_implicit_subsets): Make 'Zacas' to imply 'A' extension. (riscv_supported_std_z_ext): Add 'Zacas' to the supported list. (riscv_multi_subset_supports, riscv_multi_subset_supports_ext): Add handling for new instruction class. gas/ChangeLog: * testsuite/gas/riscv/zacas-32.s: New test. * testsuite/gas/riscv/zacas-32.d: Likewise. * testsuite/gas/riscv/zacas-64.s: Likewise. * testsuite/gas/riscv/zacas-64.d: Likewise. * testsuite/gas/riscv/zacas-32-fail.s: New failure test. * testsuite/gas/riscv/zacas-32-fail.d: Likewise. * testsuite/gas/riscv/zacas-32-fail.l: Likewise. * testsuite/gas/riscv/zacas-64-fail.s: New failure test. * testsuite/gas/riscv/zacas-64-fail.d: Likewise. * testsuite/gas/riscv/zacas-64-fail.l: Likewise. include/ChangeLog: * opcode/riscv-opc.h (MATCH_AMOCAS_D, MASK_AMOCAS_D, MATCH_AMOCAS_Q, MASK_AMOCAS_Q, MATCH_AMOCAS_W, MASK_AMOCAS_W): New. * opcode/riscv.h (enum riscv_insn_class): Add new instruction class INSN_CLASS_ZACAS. opcodes/ChangeLog: * riscv-opc.c (REGGROUP_REGS_x, REGGROUP_REGS_1, REGGROUP_REGS_2, DEFINE_MATCH_FUNC_R): New match function template with register groups. (match_reggroup_r_1_1_1, match_reggroup_r_1_2_2): New. (riscv_opcodes): Add atomic CAS instructions.
1 parent 0e17d3f commit d26cfc8

File tree

14 files changed

+156
-0
lines changed

14 files changed

+156
-0
lines changed

bfd/elfxx-riscv.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
11481148
{"zhinx", "zhinxmin", check_implicit_always},
11491149
{"zhinxmin", "zfinx", check_implicit_always},
11501150
{"zfinx", "zicsr", check_implicit_always},
1151+
{"zacas", "a", check_implicit_always},
11511152
{"zk", "zkn", check_implicit_always},
11521153
{"zk", "zkr", check_implicit_always},
11531154
{"zk", "zkt", check_implicit_always},
@@ -1259,6 +1260,7 @@ static struct riscv_supported_ext riscv_supported_std_z_ext[] =
12591260
{"zihintntl", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
12601261
{"zihintpause", ISA_SPEC_CLASS_DRAFT, 2, 0, 0 },
12611262
{"zmmul", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
1263+
{"zacas", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
12621264
{"zawrs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
12631265
{"zfa", ISA_SPEC_CLASS_DRAFT, 0, 1, 0 },
12641266
{"zfh", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
@@ -2409,6 +2411,8 @@ riscv_multi_subset_supports (riscv_parse_subset_t *rps,
24092411
return riscv_subset_supports (rps, "zmmul");
24102412
case INSN_CLASS_A:
24112413
return riscv_subset_supports (rps, "a");
2414+
case INSN_CLASS_ZACAS:
2415+
return riscv_subset_supports (rps, "zacas");
24122416
case INSN_CLASS_ZAWRS:
24132417
return riscv_subset_supports (rps, "zawrs");
24142418
case INSN_CLASS_F:
@@ -2619,6 +2623,8 @@ riscv_multi_subset_supports_ext (riscv_parse_subset_t *rps,
26192623
return _ ("m' or `zmmul");
26202624
case INSN_CLASS_A:
26212625
return "a";
2626+
case INSN_CLASS_ZACAS:
2627+
return "zacas";
26222628
case INSN_CLASS_ZAWRS:
26232629
return "zawrs";
26242630
case INSN_CLASS_F:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#as: -march=rv32i_zacas
2+
#error_output: zacas-32-fail.l
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.*: Assembler messages:
2+
.*: Error: illegal operands `amocas\.d a1,a4,\(a3\)'
3+
.*: Error: illegal operands `amocas\.d a0,a5,\(a3\)'
4+
.*: Error: illegal operands `amocas\.d\.aq a1,a4,\(a3\)'
5+
.*: Error: illegal operands `amocas\.d\.aq a0,a5,\(a3\)'
6+
.*: Error: illegal operands `amocas\.d\.rl a1,a4,\(a3\)'
7+
.*: Error: illegal operands `amocas\.d\.rl a0,a5,\(a3\)'
8+
.*: Error: illegal operands `amocas\.d\.aqrl a1,a4,\(a3\)'
9+
.*: Error: illegal operands `amocas\.d\.aqrl a0,a5,\(a3\)'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
target:
2+
# amocas.d (RV32): rd (operand 1) and rs2 (operand 2) must be even.
3+
amocas.d a1, a4, (a3)
4+
amocas.d a0, a5, (a3)
5+
amocas.d.aq a1, a4, (a3)
6+
amocas.d.aq a0, a5, (a3)
7+
amocas.d.rl a1, a4, (a3)
8+
amocas.d.rl a0, a5, (a3)
9+
amocas.d.aqrl a1, a4, (a3)
10+
amocas.d.aqrl a0, a5, (a3)

gas/testsuite/gas/riscv/zacas-32.d

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#as: -march=rv32i_zacas
2+
#objdump: -d
3+
4+
.*:[ ]+file format .*
5+
6+
7+
Disassembly of section .text:
8+
9+
0+000 <target>:
10+
[ ]+[0-9a-f]+:[ ]+28f6a5af[ ]+amocas\.w[ ]+a1,a5,\(a3\)
11+
[ ]+[0-9a-f]+:[ ]+2cf6a5af[ ]+amocas\.w\.aq[ ]+a1,a5,\(a3\)
12+
[ ]+[0-9a-f]+:[ ]+2af6a5af[ ]+amocas\.w\.rl[ ]+a1,a5,\(a3\)
13+
[ ]+[0-9a-f]+:[ ]+2ef6a5af[ ]+amocas\.w\.aqrl[ ]+a1,a5,\(a3\)
14+
[ ]+[0-9a-f]+:[ ]+28e6b52f[ ]+amocas\.d[ ]+a0,a4,\(a3\)
15+
[ ]+[0-9a-f]+:[ ]+2ce6b52f[ ]+amocas\.d\.aq[ ]+a0,a4,\(a3\)
16+
[ ]+[0-9a-f]+:[ ]+2ae6b52f[ ]+amocas\.d\.rl[ ]+a0,a4,\(a3\)
17+
[ ]+[0-9a-f]+:[ ]+2ee6b52f[ ]+amocas\.d\.aqrl[ ]+a0,a4,\(a3\)

gas/testsuite/gas/riscv/zacas-32.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
target:
2+
amocas.w a1, a5, (a3)
3+
amocas.w.aq a1, a5, (a3)
4+
amocas.w.rl a1, a5, (a3)
5+
amocas.w.aqrl a1, a5, (a3)
6+
amocas.d a0, a4, (a3)
7+
amocas.d.aq a0, a4, (a3)
8+
amocas.d.rl a0, a4, (a3)
9+
amocas.d.aqrl a0, a4, (a3)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#as: -march=rv64i_zacas
2+
#error_output: zacas-64-fail.l
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.*: Assembler messages:
2+
.*: Error: illegal operands `amocas\.q a1,a4,\(a3\)'
3+
.*: Error: illegal operands `amocas\.q a0,a5,\(a3\)'
4+
.*: Error: illegal operands `amocas\.q\.aq a1,a4,\(a3\)'
5+
.*: Error: illegal operands `amocas\.q\.aq a0,a5,\(a3\)'
6+
.*: Error: illegal operands `amocas\.q\.rl a1,a4,\(a3\)'
7+
.*: Error: illegal operands `amocas\.q\.rl a0,a5,\(a3\)'
8+
.*: Error: illegal operands `amocas\.q\.aqrl a1,a4,\(a3\)'
9+
.*: Error: illegal operands `amocas\.q\.aqrl a0,a5,\(a3\)'
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
target:
2+
# amocas.q (RV64): rd (operand 1) and rs2 (operand 2) must be even.
3+
amocas.q a1, a4, (a3)
4+
amocas.q a0, a5, (a3)
5+
amocas.q.aq a1, a4, (a3)
6+
amocas.q.aq a0, a5, (a3)
7+
amocas.q.rl a1, a4, (a3)
8+
amocas.q.rl a0, a5, (a3)
9+
amocas.q.aqrl a1, a4, (a3)
10+
amocas.q.aqrl a0, a5, (a3)

gas/testsuite/gas/riscv/zacas-64.d

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#as: -march=rv64i_zacas
2+
#objdump: -d
3+
4+
.*:[ ]+file format .*
5+
6+
7+
Disassembly of section .text:
8+
9+
0+000 <target>:
10+
[ ]+[0-9a-f]+:[ ]+28f6a5af[ ]+amocas\.w[ ]+a1,a5,\(a3\)
11+
[ ]+[0-9a-f]+:[ ]+2cf6a5af[ ]+amocas\.w\.aq[ ]+a1,a5,\(a3\)
12+
[ ]+[0-9a-f]+:[ ]+2af6a5af[ ]+amocas\.w\.rl[ ]+a1,a5,\(a3\)
13+
[ ]+[0-9a-f]+:[ ]+2ef6a5af[ ]+amocas\.w\.aqrl[ ]+a1,a5,\(a3\)
14+
[ ]+[0-9a-f]+:[ ]+28f6b5af[ ]+amocas\.d[ ]+a1,a5,\(a3\)
15+
[ ]+[0-9a-f]+:[ ]+2cf6b5af[ ]+amocas\.d\.aq[ ]+a1,a5,\(a3\)
16+
[ ]+[0-9a-f]+:[ ]+2af6b5af[ ]+amocas\.d\.rl[ ]+a1,a5,\(a3\)
17+
[ ]+[0-9a-f]+:[ ]+2ef6b5af[ ]+amocas\.d\.aqrl[ ]+a1,a5,\(a3\)
18+
[ ]+[0-9a-f]+:[ ]+28e6c52f[ ]+amocas\.q[ ]+a0,a4,\(a3\)
19+
[ ]+[0-9a-f]+:[ ]+2ce6c52f[ ]+amocas\.q\.aq[ ]+a0,a4,\(a3\)
20+
[ ]+[0-9a-f]+:[ ]+2ae6c52f[ ]+amocas\.q\.rl[ ]+a0,a4,\(a3\)
21+
[ ]+[0-9a-f]+:[ ]+2ee6c52f[ ]+amocas\.q\.aqrl[ ]+a0,a4,\(a3\)

0 commit comments

Comments
 (0)