From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0087.outbound.protection.outlook.com [104.47.36.87]) by dpdk.org (Postfix) with ESMTP id 56C7AA2F for ; Thu, 27 Apr 2017 16:10:30 +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=DsxygULx/C1wgHPJ2algWwoO+fgoM0tCwnPuObNRmvQ=; b=WkAzHkzr8YZk9+/kakbogfmdeENFj9uAiCkTsetMO2fFQz+r1ohE92gYU6k7Ek07zm8piIladeL06M8YAb318wjx8yeQpjRP3juVTGyygUAbvEFEI1//wfE8pBrnbRS8arYaom7nbeYJUdbeYSfFWpiwkBXTADIj5Pu/0pbLEYE= Authentication-Results: monjalon.net; dkim=none (message not signed) header.d=none;monjalon.net; dmarc=none action=none header.from=caviumnetworks.com; Received: from 1scrb-1.caveonetworks.com (50.233.148.156) by BY2PR07MB2424.namprd07.prod.outlook.com (10.166.115.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1061.12; Thu, 27 Apr 2017 14:10:27 +0000 From: Ashwin Sekhar T K To: thomas@monjalon.net, jasvinder.singh@intel.com, viktorin@rehivetech.com, jerin.jacob@caviumnetworks.com, jianbo.liu@linaro.org Cc: dev@dpdk.org, Ashwin Sekhar T K Date: Thu, 27 Apr 2017 07:10:20 -0700 Message-Id: <20170427141021.18767-1-ashwin.sekhar@caviumnetworks.com> X-Mailer: git-send-email 2.13.0.rc1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: CY4PR13CA0038.namprd13.prod.outlook.com (10.173.156.152) To BY2PR07MB2424.namprd07.prod.outlook.com (10.166.115.16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 23a0e991-0056-4cea-11ce-08d48d772841 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:BY2PR07MB2424; X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2424; 3:C1FFERYOw4vZXKohG4KnexW+wLKj/mVPt7ckxUObRUruXtwXv2Fy7qPzNgeTGo7Ixkz9Wr9rJis/ajDPdG+5m8jiQT96v3ylYuybFqJx6GCLME5u/DWvIggeiiWUt1jh+oeS3FPjxLOrh0nEN0H776N3JMCT3QACro8vsei4Wnpu0/wjeXjxnT5712h6vgpRkmOUFwVBLP18s2GKgQdEPyjnR84fmDNkaUTb5tQNyxG4kfosk3QJElzfntD5ywBcvW2Y4zDkxIDU+gpZeQHx4Scy7Pfzl31otRwQRVXgaZcXYoD6n1TdnWAYG/xMs0CcvqqXyYfVupvoyYsvey75rA==; 25:MVL0pgK8i/CL4cBtRTFA00b7QwOcr9ZHhFo7XIRbqI0bYkuFMIqsXHM039KIjUYMsS46UFDvCOuhtB5yz7q8hR7fg21zAq72XEqO7JUhSULbd7NK9/jqRK3/lDDOGxtxZnDT86/BdDeR3GL5KGW18jGzKDa9pVyd3BEeCAudyiZYiFELF2dnTRDSVKKFqq9a1JOteCB1DxyFk6jF4w97UDVzLsvDM9wO8mmrlPqB4NWzRVaU8b0xmOy853mpxgi2Q3CXgJb7xbVOHG9JXfPWg0HJCTauU3G/Dbu+H7YHnMlas0ZVSTWmfSma6nNSj8o6JhSEQphux6sRVI2GVkYvGkVLEmJXN2Pffs0iXu85gofAY8DxHbyuJp5aOv3PaoLneuowidj7wdvr37kcjX1ugrNFeh5KeWrXD9VC6UowyqjoS3BIZNuUNKTHr9/q5NBy2zMLvbL3k8qvEI9UNPYTUw== X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2424; 31:4YvVCfVDYRUk+LQ4FQaYgtCkwlnmoBdzO35tVAKUELpn1Ep8Wd4Wk1mPXutMYtzmomW0jMGo2T/XYdLQCrHTDv+CJJ9IBynNkosuufj+R5VLwLj+DOdJVcwvGQR5+YVJHehkNcCKvrCDyRdHn4uvh5n46LdIC/UMZB1ANs0U2gak56pY/TktTzqQKYX32hM8FXxt7Ep6dkKmp7z5vUOKoqpYlcXDgzZ4Yskqf4rTN7o=; 20:1IBlUYqfQSFcLOQQx+gRnBejODLRWa6oRXPfP6PddACd9LXoCqOZiozn0DMvIwX7JzMr/M8fwXA3NQyKbuH1Pqn81UKViDOMLii7JwoG94R/4y76hI2j4HZa36lgKYylXk31Z9nL1p2JX4jiAJHpBTd5vop98UAwUOorxNOFX2CD/9fRZV6ZUMQGAjlEcy4rcgelsetl4/4SCIr0QAETOY9NpgCDZdA6kAgBaL8SLKjzgDsDUg68ZP59+PjBKhHXFmiA9Y4DxA0SMJcJPTgsPpbN3IQi5nMlIirq2KxSmqEUKMVMfSYTIfWddXthEUTdJmZZ7rpZMv5Xtgq5LZBy3TYFvxY9E1+DswG2J1PY/Plyzi55rd7Ze+DFB/s2m8y4U2HOUKhYjq3/LPUcuBuqo6K7siAC/fASCFSJpf2lvn6OWRh0ShEaT6jDj5h2wjVIohcBrJo4qQET20uZN4E84JQhapf5dn4x4xpgYrn1GMmzyb4U4tq38Il3DVZbbvcXtpPYEfm8hrKDzVDUUV3GZvIsMBlFiLTxKZfgZiDaDGDHkeOAcMDl7oSxanlKWheSfOwzbMO8XHb4r3nvaXigiO8dyluZrAXWUpGVdPpM2Z0= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(3002001)(10201501046)(6041248)(20161123562025)(20161123564025)(20161123560025)(20161123555025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148); SRVR:BY2PR07MB2424; BCL:0; PCL:0; RULEID:; SRVR:BY2PR07MB2424; X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2424; 4:A3ZG9E6CCIoye6jRqyf4Q4vaz4iF6dIWk7f33ipYey79y+fC5dn53xvOXx+b7z/SbPnuyK6ORTMs7ObyyDNbCjRXG0xQwM22P8j/Mi1uXUAVBhW7kdFOfwWGPLDzBj2jD7KUO1ZKB3bcRqPixVEr1pTSJuCCO4SJ+ivgoYwgbA3wQQD6NR8LhkxAbAdCyOvabbvUX3QK/tYYoTPrya17OkxLGOSyVJcRWFROfjyUpCbkwKrGwBGEwL3KsquLXfo9b0xMpCMFSTcFk73MZp5BOz1AALmAMqdLNNA9dDzDRoEVDgHE+PFdG3A0m6OQHr5DdKEn+2o5tCNHEZ/PvkZxIGMutjJlu2d7rPGG3pS7zoVMigETcmWllGXM2syuIRZc+26NpT0qzD+lbUWmbiTH+xM04LYcrzS2z9/H4T1cV6qomkRbM7eOSefAkzMJdMoGMnSMtRUuObMSChQNjdraVd3yx83yjRbSL/YyCOTp953cV9pcNFW6Jdc0OnBL+5h1MXS/brDr7S5Lzv8g6RlzrxsUbPj07OfkoiUVe27MdyDZuPllN4rCLcZhrJxA2FSToGvjzE2a5NszuYQxPvxYfr54q/v+s+UdC8xz62oygcIH5DoFgG2e/2QLG0T1zrf6l44K8JVZ6zcB6w0tbXgjJnpe9jvbgaaxT3ZFech/pu59R2FSKNC63fjdwrTlolgV/nqAwoMdoqbElS7E5J4thubZfBpbBGpCxBiWWchnUkA/V+iffJVi/LSGsjTGFScD6vCIhFnCdCaubVvGz5JnGA== X-Forefront-PRVS: 029097202E X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39400400002)(39410400002)(39840400002)(39450400003)(39850400002)(575784001)(5003940100001)(6116002)(6506006)(8676002)(110136004)(107886003)(81166006)(38730400002)(1076002)(6486002)(66066001)(3846002)(6512007)(36756003)(189998001)(50466002)(53936002)(48376002)(4326008)(33646002)(50226002)(47776003)(42186005)(25786009)(5660300001)(53416004)(2906002)(6666003)(42882006)(305945005)(50986999); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR07MB2424; H:1scrb-1.caveonetworks.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR07MB2424; 23:Kte8MR2XmsLqYjhRIm8tzRDqc0KWQHCWtWzK7TxW2?= =?us-ascii?Q?ZGDjb1rjpQF1VZ9L2YyaZwS572YW0wFH8dckyM+uhbENVBE0dw6sAc/la7A7?= =?us-ascii?Q?BzO3kFGKBn5PKLzgP4EFlCjE/2t+Z+LJpWRDbaHHWGMP/85wgZioxGPeYpdQ?= =?us-ascii?Q?IU8sq2ovXWoNUpU6xR8+gJxfGsGDVefuNLUJ3QbcndBgrFg9S/jP0kxRW/i4?= =?us-ascii?Q?XIlsRvC2gf9in/Qzq1rZU4KtXuv8c4g2DEzZ20OefpDKYNDToaGQU+AmiUxc?= =?us-ascii?Q?EIckdnVpKKtVnX23cVd+vkdDIfPjzteM5JEPFwMVOrCGOYSpdIWzaaeE0KDZ?= =?us-ascii?Q?gLdajepRe7TE/cswx6kMW47akQ+C9BWcW0+jeBRYMTxgSynGd8oH9ejlTyMg?= =?us-ascii?Q?XSh4JL6YHOXAaed0BlH6HNZppeb40yaeok1y0fUUQFTn8UgH+GKgbEr77TAO?= =?us-ascii?Q?eljc6el0JSn8VD5etBow0wybHfpxolpBjVLH1NXu4qqTecipt9lGhNCvVVs4?= =?us-ascii?Q?p6HEAXlTx+cp4nsSt4BUAZ3grxIoljwLd3WRx0pyKHoEZYWutjkLpq9A+07b?= =?us-ascii?Q?AgTFV2RDtC3jVLRbKYEReLZ0QZIwIvVkI0nAXJJpwYYsFDia4AfqVIl1BSc8?= =?us-ascii?Q?hUt1/550V6azQahR9fIs/UkWDRcBRo1u2JRT6nBJqCJlMpsJHq6wxJiz+DUE?= =?us-ascii?Q?5BaUjXNwRPelTYBXcHn/dHMBsemAtDya5BLR7hEJheE8FGkGONydMJJthh2/?= =?us-ascii?Q?CzV3rKLMuSljwDa0y3NElktEttVpbjJhhjLInOhp/72bQjREwMlDSjpmdAhO?= =?us-ascii?Q?gpKHZ5pUErclM9hjRBxqABhRnxlG4cV97oxCUsXu2svgNiR5acTCV74Bumdt?= =?us-ascii?Q?tVXxPtO3oqC1h8EBVakOWgZQccLX94DZjUjfMBH1S5bCZDTqQmnTIXWrjNpc?= =?us-ascii?Q?x6MjxA8F29sd0+nwkqf4zkbTPD9k1hzGpD2PykYxMtJ78D/v2Wrl4Urn/Tkp?= =?us-ascii?Q?S1HSYNIdkpflMCW4eSnbjUL?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2424; 6:CluSPdAb7I5OtKWcDMb9dz/hFErMvnsXF0xh3yJ7ubpnSR0M0oCxsRZSfyESPAqICcUJQlV3LbrTUUSu1f4Adk4woiGISOpKyixcxKdFY74OBVrf/ows1uUeLnckdr8Et/Oxus4Bxei0nBHfCwCFRyt3es5r26ba2lzqb3Pm8/KIQ6m5T27TmL542mtnejCpFMMi5xOalccZRmjdO3BuCT1clCZT8ytaG/4fJc0SfHvIuAJQA2jXSR8MFKtJ8A2MYjxf9nf72S5euuSw/tw9baL82560XqK2R/Bd23J+cok7lmATxXhwxAd1nPStAl2GbK8P0TE1BdlMQgG2LFKmp1VP6NGfRm1j645tvBT9EVHVMMrgQuImnXmf67F0S1NQPxzQEaTHBfshhRQVTDuBMwYItByiLIA1ST8bu1GRtHXamOFoBhk+FArObPOYOFu8i3Bgf3yazvPxGdmSN1Y3fggf9x53CrrS5kIdWgsBfieQ+0e8wNpqnSAPMRdcXnaLMQem7qA/SwOuiFeT0Co8eg==; 5:BR2OZWuMjjHUA4EzVAliKtJOyUtZ8FkNO4JTGClSaPX37su4+pvTS4dFnaOAeQFCrvMuo0EjTAlczjXXbsZFeDco/Kt09pfEcohemj3BhHFPo0vfwClaISY3FLg1bFRJJfIx7LT3AqaXXBGyKsB2oA==; 24:eRYmqw5PsrlMSVk3xuJgdF0ziXeOKHJBrT6RUumR9d5ejwOWAQtLaOSyu6U6KaXkdHwnoRllGS0WnXkbjfTfyWj/a7ehuVrwMiwEbWFeuzc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR07MB2424; 7:dErgT9A+wUaDuSiAXFNw4ytW5dwgkZD17NJeNXPXWUJQwagh6lUkTRsKJbsflU8BdER1JfI2cB5r7f1sD+tkpmJg8J18t5Y10Dw00oA9r2HbpuQeFH6UnqGyBPTEw2KTFrj6R1zVVb0ROeDNwh89LObjpMvWKMC6xeJWjzUuiDnyKMiw14V9nMF8kEaBLMZx8f3sB1rfins+cdMD7YaUw+zajv0M1U2YWorVa8MUrWh4NUSZCOqjPQLcJigU4V+6I5l/hXxe60DeAPkbFAUa0uKGymH6W8UoIenuhr+BCONkfz68wq0AYnND6wpADPJxs9uV5aqEKLn3SHd5rUXV+g== X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2017 14:10:27.6591 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR07MB2424 Subject: [dpdk-dev] [PATCH 1/2] 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: Thu, 27 Apr 2017 14:10:31 -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 crypto capability in compilation of generic armv8 and thunderx targets * pmull CRC version is used only after checking the pmull capability at runtime * 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 | 45 +++ lib/librte_net/net_crc_neon.h | 357 ++++++++++++++++++++++ lib/librte_net/rte_net_crc.c | 32 +- lib/librte_net/rte_net_crc.h | 2 + mk/machine/armv8a/rte.vars.mk | 2 +- mk/machine/thunderx/rte.vars.mk | 2 +- mk/rte.cpuflags.mk | 3 + mk/toolchain/gcc/rte.toolchain-compat.mk | 1 + 9 files changed, 438 insertions(+), 7 deletions(-) create mode 100644 lib/librte_net/net_crc_neon.h diff --git a/MAINTAINERS b/MAINTAINERS index 576d60a..283743e 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -149,6 +149,7 @@ F: lib/librte_lpm/rte_lpm_neon.h F: lib/librte_hash/rte*_arm64.h F: lib/librte_efd/rte*_arm64.h F: lib/librte_table/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 4107c99..9a3dfdf 100644 --- a/lib/librte_eal/common/include/arch/arm/rte_vect.h +++ b/lib/librte_eal/common/include/arch/arm/rte_vect.h @@ -34,9 +34,18 @@ #define _RTE_VECT_ARM_H_ #include +#include + #include "generic/rte_vect.h" #include "arm_neon.h" +#ifdef GCC_VERSION +#undef GCC_VERSION +#endif + +#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + #ifdef __cplusplus extern "C" { #endif @@ -78,6 +87,42 @@ vqtbl1q_u8(uint8x16_t a, uint8x16_t b) } #endif +#if (GCC_VERSION < 70000) +/* + * NEON intrinsic vreinterpretq_u64_p128() is not supported + * in GCC versions < 7 + */ +static inline uint64x2_t +vreinterpretq_u64_p128(poly128_t x) +{ + return (uint64x2_t)x; +} + +/* + * NEON intrinsic vreinterpretq_p64_u64() is not supported + * in GCC versions < 7 + */ +static inline poly64x2_t +vreinterpretq_p64_u64(uint64x2_t x) +{ + return (poly64x2_t)x; +} + +/* + * NEON intrinsic vgetq_lane_p64() is not supported + * in GCC versions < 7 + */ +static inline poly64_t +vgetq_lane_p64(poly64x2_t x, const int lane) +{ + assert(lane >= 0 && lane <= 1); + + poly64_t *p = (poly64_t *)&x; + + return p[lane]; +} +#endif + #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 0000000..05120a7 --- /dev/null +++ b/lib/librte_net/net_crc_neon.h @@ -0,0 +1,357 @@ +/* + * 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); + +static inline uint8x16_t +extract_vector(uint8x16_t v0, uint8x16_t v1, const int n) +{ + switch (n) { + 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 v1; +} + +/** + * Shifts right 128 bit register by specified number of bytes + * + * @param reg 128 bit value + * @param num number of bytes to shift reg by (0-16) + * + * @return reg << (num * 8) + */ +static inline uint64x2_t +shift_bytes_right(uint64x2_t reg, const unsigned int num) +{ + /* Right Shift */ + return vreinterpretq_u64_u8(extract_vector( + vreinterpretq_u8_u64(reg), + vdupq_n_u8(0), + num)); +} + +/** + * Shifts left 128 bit register by specified number of bytes + * + * @param reg 128 bit value + * @param num number of bytes to shift reg by (0-16) + * + * @return reg << (num * 8) + */ +static inline uint64x2_t +shift_bytes_left(uint64x2_t reg, const unsigned int num) +{ + /* Left Shift */ + return vreinterpretq_u64_u8(extract_vector( + vdupq_n_u8(0), + vreinterpretq_u8_u64(reg), + 16 - num)); +} + +/** + * @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 = shift_bytes_right(data128, 8); + tmp0 = veorq_u64(tmp0, tmp1); + + /* 32b fold */ + tmp2 = shift_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 = shift_bytes_left(fold, 8 - data_len); + goto barret_reduction; + } + fold = shift_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 = shift_bytes_left(fold, 16 - rem); + b = shift_bytes_right(fold, rem); + mask = shift_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 e8326fe..be65f34 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; 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 76fd129..1daed30 100644 --- a/lib/librte_net/rte_net_crc.h +++ b/lib/librte_net/rte_net_crc.h @@ -55,6 +55,7 @@ enum rte_net_crc_type { enum rte_net_crc_alg { RTE_NET_CRC_SCALAR = 0, RTE_NET_CRC_SSE42, + RTE_NET_CRC_NEON, }; /** @@ -66,6 +67,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); diff --git a/mk/machine/armv8a/rte.vars.mk b/mk/machine/armv8a/rte.vars.mk index d5049e1..51966a5 100644 --- a/mk/machine/armv8a/rte.vars.mk +++ b/mk/machine/armv8a/rte.vars.mk @@ -55,4 +55,4 @@ # CPU_LDFLAGS = # CPU_ASFLAGS = -MACHINE_CFLAGS += -march=armv8-a+crc +MACHINE_CFLAGS += -march=armv8-a+crc+crypto diff --git a/mk/machine/thunderx/rte.vars.mk b/mk/machine/thunderx/rte.vars.mk index ad5a379..6784105 100644 --- a/mk/machine/thunderx/rte.vars.mk +++ b/mk/machine/thunderx/rte.vars.mk @@ -55,4 +55,4 @@ # CPU_LDFLAGS = # CPU_ASFLAGS = -MACHINE_CFLAGS += -march=armv8-a+crc -mcpu=thunderx +MACHINE_CFLAGS += -march=armv8-a+crc+crypto -mcpu=thunderx diff --git a/mk/rte.cpuflags.mk b/mk/rte.cpuflags.mk index e634abc..6bbd742 100644 --- a/mk/rte.cpuflags.mk +++ b/mk/rte.cpuflags.mk @@ -119,6 +119,9 @@ ifneq ($(filter $(AUTO_CPUFLAGS),__ARM_FEATURE_CRC32),) CPUFLAGS += CRC32 endif +ifneq ($(filter $(AUTO_CPUFLAGS),__ARM_FEATURE_CRYPTO),) +CPUFLAGS += PMULL +endif MACHINE_CFLAGS += $(addprefix -DRTE_MACHINE_CPUFLAG_,$(CPUFLAGS)) diff --git a/mk/toolchain/gcc/rte.toolchain-compat.mk b/mk/toolchain/gcc/rte.toolchain-compat.mk index 280dde2..01ac7e2 100644 --- a/mk/toolchain/gcc/rte.toolchain-compat.mk +++ b/mk/toolchain/gcc/rte.toolchain-compat.mk @@ -60,6 +60,7 @@ else # ifeq ($(shell test $(GCC_VERSION) -le 49 && echo 1), 1) MACHINE_CFLAGS := $(patsubst -march=armv8-a+crc,-march=armv8-a+crc -D__ARM_FEATURE_CRC32=1,$(MACHINE_CFLAGS)) + MACHINE_CFLAGS := $(patsubst -march=armv8-a+crc+crypto,-march=armv8-a+crc+crypto -D__ARM_FEATURE_CRC32=1,$(MACHINE_CFLAGS)) endif ifeq ($(shell test $(GCC_VERSION) -le 47 && echo 1), 1) MACHINE_CFLAGS := $(patsubst -march=core-avx-i,-march=corei7-avx,$(MACHINE_CFLAGS)) -- 2.7.4