From patchwork Sun Feb 4 08:51:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Sanpe X-Patchwork-Id: 13544570 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67A99C4828F for ; Sun, 4 Feb 2024 08:52:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1E896B007D; Sun, 4 Feb 2024 03:52:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CCCD46B007E; Sun, 4 Feb 2024 03:52:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B6BF86B0080; Sun, 4 Feb 2024 03:52:21 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A38A46B007D for ; Sun, 4 Feb 2024 03:52:21 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7F49480422 for ; Sun, 4 Feb 2024 08:52:20 +0000 (UTC) X-FDA: 81753504840.03.2860D8C Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf22.hostedemail.com (Postfix) with ESMTP id A42B0C0017 for ; Sun, 4 Feb 2024 08:52:18 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="lsInmJ/Z"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of sanpeqf@gmail.com designates 209.85.215.195 as permitted sender) smtp.mailfrom=sanpeqf@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707036738; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=r4z0nvVWnIAYTJA2M72IaGWpdL1cvbNZSmvJznW48f8=; b=ylnUF50TL5pqNXaNzCcylbaHD0XZ0FsrHz2+Zf2A6bcfjzc6LMGyhmYqsyTvBoADhZJHqH O5d2e6QuNCwL8cuWYEbgsUpgMe7rmBoognGm54mG96yTt7gOFUT7EhQWgRY3f/Ny8EeFVk nXO8AOltS5HJrXH3s8z3IjmJ8DEMI+o= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="lsInmJ/Z"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of sanpeqf@gmail.com designates 209.85.215.195 as permitted sender) smtp.mailfrom=sanpeqf@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707036738; a=rsa-sha256; cv=none; b=FL+C7mtoDIe6+N0NbHrwGJIJJ7NYE5lfDhUyiSBM6kQ3jzH2KXbPP4N0kAGyOBwuwrWw/I p6SUDezaAPbMIXDM5O0tzFyIIKs4mbUrJ93uibFBCyDxGHaixuu7YJQ7dSRHQtIIfBqVtc KmhdBFydK/bNIDz4bUQUqZ7p+HN68bY= Received: by mail-pg1-f195.google.com with SMTP id 41be03b00d2f7-5ce2aada130so3233157a12.1 for ; Sun, 04 Feb 2024 00:52:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707036737; x=1707641537; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=r4z0nvVWnIAYTJA2M72IaGWpdL1cvbNZSmvJznW48f8=; b=lsInmJ/ZvYc2xyzNRLktj0yK3fGyc+2dNYzr3/XnJxRbiJtgPINlDQCcvLJCPiSyqy jqvdqKT2vMx0kExEzXwEjBRB7aI9xJI9lC+KYpCpIFL+FMUghqNVh/gyBBgeMzq7WOeG Ktj+vcA8mzg2sAw//mR54bxmUStsuov87Z10LNB4WhVofaqMFCTkJse95CjTuy0j+ZIs 5KTC/oXpCAfM+AzD8NwuLGPCBFKggaua3NJPx0wfFj5WppXr/1M7nGB5yl7cANoN9TOi hxLyBLkb682URaBST56ExeFu6GWC6UhWwwHHkmqTg8LcmBbJ4TaU/yKqrHXB8+nYaf10 fx7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707036737; x=1707641537; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=r4z0nvVWnIAYTJA2M72IaGWpdL1cvbNZSmvJznW48f8=; b=uCmP9k4OKpcjCzVp4/TlEnQcCScEld2RIu1Zw+EXe6aqoqkfkVcTcFN7oHDSGBA7xb P3IZLpykgBRzkphEQSqfD4LxO6mjoFvG/zyrZ6hSrquxz837sWoMJ/oRqcD+JJzEKpaO 6pxyTL/c/IVNl+FrtuH0vxvcmNDhwFUZJEO71URc+gPyzbbgmZ9KJUMiMqoPQpaVT0Sk Pu/33AceY+pJyLpWUYirBl22kuqMQVtA0mj++TYArZPFT8d8NUwfDknD0VsKur+5RjDH m2KqNKYojxjryj8ldQDMl3PXXhLHab9Z/zQVqRn87Odi2phiBKryg5DYI3cw42GuVndF xbpA== X-Gm-Message-State: AOJu0YyRgnvEoUy+eszoTtzBGyQqdBzwPhFXihm6ul0vL4b3kn+7evXs R+SEyAzH54ayboBDJOTzGZe6ADYhLzlovb3DBjN/Pimx3Q9xc+LmnzgTBa8Fu65zGpAi X-Google-Smtp-Source: AGHT+IEcYiw8dThyDCH2LzMECBuzlS6CvMGFjjK3PsTXXNtFA4KTa7waR4fjoN14ngsgKukNtaGsWg== X-Received: by 2002:a17:90b:3846:b0:296:2383:fb80 with SMTP id nl6-20020a17090b384600b002962383fb80mr7152730pjb.26.1707036736861; Sun, 04 Feb 2024 00:52:16 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUjBlxxA1lFb+5HgSJ3g90MGzz9eA948Va1u/N809Q9E5kqkDLPRvj0mQI4uNIpZ4nGuZJNNBCUxsz+HJvP4L8jPM096pfXyCamjBmmupfo4xygz3oogZ8yR+ESO+qnGhx37JRnZ2upccyBrV53ekfJBS60K5J8sa2L1EJWI6AxA6NH5Nqu6CjWdtlWR/FGYXUwnx+q4KWRtmc2b+G6t3i6n6n53FQIex+mtrBGnlMWkAJuIFBnvsRy+ufYqK5wkPnlnrbLwArD Received: from localhost ([112.7.96.15]) by smtp.gmail.com with ESMTPSA id jx15-20020a17090b46cf00b00296540086a5sm2898818pjb.23.2024.02.04.00.52.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Feb 2024 00:52:16 -0800 (PST) From: John Sanpe To: linux-mm@kvack.org, akpm@linux-foundation.org, rdunlap@infradead.org, torvalds@linux-foundation.org, unixbhaskar@gmail.com Cc: mm-commits@vger.kernel.org, linux-kernel@vger.kernel.org, John Sanpe Subject: [PATCH] lib/bch.c: increase bitrev single conversion length Date: Sun, 4 Feb 2024 16:51:55 +0800 Message-ID: <20240204085155.6745-1-sanpeqf@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A42B0C0017 X-Stat-Signature: qfxopcwxzz8wbzs4to68eyx9hdt47qjf X-Rspam-User: X-HE-Tag: 1707036738-799953 X-HE-Meta: U2FsdGVkX18vfm5zGdsu8ldpRrk0z7LNRn8IN6sNR1u3wjo9hFhuPLDCpCrO2GqTJgWB6j96i+TfXff6AdB3gJFU0eyr7Jz+r2Az5GTzvdzKkxayF3Ghh7mR8TASnMrhkb7W3MnFdhYtJOGoSw87GV6Xn2v8Dv382Ob31OUrxIYs9emC78gmQSMikS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UqrHScxd13GGNRhfi27dEhj38bK0WGgHd8O34Z4wEPOSgyShQ99wgHk9pJ1AcCsKBF5mT7BS8EUj2P4DRp+Kr3MDI6j2c3zehPVQh6O21OM1TXHcGUKLhQ1+QEb/GT/PUNTbVL/myDYo6HxfceV0LdiDdOm5qRXvS1YStfxss/BG+1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Optimized the performance of the three functions (load_ecc8 store_ecc8 and bch_encode) using a larger calculation length. Signed-off-by: John Sanpe --- lib/bch.c | 87 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 38 deletions(-) diff --git a/lib/bch.c b/lib/bch.c index 5f71fd76eca8..e9a9517e7b1b 100644 --- a/lib/bch.c +++ b/lib/bch.c @@ -73,6 +73,7 @@ #include #include #include +#include #include #if defined(CONFIG_BCH_CONST_PARAMS) @@ -115,14 +116,6 @@ struct gf_poly_deg1 { unsigned int c[2]; }; -static u8 swap_bits(struct bch_control *bch, u8 in) -{ - if (!bch->swap_bits) - return in; - - return bitrev8(in); -} - /* * same as bch_encode(), but process input data one byte at a time */ @@ -135,7 +128,10 @@ static void bch_encode_unaligned(struct bch_control *bch, const int l = BCH_ECC_WORDS(bch)-1; while (len--) { - u8 tmp = swap_bits(bch, *data++); + u8 tmp = *data++; + + if (bch->swap_bits) + tmp = bitrev8(tmp); p = bch->mod8_tab + (l+1)*(((ecc[0] >> 24)^(tmp)) & 0xff); @@ -152,20 +148,27 @@ static void bch_encode_unaligned(struct bch_control *bch, static void load_ecc8(struct bch_control *bch, uint32_t *dst, const uint8_t *src) { - uint8_t pad[4] = {0, 0, 0, 0}; unsigned int i, nwords = BCH_ECC_WORDS(bch)-1; + uint32_t value, bytes = 0; + + for (i = 0; i < nwords; i++, src += 4) { + if (!bch->swap_bits) + value = get_unaligned_be32(src); + else { + value = get_unaligned_le32(src); + value = bitrev32(value); + } + dst[i] = value; + } - for (i = 0; i < nwords; i++, src += 4) - dst[i] = ((u32)swap_bits(bch, src[0]) << 24) | - ((u32)swap_bits(bch, src[1]) << 16) | - ((u32)swap_bits(bch, src[2]) << 8) | - swap_bits(bch, src[3]); - - memcpy(pad, src, BCH_ECC_BYTES(bch)-4*nwords); - dst[nwords] = ((u32)swap_bits(bch, pad[0]) << 24) | - ((u32)swap_bits(bch, pad[1]) << 16) | - ((u32)swap_bits(bch, pad[2]) << 8) | - swap_bits(bch, pad[3]); + memcpy(&bytes, src, BCH_ECC_BYTES(bch)-4*nwords); + if (!bch->swap_bits) + value = be32_to_cpup((__be32 *)&bytes); + else { + value = le32_to_cpup((__le32 *)&bytes); + value = bitrev32(value); + } + dst[nwords] = value; } /* @@ -174,20 +177,27 @@ static void load_ecc8(struct bch_control *bch, uint32_t *dst, static void store_ecc8(struct bch_control *bch, uint8_t *dst, const uint32_t *src) { - uint8_t pad[4]; unsigned int i, nwords = BCH_ECC_WORDS(bch)-1; + uint32_t value, bytes; + + for (i = 0; i < nwords; i++, dst += 4) { + value = src[i]; + if (!bch->swap_bits) + put_unaligned_be32(value, dst); + else { + value = bitrev32(value); + put_unaligned_le32(value, dst); + } + } - for (i = 0; i < nwords; i++) { - *dst++ = swap_bits(bch, src[i] >> 24); - *dst++ = swap_bits(bch, src[i] >> 16); - *dst++ = swap_bits(bch, src[i] >> 8); - *dst++ = swap_bits(bch, src[i]); + value = src[nwords]; + if (!bch->swap_bits) + *(__be32 *)&bytes = cpu_to_be32(value); + else { + value = bitrev32(value); + *(__le32 *)&bytes = cpu_to_le32(value); } - pad[0] = swap_bits(bch, src[nwords] >> 24); - pad[1] = swap_bits(bch, src[nwords] >> 16); - pad[2] = swap_bits(bch, src[nwords] >> 8); - pad[3] = swap_bits(bch, src[nwords]); - memcpy(dst, pad, BCH_ECC_BYTES(bch)-4*nwords); + memcpy(dst, &bytes, BCH_ECC_BYTES(bch)-4*nwords); } /** @@ -257,12 +267,13 @@ void bch_encode(struct bch_control *bch, const uint8_t *data, */ while (mlen--) { /* input data is read in big-endian format */ - w = cpu_to_be32(*pdata++); - if (bch->swap_bits) - w = (u32)swap_bits(bch, w) | - ((u32)swap_bits(bch, w >> 8) << 8) | - ((u32)swap_bits(bch, w >> 16) << 16) | - ((u32)swap_bits(bch, w >> 24) << 24); + if (!bch->swap_bits) + w = be32_to_cpup((__be32 *)pdata++); + else { + w = le32_to_cpup((__le32 *)pdata++); + w = bitrev32(w); + } + w ^= r[0]; p0 = tab0 + (l+1)*((w >> 0) & 0xff); p1 = tab1 + (l+1)*((w >> 8) & 0xff);