From: Andre Muezerie <andremue@linux.microsoft.com>
To: Yipeng Wang <yipeng1.wang@intel.com>,
Sameh Gobriel <sameh.gobriel@intel.com>,
Bruce Richardson <bruce.richardson@intel.com>,
Vladimir Medvedkin <vladimir.medvedkin@intel.com>
Cc: dev@dpdk.org, Andre Muezerie <andremue@linux.microsoft.com>
Subject: [PATCH 2/2] app/test: add test_init_m128i using compiler intrinsic
Date: Wed, 27 Nov 2024 14:57:58 -0800 [thread overview]
Message-ID: <1732748278-14796-2-git-send-email-andremue@linux.microsoft.com> (raw)
In-Reply-To: <1732748278-14796-1-git-send-email-andremue@linux.microsoft.com>
This test initializes an __m128i data type using the old
non-portable way used until now and the more portable way
using compiler intrinsics. The test ensures the resulting
values after initialization match.
Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
---
app/test/test_thash.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/app/test/test_thash.c b/app/test/test_thash.c
index b9c6e9118e..c121b1f43f 100644
--- a/app/test/test_thash.c
+++ b/app/test/test_thash.c
@@ -1030,6 +1030,38 @@ test_keygen(void)
return TEST_SUCCESS;
}
+#ifdef RTE_ARCH_X86
+#ifndef RTE_TOOLCHAIN_MSVC
+static int
+test_init_m128i(void)
+{
+ /* When initializing __m128i with two constant values like below
+ * MSVC issues warning C4305:
+ * 'initializing': truncation from 'unsigned __int64' to 'char'
+ */
+ static const __m128i a = {
+ 0x0405060700010203ULL, 0x0C0D0E0F08090A0BULL};
+
+ /* Using compiler intrinsics to initialize __m128i is therefore
+ * preferred, like below
+ */
+ static const uint8_t b_bytes[] = {
+ 0x03, 0x02, 0x01, 0x00, 0x07, 0x06, 0x05, 0x04,
+ 0x0B, 0x0A, 0x09, 0x08, 0x0F, 0x0E, 0x0D, 0x0C};
+ const __m128i b =
+ _mm_loadu_si128((const __m128i *)&b_bytes);
+
+ if (memcmp(&a, &b, sizeof(a)) != 0) {
+ printf("Same value was expected when initializing data "
+ "type using compiler intrinsic\n");
+ return -1;
+ }
+
+ return TEST_SUCCESS;
+}
+#endif
+#endif
+
static struct unit_test_suite thash_tests = {
.suite_name = "thash autotest",
.setup = NULL,
@@ -1052,6 +1084,11 @@ static struct unit_test_suite thash_tests = {
TEST_CASE(test_adjust_tuple),
TEST_CASE(test_adjust_tuple_mult_reta),
TEST_CASE(test_keygen),
+#ifdef RTE_ARCH_X86
+#ifndef RTE_TOOLCHAIN_MSVC
+ TEST_CASE(test_init_m128i),
+#endif
+#endif
TEST_CASES_END()
}
};
--
2.34.1
next prev parent reply other threads:[~2024-11-27 22:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-27 22:57 [PATCH 1/2] lib/hash: initialize __m128i data type in a portable way Andre Muezerie
2024-11-27 22:57 ` Andre Muezerie [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-11-27 22:55 Andre Muezerie
2024-11-27 22:55 ` [PATCH 2/2] app/test: add test_init_m128i using compiler intrinsic Andre Muezerie
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=1732748278-14796-2-git-send-email-andremue@linux.microsoft.com \
--to=andremue@linux.microsoft.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=sameh.gobriel@intel.com \
--cc=vladimir.medvedkin@intel.com \
--cc=yipeng1.wang@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).