Skip to content

Commit 88a6a2a

Browse files
committed
RISC-V: Add tentative 'Zicntr' and 'Zihpm' support
This commit adds tentative support for 'Zicntr' and 'Zihpm' extensions. It is designed NOT to emit existence of 'Zicntr' and 'Zihpm' extensions to output files unless we specify those extensions with version number in the "-march" option. In a sense, those extensions are nearly transparent on supported ISAs (unless we explicitly touch them). This makes adopting this commit possible without actual ratification. bfd/ChangeLog: * elfxx-riscv.c (check_implicit_for_counters): New function for 'Zicntr' -> 'Zicsr' and 'Zihpm' -> 'Zicsr' implications. (riscv_implicit_subsets): Add implications for those extensions so that current "i" always assume both. (riscv_supported_std_z_ext): Add tentative 'Zicntr' and 'Zihpm' extensions with undetermined version numbers to prevent arch string emitting. (riscv_parse_add_subset): Add "zicntr" and "zihpm" to exceptions to recognize on older ISAs if there's no version number. (riscv_multi_subset_supports): Add support for 'Zicntr'. (riscv_multi_subset_supports_ext): Likewise. gas/ChangeLog: * config/tc-riscv.c (enum riscv_csr_class): Add CSR classes for 'Zicntr' and 'Zihpm' extensions. (riscv_csr_address): Add handling for new CSR classes. * testsuite/gas/riscv/march-imply-i.s: Add 'Zicntr' instructions. include/ChangeLog: * opcode/riscv-opc.h: Change CSR classes for counter CSRs. * opcode/riscv.h (enum riscv_insn_class): Add INSN_CLASS_ZICNTR for 'Zicntr' pseudoinstructions.
1 parent 92f4603 commit 88a6a2a

File tree

6 files changed

+211
-163
lines changed

6 files changed

+211
-163
lines changed

bfd/elfxx-riscv.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,16 @@ check_implicit_for_i (const char *implicit ATTRIBUTE_UNUSED,
10841084
&& subset->minor_version < 1));
10851085
}
10861086

