[for-4.13,3/6] xen/arm: cpuerrata: Match register size with value size in check_workaround_*
diff mbox series

Message ID 20191002180047.17144-4-julien.grall@arm.com
State New
Headers show
Series
  • xen/arm: Add support to build with clang
Related show

Commit Message

Julien Grall Oct. 2, 2019, 6 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 not really
improve the assembly generated. Instead, replace switch the variable
to use register_t.

Signed-off-by: Julien Grall <julien.grall@arm.com>

---
    Changes in v2:
        - Use !! per Stefano's request
---
 xen/include/asm-arm/cpuerrata.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andrew Cooper Oct. 2, 2019, 6:42 p.m. UTC | #1
On 02/10/2019 19:00, 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 not really
> improve the assembly generated. Instead, replace switch the variable
> to use register_t.
>
> Signed-off-by: Julien Grall <julien.grall@arm.com>
>
> ---
>     Changes in v2:
>         - Use !! per Stefano's request

You are aware that unlikley(), deliberately, has an embedded !! ?

include/xen/compiler.h:11:#define unlikely(x)   __builtin_expect(!!(x),0)

~Andrew
Julien Grall Oct. 2, 2019, 7:17 p.m. UTC | #2
Hi Andrew,

On 10/2/19 7:42 PM, Andrew Cooper wrote:
> On 02/10/2019 19:00, 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 not really
>> improve the assembly generated. Instead, replace switch the variable
>> to use register_t.
>>
>> Signed-off-by: Julien Grall <julien.grall@arm.com>
>>
>> ---
>>      Changes in v2:
>>          - Use !! per Stefano's request
> 
> You are aware that unlikley(), deliberately, has an embedded !! ?

I forgot it, sorry about that :/. Stefano are you happy if I revert to v1?

> 
> include/xen/compiler.h:11:#define unlikely(x)   __builtin_expect(!!(x),0)
> 
> ~Andrew
> 

Cheers,
Stefano Stabellini Oct. 2, 2019, 10:27 p.m. UTC | #3
On Wed, 2 Oct 2019, Julien Grall wrote:
> Hi Andrew,
> 
> On 10/2/19 7:42 PM, Andrew Cooper wrote:
> > On 02/10/2019 19:00, 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 not really
> > > improve the assembly generated. Instead, replace switch the variable
> > > to use register_t.
> > > 
> > > Signed-off-by: Julien Grall <julien.grall@arm.com>
> > > 
> > > ---
> > >      Changes in v2:
> > >          - Use !! per Stefano's request
> > 
> > You are aware that unlikley(), deliberately, has an embedded !! ?
> 
> I forgot it, sorry about that :/. Stefano are you happy if I revert to v1?

I forgot about that too. Yes, that's fine and add my acked-by.


> > 
> > include/xen/compiler.h:11:#define unlikely(x)   __builtin_expect(!!(x),0)
> > 
> > ~Andrew

Patch
diff mbox series

diff --git a/xen/include/asm-arm/cpuerrata.h b/xen/include/asm-arm/cpuerrata.h
index 55ddfda272..0896fe6e25 100644
--- a/xen/include/asm-arm/cpuerrata.h
+++ b/xen/include/asm-arm/cpuerrata.h
@@ -14,14 +14,14 @@  static inline bool check_workaround_##erratum(void)             \
         return false;                                           \
     else                                                        \
     {                                                           \
-        bool ret;                                               \
+        register_t ret;                                         \
                                                                 \
         asm volatile (ALTERNATIVE("mov %0, #0",                 \
                                   "mov %0, #1",                 \
                                   feature)                      \
                       : "=r" (ret));                            \
                                                                 \
-        return unlikely(ret);                                   \
+        return unlikely(!!ret);                                 \
     }                                                           \
 }