public inbox for linux-riscv@lists.infradead.org
 help / color / mirror / Atom feed
From: Charlie Jenkins <thecharlesjenkins@gmail.com>
To: Dmitry Antipov <dmantipov@yandex.ru>
Cc: Andy Shevchenko <andriy.shevchenko@intel.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Ard Biesheuvel <ardb@kernel.org>,
	linux-riscv@lists.infradead.org
Subject: Re: [PATCH v2 2/2] lib: kunit: add tests for __ashldi3(), __ashrdi3(), and __lshrdi3()
Date: Thu, 9 Apr 2026 14:02:09 -0700	[thread overview]
Message-ID: <20260409210209.GA495379@inky.localdomain> (raw)
In-Reply-To: <20260409033824.465455-3-dmantipov@yandex.ru>

On Thu, Apr 09, 2026 at 06:38:24AM +0300, Dmitry Antipov wrote:
> Add KUnit tests for '__ashldi3()', '__ashrdi3()', and '__lshrdi3()'
> helper functions used to implement 64-bit arithmetic shift left,
> arithmetic shift right and logical shift right, respectively,
> on a 32-bit CPUs.
> 
> Tested with 'qemu-system-riscv32 -M virt' and 'qemu-system-arm -M virt'.
> 
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>

I was able to reproduce these three tests passing on riscv32 qemu.

Tested-by: Charlie Jenkins <thecharlesjenkins@gmail.com>

