[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aSQeD-RSZxeuPj_h@google.com>
Date: Mon, 24 Nov 2025 16:57:51 +0800
From: Kuan-Wei Chiu <visitorckw@...il.com>
To: Nikolay Borisov <nik.borisov@...e.com>
Cc: linux-edac@...r.kernel.org, linux-kernel@...r.kernel.org, bp@...en8.de,
Yazen.Ghannam@....com
Subject: Re: [PATCH v2] RAS/AMD/ATL: Remove bitwise_xor_bits
Hi Nikolay,
On Mon, Nov 24, 2025 at 10:40:11AM +0200, Nikolay Borisov wrote:
> Both LLVM/GCC support a __builtin_parity function which is functionally
> equivalent to the custom bitwise_xor_bits() one. Let's simplify the code by
> relying on the built-in. No functional changes.
IIRC in some cases, if the compiler decides not to inline
__builtin_parity(), it generates a libgcc function call like
__paritysi2(). Since the kernel currently lacks this symbol, this could
lead to a build failure at link time. Although the compiler inlines it
in most cases, I am not sure if using __builtin_parity() here is a good
idea.
Regards,
Kuan-Wei
>
> Signed-off-by: Nikolay Borisov <nik.borisov@...e.com>
> ---
>
> Changes since v1:
>
> * Reworded the commit message
>
> drivers/ras/amd/atl/umc.c | 22 +++++-----------------
> 1 file changed, 5 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/ras/amd/atl/umc.c b/drivers/ras/amd/atl/umc.c
> index 6e072b7667e9..7ff4a5a1c5da 100644
> --- a/drivers/ras/amd/atl/umc.c
> +++ b/drivers/ras/amd/atl/umc.c
> @@ -49,18 +49,6 @@ static u8 get_coh_st_inst_id_mi300(struct atl_err *err)
> return i;
> }
>
> -/* XOR the bits in @val. */
> -static u16 bitwise_xor_bits(u16 val)
> -{
> - u16 tmp = 0;
> - u8 i;
> -
> - for (i = 0; i < 16; i++)
> - tmp ^= (val >> i) & 0x1;
> -
> - return tmp;
> -}
> -
> struct xor_bits {
> bool xor_enable;
> u16 col_xor;
> @@ -250,17 +238,17 @@ static unsigned long convert_dram_to_norm_addr_mi300(unsigned long addr)
> if (!addr_hash.bank[i].xor_enable)
> continue;
>
> - temp = bitwise_xor_bits(col & addr_hash.bank[i].col_xor);
> - temp ^= bitwise_xor_bits(row & addr_hash.bank[i].row_xor);
> + temp = (u16)__builtin_parity(col & addr_hash.bank[i].col_xor);
> + temp ^= (u16)__builtin_parity(row & addr_hash.bank[i].row_xor);
> bank ^= temp << i;
> }
>
> /* Calculate hash for PC bit. */
> if (addr_hash.pc.xor_enable) {
> - temp = bitwise_xor_bits(col & addr_hash.pc.col_xor);
> - temp ^= bitwise_xor_bits(row & addr_hash.pc.row_xor);
> + temp = (u16)__builtin_parity(col & addr_hash.pc.col_xor);
> + temp ^= (u16)__builtin_parity(row & addr_hash.pc.row_xor);
> /* Bits SID[1:0] act as Bank[5:4] for PC hash, so apply them here. */
> - temp ^= bitwise_xor_bits((bank | sid << NUM_BANK_BITS) & addr_hash.bank_xor);
> + temp ^= (u16)__builtin_parity((bank | sid << NUM_BANK_BITS) & addr_hash.bank_xor);
> pc ^= temp;
> }
>
> --
> 2.52.0
>
>
Powered by blists - more mailing lists