Skip to content

Commit c3acf0e

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 d80081e commit c3acf0e

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
@@ -1030,6 +1030,16 @@ check_implicit_for_i (const char *implicit ATTRIBUTE_UNUSED,
10301030
&& subset->minor_version < 1));
10311031
}
10321032

1033+
/* Add the IMPLICIT only when the version of SUBSET is determined. */
1034+
1035+
static bool
1036+
check_implicit_for_counters (const char *implicit ATTRIBUTE_UNUSED,
1037+
riscv_subset_t *subset)
1038+
{
1039+
return (subset->major_version != RISCV_UNKNOWN_VERSION
1040+
&& subset->minor_version != RISCV_UNKNOWN_VERSION);
1041+
}
1042+
10331043
/* Record all implicit information for the subsets. */
10341044
struct riscv_implicit_subset
10351045
{
@@ -1043,6 +1053,8 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
10431053
{"e", "i", check_implicit_always},
10441054
{"i", "zicsr", check_implicit_for_i},
10451055
{"i", "zifencei", check_implicit_for_i},
1056+
{"i", "zicntr", check_implicit_always}, /* Mock. */
1057+
{"i", "zihpm", check_implicit_always}, /* Mock. */
10461058
{"g", "i", check_implicit_always},
10471059
{"g", "m", check_implicit_always},
10481060
{"g", "a", check_implicit_always},
@@ -1101,6 +1113,8 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
11011113
{"zks", "zbkx", check_implicit_always},
11021114
{"zks", "zksed", check_implicit_always},
11031115
{"zks", "zksh", check_implicit_always},
1116+
{"zicntr", "zicsr", check_implicit_for_counters},
1117+
{"zihpm", "zicsr", check_implicit_for_counters},
11041118
{"smaia", "ssaia", check_implicit_always},
11051119
{"smstateen", "ssstateen", check_implicit_always},
11061120
{"smepmp", "zicsr", check_implicit_always},
@@ -1168,11 +1182,13 @@ static struct riscv_supported_ext riscv_supported_std_z_ext[] =
11681182
{"zicbom", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
11691183
{"zicbop", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
11701184
{"zicboz", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
1185+
{"zicntr", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 }, /* Mock. */
11711186
{"zicsr", ISA_SPEC_CLASS_20191213, 2, 0, 0 },
11721187
{"zicsr", ISA_SPEC_CLASS_20190608, 2, 0, 0 },
11731188
{"zifencei", ISA_SPEC_CLASS_20191213, 2, 0, 0 },
11741189
{"zifencei", ISA_SPEC_CLASS_20190608, 2, 0, 0 },
11751190
{"zihintpause", ISA_SPEC_CLASS_DRAFT, 2, 0, 0 },
1191+
{"zihpm", ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 }, /* Mock. */
11761192
{"zmmul", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
11771193
{"zawrs", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
11781194
{"zfh", ISA_SPEC_CLASS_DRAFT, 1, 0, 0 },
@@ -1568,9 +1584,12 @@ riscv_parse_add_subset (riscv_parse_subset_t *rps,
15681584
rps->error_handler
15691585
(_("x ISA extension `%s' must be set with the versions"),
15701586
subset);
1571-
/* Allow old ISA spec can recognize zicsr and zifencei. */
1587+
/* Allow old ISA spec can recognize extensions
1588+
effectively split from the base 'I' ISA version 2.2. */
15721589
else if (strcmp (subset, "zicsr") != 0
1573-
&& strcmp (subset, "zifencei") != 0)
1590+
&& strcmp (subset, "zifencei") != 0
1591+
&& strcmp (subset, "zicntr") != 0
1592+
&& strcmp (subset, "zihpm") != 0)
15741593
rps->error_handler
15751594
(_("cannot find default versions of the ISA extension `%s'"),
15761595
subset);
@@ -2258,6 +2277,8 @@ riscv_multi_subset_supports (riscv_parse_subset_t *rps,
22582277
return riscv_subset_supports (rps, "zicbop");
22592278
case INSN_CLASS_ZICBOZ:
22602279
return riscv_subset_supports (rps, "zicboz");
2280+
case INSN_CLASS_ZICNTR:
2281+
return riscv_subset_supports (rps, "zicntr");
22612282
case INSN_CLASS_ZICSR:
22622283
return riscv_subset_supports (rps, "zicsr");
22632284
case INSN_CLASS_ZIFENCEI:
@@ -2407,6 +2428,8 @@ riscv_multi_subset_supports_ext (riscv_parse_subset_t *rps,
24072428
return "zicbop";
24082429
case INSN_CLASS_ZICBOZ:
24092430
return "zicboz";
2431+
case INSN_CLASS_ZICNTR:
2432+
return "zicntr";
24102433
case INSN_CLASS_ZICSR:
24112434
return "zicsr";
24122435
case INSN_CLASS_ZIFENCEI:

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 */
@@ -1028,6 +1032,18 @@ riscv_csr_address (const char *csr_name,
10281032
need_check_version = true;
10291033
extension = "i";
10301034
break;
1035+
case CSR_CLASS_ZICNTR_32:
1036+
is_rv32_only = true;
1037+
/* Fall through. */
1038+
case CSR_CLASS_ZICNTR:
1039+
extension = "zicntr";
1040+
break;
1041+
case CSR_CLASS_ZIHPM_32:
1042+
is_rv32_only = true;
1043+
/* Fall through. */
1044+
case CSR_CLASS_ZIHPM:
1045+
extension = "zihpm";
1046+
break;
10311047
case CSR_CLASS_H_32:
10321048
is_rv32_only = true;
10331049
/* 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)