mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nikolay Borisov <nik.borisov@suse.com>
To: linux-edac@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, bp@alien8.de,
	Yazen.Ghannam@amd.com, Nikolay Borisov <nik.borisov@suse.com>
Subject: [PATCH v2] RAS/AMD/ATL: Remove bitwise_xor_bits
Date: Mon, 24 Nov 2025 10:40:11 +0200	[thread overview]
Message-ID: <20251124084011.1575166-1-nik.borisov@suse.com> (raw)

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.

Signed-off-by: Nikolay Borisov <nik.borisov@suse.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


             reply	other threads:[~2025-11-24  8:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-24  8:40 Nikolay Borisov [this message]
2025-11-24  8:57 ` Kuan-Wei Chiu
2025-11-24 11:05   ` Borislav Petkov
2025-11-24 12:03     ` Kuan-Wei Chiu
2025-11-24 12:52       ` Borislav Petkov
2025-11-24 13:24         ` Nikolay Borisov
2025-11-24 13:34           ` Borislav Petkov
2025-11-25  9:35 ` david laight

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=20251124084011.1575166-1-nik.borisov@suse.com \
    --to=nik.borisov@suse.com \
    --cc=Yazen.Ghannam@amd.com \
    --cc=bp@alien8.de \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®