From patchwork Wed Jan 17 18:19:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 135933 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5276A438E4; Wed, 17 Jan 2024 19:25:59 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B547240DFD; Wed, 17 Jan 2024 19:25:54 +0100 (CET) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by mails.dpdk.org (Postfix) with ESMTP id 103E24014F for ; Wed, 17 Jan 2024 19:25:52 +0100 (CET) Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-5ce6b5e3c4eso5370770a12.2 for ; Wed, 17 Jan 2024 10:25:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1705515952; x=1706120752; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FjNP8Pw9BHz6L17zt5K6cyppa2mxqxirZwMu7iwBbXc=; b=JB87M1Qs1Fk15oNyEeumCeJ5bSzwyN37d2uVH6XpsMX0vXyaysE9GrO5jdvYFXpb19 pQEW30PCYC5Pa2e4nk/MwhBGBmNyt3pZ3M2uO4sKLNGkByTctAYbKO32kv3K323VxhGY 8aq2KYAP0ZZhzuGP8+3j2TsVqXNvorYQPP9VsNwUOuMlvu4hw74RbM21CY5OBLTPkXGz riZ0TYJ68TmA2nuqKVAjikT3CNhlucgYxtJIU7k68SBEBn8AYxSd/v3HOE/IinJDkMIo eB2d+04MUThr5Unfnq9MKBwZGT1A14FVj/VSKYyF3KG8mpp4v2Qo/sazModVCm7Cvj8j Hwxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705515952; x=1706120752; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FjNP8Pw9BHz6L17zt5K6cyppa2mxqxirZwMu7iwBbXc=; b=ny1WCUh+f/XjNFajmJiH1gnJ3LR8SZU+5n12BHkAOSujcaZCeMlVYDQLbAOBRyDCj5 TrUKn4Nwx8ICjJrJf8KP/R1mJSa5yhR/A3QgsxJwITYemA3v8r8qavowWDyaMrj5YIpQ 7Ssy8fI8PxUuY6c9DZ1kaTrNkYw0AYIuOR+nYFf8ilI/E02M/xJ6PyhwDcl15lfaPBSp O8RbxMtJDH5LZytp6tMpCd4HJ+3xAzDxMyBCG4SL6FtkDAfEDP+bSSVulwve3UnjhcDY qobzr3V7HOVefTGuLAjMWs65cUOYBiQ+jkhxCnrfbdT/Ri+89jmUvdN0yKCFHwH/U8rH y/vA== X-Gm-Message-State: AOJu0YwjdMGKW2vOqv6dnnuO9ePisUZp8D4P7G6zA8i0YqzmKJs5+17B 45fqY0errU7QJk1lkrOcilaILfzhEg8WpAwOPpeiu3Fe0J8wOQ== X-Google-Smtp-Source: AGHT+IG0//Lu57FHHCvpHwenl/xfF8lt+2ziboKXEDlvZmY02MzXRtWzbUdlVHfWBd2Qxx6zdM2osw== X-Received: by 2002:a17:90b:30d5:b0:290:9b:252f with SMTP id hi21-20020a17090b30d500b00290009b252fmr837831pjb.18.1705515952158; Wed, 17 Jan 2024 10:25:52 -0800 (PST) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id qj15-20020a17090b28cf00b0028ce507cd7dsm14334124pjb.55.2024.01.17.10.25.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jan 2024 10:25:51 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [PATCH v4 1/6] eal: introduce RTE_MIN_T() and RTE_MAX_T() macros Date: Wed, 17 Jan 2024 10:19:55 -0800 Message-ID: <20240117182541.211125-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240117182541.211125-1-stephen@networkplumber.org> References: <20231111172153.57461-1-stephen@networkplumber.org> <20240117182541.211125-1-stephen@networkplumber.org> MIME-Version: 1.0 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 These macros work like RTE_MIN and RTE_MAX but take an explicit type. Necessary when being used in static assertions since RTE_MIN and RTE_MAX use temporary variables which confuses compilers constant expression checks. These macros could also be useful in other scenarios when bounded range is useful. Naming is chosen to be similar to Linux kernel conventions. Signed-off-by: Stephen Hemminger Acked-by: Konstantin Ananyev Acked-by: Andrew Rybchenko Acked-by: Tyler Retzlaff --- lib/eal/include/rte_common.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index c1ba32d00e47..33680e818bfb 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -585,6 +585,14 @@ __extension__ typedef uint64_t RTE_MARKER64[0]; _a < _b ? _a : _b; \ }) +/** + * Macro to return the minimum of two numbers + * does not use temporarys so not safe if a or b is expression + * but is guaranteed to be constant for use in static_assert() + */ +#define RTE_MIN_T(a, b, t) \ + ((t)(a) < (t)(b) ? (t)(a) : (t)(b)) + /** * Macro to return the maximum of two numbers */ @@ -595,6 +603,14 @@ __extension__ typedef uint64_t RTE_MARKER64[0]; _a > _b ? _a : _b; \ }) +/** + * Macro to return the maxiimum of two numbers + * does not use temporarys so not safe if a or b is expression + * but is guaranteed to be constant for use in static_assert() + */ +#define RTE_MAX_T(a, b, t) \ + ((t)(a) > (t)(b) ? (t)(a) : (t)(b)) + /*********** Other general functions / macros ********/ #ifndef offsetof