From nobody Mon Feb 9 17:07:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1708969178; cv=none; d=zohomail.com; s=zohoarc; b=PTi6NS3ojkNhHAGTp6sC/6Wpfhhn4LGcZaMrWH3i5xV/sPtDgKWGcqnHWM7LkworXva2LYzUlExZPQOZVx3idkCfRtYJaOqP+rhdorTeGkqyTcJ7zfUjc1IPDH8VThyrRRszTxBTCuUv/KgP39Eie2v+vbLPCXAZ5hgqA8G45NI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1708969178; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cZDHTEej6Jv3SYqhJWcdCnlmv5/Saryrf0OJ+2bCraY=; b=UFAf8Zg8VWZSJ1sF36TJqE8cUI2sivaaRbTeebkcfN183mLjhdpX0DL3Enyc6Gx4TXW7WMtwW41CiHYuoceJcg0RzQW12FjevtqpX1w99os9L3E/EaCEgjRG3IfHwWfnu4m88t7C0cRxashmxcRCVkhO6vZlzI4hJbJJM6r1LEU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1708969178221423.85346539341697; Mon, 26 Feb 2024 09:39:38 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.685695.1066854 (Exim 4.92) (envelope-from ) id 1reewi-0000To-Qb; Mon, 26 Feb 2024 17:39:20 +0000 Received: by outflank-mailman (output) from mailman id 685695.1066854; Mon, 26 Feb 2024 17:39:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1reewi-0000SY-L6; Mon, 26 Feb 2024 17:39:20 +0000 Received: by outflank-mailman (input) for mailman id 685695; Mon, 26 Feb 2024 17:39:19 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1reewh-0007o5-8r for xen-devel@lists.xenproject.org; Mon, 26 Feb 2024 17:39:19 +0000 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [2a00:1450:4864:20::233]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f71e570e-d4cd-11ee-98f5-efadbce2ee36; Mon, 26 Feb 2024 18:39:17 +0100 (CET) Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2d26227d508so37271881fa.2 for ; Mon, 26 Feb 2024 09:39:17 -0800 (PST) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id z8-20020a2e8e88000000b002d0ae22ff6fsm920883ljk.60.2024.02.26.09.39.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 09:39:15 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: f71e570e-d4cd-11ee-98f5-efadbce2ee36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708969157; x=1709573957; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cZDHTEej6Jv3SYqhJWcdCnlmv5/Saryrf0OJ+2bCraY=; b=f/BTuAOOL9lrH1hLeKUPooDvh2qzJ8i95BO0kUpxtORTrQW+t+1xPGBXirQuum6B8G XJgntsVAix3Z5bMWIgJblP31oSvyiRyMQuQTkHt6BeXU6EgPIcr8SZ9I2tcAgwq3HyIx chQBzR01FGqxnhiXX6OP2YSUJaXxm/l5OdE0sCw1K3e/7epV7oAPNeQ//JYpOq8ETPQZ saK4ZsTzRyY0KG1p1P0TIz94zRt28Pri4vKEukhiSYIO+lWGi4NXfIu/wJ0MI3kJO1I5 Mzd4RwgNtEoz2Wd8PXO9q9aD4YOt8qJYXHbyiXi8wZC+qYcfi3LRmUvzlsRCSfbhID/L 30Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708969157; x=1709573957; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cZDHTEej6Jv3SYqhJWcdCnlmv5/Saryrf0OJ+2bCraY=; b=j7p44ND+o0vi4ndD/kHTFYAOm+oEC/WVhJE7/Qmr9Jb0tj8Dr3m6a1jxYhtz+dS038 FSedbsSIw2LZviCgB3g8/9gYqgnlw+tRyvy+tYZkSUdLNZ5+uiz+qYYl20ZxTxPfse1V 15cxC91TL8SqGPLa8ADUTJbeuarOfw3KgdzetLZFkjNL5Xz1o4j1+sbCw+OwlOZsqiLH Q8EaWh0NopXdA4qx/Zb4IE79yQ5H4HKhhaB841RsWxq8TJgcKlx6OQZjZlqFbS0y1B4H 2gaFNHpjP4VCftIyVMqqs7r1s0kHHBvFdk6a2Pl/7ME+W3gSyZ/b8LAV4G3m8hybrhcl aTxw== X-Gm-Message-State: AOJu0YxzlJuf3WMo6o7rierF08/8j8jQHTnKQsujIcAz1wAjLIZ9vBKV GOzfZZYX+97NKWTpCADuqRryS9dvzRGpMkSdkDNbDwiL5x+BE1LuSKca3WfX X-Google-Smtp-Source: AGHT+IHFR4+Ivxmy7gFlPOXPEnFVpLHuKhIHnvGtUwBdkWRa4mfpFeN/WIg0Q58ss7HZNSYz5/nM6Q== X-Received: by 2002:a2e:bc12:0:b0:2d2:607e:8121 with SMTP id b18-20020a2ebc12000000b002d2607e8121mr5407859ljf.43.1708969156635; Mon, 26 Feb 2024 09:39:16 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Oleksii Kurochko , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH v5 05/23] xen/asm-generic: introduce generic find first set bit functions Date: Mon, 26 Feb 2024 18:38:47 +0100 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1708969178900100004 Content-Type: text/plain; charset="utf-8" These functions can be useful for architectures that don't have corresponding arch-specific instructions. Signed-off-by: Oleksii Kurochko --- Changes in V5: - new patch --- xen/include/asm-generic/bitops/__ffs.h | 47 +++++++++++++++++++ xen/include/asm-generic/bitops/ffs.h | 9 ++++ xen/include/asm-generic/bitops/ffsl.h | 16 +++++++ .../asm-generic/bitops/find-first-set-bit.h | 17 +++++++ 4 files changed, 89 insertions(+) create mode 100644 xen/include/asm-generic/bitops/__ffs.h create mode 100644 xen/include/asm-generic/bitops/ffs.h create mode 100644 xen/include/asm-generic/bitops/ffsl.h create mode 100644 xen/include/asm-generic/bitops/find-first-set-bit.h diff --git a/xen/include/asm-generic/bitops/__ffs.h b/xen/include/asm-gener= ic/bitops/__ffs.h new file mode 100644 index 0000000000..fecb4484d9 --- /dev/null +++ b/xen/include/asm-generic/bitops/__ffs.h @@ -0,0 +1,47 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS___FFS_H_ +#define _ASM_GENERIC_BITOPS___FFS_H_ + +/** + * ffs - find first bit in word. + * @word: The word to search + * + * Returns 0 if no bit exists, otherwise returns 1-indexed bit location. + */ +static inline unsigned int __ffs(unsigned long word) +{ + unsigned int num =3D 0; + +#if BITS_PER_LONG =3D=3D 64 + if ( (word & 0xffffffff) =3D=3D 0 ) + { + num +=3D 32; + word >>=3D 32; + } +#endif + if ( (word & 0xffff) =3D=3D 0 ) + { + num +=3D 16; + word >>=3D 16; + } + if ( (word & 0xff) =3D=3D 0 ) + { + num +=3D 8; + word >>=3D 8; + } + if ( (word & 0xf) =3D=3D 0 ) + { + num +=3D 4; + word >>=3D 4; + } + if ( (word & 0x3) =3D=3D 0 ) + { + num +=3D 2; + word >>=3D 2; + } + if ( (word & 0x1) =3D=3D 0 ) + num +=3D 1; + return num; +} + +#endif /* _ASM_GENERIC_BITOPS___FFS_H_ */ diff --git a/xen/include/asm-generic/bitops/ffs.h b/xen/include/asm-generic= /bitops/ffs.h new file mode 100644 index 0000000000..3f75fded14 --- /dev/null +++ b/xen/include/asm-generic/bitops/ffs.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FFS_H_ +#define _ASM_GENERIC_BITOPS_FFS_H_ + +#include + +#define ffs(x) ({ unsigned int t_ =3D (x); fls(ISOLATE_LSB(t_)); }) + +#endif /* _ASM_GENERIC_BITOPS_FFS_H_ */ diff --git a/xen/include/asm-generic/bitops/ffsl.h b/xen/include/asm-generi= c/bitops/ffsl.h new file mode 100644 index 0000000000..d0996808f5 --- /dev/null +++ b/xen/include/asm-generic/bitops/ffsl.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FFSL_H_ +#define _ASM_GENERIC_BITOPS_FFSL_H_ + +/** + * ffsl - find first bit in long. + * @word: The word to search + * + * Returns 0 if no bit exists, otherwise returns 1-indexed bit location. + */ +static inline unsigned int ffsl(unsigned long word) +{ + return generic_ffsl(word); +} + +#endif /* _ASM_GENERIC_BITOPS_FFSL_H_ */ diff --git a/xen/include/asm-generic/bitops/find-first-set-bit.h b/xen/incl= ude/asm-generic/bitops/find-first-set-bit.h new file mode 100644 index 0000000000..7d28b8a89b --- /dev/null +++ b/xen/include/asm-generic/bitops/find-first-set-bit.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FIND_FIRST_SET_BIT_H_ +#define _ASM_GENERIC_BITOPS_FIND_FIRST_SET_BIT_H_ + +/** + * find_first_set_bit - find the first set bit in @word + * @word: the word to search + * + * Returns the bit-number of the first set bit (first bit being 0). + * The input must *not* be zero. + */ +static inline unsigned int find_first_set_bit(unsigned long word) +{ + return ffsl(word) - 1; +} + +#endif /* _ASM_GENERIC_BITOPS_FIND_FIRST_SET_BIT_H_ */ --=20 2.43.0