From patchwork Mon Jan 19 21:48:34 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1666 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768859383; bh=uD22uAQz206AzJ0M0Ao4ZejKdqg+QzkaNxGYVUNFH/Q=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=cqrYeIBtex1uW3QMEfCWefWiCylNpfbs0JqVTpIqa67dv+FGcNxNWCxp0bOT5ifxN pJtfZxZ7lJk8X8QOamj2DqW5otYQH/8G0Owzz9QftyVUifkHPf4SdWupWMfYkg5zIX 7/Z445BDdIMM/R1dJVudXoB4FEK4p0pFpk6D8kWx6iPCFlxRv91kVW60pf+9iGK5RC LKeiwY4BumAdMA/8lyJyo4SNJFYiC5wJ7rUy5dvwaT/KZLyq0sbP89ghPCAdx+C3c4 TrD4qNHYl63o4Pb9ApFShmRxzIQGZ2anLSpU+AzCDRcKwlcm3QZRE27BpGvUT1kNVs 2S/Xe5FFdV8kA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id CC3EC69520 for ; Mon, 19 Jan 2026 14:49:43 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 5v52qdKZ-L9C for ; Mon, 19 Jan 2026 14:49:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768859383; bh=uD22uAQz206AzJ0M0Ao4ZejKdqg+QzkaNxGYVUNFH/Q=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=cqrYeIBtex1uW3QMEfCWefWiCylNpfbs0JqVTpIqa67dv+FGcNxNWCxp0bOT5ifxN pJtfZxZ7lJk8X8QOamj2DqW5otYQH/8G0Owzz9QftyVUifkHPf4SdWupWMfYkg5zIX 7/Z445BDdIMM/R1dJVudXoB4FEK4p0pFpk6D8kWx6iPCFlxRv91kVW60pf+9iGK5RC LKeiwY4BumAdMA/8lyJyo4SNJFYiC5wJ7rUy5dvwaT/KZLyq0sbP89ghPCAdx+C3c4 TrD4qNHYl63o4Pb9ApFShmRxzIQGZ2anLSpU+AzCDRcKwlcm3QZRE27BpGvUT1kNVs 2S/Xe5FFdV8kA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id BB23869525 for ; Mon, 19 Jan 2026 14:49:43 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768859381; bh=A5FO+nV5cRdr2P+7Ai0YU5IZPepIrxKtJA5q0CpgjZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vLI4iJc9c6xyb9gYjrppsDeNpdF4GtV16MA9/L0RyLfL8AKRZqIM2TREWYGNf5Z/w qUx6l4lzK1nUmzpoWB3m0McTWF+5+HK7Mm5HtCs3qHIsqnvAza75IaZThC4kwl5PAt EzH0HWltznJRwp0DX9vbG0hZvESgfCF6r5hGbATLKYVfNy7LZp72k/qrQATFbftpe9 ZHiO1udiyqsSNGDPBEt5kEJQEUj0jBRCspsuoLNOSuz+paN3bTjm6Dujf7F7g3hEO5 COfKAQUVWDZqiMWZdjzVVsMHZKXIw04rZwiVs8I+4+yp/P0AVFhAExsCfca+bPXuLq xbsz7WPPjs6Bg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B76B569520; Mon, 19 Jan 2026 14:49:41 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id bQgtvvmKk5mU; Mon, 19 Jan 2026 14:49:41 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768859377; bh=zUcdg0GAaOGOZCEPf4/aef+w3mtH8GArL3aj0KdxZko=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FZzx0hRiqwMCKQKRpDxiWIFgh0ztLFE/uE1Sc80KYL9kpgp3NhRqd30k29//nMy5B sF7Y45Hh1DsytbbzRxTsVaYWbVzysVROh5Yujfsu2rR7+GAzrU4KxXb+olQ6pl5oLf VUwXAjxuqeleXBGu9HOq5L3ImnpcjBVvla+5tsBDlU1MSr9NbQMi2u7qiJHJ/H/YIr DxBhlrNl19UF+1PQeyty7CET2lTDFDc2xNhEujoDgM4QY7mF2X8DFTRoWW4E4LQTZq l2NnMgyt1h4eL2eKpRWawzLSSHOyEHTzMgda+daZ3bMNQ6vhubK5CooxedZnRU5/hi +bsbMW1UjukXA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id CDE0E69533; Mon, 19 Jan 2026 14:49:36 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Mon, 19 Jan 2026 14:48:34 -0700 Message-ID: <20260119214846.3087611-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260119214846.3087611-1-sjg@u-boot.org> References: <20260119214846.3087611-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: MEBK7J4EBQHKSYOZETJ7VDL4SWREXZBK X-Message-ID-Hash: MEBK7J4EBQHKSYOZETJ7VDL4SWREXZBK X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 09/16] ext4l: Move memweight to linux/string.h List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Move the memweight() function to include/linux/string.h where it belongs in the Linux kernel header hierarchy. Use an inline popcount algorithm to avoid header include dependencies. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- fs/ext4l/ext4_uboot.h | 12 +----------- include/linux/string.h | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 79d70d78bfd..6772fd8328f 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -640,17 +640,7 @@ struct dx_hash_info { /* strtomem_pad is in linux/string.h */ /* strscpy_pad is in linux/string.h */ -/* Memory weight - count set bits */ -static inline unsigned long memweight(const void *ptr, size_t bytes) -{ - unsigned long ret = 0; - const unsigned char *p = ptr; - size_t i; - - for (i = 0; i < bytes; i++) - ret += hweight8(p[i]); - return ret; -} +/* memweight is in linux/string.h */ /* BITS_PER_BYTE is in linux/bitops.h */ diff --git a/include/linux/string.h b/include/linux/string.h index 591d99c46a1..8dff476c60d 100644 --- a/include/linux/string.h +++ b/include/linux/string.h @@ -188,6 +188,30 @@ char *strreplace(char *str, char old, char new); */ #define strscpy_pad(dest, src) strncpy(dest, src, sizeof(dest)) +/** + * memweight - Count total number of bits set in a memory region + * @ptr: Pointer to memory region + * @bytes: Number of bytes to examine + * + * Return: Number of set bits in the memory region + */ +static inline unsigned long memweight(const void *ptr, size_t bytes) +{ + unsigned long ret = 0; + const unsigned char *p = ptr; + size_t i; + + for (i = 0; i < bytes; i++) { + /* Inline popcount for byte */ + unsigned char v = p[i]; + + v = v - ((v >> 1) & 0x55); + v = (v & 0x33) + ((v >> 2) & 0x33); + ret += (v + (v >> 4)) & 0x0f; + } + return ret; +} + #ifdef __cplusplus } #endif