[PATCH v3 1/3] RISC-V: Minimal support of scalar crypto extension

Nelson Chu nelson.chu@sifive.com
Wed Nov 10 02:38:48 GMT 2021


On Thu, Nov 4, 2021 at 1:56 PM jiawei <jiawei@iscas.ac.cn> wrote:
>
> Minimal support of scalar crypto extension, add "k" in riscv_supported_std_ext[] to make the   order check right with "zk" behind "zb". "zbk*" is sub-extension for k-ext, so it added behind "zbs" in riscv_supported_std_z_ext[].
> ---
>  bfd/elfxx-riscv.c      | 28 ++++++++++++++++++++++++++++
>  gas/config/tc-riscv.c  | 25 +++++++++++++++++++++++++
>  include/opcode/riscv.h | 11 +++++++++++
>  3 files changed, 64 insertions(+)
>
> diff --git a/bfd/elfxx-riscv.c b/bfd/elfxx-riscv.c
> index cdb4fa0996a..045b5a68a10 100644
> --- a/bfd/elfxx-riscv.c
> +++ b/bfd/elfxx-riscv.c
> @@ -1075,6 +1075,20 @@ static struct riscv_implicit_subset riscv_implicit_subsets[] =
>    {"q", "d",           check_implicit_always},
>    {"d", "f",           check_implicit_always},
>    {"f", "zicsr",       check_implicit_always},
> +  {"zk", "zkn",        check_implicit_always},
> +  {"zk", "zkr",        check_implicit_always},
> +  {"zk", "zkt",        check_implicit_always},
> +  {"zkn", "zbkb",      check_implicit_always},
> +  {"zkn", "zbkc",      check_implicit_always},
> +  {"zkn", "zbkx",      check_implicit_always},
> +  {"zkn", "zkne",      check_implicit_always},
> +  {"zkn", "zknd",      check_implicit_always},
> +  {"zkn", "zknh",      check_implicit_always},
> +  {"zks", "zbkb",      check_implicit_always},
> +  {"zks", "zbkc",      check_implicit_always},
> +  {"zks", "zbkx",      check_implicit_always},
> +  {"zks", "zksed",     check_implicit_always},
> +  {"zks", "zksh",      check_implicit_always},
>    {NULL, NULL, NULL}
>  };
>
> @@ -1128,6 +1142,7 @@ static struct riscv_supported_ext riscv_supported_std_ext[] =
>    {"c",                ISA_SPEC_CLASS_2P2,             2, 0, 0 },
>    {"b",                ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
>    {"j",                ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
> +  {"k",                ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
>    {"t",                ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
>    {"p",                ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },
>    {"v",                ISA_SPEC_CLASS_NONE, RISCV_UNKNOWN_VERSION, RISCV_UNKNOWN_VERSION, 0 },

After checking the table 27.1 (Standard ISA extension names...) in the
riscv ISA spec, I think the k extension should be placed after b, and
before j extension.

> @@ -1146,6 +1161,19 @@ static struct riscv_supported_ext riscv_supported_std_z_ext[] =
>    {"zba",              ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
>    {"zbc",              ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
>    {"zbs",               ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zbkb",             ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zbkc",             ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zbkx",             ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zk",               ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zkn",              ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zknd",             ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zkne",             ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zknh",             ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zkr",              ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zks",              ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zksed",    ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zksh",             ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
> +  {"zkt",              ISA_SPEC_CLASS_DRAFT,           1, 0,  0 },
>    {NULL, 0, 0, 0, 0}
>  };
>
> diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
> index eb626f8e1d5..5e7009b5696 100644
> --- a/gas/config/tc-riscv.c
> +++ b/gas/config/tc-riscv.c
> @@ -301,6 +301,31 @@ riscv_multi_subset_supports (enum riscv_insn_class insn_class)
>        return riscv_subset_supports ("zbc");
>      case INSN_CLASS_ZBS:
>        return riscv_subset_supports ("zbs");
> +    case INSN_CLASS_ZBKB:
> +      return riscv_subset_supports ("zbkb");
> +    case INSN_CLASS_ZBKC:
> +      return riscv_subset_supports ("zbkc");
> +    case INSN_CLASS_ZBKX:
> +      return riscv_subset_supports ("zbkx");
> +    case INSN_CLASS_ZBB_OR_ZBKB:
> +      return (riscv_subset_supports ("zbb")
> +        || riscv_subset_supports ("zbkb"));
> +    case INSN_CLASS_ZBC_OR_ZBKC:
> +      return (riscv_subset_supports ("zbc")
> +        || riscv_subset_supports ("zbkc"));
> +    case INSN_CLASS_ZKND:
> +      return riscv_subset_supports ("zknd");
> +    case INSN_CLASS_ZKNE:
> +      return riscv_subset_supports ("zkne");
> +    case INSN_CLASS_ZKNH:
> +      return riscv_subset_supports ("zknh");
> +    case INSN_CLASS_ZKND_OR_ZKNE:
> +      return (riscv_subset_supports ("zknd")
> +        || riscv_subset_supports ("zkne"));
> +    case INSN_CLASS_ZKSED:
> +      return riscv_subset_supports ("zksed");
> +    case INSN_CLASS_ZKSH:
> +      return riscv_subset_supports ("zksh");
>      default:
>        as_fatal ("internal: unreachable");
>        return false;
> diff --git a/include/opcode/riscv.h b/include/opcode/riscv.h
> index afcd41ff1dd..f61004bdf95 100644
> --- a/include/opcode/riscv.h
> +++ b/include/opcode/riscv.h
> @@ -320,6 +320,17 @@ enum riscv_insn_class
>    INSN_CLASS_ZBB,
>    INSN_CLASS_ZBC,
>    INSN_CLASS_ZBS,
> +  INSN_CLASS_ZBKB,
> +  INSN_CLASS_ZBKC,
> +  INSN_CLASS_ZBKX,
> +  INSN_CLASS_ZKND,
> +  INSN_CLASS_ZKNE,
> +  INSN_CLASS_ZKNH,
> +  INSN_CLASS_ZKSED,
> +  INSN_CLASS_ZKSH,
> +  INSN_CLASS_ZBB_OR_ZBKB,
> +  INSN_CLASS_ZBC_OR_ZBKC,
> +  INSN_CLASS_ZKND_OR_ZKNE,
>  };
>
>  /* This structure holds information for a particular instruction.  */
> --

Likewise, the INSN_CLASS* classes can be moved to the later patches,
so this patch can focus on the architecture string parser support.
Except for the above comments, this patch looks good to me.

Thanks
Nelson


More information about the Binutils mailing list