From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 160B43D811E for ; Wed, 20 May 2026 12:40:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779280806; cv=none; b=GPVT2jhetksvSufGq7MW7Yu4FRNVR7o6+lHQDhDLl6dBBQDjGENe8vqEBaOtuIpiQ4Y69jiXY+OKb9veGnAZR4Bd5bWgzubYSQIgdOyu1H/OfRj5FVbh7kkSUMwnskVrxKZD3VrxdPP2cfvmA94SDiSfV3uvygkSbUvbsTeh5Is= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779280806; c=relaxed/simple; bh=j5Dhu/C427Mc96rLjuNTCKrByvq16NPlOapdfKSW+wc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=TfFt9x1OaRR6yT7xs6gFd4bnBLsPfwGluAIuKOreG523QSmSY7ESzhUJfDJDZ/4KidknHf6mD6L7njXYCtU212Y437k+F+OyrgsBxg5u/5IS+MXjel6qDUyB6cNZjhquzw00lqFrxq8haz5W2gsj+179akZ/2KONGtT9WQhXPEw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Q9BRWlOK; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Q9BRWlOK" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4891c00e7aeso36035255e9.2 for ; Wed, 20 May 2026 05:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779280803; x=1779885603; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SuH6Fo8n73X094Nx+BXIM9AYUCXKRRgGdAspq57tSsc=; b=Q9BRWlOKCkueTp/KKpAP5EVIQlrJtUpDmlpX/AGIsrhV+wyAlRhpvCTn0Oqakb3GHP KMylu5mqW8dAcJ3VQ4LnthaCbzUOa0DKDFAmkllnDCnVhosBKJ1EVnQsSnrsrdDpIqQ8 XYbYKWtRZ6bz/DWtOZhc/t/DALeidl4wn7HRKdmd9LG3efVqQa8snuiv5hsaDlZe4Dro UlctsM9J0qFaJWrD9PyjtMJenwvuw/KWZMeedGlQwBmccuUMXT/R3I+ZqlMsVYMBcJuu hZ8wJ9b2BCoIzJ+90f01jUXhRBhYIUyiam1Ui1pKtqwwALkuF+JHHYNeD8MEmNQC6oxT +TAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779280803; x=1779885603; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=SuH6Fo8n73X094Nx+BXIM9AYUCXKRRgGdAspq57tSsc=; b=itIIHx2QhcOJImA/ZtqEURo/weKb/5PYlJ/kYYfe4p+T5lIMJ7M1dwCfyS2EgB9E9c CWU5OdsjJmTKhcfkW0D23Oq9eEuJyshIpdbu8q1IxUYu7I+QbCMtKm9maz3/Hn7WhNJM /s7HOsGexMAYdpFQPSp/xky5k/t7ptWcbMMxKmoZXnCVefvBB/Z4fwQSVPh1GvKM5Ho1 j+6mPZe7hfIcbKUcsat+fkuKsNxnoiD4J5OaWU7o5G3p/N2/fXiP7GK0711apmBuSsYl sC1/WIIuIPHYqVyANFI4b6dAHIpYWE9Kyc8cZSt4lbuMgzZq5zSRdB+eUQKIEcQ8iNG3 VtnQ== X-Forwarded-Encrypted: i=1; AFNElJ/Qs1E9ZGKpy4HiuNXk1guX677usb81t+Kv75S45+GZnvK1uBCtkZe10GsxZpuC7DzA6MSrebtTifGbai8=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0s7YUiBy+cmF6EJ/IzST2OIg2ZzlIk2atIjRXznZEtXBFyCsV jwhL6E2sDkCCtFvWMMc931oy3SNJnfh4FvDY+nwCZQdXi0YLYVDqNHG7 X-Gm-Gg: Acq92OF63yLXX+uXEiq/pOKAlc9l8jfVMkqfJPw8u1ak/eVT9chmFlW0FRiEe+DGj+/ YMxnNjBBudbEwWX0u3Fa6W187OfWliZeLCxz4Lj7qt1q/fopVYbiOuetRlBzmejc3TBT2hXqBbE Mo3XKulaQBnUZf3/86mGQZR5PrVMD/2RvKQUrUix8poCVznumS780ZsDtlaT+TnNvO077LslOez 4EDauHaGDz61JJWZ/NB8BmrHizgs+9Z7y5GFlxbgNTbKWWjPwaGTnRLWlRjZ9le26yeDiUqAOGq cS1lS7HgJ1YaFKVb78PtOO0aZ1pKx0Q4SP7d9L+xeFy/cU0Zi9VrK/5xi+zDXIPt2NH572L5iPI fQg3qcegECy9j8ANMXTaE1nnAPF3UpH+QfyKiUVctbaB5TcJe8WFbT2q2y0xqLr/V26SGUSHiIS QoZSceJqgBPlY0fgqUqCfFFpxm2D8AU9KN7F59n8iPvQ== X-Received: by 2002:a05:600c:1d0d:b0:48f:da34:ec4e with SMTP id 5b1f17b1804b1-48fe632343dmr344264205e9.19.1779280803275; Wed, 20 May 2026 05:40:03 -0700 (PDT) Received: from RTRKW671-LIN.domain.local ([89.216.37.146]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45d9ec3acf7sm54460252f8f.12.2026.05.20.05.40.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2026 05:40:02 -0700 (PDT) From: Milan Tripkovic To: pjw@kernel.org, palmer@dabbelt.com, aou@eecs.berkeley.edu, kees@kernel.org Cc: alex@ghiti.fr, andy@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Dusan.Stojkovic@rt-rk.com, Milan Tripkovic , Milan Tripkovic Subject: [PATCH v6 0/2] riscv: lib: add optimized memcmp() and extend KUnit tests Date: Wed, 20 May 2026 14:39:52 +0200 Message-ID: <20260520123954.379630-1-milant2002@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This v6 series provides an optimized RISC-V memcmp() implementation along with extended KUnit tests for functional verification and benchmarking The memcmp() implementation now uses word-aligned loads for the generic path and leverages Zbb for fast sign resolution on supported hardware. A robust fallback to byte-by-byte comparison is implemented for non-Zbb systems to ensure correctness and stability across different toolchains and hardware revisions. Signed-off-by: Milan Tripkovic --- v6 changes: - Fixed build errors kernel test robot noticed. - Link to v5: https://lore.kernel.org/all/20260519140029.1190381-1-milant2002@gmail.com/ v5 changes: - Removed redundant warm-up from test case - Optimized generic memcmp path with word-aligned loads. - Implemented non-ZBB fallback to byte comparison per review. - Link to v4: https://lore.kernel.org/all/20260518131407.1026049-2-milant2002@gmail.com/ v4 changes: - Fixed build error: call to undeclared function 'STRING_BENCH' - Link to v3: https://lore.kernel.org/all/20260515141019.1234037-1-milant2002@gmail.com/ v3 changes: - Split memcmp benchmark into wrapper (string_bench_memcmp) and worker function (do_string_bench_memcmp). - Removed all C99 mixed declarations; moved all variable declarations to the top of each function. - Converted len, iterations and loop counters in the benchmark to u64 to avoid implicit casts. - Cleaned up spacing, indentation and minor style issues. - Added #if defined(CONFIG_RISCV_ISA_ZBB)... in memcmp.S - Link to v2: https://lore.kernel.org/all/20260514121359.931999-1-milant2002@gmail.com/ v2 changes: - Added alignment checks for buffers to avoid expensive misaligned loads. - Optimized the loop using end-pointers to reduce per-iteration overhead. - Implemented word-aligned tail handling using ZBB shifts. - Removed redundant pointer equality (a0 == a1) check. - Retained BE support via #ifndef; ZBB rev8 is used for the LE fast-path. - Fixed KUnit build failures for Clang and non-benchmark configs. - Link to v1: https://lore.kernel.org/all/20260512141007.1193033-1-milant2002@gmail.com/ Milan Tripkovic (2): riscv: lib: add memcmp() implementation lib/string_kunit: extend benchmarks and unit test to memcmp() arch/riscv/include/asm/string.h | 2 + arch/riscv/lib/Makefile | 1 + arch/riscv/lib/memcmp.S | 107 ++++++++++++++++++++++++++++++++ arch/riscv/purgatory/Makefile | 5 +- lib/tests/string_kunit.c | 106 +++++++++++++++++++++++++++++++ 5 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/lib/memcmp.S -- 2.43.0