From patchwork Mon Jun 12 12:29:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Herve Codina X-Patchwork-Id: 106554 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2552113vqr; Mon, 12 Jun 2023 05:32:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6a3tcP/id/PB+ToKideYEt0Mg4G6jD45QsIMcWPah59EYkaYp2Y730PUCYkfwK6obP/6by X-Received: by 2002:a05:6402:2cd:b0:510:487a:ca3d with SMTP id b13-20020a05640202cd00b00510487aca3dmr4882284edx.23.1686573148220; Mon, 12 Jun 2023 05:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686573148; cv=none; d=google.com; s=arc-20160816; b=EHulzOYxdtGl1bot8nHn4FvHo4mRg54h2gVzm/Hmt9sGqWEhPft+KlOtGVbkHQ+5Qs Pdcq7LHYON7ECvSe6VJlzP3j5arPigswSgGeAUnbU0ayuaIOQJ6691f3bwYAJ7oBewVj B2+XO1L5lf4U4Axq4KTT4YmO9IVJcO0CsYCNnnEWtrmL9CwWrptlhm/EjdD9H4i96rj7 iumASk4DhDfc7PWhoGaAxibca525HLDWJIiC9/xfkWjrdWWZW0ZiwjoqcxO4gd/tOuBm g7OGqut2LBgJxBansunv1BpEF4NQohOHn3vFHx24GCQTJM702JLrQb6d/cMfi2dDj2k7 N6Rg== 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=0zjmMFQWF61zw9+cDMz5UXwQs5v91FQYhgIX9kfi+g8=; b=L+3sEutKavm4YWOs1sIzlrZ02nOA23lWM0Ton7oxnXV+nYwewaPh0yGh6XqlnUWdOW fCTSQWf01vFpdxcuzOooUjztoALIk0T+qyHv4rgtk05ow5WhurwgyyK7qckKMF5bEcID 7t0VCNizkHcikt3JmCXj4i1Z6W4W2N1d3FAXOJv/mLItNNmE7JkrgTNEaPUnCBl1uzAI 4FcW1hxaOCz6nPHnK74FOp94gLBuR33Cbye8lw97oVHwJwJuE0otY/BfAlql9qk2XuzR VkBzQpCcaO4Eh8ITLLJwxgl17IJQnQE02XB2roOKGUqIKOUNpuYBVUnmZJ44UkH/78RE omkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=GPwEuaot; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j5-20020aa7de85000000b005184ac0d978si278103edv.604.2023.06.12.05.32.03; Mon, 12 Jun 2023 05:32:28 -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=@bootlin.com header.s=gm1 header.b=GPwEuaot; 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=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234160AbjFLMbD (ORCPT + 99 others); Mon, 12 Jun 2023 08:31:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234050AbjFLMa3 (ORCPT ); Mon, 12 Jun 2023 08:30:29 -0400 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 927CC10E0; Mon, 12 Jun 2023 05:30:16 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1686573014; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0zjmMFQWF61zw9+cDMz5UXwQs5v91FQYhgIX9kfi+g8=; b=GPwEuaotHYy+KeLmHieSOGl4ZFBSI5jW9fbAzyelPnPJgZSUYNy2nJ9FQH481z2kbd79ev mWK4v88w1xCDOy6EglLRLeaHs00makBSqA4AJGxjD6TwPfQDBwPPuKovSv7V3mxM5r2QCp 4VJ4UhiAKmRONu8MVSCmGOtzpzNqp/GrwQrjNtfnG+qvyDEhHEeQy84ifJMS/jfoKeB2Nu nL1gGVg//0h7FtGkBRbit2gDlLHOX6XzuJD2VJwlxwdDUnQv5HshickA5soSnBtXunBI28 F9NolqiQPJl671dfvtxW3HhlH+LUGXfIaVs81/ZEVZ8FUjXXh369AS6RxJxgdw== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPA id F177A24000C; Mon, 12 Jun 2023 12:30:11 +0000 (UTC) From: Herve Codina To: Herve Codina , Liam Girdwood , Mark Brown , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Jonathan Cameron , Lars-Peter Clausen , Jaroslav Kysela , Takashi Iwai , Kuninori Morimoto , Andy Shevchenko Cc: alsa-devel@alsa-project.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, Christophe Leroy , Thomas Petazzoni Subject: [PATCH v3 06/12] minmax: Introduce {min,max}_array() Date: Mon, 12 Jun 2023 14:29:20 +0200 Message-Id: <20230612122926.107333-7-herve.codina@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230612122926.107333-1-herve.codina@bootlin.com> References: <20230612122926.107333-1-herve.codina@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768500125848482974?= X-GMAIL-MSGID: =?utf-8?q?1768500125848482974?= Introduce min_array() (resp max_array()) in order to get the minimal (resp maximum) of values present in an array. Signed-off-by: Herve Codina Reviewed-by: Andy Shevchenko --- include/linux/minmax.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index 396df1121bff..37a211f22404 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -133,6 +133,32 @@ */ #define max_t(type, x, y) __careful_cmp((type)(x), (type)(y), >) +#define __minmax_array(op, array, len) ({ \ + typeof(array) __array = (array); \ + typeof(len) __len = (len); \ + typeof(*__array + 0) __element = __array[--__len]; \ + while (__len--) \ + __element = op(__element, __array[__len]); \ + __element; }) + +/** + * min_array - return minimum of values present in an array + * @array: array + * @len: array length + * + * Note that @len must not be zero (empty array). + */ +#define min_array(array, len) __minmax_array(min, array, len) + +/** + * max_array - return maximum of values present in an array + * @array: array + * @len: array length + * + * Note that @len must not be zero (empty array). + */ +#define max_array(array, len) __minmax_array(max, array, len) + /** * clamp_t - return a value clamped to a given range using a given type * @type: the type of variable to use