diff mbox series

[08/12] xen/arm: cpufeature: Match register size with value size in cpus_have_const_cap

Message ID 20190327184531.30986-9-julien.grall@arm.com (mailing list archive)
State New, archived
Headers show
Series xen/arm: Add support to build with clang | expand

Commit Message

Julien Grall March 27, 2019, 6:45 p.m. UTC
Clang is pickier than GCC for the register size in asm statement. It
expects the register size to match the value size.

The asm statement expects a 32-bit (resp. 64-bit) value on Arm32
(resp. Arm64) whereas the value is a boolean (Clang consider to be
32-bit).

It would be possible to impose 32-bit register for both architecture
but this require the code to use __OP32. However, it does no really
improve the assembly generated. Instead, replace switch the variable to
use register_t.

Signed-off-by: Julien Grall <julien.grall@arm.com>
---
 xen/include/asm-arm/cpufeature.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stefano Stabellini April 17, 2019, 8:29 p.m. UTC | #1
On Wed, 27 Mar 2019, Julien Grall wrote:
> Clang is pickier than GCC for the register size in asm statement. It
> expects the register size to match the value size.
> 
> The asm statement expects a 32-bit (resp. 64-bit) value on Arm32
> (resp. Arm64) whereas the value is a boolean (Clang consider to be
> 32-bit).
> 
> It would be possible to impose 32-bit register for both architecture
> but this require the code to use __OP32. However, it does no really
> improve the assembly generated. Instead, replace switch the variable to
> use register_t.
> 
> Signed-off-by: Julien Grall <julien.grall@arm.com>
> ---
>  xen/include/asm-arm/cpufeature.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
> index c2c8f3417c..d06f09ecfa 100644
> --- a/xen/include/asm-arm/cpufeature.h
> +++ b/xen/include/asm-arm/cpufeature.h
> @@ -67,7 +67,7 @@ static inline bool cpus_have_cap(unsigned int num)
>  
>  /* System capability check for constant cap */
>  #define cpus_have_const_cap(num) ({                 \
> -        bool __ret;                                 \
> +        register_t __ret;                           \
>                                                      \
>          asm volatile (ALTERNATIVE("mov %0, #0",     \
>                                    "mov %0, #1",     \

As per the previous one, this is fine, but could you also change the
last statement below to unlikely(!!__ret);
Julien Grall April 17, 2019, 9:16 p.m. UTC | #2
On 4/17/19 9:29 PM, Stefano Stabellini wrote:
> On Wed, 27 Mar 2019, Julien Grall wrote:
>> Clang is pickier than GCC for the register size in asm statement. It
>> expects the register size to match the value size.
>>
>> The asm statement expects a 32-bit (resp. 64-bit) value on Arm32
>> (resp. Arm64) whereas the value is a boolean (Clang consider to be
>> 32-bit).
>>
>> It would be possible to impose 32-bit register for both architecture
>> but this require the code to use __OP32. However, it does no really
>> improve the assembly generated. Instead, replace switch the variable to
>> use register_t.
>>
>> Signed-off-by: Julien Grall <julien.grall@arm.com>
>> ---
>>   xen/include/asm-arm/cpufeature.h | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
>> index c2c8f3417c..d06f09ecfa 100644
>> --- a/xen/include/asm-arm/cpufeature.h
>> +++ b/xen/include/asm-arm/cpufeature.h
>> @@ -67,7 +67,7 @@ static inline bool cpus_have_cap(unsigned int num)
>>   
>>   /* System capability check for constant cap */
>>   #define cpus_have_const_cap(num) ({                 \
>> -        bool __ret;                                 \
>> +        register_t __ret;                           \
>>                                                       \
>>           asm volatile (ALTERNATIVE("mov %0, #0",     \
>>                                     "mov %0, #1",     \
> 
> As per the previous one, this is fine, but could you also change the
> last statement below to unlikely(!!__ret);

As per the previous one, the current code is valid. Please justify why 
!! is necessary.

Cheers,
diff mbox series

Patch

diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h
index c2c8f3417c..d06f09ecfa 100644
--- a/xen/include/asm-arm/cpufeature.h
+++ b/xen/include/asm-arm/cpufeature.h
@@ -67,7 +67,7 @@  static inline bool cpus_have_cap(unsigned int num)
 
 /* System capability check for constant cap */
 #define cpus_have_const_cap(num) ({                 \
-        bool __ret;                                 \
+        register_t __ret;                           \
                                                     \
         asm volatile (ALTERNATIVE("mov %0, #0",     \
                                   "mov %0, #1",     \