[PATCH 1/2] RISC-V: Base for complex extension implications
Kito Cheng
kito.cheng@gmail.com
Fri May 9 09:34:20 GMT 2025
Oh, good point, and I found actually my second patch isn't really use
that as well, let me drop that and send v2
On Fri, May 9, 2025 at 5:26 PM Nelson Chu <nelson@rivosinc.com> wrote:
>
> Yeah according to the next patch, passing rps to check_func to get the xlen is reasonable, as my pended patch did the same thing,
> https://sourceware.org/pipermail/binutils/2024-November/137651.html
>
> But passing "struct riscv_implicit_subset *t" itself to t->check_func is weird in fact. I guess you want to use the implicit string and then do the similar stuff as my above patch, maybe something that just replaces `+' into `-' when removing the extension which is the superset. But... the t->ext is the extension name, and is the same as the passed subset->name of check_func, that's duplicate. Besides that, users also cannot use the information t->check_func->check_func..., since it will be an unlimited loop? I don't know, but the only useful information for now from "struct riscv_implicit_subset *t" seems to be t->implicit_exts, which doesn't seem that useful in fact... So until we really need it and have a real example, we can decide which arguments to pass to check_func, that's probably a better way to go.
>
> Thanks
> Nelson
>
> On Fri, May 9, 2025 at 3:40 PM Kito Cheng <kito.cheng@sifive.com> wrote:
>>
>> From: Tsukasa OI <research_trasio@irq.a4lg.com>
>>
>> Thanks to the commit 48558a5e5471 ("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.
>> ---
>> bfd/elfxx-riscv.c | 32 +++++++++++++++++++++-----------
>> 1 file changed, 21 insertions(+), 11 deletions(-)
>>
>> diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
>> index 83e237c2a03..4132ecf33fb 100644
>> --- a/bfd/elfxx-riscv.c
>> +++ b/bfd/elfxx-riscv.c
>> @@ -1145,10 +1145,25 @@ riscv_elf_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED,
>> return bfd_reloc_ok;
>> }
>>
>> +/* Record all implicit information for the subsets. */
>> +
>> +struct riscv_implicit_subset
>> +{
>> + const char *ext;
>> + const char *implicit_exts;
>> + /* 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 *);
>> +};
>> +
>> /* Always add implicit extensions for the SUBSET. */
>>
>> static bool
>> -check_implicit_always (riscv_subset_t *subset ATTRIBUTE_UNUSED)
>> +check_implicit_always (riscv_parse_subset_t *rps ATTRIBUTE_UNUSED,
>> + const struct riscv_implicit_subset *implicit
>> + ATTRIBUTE_UNUSED,
>> + const riscv_subset_t *subset ATTRIBUTE_UNUSED)
>> {
>> return true;
>> }
>> @@ -1156,21 +1171,16 @@ check_implicit_always (riscv_subset_t *subset ATTRIBUTE_UNUSED)
>> /* Add implicit extensions only when the version of SUBSET less than 2.1. */
>>
>> static bool
>> -check_implicit_for_i (riscv_subset_t *subset)
>> +check_implicit_for_i (riscv_parse_subset_t *rps ATTRIBUTE_UNUSED,
>> + const struct riscv_implicit_subset *implicit
>> + ATTRIBUTE_UNUSED,
>> + const riscv_subset_t *subset ATTRIBUTE_UNUSED)
>> {
>> 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 *ext;
>> - const char *implicit_exts;
>> - /* A function to determine if we need to add the implicit subsets. */
>> - bool (*check_func) (riscv_subset_t *);
>> -};
>> /* Please added in order since this table is only run once time. */
>> static struct riscv_implicit_subset riscv_implicit_subsets[] =
>> {
>> @@ -2083,7 +2093,7 @@ riscv_parse_add_implicit_subsets (riscv_parse_subset_t *rps)
>> {
>> riscv_subset_t *subset = NULL;
>> if (riscv_lookup_subset (rps->subset_list, t->ext, &subset)
>> - && t->check_func (subset))
>> + && t->check_func (rps, t, subset))
>> riscv_update_subset1 (rps, subset, t->implicit_exts);
>> }
>> }
>> --
>> 2.34.1
>>
More information about the Binutils
mailing list