Skip to content

Commit

Permalink
RISC-V: Base for complex extension implications
Browse files Browse the repository at this point in the history
Thanks to the commit 48558a5 ("RISC-V: Allow nested implications for
extensions"), we can write complex extension implications in theory.
However, to actually do that, we need to pass more information to
check_func.

For example, we want to imply 'Zcf' from 'F' if and only if the 'Zce'
extension is also enabled and XLEN is 32.  Passing rps is a way to
enable this.

This commit prepares for such complex extension implications.

bfd/ChangeLog:

	* elfxx-riscv.c (struct riscv_implicit_subset) Move around and
	change check_func function prototype.
	(check_implicit_always): New arguments.
	(check_implicit_for_i): Likewise.
	(riscv_implicit_subsets): Add comment for this variable.
	(riscv_parse_add_implicit_subsets): Call check_func with
	new arguments.
  • Loading branch information
a4lg committed Aug 15, 2023
1 parent 2d7f310 commit 2beec86
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions bfd/elfxx-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1064,35 +1064,44 @@ riscv_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED,
return bfd_reloc_ok;
}

/* Record all implicit information for the subsets. */

typedef struct riscv_implicit_subset
{
const char *subset_name;
const char *implicit_name;
/* A function to determine if we need to add the implicit subset. */
bool (*check_func) (riscv_parse_subset_t *,
const struct riscv_implicit_subset *,
const riscv_subset_t *);
} riscv_implicit_subset_t;

/* Always add the IMPLICIT for the SUBSET. */

static bool
check_implicit_always (const char *implicit ATTRIBUTE_UNUSED,
riscv_subset_t *subset ATTRIBUTE_UNUSED)
check_implicit_always (riscv_parse_subset_t *rps ATTRIBUTE_UNUSED,
const riscv_implicit_subset_t *implicit
ATTRIBUTE_UNUSED,
const riscv_subset_t *subset ATTRIBUTE_UNUSED)
{
return true;
}

/* Add the IMPLICIT only when the version of SUBSET less than 2.1. */

static bool
check_implicit_for_i (const char *implicit ATTRIBUTE_UNUSED,
riscv_subset_t *subset)
check_implicit_for_i (riscv_parse_subset_t *rps ATTRIBUTE_UNUSED,
const riscv_implicit_subset_t *implicit ATTRIBUTE_UNUSED,
const riscv_subset_t *subset)
{
return (subset->major_version < 2
|| (subset->major_version == 2
&& subset->minor_version < 1));
}

/* Record all implicit information for the subsets. */
struct riscv_implicit_subset
{
const char *subset_name;
const char *implicit_name;
/* A function to determine if we need to add the implicit subset. */
bool (*check_func) (const char *, riscv_subset_t *);
};
static struct riscv_implicit_subset riscv_implicit_subsets[] =
/* All extension implications. */

static riscv_implicit_subset_t riscv_implicit_subsets[] =
{
{"e", "i", check_implicit_always},
{"i", "zicsr", check_implicit_for_i},
Expand Down Expand Up @@ -1905,7 +1914,7 @@ riscv_parse_extensions (riscv_parse_subset_t *rps,
static void
riscv_parse_add_implicit_subsets (riscv_parse_subset_t *rps)
{
struct riscv_implicit_subset *t = riscv_implicit_subsets;
riscv_implicit_subset_t *t = riscv_implicit_subsets;
bool finished = false;
while (!finished)
{
Expand All @@ -1917,7 +1926,7 @@ riscv_parse_add_implicit_subsets (riscv_parse_subset_t *rps)
if (riscv_lookup_subset (rps->subset_list, t->subset_name, &subset)
&& !riscv_lookup_subset (rps->subset_list, t->implicit_name,
&implicit_subset)
&& t->check_func (t->implicit_name, subset))
&& t->check_func (rps, t, subset))
{
riscv_parse_add_subset (rps, t->implicit_name,
RISCV_UNKNOWN_VERSION,
Expand Down

0 comments on commit 2beec86

Please sign in to comment.