All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Linton <jeremy.linton@arm.com>
To: Liao Chang <liaochang1@huawei.com>,
	catalin.marinas@arm.com, will@kernel.org, broonie@kernel.org,
	mark.rutland@arm.com, maz@kernel.org, joey.gouly@arm.com,
	kristina.martsenko@arm.com, ryan.roberts@arm.com
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] arm64: cpufeatures: Clean up temporary variable to simplify code
Date: Fri, 1 Mar 2024 13:46:36 -0600	[thread overview]
Message-ID: <e364b4f9-ce92-43a9-ab06-a0391c5dcc5f@arm.com> (raw)
In-Reply-To: <20240229105208.456704-1-liaochang1@huawei.com>

Hi,

On 2/29/24 04:52, Liao Chang wrote:
> Clean up one temporary variable to simplifiy code in capability
> detection.
> 
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> ---
>   arch/arm64/kernel/cpufeature.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
> index 8d1a634a403e..0e900b23f7ab 100644
> --- a/arch/arm64/kernel/cpufeature.c
> +++ b/arch/arm64/kernel/cpufeature.c
> @@ -3052,13 +3052,9 @@ static void __init enable_cpu_capabilities(u16 scope_mask)
>   	boot_scope = !!(scope_mask & SCOPE_BOOT_CPU);
>   
>   	for (i = 0; i < ARM64_NCAPS; i++) {
> -		unsigned int num;
> -
>   		caps = cpucap_ptrs[i];
> -		if (!caps || !(caps->type & scope_mask))
> -			continue;
> -		num = caps->capability;
> -		if (!cpus_have_cap(num))
> +		if (!caps || !(caps->type & scope_mask) ||
> +		    !cpus_have_cap(caps->capability))
>   			continue;
>   
>   		if (boot_scope && caps->cpu_enable)

Looks functionality equivalent to me, and just to see if it makes a 
binary difference I compiled both variations (gcc 14.0.1) and they do 
result in the same instruction sequence. Meaning gcc is smart enough to 
drop the tmp, its also smart enough equate/apply de Morgan's law. The 
latter might make it more readable too, but I guess its all a matter of 
taste.


Reviewed-by: Jeremy Linton <jeremy.linton@arm.com>



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Jeremy Linton <jeremy.linton@arm.com>
To: Liao Chang <liaochang1@huawei.com>,
	catalin.marinas@arm.com, will@kernel.org, broonie@kernel.org,
	mark.rutland@arm.com, maz@kernel.org, joey.gouly@arm.com,
	kristina.martsenko@arm.com, ryan.roberts@arm.com
Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] arm64: cpufeatures: Clean up temporary variable to simplify code
Date: Fri, 1 Mar 2024 13:46:36 -0600	[thread overview]
Message-ID: <e364b4f9-ce92-43a9-ab06-a0391c5dcc5f@arm.com> (raw)
In-Reply-To: <20240229105208.456704-1-liaochang1@huawei.com>

Hi,

On 2/29/24 04:52, Liao Chang wrote:
> Clean up one temporary variable to simplifiy code in capability
> detection.
> 
> Signed-off-by: Liao Chang <liaochang1@huawei.com>
> ---
>   arch/arm64/kernel/cpufeature.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
> index 8d1a634a403e..0e900b23f7ab 100644
> --- a/arch/arm64/kernel/cpufeature.c
> +++ b/arch/arm64/kernel/cpufeature.c
> @@ -3052,13 +3052,9 @@ static void __init enable_cpu_capabilities(u16 scope_mask)
>   	boot_scope = !!(scope_mask & SCOPE_BOOT_CPU);
>   
>   	for (i = 0; i < ARM64_NCAPS; i++) {
> -		unsigned int num;
> -
>   		caps = cpucap_ptrs[i];
> -		if (!caps || !(caps->type & scope_mask))
> -			continue;
> -		num = caps->capability;
> -		if (!cpus_have_cap(num))
> +		if (!caps || !(caps->type & scope_mask) ||
> +		    !cpus_have_cap(caps->capability))
>   			continue;
>   
>   		if (boot_scope && caps->cpu_enable)

Looks functionality equivalent to me, and just to see if it makes a 
binary difference I compiled both variations (gcc 14.0.1) and they do 
result in the same instruction sequence. Meaning gcc is smart enough to 
drop the tmp, its also smart enough equate/apply de Morgan's law. The 
latter might make it more readable too, but I guess its all a matter of 
taste.


Reviewed-by: Jeremy Linton <jeremy.linton@arm.com>



  parent reply	other threads:[~2024-03-01 19:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-29 10:52 [PATCH] arm64: cpufeatures: Clean up temporary variable to simplify code Liao Chang
2024-02-29 10:52 ` Liao Chang
2024-02-29 11:10 ` Mark Rutland
2024-02-29 11:10   ` Mark Rutland
2024-03-01 18:29 ` Catalin Marinas
2024-03-01 18:29   ` Catalin Marinas
2024-03-01 19:46 ` Jeremy Linton [this message]
2024-03-01 19:46   ` Jeremy Linton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e364b4f9-ce92-43a9-ab06-a0391c5dcc5f@arm.com \
    --to=jeremy.linton@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=joey.gouly@arm.com \
    --cc=kristina.martsenko@arm.com \
    --cc=liaochang1@huawei.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.