From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 56FA645DBB; Wed, 27 Nov 2024 23:55:43 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4A9F44060C; Wed, 27 Nov 2024 23:55:43 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id E870D40280 for ; Wed, 27 Nov 2024 23:55:41 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1213) id 175D22053045; Wed, 27 Nov 2024 14:55:41 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 175D22053045 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1732748141; bh=BVUjuLLUXFX0fNr8zNpnlV/b4IvfjOFzL1zMcrN0vxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g5CsScSYmaDd/M802dbP364aVnfsthj/aT9+IkK8PGIHjQLfuVTg9GZwPQo7MUQk5 UeP21UxtlrxKfXM16owTSPDOe5MgKg8NqIKFzRxkpll8R/8+xhCbGerlC6kVfIiDFH FT29ybssU1unX/zwS+ArnSge1zydWNyM5YZlfjqg= From: Andre Muezerie To: maintainer@some.org Cc: dev@dpdk.org, Andre Muezerie Subject: [PATCH 2/2] app/test: add test_init_m128i using compiler intrinsic Date: Wed, 27 Nov 2024 14:55:06 -0800 Message-Id: <1732748106-14324-2-git-send-email-andremue@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1732748106-14324-1-git-send-email-andremue@linux.microsoft.com> References: <1732748106-14324-1-git-send-email-andremue@linux.microsoft.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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