Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp4450869rwb; Mon, 8 Aug 2022 00:41:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR7aWXdDchxoIOR6kcBXc/bVqb4UMbNRXD2kViKDV+xgZHwErdjcdePIXKDqpTvEA/HPeoW0 X-Received: by 2002:a63:6884:0:b0:415:b761:efa4 with SMTP id d126-20020a636884000000b00415b761efa4mr14891698pgc.274.1659944512287; Mon, 08 Aug 2022 00:41:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659944512; cv=none; d=google.com; s=arc-20160816; b=sPExw0cHO2+omfMhTbmnaavAEhqZ+bk0yRIXN2FJYaH2MuFnraBYkO1DAqGadmP3db 77N5ujdS5pjIH5TMUlbFRV4w1amUepIT6DFU2jxPuxr42mu7QUbt0W1Fk+p/lWYAQW4C wm0FVWzpWe/2yuDA0TI9nLYpwPdN+pLWC0WBhGn0LQJ6bSeG04SEVfUrVeP/cqylD2F4 8a2LyzYyv3fY+KcZlMW52A0aG1Y7DKj14O4Mcfno7N0NEIgetTQQzIjKTA/UueMeQfqw zGK9pRDHJ5L5kf3YsBnCJeDG/HhGlZze457l00l49Glq98Twe6cPsCWf6H1Wu9Ko+2W7 t4mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QsRY2tIfY7UBaIPWAap3Z+BS4Vv0ACy8asMUJ+/ScDY=; b=FXhgtUs1BSZE2tAvgEXXMgxGneUkdybT5GSgmhhIiUpyfLtDiISLi/YCVyU/D5eDHl CmalxDYyENb95Qz5nCWuxpShbU3zPRfSm35rUtYJ99uZVsV4P1a+Ek2y+f7/gXaYNXuz oM8DpLCpnzBUOiUwwLcnOuyjLV7uY1HS0p0q1BZ0WzUUD99D9BM5B1YPDSUYz2bnge/g Wl+jeJC88SCVOsxADhuqWJV7MaCUSHuT8mST14yfBvI1ExLFgNha/Hb0dzsDIeB3PFpn fb8rYdV1HceaMKgHm4P96Qc8xJcRdLGF1wYm1/5B4U+Vm+mdn0LqTcdXSHhpDZdwtY0M mmAQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XgzOZi5p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu12-20020a17090b1b0c00b001eee6b10d6fsi12077446pjb.51.2022.08.08.00.41.35; Mon, 08 Aug 2022 00:41:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XgzOZi5p; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238420AbiHHHh2 (ORCPT + 99 others); Mon, 8 Aug 2022 03:37:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235736AbiHHHgu (ORCPT ); Mon, 8 Aug 2022 03:36:50 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39AA46399; Mon, 8 Aug 2022 00:36:47 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id bv3so9860041wrb.5; Mon, 08 Aug 2022 00:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=QsRY2tIfY7UBaIPWAap3Z+BS4Vv0ACy8asMUJ+/ScDY=; b=XgzOZi5pw9a1fvi3NQY8A12+/3RvsZuN5DIGfqmf/DCMA+97OVp6Zg16H1Am3pArr9 uA6LAr+VGVvp6gsf8tu+7eUcVKX1bVijpRByZnAhoPcv2AE2P0f9cMeAUEKRm0OJaONx R3OaIK3y0EIHIHSSxwwlOSb9G+2O3MH4DU4fJLx905DsTQ7JBdk5urHrRgLasEXVS0rj h6k167OuZhwbzHjTh7zhbQg/Kz/ntjmZ4ChJWxhnmJ0jGXpmbYXjVLvowTgoxBECPXWE Z/Mk1dMrrmCe5Gryk0TIUc8VA/av1l24VHNgvz/ur+K2hti+Di04v1xg+D3yJ2x/7kn0 uZgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=QsRY2tIfY7UBaIPWAap3Z+BS4Vv0ACy8asMUJ+/ScDY=; b=P34ouv3/xTpIfw3PjBTWcve5Spwf/qN2TrZCgItNOvQhKV9p6DaGGjOHj1q6bj+2Fv ouITydqz3ngszZ6mDgEtmjmjFzqIXPxs4eN5+J5jwudb5pdYCAuQqNN9wZjiI4G6cHEt AeMIF607eAiA8NhZVnTQ3w4rANdLpvbEWxzGOKr+Ied7PZkst3x1b6x2IXZyXCZ1EKF4 tkT1d9TyKZP2ZZsg3TVeVP4jxjJuD6n1nWPI4MYdP9rzL96uadqv57gQMF/tG89gr2Bl WJCQQDtkd4KAKH1xcGHCcPJZ8uPckSrLmvDiv3O1EixwTIesry/hrCXkCU+ZTVyomCMd q1pA== X-Gm-Message-State: ACgBeo0llco5zW8pGJLS6m7GBqGTq8unqfv7ZZZXzYsFepItr3qS0h0/ 6n432VXJj6ExivLApb8013I= X-Received: by 2002:a05:6000:888:b0:21f:bc6:cc12 with SMTP id ca8-20020a056000088800b0021f0bc6cc12mr10815745wrb.90.1659944205774; Mon, 08 Aug 2022 00:36:45 -0700 (PDT) Received: from localhost.localdomain ([105.235.133.111]) by smtp.gmail.com with ESMTPSA id cc11-20020a5d5c0b000000b002205ffe88edsm8333364wrb.31.2022.08.08.00.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Aug 2022 00:36:45 -0700 (PDT) From: Yassine Oudjana X-Google-Original-From: Yassine Oudjana To: Sebastian Reichel , Rob Herring , Krzysztof Kozlowski , Andy Gross , Bjorn Andersson Cc: Yassine Oudjana , Yassine Oudjana , Alejandro Tafalla , Konrad Dybcio , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, phone-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/8] util_macros.h: Add macro to find closest smaller value in array Date: Mon, 8 Aug 2022 08:34:58 +0100 Message-Id: <20220808073459.396278-8-y.oudjana@protonmail.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808073459.396278-1-y.oudjana@protonmail.com> References: <20220808073459.396278-1-y.oudjana@protonmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yassine Oudjana Add a macro to find the value closest to but smaller than a given value in an array. Signed-off-by: Yassine Oudjana --- include/linux/util_macros.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/linux/util_macros.h b/include/linux/util_macros.h index 72299f261b25..ad0020e7932b 100644 --- a/include/linux/util_macros.h +++ b/include/linux/util_macros.h @@ -38,4 +38,26 @@ */ #define find_closest_descending(x, a, as) __find_closest(x, a, as, >=) +/** + * find_closest_smaller - locate the closest smaller element in a sorted array + * @x: The reference value. + * @a: The array in which to look for the closest smaller element. Must be + * sorted in ascending order. + * @as: Size of 'a'. + * + * Returns the index of the element closest to and smaller than 'x', or -1 + * if no element smaller than 'x' exists in the array. + */ +#define find_closest_smaller(x, a, as) \ +({ \ + typeof(as) __fcs_i; \ + typeof(x) __fcs_x = (x); \ + typeof(*a) const *__fcs_a = (a); \ + for (__fcs_i = 0; __fcs_i < (as); __fcs_i++) { \ + if (__fcs_x < __fcs_a[__fcs_i]) \ + break; \ + } \ + (__fcs_i - 1); \ +}) + #endif -- 2.37.1