From nobody Tue Sep 22 22:51:42 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1784141845; cv=none; d=zohomail.com; s=zohoarc; b=lzQBQFxyi+BHebKE1lJoDZUTLB/ITTpwPsn6p+qo+KPdYTVPT+m7z3ujVtGsU9DWcXh+wnlXA3jZyz/xV2tps8EEsKYlOHTpz7uAPcqHfozuQxIGREmuf5cF7bp19R6u/uEH98uHxkqMgQ7JPl1gD7ynKkActIh+YNcB9pW+SOE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784141845; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A1dKhWmVEpScQ2nw0jysc1Wm3J7x83ChWxRAi/X43Y0=; b=foUvHUfHxFUWR6yD7B+kRJnatE3lvO155apbr0RZabAQffy3j9Ook+0sxGXkipf+vu0L0MrJGLqgGb3Tm18PK0WvRm9H5Y3RS2OBDag8T0osk5QmWAekl3w0SZhoBvMOK6NQv5CtBcu1f7fv7gSa7C9SN03MFTpo9hfvT7xsgTU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784141845658785.1109244882994; Wed, 15 Jul 2026 11:57:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wk4nC-0002kb-1D; Wed, 15 Jul 2026 14:57:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wk4nA-0002k2-He for qemu-devel@nongnu.org; Wed, 15 Jul 2026 14:57:12 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wk4n8-0005yV-LY for qemu-devel@nongnu.org; Wed, 15 Jul 2026 14:57:12 -0400 Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66FHBX3x051127 for ; Wed, 15 Jul 2026 18:57:09 GMT Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4fecny8yfr-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 15 Jul 2026 18:57:09 +0000 (GMT) Received: by mail-pj1-f69.google.com with SMTP id 98e67ed59e1d1-38d7fcd1f66so8516520a91.2 for ; Wed, 15 Jul 2026 11:57:09 -0700 (PDT) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3140e6c2b17sm5469546eec.25.2026.07.15.11.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2026 11:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= A1dKhWmVEpScQ2nw0jysc1Wm3J7x83ChWxRAi/X43Y0=; b=D9A2/0VS0Jo8pQuX wXzcA19r94WKf/ZEjtCMGM+wtMyHQXnAKB7rtGBawoUHImI481OvrakuAPvpohsM 1K0af8rxi2Y9k1/onlfyCjRDQ1RER1r7U+yFCS+nTDwMMMCcKHFvxM/Ido3LBHmt Xym5ggDeejSvxDcv15/NEjrTJdcJrZc1L00uUP41XV2VHukucl6nwDf2wzTg4N9b VhN3QGlFBkqOlOzkFWr4Veo9Umsgq2mBOb39mdx6y5RfA5Xc6zlpjNrx3cYFqyQm 0Ladhd3jouQfRA2xrGbGQMuZkGXUT43aQz46Vp7cu9yfGImcnwMz2aZCfwETt4cv pK3T/w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1784141829; x=1784746629; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=A1dKhWmVEpScQ2nw0jysc1Wm3J7x83ChWxRAi/X43Y0=; b=cqbMMDDwVlBDqVH8TULdyraK5TjPAMnLjK4lhNga84UOvX48yA892Jro2MqqqKztoG te71lDFzDk/zUaz++kN+EmFRDCxtvaEg/NKXlBKm90rVTcpoER2tlCTvBGJOdJ8E+kv4 OmA2hxZHsDbFf6FAklV/oJ06d/uEINdESH+f7nIGQq0NbOwRTDXywkETtdbYKmEm46hN wWoQmoFTjgTcaREz+Zc4Jyt9JdKAWPvyelsLz/CSGkwWVPHIiqKuUnlIdPUyZpj1v6hA cbUuc3JKc1VPGu8uj8WM49833eXu0FwuCWUzN0RNyXnNtZgoPQeXq8ZEttEqtYzRLnko 0B5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784141829; x=1784746629; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=A1dKhWmVEpScQ2nw0jysc1Wm3J7x83ChWxRAi/X43Y0=; b=X8TPE+mgmelnINfDR/5juJ8vlDnEqVRyLPVltJP3UkGr+kJFoTVt6Jfks6TAOifa65 7bYqNPqiXjnuGzb/MTURxK9pmXJPc+gGuHeLBriNwWu0epOX3+BhfvA6yGV0Dl8gPrLc oHunfVE9HcMuIK4+Ikz/np9srsZFzkZoF5SrXeRmOoqgsJu3QpZ101NqBA8tFnBk2EiS 2T7ZZ1mmT7v8ylESj1dcWA6HyjOmtV8/6+Szz0qZ19OuxoAOe1wlkGpcZd71cNo7BcL1 9CvpVolhfanmxWfVwaHXGPkJ9mOWU9LP+TT9VnGf2ylBztTR53CKhhdmAGHWB8DHAM9L uqmw== X-Gm-Message-State: AOJu0YzLpMJMqFv9erDxG9WmoGrl1Z47zDwmby0LGrn+BmPPOKYdMfvE g20zdk8NISS5cj4Zmh7+qJTj5TNLAVO+Yv5/osxlIRH4x9srM9uQWDEwOY4pXYeDJCjJqjW5M++ IIdCIKOm2d381r9sUeENkooePx8CisWfXQKpwrlsLXx98DArHs3aMpWb1+05CMcXR2A== X-Gm-Gg: AfdE7cmyNkAg3EdGoaoNInrh9KDwBDvDfXdm+EtdVO3fDLT+oZbZysE88TREoJdPVSW bFHNrn2h47WQNRcr8OP9BySSaCnJuTLJwRAcpC4dwr/BCvx6dJmqysGHqf9+PdrHbmmvRtBLuSa 1lqdV6TYiJMK6srd9AqpCeRBdUpZ9tIc9Yv0EqGOwgsNwjRXBMqpqR2lXzM54sDlxbubFXTbAML ooLTfaWGH1QNsF/HUhRexBhAeZDmoOLnRvcpg+XCmYW/O2raHIRrPsn9fBknscIvQSLlDOS+3vn r2MueTySD6EP7qh4kkRiB/UK6u0wFMZuyo4rS+ayMSM/jxUWa+QMQNDIyV1dB4zCWxUzRwTTTvJ R+zveh2OE/A57Nu5RV7ze4l4rdX1WaIH8maRclE3xbPeN097eIdaAvFw5mQA= X-Received: by 2002:a17:90b:3b8b:b0:380:a568:cc4e with SMTP id 98e67ed59e1d1-38e1add8e69mr6794556a91.9.1784141828558; Wed, 15 Jul 2026 11:57:08 -0700 (PDT) X-Received: by 2002:a17:90b:3b8b:b0:380:a568:cc4e with SMTP id 98e67ed59e1d1-38e1add8e69mr6794518a91.9.1784141827877; Wed, 15 Jul 2026 11:57:07 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: philmd@oss.qualcomm.com, pierrick.bouvier@oss.qualcomm.com, Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , peter.maydell@linaro.org, matheus.bernardino@oss.qualcomm.com, ltaylorsimpson@gmail.com, Thomas Huth , Brian Cain , Laurent Vivier , Fabiano Rosas , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v2 3/7] bitops.h: Add find_first_bit32() Date: Wed, 15 Jul 2026 11:56:57 -0700 Message-Id: <20260715185701.1287176-4-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260715185701.1287176-1-brian.cain@oss.qualcomm.com> References: <20260715185701.1287176-1-brian.cain@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYwNzE1MDE4OCBTYWx0ZWRfX3USrGKvYaPx9 MByP1pP2fdO/xUTTM4X/smYeNH3NyNRHD+BQnx92jMnhhkiPLNMOwrvcci5lb3abD7su/rDv/XB AbZSOVm6iCzYFrTpDnSVJh5MHmGSVU8= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNzE1MDE4OCBTYWx0ZWRfX1aqg2Z/66Enl uKQQaufRZdceXeEsuNYPphEaz3XjGojQg98BEBGDYZ541rlnSIy9sFLtfgBHlNbcbREJsRXA5o4 7LVtG9BIZqVTmP66HOMBY7E69F7LGQnc2iX/O1GpBqk5tnWsJ8MdlcC4b7Wzq6FI4JeRj/yME34 5E3NIPL18lz6tBW6EBccy26PflbFKqUsNLqFwPFjVnOQRsSB9zpJcqz9L6syfszFKBsMJkY/LiC 9dmynmocZOF7YouGXLhGlFvEw7VnBq2V3B2t1PxJGEyrVMjtb6KLqoN9hAF2MeRnKJ0kHLC90v2 qajgRIWs05/ZVPvaxWySlkB6aJ2nIv2oYPbauvEaTvVmKv9Zsy3C32dJVjupfEOHgWzEGjsZhML ng4HFcGScRsv8NfrgKI5b+sMdT8qn6yGJujG4jX6OYgykuAQoyA55kQMJoE+ckKeYn8cPN69jZu rqwuoeAfJrKjZPgI1Xg== X-Proofpoint-ORIG-GUID: PfLVYwE6NlGyCqc0cLNT_5fezwoO11pt X-Authority-Analysis: v=2.4 cv=Lt2iDHdc c=1 sm=1 tr=0 ts=6a57d805 cx=c_pps a=vVfyC5vLCtgYJKYeQD43oA==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yx91gb_oNiZeI1HMLzn7:22 a=EUspDBNiAAAA:8 a=w2bVgGKsJa40EddZz84A:9 a=QEXdDO2ut3YA:10 a=rl5im9kqc5Lf4LNbBjHf:22 X-Proofpoint-GUID: PfLVYwE6NlGyCqc0cLNT_5fezwoO11pt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-07-15_04,2026-07-15_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 adultscore=0 spamscore=0 suspectscore=0 clxscore=1015 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607150188 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=brian.cain@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @qualcomm.com) X-ZM-MESSAGEID: 1784141846777158500 set_bit32()/test_bit32()/etc already let devices operate on guest-visible uint32_t register arrays without depending on the host's 'unsigned long' size. find_first_bit() has no such equivalent, which pushes callers towards casting a uint32_t array to 'unsigned long *'. Add find_first_bit32(), implemented the same way as find_first_bit(). Reviewed-by: Pierrick Bouvier Signed-off-by: Brian Cain --- include/qemu/bitops.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index c7b838a6283..f7363a5479f 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -43,10 +43,9 @@ * be some guest-visible register view of the bit array. * * We do not currently implement uint32_t versions of find_last_bit(), - * find_next_bit(), find_next_zero_bit(), find_first_bit() or - * find_first_zero_bit(), because we haven't yet needed them. If you - * need them you should implement them similarly to the 'unsigned long' - * versions. + * find_next_bit(), find_next_zero_bit() or find_first_zero_bit(), + * because we haven't yet needed them. If you need them you should + * implement them similarly to the 'unsigned long' versions. * * You can declare a bitmap to be used with these functions via the * DECLARE_BITMAP and DECLARE_BITMAP32 macros in bitmap.h. @@ -382,6 +381,29 @@ static inline int test_bit32(long nr, const uint32_t *= addr) return 1U & (addr[BIT32_WORD(nr)] >> (nr & 31)); } =20 +/** + * find_first_bit32 - find the first set bit in a memory region + * @addr: The address to start the search at + * @size: The maximum size to search + * + * Returns the bit number of the first set bit, + * or @size if there is no set bit in the bitmap. + */ +static inline uint32_t find_first_bit32(const uint32_t *addr, uint32_t siz= e) +{ + uint32_t result; + + for (result =3D 0; result < size; result +=3D 32) { + uint32_t tmp =3D *addr++; + if (tmp) { + result +=3D ctz32(tmp); + return result < size ? result : size; + } + } + /* Not found */ + return size; +} + /** * DOC: Miscellaneous bit operations on single values * --=20 2.34.1