diff mbox series

[v13,14/26] target/riscv/tcg: add hash table insert helpers

Message ID 20231218125334.37184-15-dbarboza@ventanamicro.com
State New
Headers show
Series riscv: RVA22 profiles support | expand

Commit Message

Daniel Henrique Barboza Dec. 18, 2023, 12:53 p.m. UTC
Previous patches added several g_hash_table_insert() patterns. Add two
helpers, one for each user hash, to make the code cleaner.

Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
---
 target/riscv/tcg/tcg-cpu.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

Comments

Alistair Francis Jan. 4, 2024, 6:25 a.m. UTC | #1
On Mon, Dec 18, 2023 at 10:57 PM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> Previous patches added several g_hash_table_insert() patterns. Add two
> helpers, one for each user hash, to make the code cleaner.
>
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

> ---
>  target/riscv/tcg/tcg-cpu.c | 28 ++++++++++++++++------------
>  1 file changed, 16 insertions(+), 12 deletions(-)
>
> diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
> index f2e0ce0f3d..01d2cc9f94 100644
> --- a/target/riscv/tcg/tcg-cpu.c
> +++ b/target/riscv/tcg/tcg-cpu.c
> @@ -42,6 +42,18 @@ static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset)
>                                   GUINT_TO_POINTER(ext_offset));
>  }
>
> +static void cpu_cfg_ext_add_user_opt(uint32_t ext_offset, bool value)
> +{
> +    g_hash_table_insert(multi_ext_user_opts, GUINT_TO_POINTER(ext_offset),
> +                        (gpointer)value);
> +}
> +
> +static void cpu_misa_ext_add_user_opt(uint32_t bit, bool value)
> +{
> +    g_hash_table_insert(misa_ext_user_opts, GUINT_TO_POINTER(bit),
> +                        (gpointer)value);
> +}
> +
>  static void riscv_cpu_write_misa_bit(RISCVCPU *cpu, uint32_t bit,
>                                       bool enabled)
>  {
> @@ -817,9 +829,7 @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
>          return;
>      }
>
> -    g_hash_table_insert(misa_ext_user_opts,
> -                        GUINT_TO_POINTER(misa_bit),
> -                        (gpointer)value);
> +    cpu_misa_ext_add_user_opt(misa_bit, value);
>
>      prev_val = env->misa_ext & misa_bit;
>
> @@ -956,9 +966,7 @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
>              continue;
>          }
>
> -        g_hash_table_insert(misa_ext_user_opts,
> -                            GUINT_TO_POINTER(bit),
> -                            (gpointer)value);
> +        cpu_misa_ext_add_user_opt(bit, profile->enabled);
>          riscv_cpu_write_misa_bit(cpu, bit, profile->enabled);
>      }
>
> @@ -973,9 +981,7 @@ static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
>              cpu_bump_multi_ext_priv_ver(&cpu->env, ext_offset);
>          }
>
> -        g_hash_table_insert(multi_ext_user_opts,
> -                            GUINT_TO_POINTER(ext_offset),
> -                            (gpointer)profile->enabled);
> +        cpu_cfg_ext_add_user_opt(ext_offset, profile->enabled);
>          isa_ext_update_enabled(cpu, ext_offset, profile->enabled);
>      }
>  }
> @@ -1038,9 +1044,7 @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
>                      multi_ext_cfg->name, lower);
>      }
>
> -    g_hash_table_insert(multi_ext_user_opts,
> -                        GUINT_TO_POINTER(multi_ext_cfg->offset),
> -                        (gpointer)value);
> +    cpu_cfg_ext_add_user_opt(multi_ext_cfg->offset, value);
>
>      prev_val = isa_ext_is_enabled(cpu, multi_ext_cfg->offset);
>
> --
> 2.43.0
>
>
diff mbox series

Patch

diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index f2e0ce0f3d..01d2cc9f94 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -42,6 +42,18 @@  static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset)
                                  GUINT_TO_POINTER(ext_offset));
 }
 
+static void cpu_cfg_ext_add_user_opt(uint32_t ext_offset, bool value)
+{
+    g_hash_table_insert(multi_ext_user_opts, GUINT_TO_POINTER(ext_offset),
+                        (gpointer)value);
+}
+
+static void cpu_misa_ext_add_user_opt(uint32_t bit, bool value)
+{
+    g_hash_table_insert(misa_ext_user_opts, GUINT_TO_POINTER(bit),
+                        (gpointer)value);
+}
+
 static void riscv_cpu_write_misa_bit(RISCVCPU *cpu, uint32_t bit,
                                      bool enabled)
 {
@@ -817,9 +829,7 @@  static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
         return;
     }
 
-    g_hash_table_insert(misa_ext_user_opts,
-                        GUINT_TO_POINTER(misa_bit),
-                        (gpointer)value);
+    cpu_misa_ext_add_user_opt(misa_bit, value);
 
     prev_val = env->misa_ext & misa_bit;
 
@@ -956,9 +966,7 @@  static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
             continue;
         }
 
-        g_hash_table_insert(misa_ext_user_opts,
-                            GUINT_TO_POINTER(bit),
-                            (gpointer)value);
+        cpu_misa_ext_add_user_opt(bit, profile->enabled);
         riscv_cpu_write_misa_bit(cpu, bit, profile->enabled);
     }
 
@@ -973,9 +981,7 @@  static void cpu_set_profile(Object *obj, Visitor *v, const char *name,
             cpu_bump_multi_ext_priv_ver(&cpu->env, ext_offset);
         }
 
-        g_hash_table_insert(multi_ext_user_opts,
-                            GUINT_TO_POINTER(ext_offset),
-                            (gpointer)profile->enabled);
+        cpu_cfg_ext_add_user_opt(ext_offset, profile->enabled);
         isa_ext_update_enabled(cpu, ext_offset, profile->enabled);
     }
 }
@@ -1038,9 +1044,7 @@  static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
                     multi_ext_cfg->name, lower);
     }
 
-    g_hash_table_insert(multi_ext_user_opts,
-                        GUINT_TO_POINTER(multi_ext_cfg->offset),
-                        (gpointer)value);
+    cpu_cfg_ext_add_user_opt(multi_ext_cfg->offset, value);
 
     prev_val = isa_ext_is_enabled(cpu, multi_ext_cfg->offset);