diff mbox series

[PATCH-for-10.1,6/8] target/mips: Introduce mips_cpu_is_64bit() helper

Message ID 20250325154058.92735-7-philmd@linaro.org
State New
Headers show
Series target/mips: Make 'cpu-qom.h' target agnostic | expand

Commit Message

Philippe Mathieu-Daudé March 25, 2025, 3:40 p.m. UTC
mips_cpu_is_64bit() returns whether the CPU is a
32-bit or a 64-bit one.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/mips/cpu-qom.h | 2 ++
 target/mips/cpu.c     | 6 ++++++
 2 files changed, 8 insertions(+)

Comments

Pierrick Bouvier March 26, 2025, 3:26 p.m. UTC | #1
On 3/25/25 08:40, Philippe Mathieu-Daudé wrote:
> mips_cpu_is_64bit() returns whether the CPU is a
> 32-bit or a 64-bit one.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   target/mips/cpu-qom.h | 2 ++
>   target/mips/cpu.c     | 6 ++++++
>   2 files changed, 8 insertions(+)
> 
> diff --git a/target/mips/cpu-qom.h b/target/mips/cpu-qom.h
> index 9acf647420c..52996e7c354 100644
> --- a/target/mips/cpu-qom.h
> +++ b/target/mips/cpu-qom.h
> @@ -33,4 +33,6 @@ OBJECT_DECLARE_CPU_TYPE(MIPSCPU, MIPSCPUClass, MIPS_CPU)
>   #define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
>   #define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
>   
> +bool mips_cpu_is_64bit(MIPSCPU *cpu);
> +
>   #endif
> diff --git a/target/mips/cpu.c b/target/mips/cpu.c
> index d8930468b7d..05b3ce42af5 100644
> --- a/target/mips/cpu.c
> +++ b/target/mips/cpu.c
> @@ -516,6 +516,12 @@ static void mips_cpu_initfn(Object *obj)
>   #endif
>   }
>   
> +bool mips_cpu_is_64bit(MIPSCPU *cpu)
> +{
> +    return !!object_class_dynamic_cast(OBJECT_CLASS(CPU(cpu)->cc),
> +                                       TYPE_MIPS64_CPU);
> +}
> +
>   static char *mips_cpu_type_name(const char *cpu_model)
>   {
>       return g_strdup_printf(MIPS_CPU_TYPE_NAME("%s"), cpu_model);

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>

On the long term, when having the TargetInfo, this is probably an 
information we want to be able to retrieve in the same way for every 
target. That said, we can always replace that later, so this patch is ok 
for now.
Richard Henderson March 26, 2025, 6:22 p.m. UTC | #2
On 3/25/25 10:40, Philippe Mathieu-Daudé wrote:
> mips_cpu_is_64bit() returns whether the CPU is a
> 32-bit or a 64-bit one.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   target/mips/cpu-qom.h | 2 ++
>   target/mips/cpu.c     | 6 ++++++
>   2 files changed, 8 insertions(+)
> 
> diff --git a/target/mips/cpu-qom.h b/target/mips/cpu-qom.h
> index 9acf647420c..52996e7c354 100644
> --- a/target/mips/cpu-qom.h
> +++ b/target/mips/cpu-qom.h
> @@ -33,4 +33,6 @@ OBJECT_DECLARE_CPU_TYPE(MIPSCPU, MIPSCPUClass, MIPS_CPU)
>   #define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
>   #define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
>   
> +bool mips_cpu_is_64bit(MIPSCPU *cpu);
> +
>   #endif
> diff --git a/target/mips/cpu.c b/target/mips/cpu.c
> index d8930468b7d..05b3ce42af5 100644
> --- a/target/mips/cpu.c
> +++ b/target/mips/cpu.c
> @@ -516,6 +516,12 @@ static void mips_cpu_initfn(Object *obj)
>   #endif
>   }
>   
> +bool mips_cpu_is_64bit(MIPSCPU *cpu)
> +{
> +    return !!object_class_dynamic_cast(OBJECT_CLASS(CPU(cpu)->cc),
> +                                       TYPE_MIPS64_CPU);
> +}

This is very nearly object_dynamic_cast.  So why not just

   return object_dynamic_cast(OBJECT(cpu), TYPE_MIPS64_CPU);

?


r~
Philippe Mathieu-Daudé March 27, 2025, 5:05 p.m. UTC | #3
On 26/3/25 19:22, Richard Henderson wrote:
> On 3/25/25 10:40, Philippe Mathieu-Daudé wrote:
>> mips_cpu_is_64bit() returns whether the CPU is a
>> 32-bit or a 64-bit one.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   target/mips/cpu-qom.h | 2 ++
>>   target/mips/cpu.c     | 6 ++++++
>>   2 files changed, 8 insertions(+)
>>
>> diff --git a/target/mips/cpu-qom.h b/target/mips/cpu-qom.h
>> index 9acf647420c..52996e7c354 100644
>> --- a/target/mips/cpu-qom.h
>> +++ b/target/mips/cpu-qom.h
>> @@ -33,4 +33,6 @@ OBJECT_DECLARE_CPU_TYPE(MIPSCPU, MIPSCPUClass, 
>> MIPS_CPU)
>>   #define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
>>   #define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
>> +bool mips_cpu_is_64bit(MIPSCPU *cpu);
>> +
>>   #endif
>> diff --git a/target/mips/cpu.c b/target/mips/cpu.c
>> index d8930468b7d..05b3ce42af5 100644
>> --- a/target/mips/cpu.c
>> +++ b/target/mips/cpu.c
>> @@ -516,6 +516,12 @@ static void mips_cpu_initfn(Object *obj)
>>   #endif
>>   }
>> +bool mips_cpu_is_64bit(MIPSCPU *cpu)
>> +{
>> +    return !!object_class_dynamic_cast(OBJECT_CLASS(CPU(cpu)->cc),
>> +                                       TYPE_MIPS64_CPU);
>> +}
> 
> This is very nearly object_dynamic_cast.  So why not just
> 
>    return object_dynamic_cast(OBJECT(cpu), TYPE_MIPS64_CPU);
> 
> ?

Good point!
diff mbox series

Patch

diff --git a/target/mips/cpu-qom.h b/target/mips/cpu-qom.h
index 9acf647420c..52996e7c354 100644
--- a/target/mips/cpu-qom.h
+++ b/target/mips/cpu-qom.h
@@ -33,4 +33,6 @@  OBJECT_DECLARE_CPU_TYPE(MIPSCPU, MIPSCPUClass, MIPS_CPU)
 #define MIPS_CPU_TYPE_SUFFIX "-" TYPE_MIPS_CPU
 #define MIPS_CPU_TYPE_NAME(model) model MIPS_CPU_TYPE_SUFFIX
 
+bool mips_cpu_is_64bit(MIPSCPU *cpu);
+
 #endif
diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index d8930468b7d..05b3ce42af5 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -516,6 +516,12 @@  static void mips_cpu_initfn(Object *obj)
 #endif
 }
 
+bool mips_cpu_is_64bit(MIPSCPU *cpu)
+{
+    return !!object_class_dynamic_cast(OBJECT_CLASS(CPU(cpu)->cc),
+                                       TYPE_MIPS64_CPU);
+}
+
 static char *mips_cpu_type_name(const char *cpu_model)
 {
     return g_strdup_printf(MIPS_CPU_TYPE_NAME("%s"), cpu_model);