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 8CD87A0093; Tue, 10 May 2022 13:58:32 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7CF5B4161A; Tue, 10 May 2022 13:58:32 +0200 (CEST) Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by mails.dpdk.org (Postfix) with ESMTP id 7966B4069D for ; Tue, 10 May 2022 13:58:31 +0200 (CEST) Received: by mail-lf1-f52.google.com with SMTP id y32so28857020lfa.6 for ; Tue, 10 May 2022 04:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1Wk+ZuKOXwx5T/3tM1PNn8WP+uxjLyS1Oi4GdwPsNdk=; b=CaC19LwCKUamfHtDA2m65wO6+7hWqYc310wE5aAcs4cUag9C2T8TJSj5bPKOel0v8q jGJ9xiJ6ugYGC1GtELsJlHbXXOaOR9a+X5GfHLE6nBTLgpAx+35+Vm3BhL+7xxpFGmXq /tBRPgE4OnC/QM0rL3slfmqhkTxvrBgZAeCSksThqkwy6J/ET8AEdqWjP8hMrJJRrKDK 2JLcwobI92LByTZYsRN754O7qL4w5bvR22Cun2R+PcvwWV3Wpbx4b02FlL2u3VmAQgkw e5+kr4iPGS3XeK7vLLppYp2ZTwNxtjKPruHhSB8C+8g07NbUwZGGmE1DVC7ArzOvqBeW c5PA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=1Wk+ZuKOXwx5T/3tM1PNn8WP+uxjLyS1Oi4GdwPsNdk=; b=wS2NpNALvl8fQfgB5/vFy6H6ioAUC3M2yXtdHxmAg8fdR1ULmnmMZZcp5dzwqLA0B0 Qb5KE5tE1aDlwjU8VJuK1vt2z56otdqg3N6NanPm6rDgDTq1PwAB2z/djdIhHllfWWjD Ty4yBFL7MiJEsmF1We79bNAcpXy+IJRw59jIY6ughaCsOGHqlqmU6FkQmBedK8Ql5JPy C6UTScPAet+W7X6TxdwmKYtfJU0Rcj56BVQC1aMlioUtAveKRy9C8NXYTMoaYCORs1Kx kqYTqallyHn88Qcsq34RsZ6eypzdwQp/7sqGccmY2tCSGGhjlo0sI+pUmiRnzohrEtnb v9uw== X-Gm-Message-State: AOAM532vBFJ8kEz9R7IqVOeBPdlEMJwBAoAJFnYLJUal+OGEHLKiAcyN 9aKEo3sv99uFyM5i9imT2zWyoA== X-Google-Smtp-Source: ABdhPJxt0n9gVklj0UC3IacDXGsPg8EXRtgJ+ALsQA5+OTkQjqYuQM1btWz1xFDF9z//gu+eSXx7ZA== X-Received: by 2002:ac2:4d14:0:b0:472:90d:d008 with SMTP id r20-20020ac24d14000000b00472090dd008mr16566117lfi.240.1652183911072; Tue, 10 May 2022 04:58:31 -0700 (PDT) Received: from toster.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id v25-20020a05651203b900b0047255d21116sm2275703lfp.69.2022.05.10.04.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 04:58:30 -0700 (PDT) From: Stanislaw Kardach To: Bruce Richardson Cc: Michal Mazurek , dev@dpdk.org, Frank Zhao , Sam Grove , mw@semihalf.com, upstream@semihalf.com, Stanislaw Kardach Subject: [PATCH 1/1] lpm: add a scalar version of lookupx4 function Date: Tue, 10 May 2022 13:58:24 +0200 Message-Id: <20220510115824.457885-1-kda@semihalf.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 From: Michal Mazurek Add an implementation of the rte_lpm_lookupx4() function for platforms without support for vector operations. This will be useful in the upcoming RISC-V port as well as any platform which may want to start with a basic level of LPM support. Signed-off-by: Michal Mazurek Signed-off-by: Stanislaw Kardach --- doc/guides/rel_notes/release_22_07.rst | 5 + lib/lpm/meson.build | 1 + lib/lpm/rte_lpm.h | 4 +- lib/lpm/rte_lpm_scalar.h | 122 +++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 lib/lpm/rte_lpm_scalar.h diff --git a/doc/guides/rel_notes/release_22_07.rst b/doc/guides/rel_notes/release_22_07.rst index 4ae91dd94d..73e8d632f2 100644 --- a/doc/guides/rel_notes/release_22_07.rst +++ b/doc/guides/rel_notes/release_22_07.rst @@ -70,6 +70,11 @@ New Features * Added AH mode support in lookaside protocol (IPsec) for CN9K & CN10K. * Added AES-GMAC support in lookaside protocol (IPsec) for CN9K & CN10K. +* **Added scalar version of the LPM library.** + + * Added scalar implementation of ``rte_lpm_lookupx4``. This is a fall-back + implementation for platforms that don't support vector operations. + Removed Items ------------- diff --git a/lib/lpm/meson.build b/lib/lpm/meson.build index 78d91d3421..6b47361fce 100644 --- a/lib/lpm/meson.build +++ b/lib/lpm/meson.build @@ -14,6 +14,7 @@ headers = files('rte_lpm.h', 'rte_lpm6.h') indirect_headers += files( 'rte_lpm_altivec.h', 'rte_lpm_neon.h', + 'rte_lpm_scalar.h', 'rte_lpm_sse.h', 'rte_lpm_sve.h', ) diff --git a/lib/lpm/rte_lpm.h b/lib/lpm/rte_lpm.h index eb91960e81..b5db6a353a 100644 --- a/lib/lpm/rte_lpm.h +++ b/lib/lpm/rte_lpm.h @@ -405,8 +405,10 @@ rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], #endif #elif defined(RTE_ARCH_PPC_64) #include "rte_lpm_altivec.h" -#else +#elif defined(RTE_ARCH_X86) #include "rte_lpm_sse.h" +#else +#include "rte_lpm_scalar.h" #endif #ifdef __cplusplus diff --git a/lib/lpm/rte_lpm_scalar.h b/lib/lpm/rte_lpm_scalar.h new file mode 100644 index 0000000000..991b94e687 --- /dev/null +++ b/lib/lpm/rte_lpm_scalar.h @@ -0,0 +1,122 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 StarFive + * Copyright(c) 2022 SiFive + * Copyright(c) 2022 Semihalf + */ + +#ifndef _RTE_LPM_SCALAR_H_ +#define _RTE_LPM_SCALAR_H_ + +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +static inline void +rte_lpm_lookupx4(const struct rte_lpm *lpm, xmm_t ip, uint32_t hop[4], + uint32_t defv) +{ + rte_xmm_t i24; + rte_xmm_t i8; + uint32_t tbl[4]; + uint64_t pt, pt2; + const uint32_t *ptbl; + + const rte_xmm_t mask8 = { + .u32 = {UINT8_MAX, UINT8_MAX, UINT8_MAX, UINT8_MAX}}; + + /* + * RTE_LPM_VALID_EXT_ENTRY_BITMASK for 2 LPM entries + * as one 64-bit value (0x0300000003000000). + */ + const uint64_t mask_xv = + ((uint64_t)RTE_LPM_VALID_EXT_ENTRY_BITMASK | + (uint64_t)RTE_LPM_VALID_EXT_ENTRY_BITMASK << 32); + + /* + * RTE_LPM_LOOKUP_SUCCESS for 2 LPM entries + * as one 64-bit value (0x0100000001000000). + */ + const uint64_t mask_v = + ((uint64_t)RTE_LPM_LOOKUP_SUCCESS | + (uint64_t)RTE_LPM_LOOKUP_SUCCESS << 32); + + /* get 4 indexes for tbl24[]. */ + i24.x = ip; + i24.u32[0] >>= CHAR_BIT; + i24.u32[1] >>= CHAR_BIT; + i24.u32[2] >>= CHAR_BIT; + i24.u32[3] >>= CHAR_BIT; + + /* extract values from tbl24[] */ + ptbl = (const uint32_t *)&lpm->tbl24[i24.u32[0]]; + tbl[0] = *ptbl; + ptbl = (const uint32_t *)&lpm->tbl24[i24.u32[1]]; + tbl[1] = *ptbl; + ptbl = (const uint32_t *)&lpm->tbl24[i24.u32[2]]; + tbl[2] = *ptbl; + ptbl = (const uint32_t *)&lpm->tbl24[i24.u32[3]]; + tbl[3] = *ptbl; + + /* get 4 indexes for tbl8[]. */ + i8.x = ip; + i8.u64[0] &= mask8.u64[0]; + i8.u64[1] &= mask8.u64[1]; + + pt = (uint64_t)tbl[0] | + (uint64_t)tbl[1] << 32; + pt2 = (uint64_t)tbl[2] | + (uint64_t)tbl[3] << 32; + + /* search successfully finished for all 4 IP addresses. */ + if (likely((pt & mask_xv) == mask_v) && + likely((pt2 & mask_xv) == mask_v)) { + *(uint64_t *)hop = pt & RTE_LPM_MASKX4_RES; + *(uint64_t *)(hop + 2) = pt2 & RTE_LPM_MASKX4_RES; + return; + } + + if (unlikely((pt & RTE_LPM_VALID_EXT_ENTRY_BITMASK) == + RTE_LPM_VALID_EXT_ENTRY_BITMASK)) { + i8.u32[0] = i8.u32[0] + + (tbl[0] & 0x00FFFFFF) * RTE_LPM_TBL8_GROUP_NUM_ENTRIES; + ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[0]]; + tbl[0] = *ptbl; + } + if (unlikely((pt >> 32 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) == + RTE_LPM_VALID_EXT_ENTRY_BITMASK)) { + i8.u32[1] = i8.u32[1] + + (tbl[1] & 0x00FFFFFF) * RTE_LPM_TBL8_GROUP_NUM_ENTRIES; + ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[1]]; + tbl[1] = *ptbl; + } + if (unlikely((pt2 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) == + RTE_LPM_VALID_EXT_ENTRY_BITMASK)) { + i8.u32[2] = i8.u32[2] + + (tbl[2] & 0x00FFFFFF) * RTE_LPM_TBL8_GROUP_NUM_ENTRIES; + ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[2]]; + tbl[2] = *ptbl; + } + if (unlikely((pt2 >> 32 & RTE_LPM_VALID_EXT_ENTRY_BITMASK) == + RTE_LPM_VALID_EXT_ENTRY_BITMASK)) { + i8.u32[3] = i8.u32[3] + + (tbl[3] & 0x00FFFFFF) * RTE_LPM_TBL8_GROUP_NUM_ENTRIES; + ptbl = (const uint32_t *)&lpm->tbl8[i8.u32[3]]; + tbl[3] = *ptbl; + } + + hop[0] = (tbl[0] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[0] & 0x00FFFFFF : defv; + hop[1] = (tbl[1] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[1] & 0x00FFFFFF : defv; + hop[2] = (tbl[2] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[2] & 0x00FFFFFF : defv; + hop[3] = (tbl[3] & RTE_LPM_LOOKUP_SUCCESS) ? tbl[3] & 0x00FFFFFF : defv; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_LPM_SCALAR_H_ */ -- 2.30.2