From patchwork Thu Jul 29 16:54:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Van Haaren, Harry" X-Patchwork-Id: 1511349 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=2605:bc80:3010::138; helo=smtp1.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GbGqJ6VBsz9sRK for ; Fri, 30 Jul 2021 02:55:08 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 50DFB83B17; Thu, 29 Jul 2021 16:55:06 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PLoxI1Le2yoB; Thu, 29 Jul 2021 16:55:05 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 9272283216; Thu, 29 Jul 2021 16:55:04 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 794E8C001A; Thu, 29 Jul 2021 16:55:04 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id D7C6EC000E for ; Thu, 29 Jul 2021 16:55:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id BA56F404ED for ; Thu, 29 Jul 2021 16:55:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mO70XKIv4joT for ; Thu, 29 Jul 2021 16:55:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by smtp4.osuosl.org (Postfix) with ESMTPS id 01B9340490 for ; Thu, 29 Jul 2021 16:55:01 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10060"; a="200106099" X-IronPort-AV: E=Sophos;i="5.84,279,1620716400"; d="scan'208";a="200106099" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jul 2021 09:54:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.84,279,1620716400"; d="scan'208";a="507352354" Received: from silpixa00401089.ir.intel.com ([10.55.129.12]) by FMSMGA003.fm.intel.com with ESMTP; 29 Jul 2021 09:54:37 -0700 From: Harry van Haaren To: ovs-dev@openvswitch.org Date: Thu, 29 Jul 2021 16:54:34 +0000 Message-Id: <20210729165434.2773795-1-harry.van.haaren@intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Subject: [ovs-dev] [PATCH] dpcls: fix build on compilers without AVX512-VPOPCNT X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" This commit adds extra checks around the AVX-512 vpopcnt instruction enabling, ensuring that in the function where the ISA is enabled the compiler has also indicated its support for the ISA. This is achieved by checking the __AVX512VPOPCNTDQ__ define, which the compiler sets if it is capable of handling the vpopcnt instruction. If the compiler is not capable of handling vpopcnt, we fall back to the emulated vpopcnt implementation. Reported-by: Ian Stokes Signed-off-by: Harry van Haaren --- Based on a very old system with GCC 7, an issue was identified where the compiler doesn't support the vpopcnt ISA, and resulted in compilation failures. --- lib/dpif-netdev-lookup-avx512-gather.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/dpif-netdev-lookup-avx512-gather.c b/lib/dpif-netdev-lookup-avx512-gather.c index ced846aa77..072831e96a 100644 --- a/lib/dpif-netdev-lookup-avx512-gather.c +++ b/lib/dpif-netdev-lookup-avx512-gather.c @@ -53,15 +53,6 @@ VLOG_DEFINE_THIS_MODULE(dpif_lookup_avx512_gather); - -/* Wrapper function required to enable ISA. */ -static inline __m512i -__attribute__((__target__("avx512vpopcntdq"))) -_mm512_popcnt_epi64_wrapper(__m512i v_in) -{ - return _mm512_popcnt_epi64(v_in); -} - static inline __m512i _mm512_popcnt_epi64_manual(__m512i v_in) { @@ -85,6 +76,23 @@ _mm512_popcnt_epi64_manual(__m512i v_in) return _mm512_sad_epu8(v_u8_pop, _mm512_setzero_si512()); } +/* Wrapper function required to enable ISA. First enable the ISA via the + * attribute target for this function, then check if the compiler actually + * #defines the ISA itself. If the ISA is not #define-ed by the compiler it + * indicates the compiler is too old or is not capable of compiling the + * requested ISA level, so fallback to the integer manual implementation. + */ +static inline __m512i +__attribute__((__target__("avx512vpopcntdq"))) +_mm512_popcnt_epi64_wrapper(__m512i v_in) +{ +#ifdef __AVX512VPOPCNTDQ__ + return _mm512_popcnt_epi64(v_in); +#else + return _mm512_popcnt_epi64_manual(v_in); +#endif +} + static inline uint64_t netdev_rule_matches_key(const struct dpcls_rule *rule, const uint32_t mf_bits_total,