From nobody Tue Sep 22 19:46:24 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=1784044345; cv=none; d=zohomail.com; s=zohoarc; b=UjX4ecjw/72lNwnwy4mfzeMbIaQnlq4y6fgstgWSBSHKWjDwmx20mYwppm0LljT+DYBx4buDRLyu4eB4X9ODQPkdgBH9fVPSTbkx3uyc7O74SIKkOk+r9FWsx1vXTIUMhRz2y8qpixMakqdRLRRoK8QkWEGsGhHENalGi+96VsY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784044345; 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=ar6lVTR4o40Y8mAt9MPiR+MLeALHdR24ouRtrSRI3B4=; b=V/ipwKnuhkCke8SRhFqSm9NOZ7v/paKONu9b3Z6z63z+2gyLolSZsLJDw7mmmx/vFjq17O5E391aoqQDqrV58q7FS68hHapr9cB6gBKPy+b5YOmPConUs08xFqBfA2RFduANRSOQ1qetI1Ag1sjD8hyWY481I//5UMCM4GyvxR0= 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 1784044345078860.5148123313661; Tue, 14 Jul 2026 08:52:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wjfQ2-0000yd-3x; Tue, 14 Jul 2026 11:51:38 -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 1wjfQ0-0000y6-IQ for qemu-devel@nongnu.org; Tue, 14 Jul 2026 11:51:36 -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 1wjfPz-00014E-16 for qemu-devel@nongnu.org; Tue, 14 Jul 2026 11:51:36 -0400 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 66EEcP9V893288 for ; Tue, 14 Jul 2026 15:51:34 GMT Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4fdnnqrr5d-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 14 Jul 2026 15:51:33 +0000 (GMT) Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-c88aab7c1fcso10349565a12.3 for ; Tue, 14 Jul 2026 08:51:33 -0700 (PDT) Received: from hu-bcain-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-13b987fc629sm41343581c88.0.2026.07.14.08.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 08:51:31 -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= ar6lVTR4o40Y8mAt9MPiR+MLeALHdR24ouRtrSRI3B4=; b=W0prmCqFYdgN7hvf Ngz5QIM5o4mQx4ZP3figoClumhz+mnEvhOHDpRfl6m8PHgGsWDKyT3S9Fi7ELOR6 OAuiV7PdYj2AWf4sBkG1KHxVqFd09LiKCtRQ0Cb9B5v4svwoDZNUGgKSnB0Upc25 k1aGgmM1mYLDFNrJ+q+F6zTQlRxwgOdeLAKkjtugq1p7USb3RzE5tJ9h75Z2JEq4 eEhELl5ug+tCoztFOVJzHzWXcQ3JnMEBYVuJ51eVf6RoMqrDZ36NxqRc5s2R4kzH 5wCeuldXgcq8u6kytAdzgHyBw0xw5AEZyyItM0RHsM30IL4rrjPxWOctR3oxX9Wn yj6wnQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1784044293; x=1784649093; 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=ar6lVTR4o40Y8mAt9MPiR+MLeALHdR24ouRtrSRI3B4=; b=csGYI9fQfLoWMcfFdl+m9fJfpti6sTq0GwdsNyDKG/tdPMvaXjTtQmpFJYtv/s/wzR EiwdSRq3fOCL0DvtN/cm2hG91xQeE9mapWe5AFEQMxmtFC7dwOmRLczLC6IkZeYZNgIx NJ3wt8GW3Ojk0LmyXnTrCX8vOn5ha+oZzJHzlJubKnhZD0Nqrg7Qxe8NqEam+4QRQx/N i4DyB5hfeR+qoOTX5Y9CqgRctoOZRe6BCyFq4DqDEGqaPqOdpZaVCdAnKjvy7OPLeDii fqYkCXNEyKchijq2K18U0EeP5TrA6hfYbsXNK1LXKrMk94lq4AicoMRlJgr31Cx1U4i0 FRTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784044293; x=1784649093; 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=ar6lVTR4o40Y8mAt9MPiR+MLeALHdR24ouRtrSRI3B4=; b=SlNsSw3ECEHs/LDQZhk6S1yxbfzQvQQ9IX7X9G/QbfqP4haUhDggqySjZPAMnaPpNM LH05URgM+0ZPOgXehFz/a9Nmno47e+U08pAlDF64KqJrvenO78yvWHgyuKBb2ui2+eqP Xnoz1QgIYEbbPUXalwaFESbMopKOw57ODSSFVerw5sRapHQkkzD+0r7ENlIcLjOiu9d/ iIuTpIinoJUMuqDFGrV8xm5ImsZYpGuywr2OTsyY4E1qct3leZ1UdyHMZ9ty5tj52RTU nZGsKDBlf+eNgCLDgv7I2fcqZj8QByaQQXamSZfwHFuUXQ3ZmwYerBs0zJmUfebFcvxj 7ZoA== X-Gm-Message-State: AOJu0YyTFq3DBc1ZSflPyM9wLMMtau9U13LWZMdmNFEn5sjm+sKZ3i8o JzAWVtQuiUTRSM/uyNDVNb/PNK19dcEwrXFw8zg3PgGIEUAW/ngjMprmpK4Nt7sPJq8bXVdBljH aUUMpeSVl44FOU3iHohhlzeEDxXG4PEwN/eNK97rbitlqU2a+snxKIVNEkSAJlnQLfQ== X-Gm-Gg: AfdE7cke59KGtCOgkqJ+NJZYqhyDt+le1OyPrL9NHC/M3WL2Y9x+/hSr0LU4jrXN4jA Pdt5PdKKiQaXpyiteqPLzLWi75EsWyo1sHaVgPIFYRmueQIq7I8GEPvptRP3RKuJx9CUMi/ExrA 1vKH+FUn7URsvFrNVJMT+5Jvt2PmPoMkOF6QnqmEI8tOt29SV5bV77t1Y3ctq0F0owJS3cwFjX/ 6xs7w72uLTwuPBY8nfphMdMPbv1Bg7epUhCNcC/umAbqArGYRmjuxqV2ocGJ3LzlM40lYisbylu QFBLzccYbXz9by7vA1/XYyZfJJbRg0thJwMr3nggM23H8qXabP6+S4vQCt6ff6d8GWj5Y1wMWrZ rxh5qwPntHchQGN2Z8NKwgx79okIzFgHCnWZQrZGMavQEgqSJISz3nlR6gTU= X-Received: by 2002:a05:6a20:c6c9:b0:3bd:3800:7538 with SMTP id adf61e73a8af0-3c35707e50dmr3251909637.33.1784044292825; Tue, 14 Jul 2026 08:51:32 -0700 (PDT) X-Received: by 2002:a05:6a20:c6c9:b0:3bd:3800:7538 with SMTP id adf61e73a8af0-3c35707e50dmr3251861637.33.1784044292239; Tue, 14 Jul 2026 08:51:32 -0700 (PDT) From: Brian Cain To: qemu-devel@nongnu.org Cc: ltaylorsimpson@gmail.com, Laurent Vivier , Thomas Huth , Paolo Bonzini , matheus.bernardino@oss.qualcomm.com, Fabiano Rosas , Brian Cain , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , philmd@oss.qualcomm.com, pierrick.bouvier@oss.qualcomm.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH 3/7] bitops.h: Add find_first_bit32() Date: Tue, 14 Jul 2026 08:51:22 -0700 Message-Id: <20260714155126.3509544-4-brian.cain@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260714155126.3509544-1-brian.cain@oss.qualcomm.com> References: <20260714155126.3509544-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-Details-Enc: AW1haW4tMjYwNzE0MDE2NCBTYWx0ZWRfX1Th+tlUXJZoR f2rhtgc2BomT9nz7VWdi5xbyJG0dlCqJhOuARrnkb4NtTbGpFJwfuJSvQrF1MmOhIKib4KzSoWs BwIKhFwsu8Cbgb3HGWZ879dYxCZOue3zHLRKtFfPZm7BnmAT4T0/92fUhOYwxBiPOT6/B4TvYxG sZLiufBjWy43maARIEl18YfqAFwM4rgJ1Udl6OCBIBi6v3fDHbDg7uKs2kTO1rmURGcaqqIMgFX E8ZrE1qQRUPnQLyKX+1exeyCQEClZYuL+z1/bVieMzfGNe9Fnpmrho2cjfJm2ZnyGkX1lwz4uX0 Kfd+NvYeTQgCxwKAXtxi0tK9bZ9hdN9zXQOLTWBjOqn3Y5f2L5jXHb0WNd0DTtQe7Jf/BMkraJi Gd/8BwArxseKP1iLxUftS+CkNh4FfHAikzdaLXvsEta44xRZZ9mYxlih8xCG9pMslRcdjrAxrCu Z2d+5quOPJmm3c+MeMg== X-Proofpoint-Spam-Info: AW1haW4tMjYwNzE0MDE2NCBTYWx0ZWRfX7LoTa7mMWgzL dHw7QuekeStm42S+vY22+/kCEobE0L8Ya/fvfF/3IRi4vPfJl91RFMaVeT2bbxLvLaMiHIWEOZ0 6py9IcwYDRpfTj9hLgjkj5pZYNyKjK8= X-Authority-Analysis: v=2.4 cv=U+Oiy+ru c=1 sm=1 tr=0 ts=6a565b05 cx=c_pps a=Qgeoaf8Lrialg5Z894R3/Q==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=IkcTkHD0fZMA:10 a=RAioF0-LDSMA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=_glEPmIy2e8OvE2BGh3C:22 a=EUspDBNiAAAA:8 a=w2bVgGKsJa40EddZz84A:9 a=QEXdDO2ut3YA:10 a=x9snwWr2DeNwDh03kgHS:22 X-Proofpoint-GUID: -fxkjmO-py6ghDaIx1IQ5-DEZc6LE4dy X-Proofpoint-ORIG-GUID: -fxkjmO-py6ghDaIx1IQ5-DEZc6LE4dy 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-14_03,2026-07-14_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 malwarescore=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 adultscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2607140164 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: 1784044345345158500 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(). Signed-off-by: Brian Cain Reviewed-by: Pierrick Bouvier --- 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