diff mbox

[RFC] Use macros rather than static inline for mfspr and mtspr

Message ID 20160719030841.GA26080@balbir.ozlabs.ibm.com
State Accepted
Headers show

Commit Message

Balbir Singh July 19, 2016, 3:08 a.m. UTC
On Wed, Jul 13, 2016 at 04:20:38PM +1000, Stewart Smith wrote:
> Fixes building skiboot without optimization.
> 
> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
> ---
>  include/processor.h | 27 +++++++++++++++------------
>  1 file changed, 15 insertions(+), 12 deletions(-)
>

From: Balbir Singh <bsingharora@gmail.com>
Date: Tue, 19 Jul 2016 13:04:08 +1000
Subject: [PATCH] Allow mt/mfspr to compile indepdent of the optimization level

The compiler expects to see a constant value in the asm operations
involving spr's. When compiling with -O0, spr is treated as a
variable on stack when inline (this can be seen from the RTL).

We do two things to fix the issue, we mark the functions as
always_inline and we pass spr as a const so that the value is
propagated as constants to the inline asm statement

Tested with -O0

Signed-off-by: Balbir Singh <bsingharora@gmail.com>
---
 include/processor.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Stewart Smith July 19, 2016, 9 a.m. UTC | #1
Balbir Singh <bsingharora@gmail.com> writes:
> On Wed, Jul 13, 2016 at 04:20:38PM +1000, Stewart Smith wrote:
>> Fixes building skiboot without optimization.
>> 
>> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
>> ---
>>  include/processor.h | 27 +++++++++++++++------------
>>  1 file changed, 15 insertions(+), 12 deletions(-)
>>
>
> From: Balbir Singh <bsingharora@gmail.com>
> Date: Tue, 19 Jul 2016 13:04:08 +1000
> Subject: [PATCH] Allow mt/mfspr to compile indepdent of the optimization level
>
> The compiler expects to see a constant value in the asm operations
> involving spr's. When compiling with -O0, spr is treated as a
> variable on stack when inline (this can be seen from the RTL).
>
> We do two things to fix the issue, we mark the functions as
> always_inline and we pass spr as a const so that the value is
> propagated as constants to the inline asm statement
>
> Tested with -O0
>
> Signed-off-by: Balbir Singh <bsingharora@gmail.com>
> ---
>  include/processor.h | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/include/processor.h b/include/processor.h
> index 48bbf90..caca804 100644
> --- a/include/processor.h
> +++ b/include/processor.h
> @@ -235,7 +235,8 @@ static inline void mtmsrd(unsigned long val, int l)
>  	asm volatile("mtmsrd %0,%1" : : "r"(val), "i"(l) : "memory");
>  }
>
> -static inline unsigned long mfspr(unsigned int spr)
> +static inline __attribute__((always_inline))
> +unsigned long mfspr(const unsigned int spr)

That's a much better way to fix it!

Merged to master as of 8bc6cc59098d04bf6bfff7130f414418da496f38
diff mbox

Patch

diff --git a/include/processor.h b/include/processor.h
index 48bbf90..caca804 100644
--- a/include/processor.h
+++ b/include/processor.h
@@ -235,7 +235,8 @@  static inline void mtmsrd(unsigned long val, int l)
 	asm volatile("mtmsrd %0,%1" : : "r"(val), "i"(l) : "memory");
 }
 
-static inline unsigned long mfspr(unsigned int spr)
+static inline __attribute__((always_inline))
+unsigned long mfspr(const unsigned int spr)
 {
 	unsigned long val;
 
@@ -243,7 +244,8 @@  static inline unsigned long mfspr(unsigned int spr)
 	return val;
 }
 
-static inline void mtspr(unsigned int spr, unsigned long val)
+static inline __attribute__((always_inline))
+void mtspr(const unsigned int spr, unsigned long val)
 {
 	asm volatile("mtspr %0,%1" : : "i"(spr), "r"(val) : "memory");
 }