LoongArch: Cleanup __builtin_constant_p() checking for cpu_has_*

Message ID 20230718064819.2549052-1-chenhuacai@loongson.cn
State New
Headers
Series LoongArch: Cleanup __builtin_constant_p() checking for cpu_has_* |

Commit Message

Huacai Chen July 18, 2023, 6:48 a.m. UTC
  In current configuration, cpu_has_lsx and cpu_has_lasx are impossible
constants. So cleanup the __builtin_constant_p() checking to reduce the
complexity.

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
---
 arch/loongarch/include/asm/fpu.h | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
  

Comments

WANG Xuerui July 18, 2023, 7:34 a.m. UTC | #1
On 2023/7/18 14:48, Huacai Chen wrote:
> In current configuration, cpu_has_lsx and cpu_has_lasx are impossible
> constants. So cleanup the __builtin_constant_p() checking to reduce the

"cannot be constants"? "impossible constants" sounds like a compile-time 
error to me.

> complexity.
> 
> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
>   arch/loongarch/include/asm/fpu.h | 11 +++--------
>   1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/loongarch/include/asm/fpu.h b/arch/loongarch/include/asm/fpu.h
> index e4193d637f66..f02f4a0d0d64 100644
> --- a/arch/loongarch/include/asm/fpu.h
> +++ b/arch/loongarch/include/asm/fpu.h
> @@ -218,12 +218,7 @@ static inline void restore_lsx(struct task_struct *t)
>   
>   static inline void init_lsx_upper(void)
>   {
> -	/*
> -	 * Check cpu_has_lsx only if it's a constant. This will allow the
> -	 * compiler to optimise out code for CPUs without LSX without adding
> -	 * an extra redundant check for CPUs with LSX.
> -	 */
> -	if (__builtin_constant_p(cpu_has_lsx) && !cpu_has_lsx)
> +	if (!cpu_has_lsx)
>   		return;
>   
>   	_init_lsx_upper();
> @@ -294,7 +289,7 @@ static inline void restore_lasx_upper(struct task_struct *t) {}
>   
>   static inline int thread_lsx_context_live(void)
>   {
> -	if (__builtin_constant_p(cpu_has_lsx) && !cpu_has_lsx)
> +	if (!cpu_has_lsx)
>   		return 0;
>   
>   	return test_thread_flag(TIF_LSX_CTX_LIVE);
> @@ -302,7 +297,7 @@ static inline int thread_lsx_context_live(void)
>   
>   static inline int thread_lasx_context_live(void)
>   {
> -	if (__builtin_constant_p(cpu_has_lasx) && !cpu_has_lasx)
> +	if (!cpu_has_lasx)
>   		return 0;
>   
>   	return test_thread_flag(TIF_LASX_CTX_LIVE);

For the foreseeable future, the changes seem appropriate to me. FWIW the 
LoongArch kernel would stay as generic as possible so I expect the 
various predicates to almost never exist as constants.

Reviewed-by: WANG Xuerui <git@xen0n.name>
  
Huacai Chen July 18, 2023, 8:18 a.m. UTC | #2
On Tue, Jul 18, 2023 at 3:35 PM WANG Xuerui <kernel@xen0n.name> wrote:
>
> On 2023/7/18 14:48, Huacai Chen wrote:
> > In current configuration, cpu_has_lsx and cpu_has_lasx are impossible
> > constants. So cleanup the __builtin_constant_p() checking to reduce the
>
> "cannot be constants"? "impossible constants" sounds like a compile-time
> error to me.
OK, thanks.

Huacai
>
> > complexity.
> >
> > Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
> > ---
> >   arch/loongarch/include/asm/fpu.h | 11 +++--------
> >   1 file changed, 3 insertions(+), 8 deletions(-)
> >
> > diff --git a/arch/loongarch/include/asm/fpu.h b/arch/loongarch/include/asm/fpu.h
> > index e4193d637f66..f02f4a0d0d64 100644
> > --- a/arch/loongarch/include/asm/fpu.h
> > +++ b/arch/loongarch/include/asm/fpu.h
> > @@ -218,12 +218,7 @@ static inline void restore_lsx(struct task_struct *t)
> >
> >   static inline void init_lsx_upper(void)
> >   {
> > -     /*
> > -      * Check cpu_has_lsx only if it's a constant. This will allow the
> > -      * compiler to optimise out code for CPUs without LSX without adding
> > -      * an extra redundant check for CPUs with LSX.
> > -      */
> > -     if (__builtin_constant_p(cpu_has_lsx) && !cpu_has_lsx)
> > +     if (!cpu_has_lsx)
> >               return;
> >
> >       _init_lsx_upper();
> > @@ -294,7 +289,7 @@ static inline void restore_lasx_upper(struct task_struct *t) {}
> >
> >   static inline int thread_lsx_context_live(void)
> >   {
> > -     if (__builtin_constant_p(cpu_has_lsx) && !cpu_has_lsx)
> > +     if (!cpu_has_lsx)
> >               return 0;
> >
> >       return test_thread_flag(TIF_LSX_CTX_LIVE);
> > @@ -302,7 +297,7 @@ static inline int thread_lsx_context_live(void)
> >
> >   static inline int thread_lasx_context_live(void)
> >   {
> > -     if (__builtin_constant_p(cpu_has_lasx) && !cpu_has_lasx)
> > +     if (!cpu_has_lasx)
> >               return 0;
> >
> >       return test_thread_flag(TIF_LASX_CTX_LIVE);
>
> For the foreseeable future, the changes seem appropriate to me. FWIW the
> LoongArch kernel would stay as generic as possible so I expect the
> various predicates to almost never exist as constants.
>
> Reviewed-by: WANG Xuerui <git@xen0n.name>
>
> --
> WANG "xen0n" Xuerui
>
> Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/
>
  

Patch

diff --git a/arch/loongarch/include/asm/fpu.h b/arch/loongarch/include/asm/fpu.h
index e4193d637f66..f02f4a0d0d64 100644
--- a/arch/loongarch/include/asm/fpu.h
+++ b/arch/loongarch/include/asm/fpu.h
@@ -218,12 +218,7 @@  static inline void restore_lsx(struct task_struct *t)
 
 static inline void init_lsx_upper(void)
 {
-	/*
-	 * Check cpu_has_lsx only if it's a constant. This will allow the
-	 * compiler to optimise out code for CPUs without LSX without adding
-	 * an extra redundant check for CPUs with LSX.
-	 */
-	if (__builtin_constant_p(cpu_has_lsx) && !cpu_has_lsx)
+	if (!cpu_has_lsx)
 		return;
 
 	_init_lsx_upper();
@@ -294,7 +289,7 @@  static inline void restore_lasx_upper(struct task_struct *t) {}
 
 static inline int thread_lsx_context_live(void)
 {
-	if (__builtin_constant_p(cpu_has_lsx) && !cpu_has_lsx)
+	if (!cpu_has_lsx)
 		return 0;
 
 	return test_thread_flag(TIF_LSX_CTX_LIVE);
@@ -302,7 +297,7 @@  static inline int thread_lsx_context_live(void)
 
 static inline int thread_lasx_context_live(void)
 {
-	if (__builtin_constant_p(cpu_has_lasx) && !cpu_has_lasx)
+	if (!cpu_has_lasx)
 		return 0;
 
 	return test_thread_flag(TIF_LASX_CTX_LIVE);