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 739F0438F4; Thu, 18 Jan 2024 17:53:34 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 45A3C42DC7; Thu, 18 Jan 2024 17:53:29 +0100 (CET) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id 507E940285 for ; Thu, 18 Jan 2024 17:53:27 +0100 (CET) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1d71207524dso3084365ad.1 for ; Thu, 18 Jan 2024 08:53:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1705596806; x=1706201606; 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=Ge5cWfhUFtdaPtGMR6xOIBTcz+rPisfRTiZR7MiWozM=; b=kInSZMIzCdRUXttTMgnVpxAWH/r/V4nFrWd40FZ71OHKZelqo9yMIS81lJ936iPf2w ykNOHTLoWZvp8qLabZxB8O/px528F3/xgHTRJ9gJtBpWi0qhZTypJF0tNe6n1HVwTmLA Nw9ScbvVK8gIuxg8Jv76/MEiAfXGo2q/o1q/Z9C94h0wUNokqsS1jegsCC8IkaWYF6r0 a+Kqc3Vhp7GgsYV3rglcIKV1wbKpbATiujx9cu0VjPOUQbqsKJDOItU8+VpYTIZyXdsE 3cbqmpIuaYQIwRlAe/tPnUmOAuVS7rTTdRXTcxBdj+kz3Ts3tvp6qjpx3lCSCodeGpS7 dPPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705596806; x=1706201606; 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=Ge5cWfhUFtdaPtGMR6xOIBTcz+rPisfRTiZR7MiWozM=; b=CqBcBI5KddyyRBrDpAub3kkxsH22m/FgqUEpO69ktVQhrdraEz4nDwGTqtKvjkCw5b Q/RQf01ilP+6JNIyFNCoh4FKMUDY+7n3jq6IuRk48vfhSG/metlybbAiMgI/PD6Fx09M J7FDj4KJxIpdFMJEnRnFDK1dnvV3P+GADPmOfOrAWyFQgntDShJnQ16xlbpAJmLeJ/Bx OvqOsVoEc7MWijPzt4qDo0yMDwc72A/ckUdNQkXtKfozUAD9z5RVRJnzb+QkwDSQURkJ gIo8yyu2OihZEvfvgiJUeTjSu7EBGIflU/JyurgUa4daZVXMaKmHsmHjYUel17ItSoG0 kihw== X-Gm-Message-State: AOJu0YzHb7vpfmEFD+of5PmHIaelPGpwjesWwUtDa6a29GqJs6BiU4Ps L3rSlzFZNkQTon212Y6TEjpSiuu8CKuV7l7elB/C/HgHuPAtpINTe06RFgYTQlDgDpems0f99lp XC2g= X-Google-Smtp-Source: AGHT+IHt2QbdxzccasfOwh+fvJIAg1hwgtQNcRa3FU7BguxVAL7NbLGEczFQUSg3zfUo4JcOwSjY4A== X-Received: by 2002:a17:903:22d1:b0:1d4:e1f1:ef69 with SMTP id y17-20020a17090322d100b001d4e1f1ef69mr1438435plg.104.1705596806522; Thu, 18 Jan 2024 08:53:26 -0800 (PST) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id u2-20020a170903304200b001d706912d1esm1427980pla.225.2024.01.18.08.53.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 08:53:26 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Konstantin Ananyev , Andrew Rybchenko Subject: [PATCH v5 1/6] eal: introduce RTE_MIN_T() and RTE_MAX_T() macros Date: Thu, 18 Jan 2024 08:50:56 -0800 Message-ID: <20240118165315.63959-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118165315.63959-1-stephen@networkplumber.org> References: <20231111172153.57461-1-stephen@networkplumber.org> <20240118165315.63959-1-stephen@networkplumber.org> 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 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 --- 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 -- 2.43.0