From nobody Wed Jun 12 10:01:04 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VzgzN3HhPz5P7Pn; Wed, 12 Jun 2024 10:01:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VzgzN2PKJz4k5t; Wed, 12 Jun 2024 10:01:04 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718186464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wWUV6K9UNxCezBpjCNDfjJ8QLG+Tr1kzPLDBsQbcNhM=; b=puY/GWuTUGmyJpm1H4/m47ojeEvR89duHycCmnHoIFIyFt846gTsm9d/8/bDKidv8k8IJs aNqxJT/LOseBrZMw1MGPdfQgzVG3/W8lRL72vw6OUH+ac0ItPMHdxsqtYamDurFnNsrvBp pekTozVoZ4Co5PkmH4th39s9xNCQ+rqgE6QWmpGNME2ANGRRmn0TZDLbJ+h8BCa6FuOWka 4/Wt7z4YP422IaovXIe4rnJltq8pnokEowMJfbWPYliXT6Ywv/Q8DmVk3KaAuB0DrRYa2P Q0WR6FFy1a5Oy84YV3PgPHkNAgDHTXy7UsLC3f9qJYlSaRkMX4nmgPRRjEGh7g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718186464; a=rsa-sha256; cv=none; b=h8yXjPm1BpX1b3OtOd7o8tzK0yAw+qP6jKGflAXuWbjbghZVu2AMfsVeK+jdzHlAfVBog5 r7PQJGJCoYa8HPpwWWvBna7ylsW72BcOhGTB7Mk5VqUOX9rkqloaqXt+xAPtZfksyl4hNS eXPktIbfcxxWhXX9KWkCYdA9GyZ77tXz21YUW0MkHr9E1KLTmEqZpXwGHMAENB0K+wTZNP sfDsLSpz8Ct1Zqk20d/f1iTMyN3gEsV937u6zZW1SplB4+L0PDjmNfIcU1dZoPNY4N+3qC ZlsjHRs6kWI2AgPI5P0fHfWN0GM3KEe/oI1B+UurIqslrKrknsrGL759ZwKLFw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718186464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wWUV6K9UNxCezBpjCNDfjJ8QLG+Tr1kzPLDBsQbcNhM=; b=h6cg4BAbjKCSi50E3uelj5wyhpmrDaJaaQbyU/Ob5vjqFtGNP1ZcWovyI45lUJvma28ukI g75ewO6A/g75hDIQlZWRYV9wwctCJt83OMmjpBwiOu7Mu58nTK2QIJTmC/Qmq90eo89BLC n/YJWth2oQoFLmpYYhxobBGBsz07ZnH6CP3UtbFwWF4Z9mfCasF0X1ZJnQ5JP9oulzbWkt kv0P8oivLmf4RVT82WLsXOO5HjzDicfO7ii7kOqUccS9/etP4eJpBxpL3XaxFTjyM6a8+J KRF4QvnGBt4S1CrgQKF3PO9WMiNRE6XHwSPdHNwz0KUThoSKjGKkM8MgY8JGjw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VzgzN1yFGzp4h; Wed, 12 Jun 2024 10:01:04 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45CA14g7068427; Wed, 12 Jun 2024 10:01:04 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45CA14oS068424; Wed, 12 Jun 2024 10:01:04 GMT (envelope-from git) Date: Wed, 12 Jun 2024 10:01:04 GMT Message-Id: <202406121001.45CA14oS068424@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Moore Subject: git: f0a0420dfd36 - main - powerof2: replace loops with fls or ilog2 List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dougm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f0a0420dfd36ae90f86cc9bfb1342b8862b8c9ec Auto-Submitted: auto-generated The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=f0a0420dfd36ae90f86cc9bfb1342b8862b8c9ec commit f0a0420dfd36ae90f86cc9bfb1342b8862b8c9ec Author: Doug Moore AuthorDate: 2024-06-12 09:26:42 +0000 Commit: Doug Moore CommitDate: 2024-06-12 10:00:48 +0000 powerof2: replace loops with fls or ilog2 In several places, a loop tests for powers of two, or iterates through powers of two. In those places, replace the loop with an invocation of fls or ilog2 without changing the meaning of the code. Reviewed by: alc, markj, kib, np, erj, avg (previous version) Differential Revision: https://reviews.freebsd.org/D45494 --- sys/dev/aic7xxx/aic79xx.c | 3 +-- sys/dev/cxgb/cxgb_sge.c | 7 ++----- sys/dev/cxgbe/t4_sge.c | 4 +--- sys/dev/irdma/irdma_ctrl.c | 16 +++++----------- sys/dev/mlx5/mlx5_en/mlx5_en_main.c | 4 +--- sys/netpfil/ipfw/ip_fw_table.c | 10 +--------- 6 files changed, 11 insertions(+), 33 deletions(-) diff --git a/sys/dev/aic7xxx/aic79xx.c b/sys/dev/aic7xxx/aic79xx.c index 0c4b615c5b24..ab68c3d8b088 100644 --- a/sys/dev/aic7xxx/aic79xx.c +++ b/sys/dev/aic7xxx/aic79xx.c @@ -8593,8 +8593,7 @@ ahd_loadseq(struct ahd_softc *ahd) if (sg_prefetch_align == 0) sg_prefetch_align = 8; /* Round down to the nearest power of 2. */ - while (powerof2(sg_prefetch_align) == 0) - sg_prefetch_align--; + sg_prefetch_align = 1 << ilog2(sg_prefetch_align); cacheline_mask = sg_prefetch_align - 1; diff --git a/sys/dev/cxgb/cxgb_sge.c b/sys/dev/cxgb/cxgb_sge.c index f57494065aec..0c5be9dd6614 100644 --- a/sys/dev/cxgb/cxgb_sge.c +++ b/sys/dev/cxgb/cxgb_sge.c @@ -553,9 +553,7 @@ t3_sge_prep(adapter_t *adap, struct sge_params *p) nqsets *= adap->params.nports; fl_q_size = min(nmbclusters/(3*nqsets), FL_Q_SIZE); - - while (!powerof2(fl_q_size)) - fl_q_size--; + fl_q_size = 1 << ilog2(fl_q_size); use_16k = cxgb_use_16k_clusters != -1 ? cxgb_use_16k_clusters : is_offload(adap); @@ -567,8 +565,7 @@ t3_sge_prep(adapter_t *adap, struct sge_params *p) jumbo_q_size = min(nmbjumbo9/(3*nqsets), JUMBO_Q_SIZE); jumbo_buf_size = MJUM9BYTES; } - while (!powerof2(jumbo_q_size)) - jumbo_q_size--; + jumbo_q_size = 1 << ilog2(jumbo_q_size); if (fl_q_size < (FL_Q_SIZE / 4) || jumbo_q_size < (JUMBO_Q_SIZE / 2)) device_printf(adap->dev, diff --git a/sys/dev/cxgbe/t4_sge.c b/sys/dev/cxgbe/t4_sge.c index e1705ae063e2..505f2d1bf677 100644 --- a/sys/dev/cxgbe/t4_sge.c +++ b/sys/dev/cxgbe/t4_sge.c @@ -4220,9 +4220,7 @@ qsize_to_fthresh(int qsize) { u_int fthresh; - while (!powerof2(qsize)) - qsize++; - fthresh = ilog2(qsize); + fthresh = qsize == 0 ? 0 : fls(qsize - 1); if (fthresh > X_CIDXFLUSHTHRESH_128) fthresh = X_CIDXFLUSHTHRESH_128; diff --git a/sys/dev/irdma/irdma_ctrl.c b/sys/dev/irdma/irdma_ctrl.c index dc42b15392c5..6078ac43815e 100644 --- a/sys/dev/irdma/irdma_ctrl.c +++ b/sys/dev/irdma/irdma_ctrl.c @@ -4909,7 +4909,7 @@ irdma_cfg_fpm_val(struct irdma_sc_dev *dev, u32 qp_count) struct irdma_virt_mem virt_mem; u32 i, mem_size; u32 qpwanted, mrwanted, pblewanted; - u32 powerof2, hte; + u32 hte; u32 sd_needed; u32 sd_diff; u32 loop_count = 0; @@ -4938,12 +4938,8 @@ irdma_cfg_fpm_val(struct irdma_sc_dev *dev, u32 qp_count) hmc_info->sd_table.sd_cnt, max_sds); qpwanted = min(qp_count, hmc_info->hmc_obj[IRDMA_HMC_IW_QP].max_cnt); - - powerof2 = 1; - while (powerof2 <= qpwanted) - powerof2 *= 2; - powerof2 /= 2; - qpwanted = powerof2; + if (qpwanted != 0) + qpwanted = 1 << ilog2(qpwanted); mrwanted = hmc_info->hmc_obj[IRDMA_HMC_IW_MR].max_cnt; pblewanted = hmc_info->hmc_obj[IRDMA_HMC_IW_PBLE].max_cnt; @@ -4986,11 +4982,9 @@ irdma_cfg_fpm_val(struct irdma_sc_dev *dev, u32 qp_count) hmc_info->hmc_obj[IRDMA_HMC_IW_MR].cnt = mrwanted; hte = round_up(qpwanted + hmc_info->hmc_obj[IRDMA_HMC_IW_FSIMC].cnt, 512); - powerof2 = 1; - while (powerof2 < hte) - powerof2 *= 2; + hte = hte == 0 ? 1 : 1 << fls(hte - 1); hmc_info->hmc_obj[IRDMA_HMC_IW_HTE].cnt = - powerof2 * hmc_fpm_misc->ht_multiplier; + hte * hmc_fpm_misc->ht_multiplier; if (dev->hw_attrs.uk_attrs.hw_rev == IRDMA_GEN_1) cfg_fpm_value_gen_1(dev, hmc_info, qpwanted); else diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c index 962705e6d258..4d9d1048448b 100644 --- a/sys/dev/mlx5/mlx5_en/mlx5_en_main.c +++ b/sys/dev/mlx5/mlx5_en/mlx5_en_main.c @@ -2331,9 +2331,7 @@ mlx5e_get_wqe_sz(struct mlx5e_priv *priv, u32 *wqe_sz, u32 *nsegs) * Stride size is 16 * (n + 1), as the first segment is * control. */ - for (n = howmany(r, MLX5E_MAX_RX_BYTES); !powerof2(n + 1); n++) - ; - + n = (1 << fls(howmany(r, MLX5E_MAX_RX_BYTES))) - 1; if (n > MLX5E_MAX_BUSDMA_RX_SEGS) return (-ENOMEM); diff --git a/sys/netpfil/ipfw/ip_fw_table.c b/sys/netpfil/ipfw/ip_fw_table.c index b6847d43081b..5cf948ce39a2 100644 --- a/sys/netpfil/ipfw/ip_fw_table.c +++ b/sys/netpfil/ipfw/ip_fw_table.c @@ -1516,15 +1516,7 @@ static uint32_t roundup2p(uint32_t v) { - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v++; - - return (v); + return (1 << fls(v - 1)); } /*