[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v5 11/19] target/riscv/cpu: add misa_ext_info_arr[]

From: Daniel Henrique Barboza
Subject: Re: [PATCH v5 11/19] target/riscv/cpu: add misa_ext_info_arr[]
Date: Tue, 27 Jun 2023 21:04:16 -0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0

On 6/27/23 18:29, Philippe Mathieu-Daudé wrote:
On 27/6/23 18:31, Daniel Henrique Barboza wrote:
Next patch will add KVM specific user properties for both MISA and
multi-letter extensions. For MISA extensions we want to make use of what
is already available in misa_ext_cfgs[] to avoid code repetition.

misa_ext_info_arr[] array will hold name and description for each MISA
extension that misa_ext_cfgs[] is declaring. We'll then use this new
array in KVM code to avoid duplicating strings.

There's nothing holding us back from doing the same with multi-letter
extensions. For now doing just with MISA extensions is enough.

Suggested-by: Andrew Jones <ajones@ventanamicro.com>
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
  target/riscv/cpu.c | 60 ++++++++++++++++++++++++++--------------------
  target/riscv/cpu.h | 11 ++++++++-
  2 files changed, 44 insertions(+), 27 deletions(-)

+const MISAExtInfo misa_ext_info_arr[] = {
+    [RVA] = {"a", "Atomic instructions"},
+    [RVC] = {"c", "Compressed instructions"},
+    [RVD] = {"d", "Double-precision float point"},
+    [RVF] = {"f", "Single-precision float point"},
+    [RVI] = {"i", "Base integer instruction set"},
+    [RVE] = {"e", "Base integer instruction set (embedded)"},
+    [RVM] = {"m", "Integer multiplication and division"},
+    [RVS] = {"s", "Supervisor-level instructions"},
+    [RVU] = {"u", "User-level instructions"},
+    [RVH] = {"h", "Hypervisor"},
+    [RVJ] = {"x-j", "Dynamic translated languages"},
+    [RVV] = {"v", "Vector operations"},
+    [RVG] = {"g", "General purpose (IMAFD_Zicsr_Zifencei)"},

Personally I prefer using a getter() helper because we can check in
a single place for empty entries in the array.

IIUC this 13-entries array takes 4MiB (RVV is '1<<21' = 2MiB).

Wouldn't it be clever to index by [a-z]? Except "x-j"...

Well .. RVA is 1<<0, RVC is 1<<2, up to RVV 1<<21. I guess this array can
be indexed at zero, and then we create a getter() that retrieves the element
we want using ctz32() to find the right index. Something in the likes of:

MISAExtInfo *get_misa_ext_info(uint32_t bit)
    return &misa_ext_info_arr[ctz32(bit)];

And now, since we're using a getter, we don't need to export the whole array

I'll see how it plays out. Thanks,


reply via email to

[Prev in Thread] Current Thread [Next in Thread]