1087+
/* Add the IMPLICIT only when the version of SUBSET is determined. */
1088+
1089+
static bool
1090+
check_implicit_for_counters (const char *implicit ATTRIBUTE_UNUSED,
1091+
riscv_subset_t *subset)
1092+
{
1093+
return (subset->major_version != RISCV_UNKNOWN_VERSION
1094+
&& subset->minor_version != RISCV_UNKNOWN_VERSION);
1095+
}
1096+
10871097
/* Record all implicit information for the subsets. */
10881098
struct riscv_implicit_subset
10891099
{
@@ -1097,6 +1107,8 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
10971107
{"e", "i", check_implicit_always},
10981108
{"i", "zicsr", check_implicit_for_i},
10991109
{"i", "zifencei", check_implicit_for_i},
1110+
{"i", "zicntr", check_implicit_always}, /* Mock. */
1111+
{"i", "zihpm", check_implicit_always}, /* Mock. */
11001112
{"g", "i", check_implicit_always},
11011113
{"g", "m", check_implicit_always},
11021114
{"g", "a", check_implicit_always},
@@ -1179,6 +1191,8 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
11791191
{"zcf", "zca", check_implicit_always},
11801192
{"zcd", "zca", check_implicit_always},
11811193
{"zcb", "zca", check_implicit_always},
1194+
{"zicntr", "zicsr", check_implicit_for_counters},
1195+
{"zihpm", "zicsr", check_implicit_for_counters},
11821196
{"smaia", "ssaia", check_implicit_always},
11831197
{"smstateen", "ssstateen", check_implicit_always},
11841198
{"smepmp", "zicsr", check_implicit_always},
@@ -1246,12 +1260,14 @@ static struct riscv_supported_ext riscv_supported_std_z_ext[] =
12461260
{"zicbom", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
12471261
{"zicbop", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
12481262
{"zicboz", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
1263+
{"zicntr", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 }, /* Mock. */
12491264
{"zicond", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
12501265
{"zicsr", ISA_SPEC_CLASS_20191213, 2, 0, 0 },
12511266
{"zicsr", ISA_SPEC_CLASS_20190608, 2, 0, 0 },
12521267
{"zifencei", ISA_SPEC_CLASS_20191213, 2, 0, 0 },
12531268
{"zifencei", ISA_SPEC_CLASS_20190608, 2, 0, 0 },
12541269
{"zihintpause", ISA_SPEC_CLASS_DRAFT, 2, 0, 0 },
1270+
{"zihpm", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 }, /* Mock. */
12551271
{"zmmul", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
12561272
{"zawrs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
12571273
{"zfa", ISA_SPEC_CLASS_DRAFT, 0, 1, 0 },
@@ -1669,9 +1685,12 @@ riscv_parse_add_subset (riscv_parse_subset_t *rps,
16691685
rps->error_handler
16701686
(_("x ISA extension `%s' must be set with the versions"),
16711687
subset);
1672-
/* Allow old ISA spec can recognize zicsr and zifencei. */
1688+
/* Allow old ISA spec can recognize extensions
1689+
effectively split from the base 'I' ISA version 2.2. */
16731690
else if (strcmp (subset, "zicsr") != 0
1674-
&& strcmp (subset, "zifencei") != 0)
1691+
&& strcmp (subset, "zifencei") != 0
1692+
&& strcmp (subset, "zicntr") != 0
1693+
&& strcmp (subset, "zihpm") != 0)
16751694
rps->error_handler
16761695
(_("cannot find default versions of the ISA extension `%s'"),
16771696
subset);
@@ -2381,6 +2400,8 @@ riscv_multi_subset_supports (riscv_parse_subset_t *rps,
23812400
return riscv_subset_supports (rps, "zicbop");
23822401
case INSN_CLASS_ZICBOZ:
23832402
return riscv_subset_supports (rps, "zicboz");
2403+
case INSN_CLASS_ZICNTR:
2404+
return riscv_subset_supports (rps, "zicntr");
23842405
case INSN_CLASS_ZICOND:
23852406
return riscv_subset_supports (rps, "zicond");
23862407
case INSN_CLASS_ZICSR:
@@ -2574,6 +2595,8 @@ riscv_multi_subset_supports_ext (riscv_parse_subset_t *rps,
25742595
return "zicbop";
25752596
case INSN_CLASS_ZICBOZ:
25762597
return "zicboz";
2598+
case INSN_CLASS_ZICNTR:
2599+
return "zicntr";
25772600
case INSN_CLASS_ZICOND:
25782601
return "zicond";
25792602
case INSN_CLASS_ZICSR:

gas/config/tc-riscv.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ enum riscv_csr_class
6666

6767
CSR_CLASS_I,
6868
CSR_CLASS_I_32, /* rv32 only */
69+
CSR_CLASS_ZICNTR, /* basic hardware perf counter */
70+
CSR_CLASS_ZICNTR_32, /* basic hardware perf counter, rv32 only */
71+
CSR_CLASS_ZIHPM, /* additional hardware perf counter */
72+
CSR_CLASS_ZIHPM_32, /* additional hardware perf counter, rv32 only */
6973
CSR_CLASS_F, /* f-ext only */
7074
CSR_CLASS_ZKR, /* zkr only */
7175
CSR_CLASS_V, /* rvv only */
@@ -1031,6 +1035,18 @@ riscv_csr_address (const char *csr_name,
10311035
need_check_version = true;
10321036
extension = "i";
10331037
break;
1038+
case CSR_CLASS_ZICNTR_32:
1039+
is_rv32_only = true;
1040+
/* Fall through. */
1041+
case CSR_CLASS_ZICNTR:
1042+
extension = "zicntr";
1043+
break;
1044+
case CSR_CLASS_ZIHPM_32:
1045+
is_rv32_only = true;
1046+
/* Fall through. */
1047+
case CSR_CLASS_ZIHPM:
1048+
extension = "zihpm";
1049+
break;
10341050
case CSR_CLASS_H_32:
10351051
is_rv32_only = true;
10361052
/* Fall through. */

gas/testsuite/gas/riscv/march-imply-i.s

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ target:
2222

2323
# zifencei
2424
fence.i
25+
26+
# zicntr
27+
rdcycle t0
28+
rdtime t0
29+
rdinstret t0
30+
rdcycleh t0
31+
rdtimeh t0
32+
rdinstreth t0

0 commit comments

Comments
 (0)