From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0089.outbound.protection.outlook.com [104.47.41.89]) by dpdk.org (Postfix) with ESMTP id 39B31689E for ; Fri, 12 May 2017 12:15:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=0fs6ju7cnw3pQTxO2FwxH/8goo6n+k9vtwbmD+kfjpc=; b=KltHNz6mvWr+lxmUJ3nWMcEh6kgJL2/K+R8kagE/XT1MizT0Hx2NACq7G5rPJBALhC3GfTA95yVmZAsewe8H3Qiig5tDE7HeoP3U3+tw07HUnmTFBce0DaRHTvKf6D0l/Id6AbGDMQ5ki8w32JyzwUODUtBannP+/Il6+MN661Q= Authentication-Results: caviumnetworks.com; dkim=none (message not signed) header.d=none;caviumnetworks.com; dmarc=none action=none header.from=caviumnetworks.com; Received: from 1scrb-1.caveonetworks.com (50.233.148.156) by BY2PR07MB2421.namprd07.prod.outlook.com (10.166.115.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1084.16; Fri, 12 May 2017 10:15:54 +0000 From: Ashwin Sekhar T K To: jerin.jacob@caviumnetworks.com, thomas@monjalon.net, viktorin@rehivetech.com, jianbo.liu@linaro.org, jasvinder.singh@intel.com Cc: dev@dpdk.org, Ashwin Sekhar T K Date: Fri, 12 May 2017 03:15:34 -0700 Message-Id: <20170512101535.7221-4-ashwin.sekhar@caviumnetworks.com> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170512101535.7221-1-ashwin.sekhar@caviumnetworks.com> References: <20170427140618.35897-1-ashwin.sekhar@caviumnetworks.com> <20170512101535.7221-1-ashwin.sekhar@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: MWHPR10CA0069.namprd10.prod.outlook.com (10.169.238.31) To BY2PR07MB2421.namprd07.prod.outlook.com (10.166.115.13) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1665ed04-8adf-4a74-77bb-08d4991fe038 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:BY2PR07MB2421; X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2421; 3:GdsTTQ8ZSW8MzDd3JdLuPonTTdNu4qtNcjAM4cfQX6eBesDrcdbHUI7TD8AqDkLIKpQpZQiAaymfUhBjZ9xTK0l86UYmuZIWexbG1LzLCww2t4HMRNpfqwVeL9zTBDsn51BzWkSYtw2FpZMXZ9W3U/6hy9ObHHLEy4EovfefhFtf9lqaaYjBlnpBQ2Aumht86e0xNHuS9aPHqfm6eFZdPbNR4CRQ89k5V0gqOvjXaFgoTKLVcGzXoN/BxcnnpJq7qGzjPjM1R3tyB/bLJFg1A6QnwnDPo+s9TN4z2Pzj0CCT3NJndMCcVSQlfdBkARqEtuMYbD1Y3k5VP05bdcfesg==; 25:j9kxo+uEPkB3b57OUhPwnf/SxjiB4LIu+FvCi8+bFhCqM9kpjfLFLtZJmGbe2PG+0+s19RKiwNa2wrxU0YwmzJEjFJmMkLx/FvsLw0ZWxfXT7Wig+TCiGU6H9QjY+6c1RCt7XjjaQ3/d6oB4vhf/hYV1C+3p0fZaQt7aiYDoS9kPxORdIR4v7VbZfs+827KF31c9P/vwAfN/mMYpm9chCNij02pURE7SSRlm6Khy9fB+GxEQd50VtgqvcYqIhaBnAN8E47UpSfPLY52CNT5LrQybcsT56Tz8y+Nyrsz+yw4Yv0k93ZRYpaPTJLrOnjWxcEZzMpKCPM1cShrFutggBxKZNKpLYrEPY0SFhbkpYWirfDcgG8SH3olPD4kmYWXEdyuPrj7O7yZrKqI20oa0Mlao84aa5t2SocjpebYDVlkJTSDjozQnJXMLio8BhrGYY0OkmVbMW0buE2cgQLvk8PcPKComvem+NIFgDoObgT8= X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2421; 31:iYI69Mnyk8gL0cUF8UzfE37NeWPVLkDdRX2u3JaUAc4w0sVCBR80qfiK17BvNZeIDSL6k78cYStZwe7F+SXkTyxjp+RsDp+vYFByYC7ExRHzCazUPFFTXBd8CF+wNaQxEFqGhDi6yYGqWj8IrK8us5VdtvS5w50Y5my64nWuRgkuLxTMlmbpBhNpFKyGHobkP96YnotWexILQ7m1ZkMT44VtfIFa6gh5GnYYlJanXdA=; 20:U8WK4ss5+H9HN1bJxCvjbhLPEyAcqDgglovJl7/m42MwSBFXz2a6Dq4aFkSJkcsix4pKPINmLSKXIGL9UheCSMFKT/WG9yQczvvC713QNZLhrdATej9YuzYPoJfnSCFvatCzDpn4dvmxN7OI1ubxlD448Kvry8x/zsBr63S6kvh/fsLrhlPHEz34ZELGRfTk9gPQF4qN8rNsZ/c2W0P+AHw7bcHNXdJOMQAuGLpdwxqDVfrAgshMapGctznzvPYHLme8U0aeWzdILI4royuZL+cbSm/YDodEDdkkuGkX8+t3bV9bCDso3oJZ8s0xMlKrGXUDbwEd85bu4NGaFlB5Cl9nMzAIWgPDg6A5EkEY4o9lbTKgDOWHr4+FGgm//dsCsUbFoi3vrSsw8Vde0waPSB5Rr6yJiGHugUCspgl9fWAHobDuAwiXkl1jyi6PiUOrcLoA3yqjaap6QJJF/2yX+D1n4LleKRqufQlXtlbAM2hY0X3QmJO9k+xuQXg8gQn74sF6GwfxnCkdqGXwCYgzJhUIAqfkdwd5vv3nv7cY0XVbfQYFQfornPCEMCtsxQI5jHg7yzQsnJVSzBYBfUOGDcJqoHbi2idTvShEPQfmeKc= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(93006095)(6041248)(20161123555025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123560025)(20161123564025)(20161123558100)(6072148); SRVR:BY2PR07MB2421; BCL:0; PCL:0; RULEID:; SRVR:BY2PR07MB2421; X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2421; 4:vIOLyqqQl4hFUjwA6btbZPSoHQtyGizh3LwY0nbKr7upbYk7TpBUc+JhwFBEFEgYXxkd/QTKtwuzn85qW0BJurctTFq5NnDz9fbi1L8ynjIL3ezmQJjLZXQICJXfgXWHr4ThWrGrIwMjGKjfe1Inwhlfam/na1H8oJVKJggbzhk5TlXVNFOg88sAfZ20ljkGlNbvtn31wVE24l1cUFYDGmTPxrmc/uPQNWrLg7dfaZL5VPiGFy59cGq5Eo8D+aTW4J/I//Z9bp2lcUhJogy3FRKgRB0DpcgzqPdc5RRbNZsRHIMV9xb5+t2dK5BGQVJ3LEfoDmBk2Oh9JkzTAxGrtTSktTPQwcmllczuphZksoGitZZoB8Tv8NoXdpF80XvyupcqkVIvsIGd3bc3xitDo+jokljiDxlTzEjj3kX3GTiyHGRm4VtpyKg1iKOMSkBMz50cJ85eg201LxAm51sL90XNYV2nzNSYMHgxTAnVam+9Sq6xEk9U6jjO8DCDExA3/5jTFzmwA06ZIvnmSlJEKzw3YMS5jxZPQ7wKNrqK9pk1Ed/2zuP8mnDcyb1ftdSsxrLpbiZPXH0O7pMbRxdFcUL4z3nfsEQtu23Davgipa8h59egG+easCEXNFaMCwTHKO5C/Wp4FDOtd5uDAW3XmRO9WkpwJeiVegqwxASFgfq49d8HfNblmzs839zka/Nlp/ci9BvZBBWRuwGCti/NNr7n8hugEnb9uwPP80U2nskXKDZw0zdNBEsZElgWx915b/y64cJfdvb498d6vRLh8w== X-Forefront-PRVS: 0305463112 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39410400002)(39400400002)(39840400002)(39450400003)(39850400002)(6486002)(8676002)(5003940100001)(6506006)(25786009)(575784001)(81166006)(76176999)(42186005)(2906002)(47776003)(189998001)(66066001)(33646002)(50986999)(48376002)(53416004)(50466002)(7736002)(4326008)(478600001)(53936002)(50226002)(305945005)(6512007)(6116002)(3846002)(2950100002)(42882006)(72206003)(110136004)(107886003)(36756003)(5660300001)(6666003)(38730400002)(1076002); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR07MB2421; H:1scrb-1.caveonetworks.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR07MB2421; 23:fm5741UrltLtMobQKq3efi2h/9TLiCHQIeaeaiLGw?= =?us-ascii?Q?IyTynzY7aw+8ZiBVkPvdv8oMW8cdU1O3ONwo60lpG1pg2UzR0mrvqXEpCcfx?= =?us-ascii?Q?f8bRH+sm0cYHycoVIO1/p4MT/EaR796vl0W4ybKRs3a/yDeqCv6YSn9gfqeT?= =?us-ascii?Q?kntQFfu2/s+TQ95qMJTyOMCskDmaoykM8ZGYj52nF2rXWIPK6R7cGDihwyim?= =?us-ascii?Q?LCUUC7CWH8N+kX34+nAN6lcOA8HB9wC7G/cwjrfoLzWFhIYhh93LCkQrlU8D?= =?us-ascii?Q?GuGZo8FLcreQvyH2s3/zCIziohUfuo8Iycfryvk1Mbp99V/NmOTpXmxRqGxW?= =?us-ascii?Q?HNEcMgC2pnCo6MzzeXWTr+F5CInbUNZDAQwRCUnNSUVhoFQDJpUkl3i2uvxY?= =?us-ascii?Q?DlHLUTi7olKxX5iZRACw7yVL6ZxliojY1ptDjcfZ4AkeAj36BlAx2aV3tnBq?= =?us-ascii?Q?lUTtFxGOPjyqp4JiVU/rlfuMKw9eVXDPrHkRrZ6YaIZzy+P04SVKICzkwHU1?= =?us-ascii?Q?Wj8+8I6q1QUuqquB21JH09OXLiu5f80E55TfPrQTV1gT03vNLwZ7H1qYhR6t?= =?us-ascii?Q?Ruw7txYAut4iEpNFXQbI5du+sF8W8t3z05z2lFadObQuVguWzjgIA2AxDXDF?= =?us-ascii?Q?sP0HiOQcxqNtRjAC7vDDT3TYyDRqYEm+alNgt+vO/mQ60RzqpXrJBjjFa30v?= =?us-ascii?Q?Dn5GdMRMaIPTdMz62UbTTjjgqYiLFy1uAhnDLVIqJv8X4cc3DMVhArGcGYEb?= =?us-ascii?Q?d5ypyWB8MsuBitPjkMVJZG+n7BMceFFPaaHzdu/8iMwwgysnoj3tvcToC5+K?= =?us-ascii?Q?K6MvDRCVt/SktgwxH8Mn44BN+9Az+AYGw3B+ovsjwweOd/8+tgGzUVnXdEer?= =?us-ascii?Q?+sjQ4CaoGB8PGbNSINwRv2t/jYBOS4apoF22g6UtShX8T6jGtdh+6745x0HA?= =?us-ascii?Q?kE+ZxUOqa3jIdVYTaAAGaJxEJlYK1uk/8OtKdZThUMIGn+Bht4ZCtX7G4dZH?= =?us-ascii?Q?YyG/UIZ63QOw2cF5DmJ2tZ2JQKzWWmmlOnpNM0vcoU1aYceRdaVJGIufK2To?= =?us-ascii?Q?ZLjYPikos1h4kENi7oDYj9DNTjvLvcXr1UM/QBSfslDk2isZ5hEGn2vN5UNY?= =?us-ascii?Q?g2r86/hYHQ=3D?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2421; 6:QvYddcY+UU0IxPR7Hk0q6eChi0hHPi4UGLmMY5SlDYIDIvKfHUdcBQvM1V8c68UQvvpvj7UuwFzlHlvtJM8VJiJwEcFNWPoQ5e9wf3LJ+J0XvaCTn5vWo5BzkfWQTtshqE6JYc4yKy16pK4Ls9bE1QRsO4DQl1U06IHIH907FB1DsAZI9PQH42DD2A0ISd1mWfpVBh9iKtDvGakInF4h2sxFTfRzogsBtt3fI1yImPoE7XCQ6jHIvMi4JsFnPuaCj8e/ZKX5zwcCj0zr3iVptBUz//KHR8VTr0nT1rrpyZet3tOaewQ1+hOcihEwm0XrCCAm09e3yUj3AGnMMTNU/T64rro2jJry2eAKYRmzHOC9fvMdRdNrfq5t8LlSNBKJGope64VJyQmRLY0nienklSvttEEWcfgEhE//H0ZjYbRtiF56/WfZ4BqfZ5mFtzdOeVVJaDLCInARrkws37tqM2JAV60YmrYTBmUn1iOshUvdTIDRQtnRIy121Hd+yt/EuU97fslc2CLz85+cbFj8OQ==; 5:2sbyjW5zL6YtgYZM/P2uOHhF1pRVo28NNdqghxWeyTxl1nfHuoOxyMPIokPbl/5/mSC0eIYbRI5GlEmYb4+a3j/bwPOOMprqyBR5dTX0RoHHjUnoVQfWp/DNrNjsUotvcxpnzKbs7XuCvrKW6gcZLQ==; 24:6CoaRT24zuVYoHwNllI02GvqfoCZzNtbDXWXLcnRSMJS3dVLWvoa2yYvars2rWVh1NO0+g/vHH8o8POzmz+1ee9Xk7UL50Hph1cfR9HXqMs= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2421; 7:GQy5ax9Lyu6YY9tloMAm003yy4YXLdv9Y5IiZ87iO55s8MAeuMhDL1l53doJ8MPIlWreGSCX6PkZvEX229gusIUmpMlk6Xq9C8QVBaSEkWauG2jE/QpAS7f8cj+hHjW0Wkrl91XnsZWFpcq94toT4matfejYcgYIOFp84kXUnE+2m4NJ2WiKCT0fb3lSAwbIIuZK/HnwDqlGjM1EkgQqoj7dv27DZdVXjVD7If4ed/iBqD72+OES+P3D9jGGDYWk+NrBSX1xOA2OkTo40oRLA/d77H0m8aMm9ldyllhKcD86vuXtTueZqdG57deumkllZ2SzR91jxiqLIzsZF+mcwg== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 May 2017 10:15:54.6696 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR07MB2421 Subject: [dpdk-dev] [PATCH v5 3/4] net: add arm64 neon version of CRC compute APIs X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 May 2017 10:15:58 -0000 Added CRC compute APIs for arm64 utilizing the pmull capability. Added new file net_crc_neon.h to hold the arm64 pmull CRC implementation. Added wrappers in rte_vect.h for those neon intrinsics which are not supported in GCC version < 7. Verified the changes with crc_autotest unit test case Signed-off-by: Ashwin Sekhar T K --- MAINTAINERS | 1 + lib/librte_eal/common/include/arch/arm/rte_vect.h | 88 +++++++ lib/librte_net/net_crc_neon.h | 297 ++++++++++++++++++++++ lib/librte_net/rte_net_crc.c | 34 ++- lib/librte_net/rte_net_crc.h | 2 + 5 files changed, 416 insertions(+), 6 deletions(-) create mode 100644 lib/librte_net/net_crc_neon.h diff --git a/MAINTAINERS b/MAINTAINERS index b6495d2b9..66d64c2c9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -147,6 +147,7 @@ F: lib/librte_eal/common/include/arch/arm/*_64.h F: lib/librte_acl/acl_run_neon.* F: lib/librte_lpm/rte_lpm_neon.h F: lib/librte_hash/rte*_arm64.h +F: lib/librte_net/net_crc_neon.h F: drivers/net/ixgbe/ixgbe_rxtx_vec_neon.c F: drivers/net/i40e/i40e_rxtx_vec_neon.c F: drivers/net/virtio/virtio_rxtx_simple_neon.c diff --git a/lib/librte_eal/common/include/arch/arm/rte_vect.h b/lib/librte_eal/common/include/arch/arm/rte_vect.h index 4107c9988..55e228a77 100644 --- a/lib/librte_eal/common/include/arch/arm/rte_vect.h +++ b/lib/librte_eal/common/include/arch/arm/rte_vect.h @@ -35,6 +35,7 @@ #include #include "generic/rte_vect.h" +#include "rte_debug.h" #include "arm_neon.h" #ifdef __cplusplus @@ -78,6 +79,93 @@ vqtbl1q_u8(uint8x16_t a, uint8x16_t b) } #endif +#if defined(RTE_ARCH_ARM64) +#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION < 70000) +/* NEON intrinsic vreinterpretq_u64_p128() is supported since GCC version 7 */ +static inline uint64x2_t +vreinterpretq_u64_p128(poly128_t x) +{ + return (uint64x2_t)x; +} + +/* NEON intrinsic vreinterpretq_p64_u64() is supported since GCC version 7 */ +static inline poly64x2_t +vreinterpretq_p64_u64(uint64x2_t x) +{ + return (poly64x2_t)x; +} + +/* NEON intrinsic vgetq_lane_p64() is supported since GCC version 7 */ +static inline poly64_t +vgetq_lane_p64(poly64x2_t x, const int lane) +{ + RTE_ASSERT(lane >= 0 && lane <= 1); + + poly64_t *p = (poly64_t *)&x; + + return p[lane]; +} +#endif +#endif + +/* + * If (0 <= index <= 15), then call the ASIMD ext intruction on the + * 128 bit regs v0 and v1 with the appropriate index. + * + * Else returns a zero vector. + */ +static inline uint8x16_t +vextract(uint8x16_t v0, uint8x16_t v1, const int index) +{ + switch (index) { + case 0: return vextq_u8(v0, v1, 0); + case 1: return vextq_u8(v0, v1, 1); + case 2: return vextq_u8(v0, v1, 2); + case 3: return vextq_u8(v0, v1, 3); + case 4: return vextq_u8(v0, v1, 4); + case 5: return vextq_u8(v0, v1, 5); + case 6: return vextq_u8(v0, v1, 6); + case 7: return vextq_u8(v0, v1, 7); + case 8: return vextq_u8(v0, v1, 8); + case 9: return vextq_u8(v0, v1, 9); + case 10: return vextq_u8(v0, v1, 10); + case 11: return vextq_u8(v0, v1, 11); + case 12: return vextq_u8(v0, v1, 12); + case 13: return vextq_u8(v0, v1, 13); + case 14: return vextq_u8(v0, v1, 14); + case 15: return vextq_u8(v0, v1, 15); + } + return vdupq_n_u8(0); +} + +/** + * Shifts right 128 bit register by specified number of bytes + * + * Value of shift parameter must be in range 0 - 16 + */ +static inline uint64x2_t +vshift_bytes_right(uint64x2_t reg, const unsigned int shift) +{ + return vreinterpretq_u64_u8(vextract( + vreinterpretq_u8_u64(reg), + vdupq_n_u8(0), + shift)); +} + +/** + * Shifts left 128 bit register by specified number of bytes + * + * Value of shift parameter must be in range 0 - 16 + */ +static inline uint64x2_t +vshift_bytes_left(uint64x2_t reg, const unsigned int shift) +{ + return vreinterpretq_u64_u8(vextract( + vdupq_n_u8(0), + vreinterpretq_u8_u64(reg), + 16 - shift)); +} + #ifdef __cplusplus } #endif diff --git a/lib/librte_net/net_crc_neon.h b/lib/librte_net/net_crc_neon.h new file mode 100644 index 000000000..2be579d6b --- /dev/null +++ b/lib/librte_net/net_crc_neon.h @@ -0,0 +1,297 @@ +/* + * BSD LICENSE + * + * Copyright (C) Cavium networks Ltd. 2017. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Cavium networks nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _NET_CRC_NEON_H_ +#define _NET_CRC_NEON_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** PMULL CRC computation context structure */ +struct crc_pmull_ctx { + uint64x2_t rk1_rk2; + uint64x2_t rk5_rk6; + uint64x2_t rk7_rk8; +}; + +struct crc_pmull_ctx crc32_eth_pmull __rte_aligned(16); +struct crc_pmull_ctx crc16_ccitt_pmull __rte_aligned(16); + +/** + * @brief Performs one folding round + * + * Logically function operates as follows: + * DATA = READ_NEXT_16BYTES(); + * F1 = LSB8(FOLD) + * F2 = MSB8(FOLD) + * T1 = CLMUL(F1, RK1) + * T2 = CLMUL(F2, RK2) + * FOLD = XOR(T1, T2, DATA) + * + * @param data_block 16 byte data block + * @param precomp precomputed rk1 constanst + * @param fold running 16 byte folded data + * + * @return New 16 byte folded data + */ +static inline uint64x2_t +crcr32_folding_round(uint64x2_t data_block, uint64x2_t precomp, + uint64x2_t fold) +{ + uint64x2_t tmp0 = vreinterpretq_u64_p128(vmull_p64( + vgetq_lane_p64(vreinterpretq_p64_u64(fold), 1), + vgetq_lane_p64(vreinterpretq_p64_u64(precomp), 0))); + + uint64x2_t tmp1 = vreinterpretq_u64_p128(vmull_p64( + vgetq_lane_p64(vreinterpretq_p64_u64(fold), 0), + vgetq_lane_p64(vreinterpretq_p64_u64(precomp), 1))); + + return veorq_u64(tmp1, veorq_u64(data_block, tmp0)); +} + +/** + * Performs reduction from 128 bits to 64 bits + * + * @param data128 128 bits data to be reduced + * @param precomp rk5 and rk6 precomputed constants + * + * @return data reduced to 64 bits + */ +static inline uint64x2_t +crcr32_reduce_128_to_64(uint64x2_t data128, + uint64x2_t precomp) +{ + uint64x2_t tmp0, tmp1, tmp2; + + /* 64b fold */ + tmp0 = vreinterpretq_u64_p128(vmull_p64( + vgetq_lane_p64(vreinterpretq_p64_u64(data128), 0), + vgetq_lane_p64(vreinterpretq_p64_u64(precomp), 0))); + tmp1 = vshift_bytes_right(data128, 8); + tmp0 = veorq_u64(tmp0, tmp1); + + /* 32b fold */ + tmp2 = vshift_bytes_left(tmp0, 4); + tmp1 = vreinterpretq_u64_p128(vmull_p64( + vgetq_lane_p64(vreinterpretq_p64_u64(tmp2), 0), + vgetq_lane_p64(vreinterpretq_p64_u64(precomp), 1))); + + return veorq_u64(tmp1, tmp0); +} + +/** + * Performs Barret's reduction from 64 bits to 32 bits + * + * @param data64 64 bits data to be reduced + * @param precomp rk7 precomputed constant + * + * @return data reduced to 32 bits + */ +static inline uint32_t +crcr32_reduce_64_to_32(uint64x2_t data64, + uint64x2_t precomp) +{ + static uint32_t mask1[4] __rte_aligned(16) = { + 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 + }; + static uint32_t mask2[4] __rte_aligned(16) = { + 0x00000000, 0xffffffff, 0xffffffff, 0xffffffff + }; + uint64x2_t tmp0, tmp1, tmp2; + + tmp0 = vandq_u64(data64, vld1q_u64((uint64_t *)mask2)); + + tmp1 = vreinterpretq_u64_p128(vmull_p64( + vgetq_lane_p64(vreinterpretq_p64_u64(tmp0), 0), + vgetq_lane_p64(vreinterpretq_p64_u64(precomp), 0))); + tmp1 = veorq_u64(tmp1, tmp0); + tmp1 = vandq_u64(tmp1, vld1q_u64((uint64_t *)mask1)); + + tmp2 = vreinterpretq_u64_p128(vmull_p64( + vgetq_lane_p64(vreinterpretq_p64_u64(tmp1), 0), + vgetq_lane_p64(vreinterpretq_p64_u64(precomp), 1))); + tmp2 = veorq_u64(tmp2, tmp1); + tmp2 = veorq_u64(tmp2, tmp0); + + return vgetq_lane_u32(vreinterpretq_u32_u64(tmp2), 2); +} + +static inline uint32_t +crc32_eth_calc_pmull( + const uint8_t *data, + uint32_t data_len, + uint32_t crc, + const struct crc_pmull_ctx *params) +{ + uint64x2_t temp, fold, k; + uint32_t n; + + /* Get CRC init value */ + temp = vreinterpretq_u64_u32(vsetq_lane_u32(crc, vmovq_n_u32(0), 0)); + + /** + * Folding all data into single 16 byte data block + * Assumes: fold holds first 16 bytes of data + */ + if (unlikely(data_len < 32)) { + if (unlikely(data_len == 16)) { + /* 16 bytes */ + fold = vld1q_u64((const uint64_t *)data); + fold = veorq_u64(fold, temp); + goto reduction_128_64; + } + + if (unlikely(data_len < 16)) { + /* 0 to 15 bytes */ + uint8_t buffer[16] __rte_aligned(16); + + memset(buffer, 0, sizeof(buffer)); + memcpy(buffer, data, data_len); + + fold = vld1q_u64((uint64_t *)buffer); + fold = veorq_u64(fold, temp); + if (unlikely(data_len < 4)) { + fold = vshift_bytes_left(fold, 8 - data_len); + goto barret_reduction; + } + fold = vshift_bytes_left(fold, 16 - data_len); + goto reduction_128_64; + } + /* 17 to 31 bytes */ + fold = vld1q_u64((const uint64_t *)data); + fold = veorq_u64(fold, temp); + n = 16; + k = params->rk1_rk2; + goto partial_bytes; + } + + /** At least 32 bytes in the buffer */ + /** Apply CRC initial value */ + fold = vld1q_u64((const uint64_t *)data); + fold = veorq_u64(fold, temp); + + /** Main folding loop - the last 16 bytes is processed separately */ + k = params->rk1_rk2; + for (n = 16; (n + 16) <= data_len; n += 16) { + temp = vld1q_u64((const uint64_t *)&data[n]); + fold = crcr32_folding_round(temp, k, fold); + } + +partial_bytes: + if (likely(n < data_len)) { + uint64x2_t last16, a, b, mask; + uint32_t rem = data_len & 15; + + last16 = vld1q_u64((const uint64_t *)&data[data_len - 16]); + a = vshift_bytes_left(fold, 16 - rem); + b = vshift_bytes_right(fold, rem); + mask = vshift_bytes_left(vdupq_n_u64(-1), 16 - rem); + b = vorrq_u64(b, vandq_u64(mask, last16)); + + /* k = rk1 & rk2 */ + temp = vreinterpretq_u64_p128(vmull_p64( + vgetq_lane_p64(vreinterpretq_p64_u64(a), 1), + vgetq_lane_p64(vreinterpretq_p64_u64(k), 0))); + fold = vreinterpretq_u64_p128(vmull_p64( + vgetq_lane_p64(vreinterpretq_p64_u64(a), 0), + vgetq_lane_p64(vreinterpretq_p64_u64(k), 1))); + fold = veorq_u64(fold, temp); + fold = veorq_u64(fold, b); + } + + /** Reduction 128 -> 32 Assumes: fold holds 128bit folded data */ +reduction_128_64: + k = params->rk5_rk6; + fold = crcr32_reduce_128_to_64(fold, k); + +barret_reduction: + k = params->rk7_rk8; + n = crcr32_reduce_64_to_32(fold, k); + + return n; +} + +static inline void +rte_net_crc_neon_init(void) +{ + /* Initialize CRC16 data */ + uint64_t ccitt_k1_k2[2] = {0x189aeLLU, 0x8e10LLU}; + uint64_t ccitt_k5_k6[2] = {0x189aeLLU, 0x114aaLLU}; + uint64_t ccitt_k7_k8[2] = {0x11c581910LLU, 0x10811LLU}; + + /* Initialize CRC32 data */ + uint64_t eth_k1_k2[2] = {0xccaa009eLLU, 0x1751997d0LLU}; + uint64_t eth_k5_k6[2] = {0xccaa009eLLU, 0x163cd6124LLU}; + uint64_t eth_k7_k8[2] = {0x1f7011640LLU, 0x1db710641LLU}; + + /** Save the params in context structure */ + crc16_ccitt_pmull.rk1_rk2 = vld1q_u64(ccitt_k1_k2); + crc16_ccitt_pmull.rk5_rk6 = vld1q_u64(ccitt_k5_k6); + crc16_ccitt_pmull.rk7_rk8 = vld1q_u64(ccitt_k7_k8); + + /** Save the params in context structure */ + crc32_eth_pmull.rk1_rk2 = vld1q_u64(eth_k1_k2); + crc32_eth_pmull.rk5_rk6 = vld1q_u64(eth_k5_k6); + crc32_eth_pmull.rk7_rk8 = vld1q_u64(eth_k7_k8); +} + +static inline uint32_t +rte_crc16_ccitt_neon_handler(const uint8_t *data, + uint32_t data_len) +{ + return (uint16_t)~crc32_eth_calc_pmull(data, + data_len, + 0xffff, + &crc16_ccitt_pmull); +} + +static inline uint32_t +rte_crc32_eth_neon_handler(const uint8_t *data, + uint32_t data_len) +{ + return ~crc32_eth_calc_pmull(data, + data_len, + 0xffffffffUL, + &crc32_eth_pmull); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _NET_CRC_NEON_H_ */ diff --git a/lib/librte_net/rte_net_crc.c b/lib/librte_net/rte_net_crc.c index 9d1ee63fa..be65f34bb 100644 --- a/lib/librte_net/rte_net_crc.c +++ b/lib/librte_net/rte_net_crc.c @@ -43,10 +43,16 @@ && defined(RTE_MACHINE_CPUFLAG_SSE4_2) \ && defined(RTE_MACHINE_CPUFLAG_PCLMULQDQ) #define X86_64_SSE42_PCLMULQDQ 1 +#elif defined(RTE_ARCH_ARM64) +#if defined(RTE_MACHINE_CPUFLAG_PMULL) +#define ARM64_NEON_PMULL 1 +#endif #endif #ifdef X86_64_SSE42_PCLMULQDQ #include +#elif defined(ARM64_NEON_PMULL) +#include #endif /* crc tables */ @@ -74,6 +80,11 @@ static rte_net_crc_handler handlers_sse42[] = { [RTE_NET_CRC16_CCITT] = rte_crc16_ccitt_sse42_handler, [RTE_NET_CRC32_ETH] = rte_crc32_eth_sse42_handler, }; +#elif defined(ARM64_NEON_PMULL) +static rte_net_crc_handler handlers_neon[] = { + [RTE_NET_CRC16_CCITT] = rte_crc16_ccitt_neon_handler, + [RTE_NET_CRC32_ETH] = rte_crc32_eth_neon_handler, +}; #endif /** @@ -162,14 +173,20 @@ void rte_net_crc_set_alg(enum rte_net_crc_alg alg) { switch (alg) { - case RTE_NET_CRC_SSE42: #ifdef X86_64_SSE42_PCLMULQDQ + case RTE_NET_CRC_SSE42: handlers = handlers_sse42; -#else - alg = RTE_NET_CRC_SCALAR; -#endif break; +#elif defined(ARM64_NEON_PMULL) + case RTE_NET_CRC_NEON: + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_PMULL)) { + handlers = handlers_neon; + break; + } + //-fallthrough +#endif case RTE_NET_CRC_SCALAR: + //-fallthrough default: handlers = handlers_scalar; break; @@ -199,8 +216,13 @@ rte_net_crc_init(void) rte_net_crc_scalar_init(); #ifdef X86_64_SSE42_PCLMULQDQ - alg = RTE_NET_CRC_SSE42; - rte_net_crc_sse42_init(); + alg = RTE_NET_CRC_SSE42; + rte_net_crc_sse42_init(); +#elif defined(ARM64_NEON_PMULL) + if (rte_cpu_get_flag_enabled(RTE_CPUFLAG_PMULL)) { + alg = RTE_NET_CRC_NEON; + rte_net_crc_neon_init(); + } #endif rte_net_crc_set_alg(alg); diff --git a/lib/librte_net/rte_net_crc.h b/lib/librte_net/rte_net_crc.h index d22286c6e..d01cf4b47 100644 --- a/lib/librte_net/rte_net_crc.h +++ b/lib/librte_net/rte_net_crc.h @@ -57,6 +57,7 @@ enum rte_net_crc_type { enum rte_net_crc_alg { RTE_NET_CRC_SCALAR = 0, RTE_NET_CRC_SSE42, + RTE_NET_CRC_NEON, }; /** @@ -68,6 +69,7 @@ enum rte_net_crc_alg { * This parameter is used to select the CRC implementation version. * - RTE_NET_CRC_SCALAR * - RTE_NET_CRC_SSE42 (Use 64-bit SSE4.2 intrinsic) + * - RTE_NET_CRC_NEON (Use ARM Neon intrinsic) */ void rte_net_crc_set_alg(enum rte_net_crc_alg alg); -- 2.12.2