> ---
> v2: include test-specific headers rather than generic linux/kernel.h
> ---
>  lib/Kconfig.debug       |  10 +++
>  lib/tests/Makefile      |   1 +
>  lib/tests/shdi3_kunit.c | 175 ++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 186 insertions(+)
>  create mode 100644 lib/tests/shdi3_kunit.c
> 
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 93f356d2b3d9..b68b1325379b 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -2942,6 +2942,16 @@ config BITS_TEST
>  
>  	  If unsure, say N.
>  
> +config SHDI3_KUNIT_TEST
> +	tristate "KUnit test for __ashldi3(), __ashrdi3(), and __lshrdi3()"
> +	depends on KUNIT
> +	depends on (32BIT || ARM)
> +	help
> +	  This builds the unit test for __ashldi3(), __ashrdi3(), and
> +	  __lshrdi3() helper functions used to implement 64-bit arithmetic
> +	  shift left, arithmetic shift right and logical shift right,
> +	  respectively, on a 32-bit CPUs.
> +
>  config SLUB_KUNIT_TEST
>  	tristate "KUnit test for SLUB cache error detection" if !KUNIT_ALL_TESTS
>  	depends on SLUB_DEBUG && KUNIT
> diff --git a/lib/tests/Makefile b/lib/tests/Makefile
> index 05f74edbc62b..db678ccdd8b1 100644
> --- a/lib/tests/Makefile
> +++ b/lib/tests/Makefile
> @@ -8,6 +8,7 @@ obj-$(CONFIG_BASE64_KUNIT) += base64_kunit.o
>  obj-$(CONFIG_BITOPS_KUNIT) += bitops_kunit.o
>  obj-$(CONFIG_BITFIELD_KUNIT) += bitfield_kunit.o
>  obj-$(CONFIG_BITS_TEST) += test_bits.o
> +obj-$(CONFIG_SHDI3_KUNIT_TEST) += shdi3_kunit.o
>  obj-$(CONFIG_BLACKHOLE_DEV_KUNIT_TEST) += blackhole_dev_kunit.o
>  obj-$(CONFIG_CHECKSUM_KUNIT) += checksum_kunit.o
>  obj-$(CONFIG_CMDLINE_KUNIT_TEST) += cmdline_kunit.o
> diff --git a/lib/tests/shdi3_kunit.c b/lib/tests/shdi3_kunit.c
> new file mode 100644
> index 000000000000..44f65e66512b
> --- /dev/null
> +++ b/lib/tests/shdi3_kunit.c
> @@ -0,0 +1,175 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later OR Apache-2.0
> +/*
> + * Test cases for __ashldi3(), __ashrdi3(), and __lshrdi3().
> + */
> +
> +#include <linux/array_size.h>
> +#include <linux/module.h>
> +#include <linux/libgcc.h>
> +#include <kunit/test.h>
> +
> +struct shdi3_test_entry {
> +	long long input;
> +	int shift;
> +	long long result;
> +};
> +
> +static const struct shdi3_test_entry ashldi3_testdata[] = {
> +	/* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/ashldi3_test.c */
> +	{ 0x0123456789ABCDEFLL, 0, 0x123456789ABCDEFLL },
> +	{ 0x0123456789ABCDEFLL, 1, 0x2468ACF13579BDELL },
> +	{ 0x0123456789ABCDEFLL, 2, 0x48D159E26AF37BCLL },
> +	{ 0x0123456789ABCDEFLL, 3, 0x91A2B3C4D5E6F78LL },
> +	{ 0x0123456789ABCDEFLL, 4, 0x123456789ABCDEF0LL },
> +	{ 0x0123456789ABCDEFLL, 28, 0x789ABCDEF0000000LL },
> +	{ 0x0123456789ABCDEFLL, 29, 0xF13579BDE0000000LL },
> +	{ 0x0123456789ABCDEFLL, 30, 0xE26AF37BC0000000LL },
> +	{ 0x0123456789ABCDEFLL, 31, 0xC4D5E6F780000000LL },
> +	{ 0x0123456789ABCDEFLL, 32, 0x89ABCDEF00000000LL },
> +	{ 0x0123456789ABCDEFLL, 33, 0x13579BDE00000000LL },
> +	{ 0x0123456789ABCDEFLL, 34, 0x26AF37BC00000000LL },
> +	{ 0x0123456789ABCDEFLL, 35, 0x4D5E6F7800000000LL },
> +	{ 0x0123456789ABCDEFLL, 36, 0x9ABCDEF000000000LL },
> +	{ 0x0123456789ABCDEFLL, 60, 0xF000000000000000LL },
> +	{ 0x0123456789ABCDEFLL, 61, 0xE000000000000000LL },
> +	{ 0x0123456789ABCDEFLL, 62, 0xC000000000000000LL },
> +	{ 0x0123456789ABCDEFLL, 63, 0x8000000000000000LL },
> +};
> +
> +static void shdi3_test_ashldi3(struct kunit *test)
> +{
> +	const struct shdi3_test_entry *e;
> +	long long ret;
> +
> +	for (e = ashldi3_testdata;
> +	     e < ashldi3_testdata + ARRAY_SIZE(ashldi3_testdata); e++) {
> +		ret = __ashldi3(e->input, e->shift);
> +		KUNIT_EXPECT_EQ_MSG(test, ret, e->result,
> +				    "    when evaluating __ashldi3(%lld, %d)",
> +				    e->input, e->shift);
> +	}
> +}
> +
> +static const struct shdi3_test_entry ashrdi3_testdata[] = {
> +	/* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/ashrdi3_test.c */
> +	{ 0x0123456789ABCDEFLL, 0, 0x123456789ABCDEFLL },
> +	{ 0x0123456789ABCDEFLL, 1, 0x91A2B3C4D5E6F7LL },
> +	{ 0x0123456789ABCDEFLL, 2, 0x48D159E26AF37BLL },
> +	{ 0x0123456789ABCDEFLL, 3, 0x2468ACF13579BDLL },
> +	{ 0x0123456789ABCDEFLL, 4, 0x123456789ABCDELL },
> +	{ 0x0123456789ABCDEFLL, 28, 0x12345678LL },
> +	{ 0x0123456789ABCDEFLL, 29, 0x91A2B3CLL },
> +	{ 0x0123456789ABCDEFLL, 30, 0x48D159ELL },
> +	{ 0x0123456789ABCDEFLL, 31, 0x2468ACFLL },
> +	{ 0x0123456789ABCDEFLL, 32, 0x1234567LL },
> +	{ 0x0123456789ABCDEFLL, 33, 0x91A2B3LL },
> +	{ 0x0123456789ABCDEFLL, 34, 0x48D159LL },
> +	{ 0x0123456789ABCDEFLL, 35, 0x2468ACLL },
> +	{ 0x0123456789ABCDEFLL, 36, 0x123456LL },
> +	{ 0x0123456789ABCDEFLL, 60, 0 },
> +	{ 0x0123456789ABCDEFLL, 61, 0 },
> +	{ 0x0123456789ABCDEFLL, 62, 0 },
> +	{ 0x0123456789ABCDEFLL, 63, 0 },
> +	{ 0xFEDCBA9876543210LL, 0, 0xFEDCBA9876543210LL },
> +	{ 0xFEDCBA9876543210LL, 1, 0xFF6E5D4C3B2A1908LL },
> +	{ 0xFEDCBA9876543210LL, 2, 0xFFB72EA61D950C84LL },
> +	{ 0xFEDCBA9876543210LL, 3, 0xFFDB97530ECA8642LL },
> +	{ 0xFEDCBA9876543210LL, 4, 0xFFEDCBA987654321LL },
> +	{ 0xFEDCBA9876543210LL, 28, 0xFFFFFFFFEDCBA987LL },
> +	{ 0xFEDCBA9876543210LL, 29, 0xFFFFFFFFF6E5D4C3LL },
> +	{ 0xFEDCBA9876543210LL, 30, 0xFFFFFFFFFB72EA61LL },
> +	{ 0xFEDCBA9876543210LL, 31, 0xFFFFFFFFFDB97530LL },
> +	{ 0xFEDCBA9876543210LL, 32, 0xFFFFFFFFFEDCBA98LL },
> +	{ 0xFEDCBA9876543210LL, 33, 0xFFFFFFFFFF6E5D4CLL },
> +	{ 0xFEDCBA9876543210LL, 34, 0xFFFFFFFFFFB72EA6LL },
> +	{ 0xFEDCBA9876543210LL, 35, 0xFFFFFFFFFFDB9753LL },
> +	{ 0xFEDCBA9876543210LL, 36, 0xFFFFFFFFFFEDCBA9LL },
> +	{ 0xAEDCBA9876543210LL, 60, 0xFFFFFFFFFFFFFFFALL },
> +	{ 0xAEDCBA9876543210LL, 61, 0xFFFFFFFFFFFFFFFDLL },
> +	{ 0xAEDCBA9876543210LL, 62, 0xFFFFFFFFFFFFFFFELL },
> +	{ 0xAEDCBA9876543210LL, 63, 0xFFFFFFFFFFFFFFFFLL },
> +};
> +
> +static void shdi3_test_ashrdi3(struct kunit *test)
> +{
> +	const struct shdi3_test_entry *e;
> +	long long ret;
> +
> +	for (e = ashrdi3_testdata;
> +	     e < ashrdi3_testdata + ARRAY_SIZE(ashrdi3_testdata); e++) {
> +		ret = __ashrdi3(e->input, e->shift);
> +		KUNIT_EXPECT_EQ_MSG(test, ret, e->result,
> +				    "    when evaluating __ashrdi3(%lld, %d)",
> +				    e->input, e->shift);
> +	}
> +}
> +
> +static const struct shdi3_test_entry lshrdi3_testdata[] = {
> +	/* https://github.com/llvm/llvm-project/compiler-rt/test/builtins/Unit/lshrdi3_test.c */
> +	{ 0x0123456789ABCDEFLL, 0, 0x123456789ABCDEFLL },
> +	{ 0x0123456789ABCDEFLL, 1, 0x91A2B3C4D5E6F7LL },
> +	{ 0x0123456789ABCDEFLL, 2, 0x48D159E26AF37BLL },
> +	{ 0x0123456789ABCDEFLL, 3, 0x2468ACF13579BDLL },
> +	{ 0x0123456789ABCDEFLL, 4, 0x123456789ABCDELL },
> +	{ 0x0123456789ABCDEFLL, 28, 0x12345678LL },
> +	{ 0x0123456789ABCDEFLL, 29, 0x91A2B3CLL },
> +	{ 0x0123456789ABCDEFLL, 30, 0x48D159ELL },
> +	{ 0x0123456789ABCDEFLL, 31, 0x2468ACFLL },
> +	{ 0x0123456789ABCDEFLL, 32, 0x1234567LL },
> +	{ 0x0123456789ABCDEFLL, 33, 0x91A2B3LL },
> +	{ 0x0123456789ABCDEFLL, 34, 0x48D159LL },
> +	{ 0x0123456789ABCDEFLL, 35, 0x2468ACLL },
> +	{ 0x0123456789ABCDEFLL, 36, 0x123456LL },
> +	{ 0x0123456789ABCDEFLL, 60, 0 },
> +	{ 0x0123456789ABCDEFLL, 61, 0 },
> +	{ 0x0123456789ABCDEFLL, 62, 0 },
> +	{ 0x0123456789ABCDEFLL, 63, 0 },
> +	{ 0xFEDCBA9876543210LL, 0, 0xFEDCBA9876543210LL },
> +	{ 0xFEDCBA9876543210LL, 1, 0x7F6E5D4C3B2A1908LL },
> +	{ 0xFEDCBA9876543210LL, 2, 0x3FB72EA61D950C84LL },
> +	{ 0xFEDCBA9876543210LL, 3, 0x1FDB97530ECA8642LL },
> +	{ 0xFEDCBA9876543210LL, 4, 0xFEDCBA987654321LL },
> +	{ 0xFEDCBA9876543210LL, 28, 0xFEDCBA987LL },
> +	{ 0xFEDCBA9876543210LL, 29, 0x7F6E5D4C3LL },
> +	{ 0xFEDCBA9876543210LL, 30, 0x3FB72EA61LL },
> +	{ 0xFEDCBA9876543210LL, 31, 0x1FDB97530LL },
> +	{ 0xFEDCBA9876543210LL, 32, 0xFEDCBA98LL },
> +	{ 0xFEDCBA9876543210LL, 33, 0x7F6E5D4CLL },
> +	{ 0xFEDCBA9876543210LL, 34, 0x3FB72EA6LL },
> +	{ 0xFEDCBA9876543210LL, 35, 0x1FDB9753LL },
> +	{ 0xFEDCBA9876543210LL, 36, 0xFEDCBA9LL },
> +	{ 0xAEDCBA9876543210LL, 60, 0xALL },
> +	{ 0xAEDCBA9876543210LL, 61, 0x5LL },
> +	{ 0xAEDCBA9876543210LL, 62, 0x2LL },
> +	{ 0xAEDCBA9876543210LL, 63, 0x1LL },
> +};
> +
> +static void shdi3_test_lshrdi3(struct kunit *test)
> +{
> +	const struct shdi3_test_entry *e;
> +	long long ret;
> +
> +	for (e = lshrdi3_testdata;
> +	     e < lshrdi3_testdata + ARRAY_SIZE(lshrdi3_testdata); e++) {
> +		ret = __lshrdi3(e->input, e->shift);
> +		KUNIT_EXPECT_EQ_MSG(test, ret, e->result,
> +				    "    when evaluating __lshrdi3(%lld, %d)",
> +				    e->input, e->shift);
> +	}
> +}
> +
> +static struct kunit_case shdi3_test_cases[] = {
> +	KUNIT_CASE(shdi3_test_ashldi3),
> +	KUNIT_CASE(shdi3_test_ashrdi3),
> +	KUNIT_CASE(shdi3_test_lshrdi3),
> +	{}
> +};
> +
> +static struct kunit_suite shdi3_test_suite = {
> +	.name = "shdi3",
> +	.test_cases = shdi3_test_cases,
> +};
> +kunit_test_suite(shdi3_test_suite);
> +
> +MODULE_DESCRIPTION("Test cases for __ashldi3(), __ashrdi3(), and __lshrdi3()");
> +MODULE_LICENSE("GPL");
> -- 
> 2.53.0
> 
> 
> _______________________________________________
> linux-riscv mailing list
> linux-riscv@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-riscv
> 

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

      reply	other threads:[~2026-04-09 21:02 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-07  5:28 [PATCH 0/2] add riscv32 double-word shifts and library test Dmitry Antipov
2026-04-07  5:28 ` [PATCH 1/2] riscv: add platform-specific double word shifts for riscv32 Dmitry Antipov
2026-04-07  5:28 ` [PATCH 2/2] lib: kunit: add tests for __ashldi3(), __ashrdi3(), and __lshrdi3() Dmitry Antipov
2026-04-08 19:41   ` Andy Shevchenko
2026-04-09  3:38     ` [PATCH v2 0/2] add riscv32 double-word shifts and library test Dmitry Antipov
2026-04-09  3:38       ` [PATCH v2 1/2] riscv: add platform-specific double word shifts for riscv32 Dmitry Antipov
2026-04-09 23:22         ` Charlie Jenkins
2026-04-10 10:49           ` Dmitry Antipov
2026-04-10 19:30             ` Charlie Jenkins
2026-04-09  3:38       ` [PATCH v2 2/2] lib: kunit: add tests for __ashldi3(), __ashrdi3(), and __lshrdi3() Dmitry Antipov
2026-04-09 21:02         ` Charlie Jenkins [this message]

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=20260409210209.GA495379@inky.localdomain \
    --to=thecharlesjenkins@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@intel.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=ardb@kernel.org \
    --cc=dmantipov@yandex.ru \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@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