From nobody Mon Feb 9 06:49:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1557148815; cv=none; d=zoho.com; s=zohoarc; b=B5FXOt7DiT18Vll32gD3o9q84ke1FXovK+K2+WeHH8DxTiichyopzKhC+lU22xN+HLkZheF7PgMYV5zC6gneTun4UweEtrU71OECuQ/UiCd3p4+k7mhJ0ceut+WvqSSnm5+Fco5i5HrOJVDOUgXe9YPtaDTmTrUyCqSMYl8uAnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557148815; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=jceWzxE33YvvsTM9ucHnRYq+hZFe1Kv2cmV0wEP3JeI=; b=Yd+mGYHL2yP9DjnA0wxRDLxtK9TBYOV7q8bXos2YnELKo/zn9uNBXmIyAR7cZgoYr6mdvivmPtvdSu3FR3qcSr6wM1qi8VZTz+x4eTIP44AQdCQDPuVzW6QMk8T2w3ayyqd38vqRLge6M9UtfzBrx61Nz7Wrx26tpc3WvPdA5+g= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1557148815182143.75458624418854; Mon, 6 May 2019 06:20:15 -0700 (PDT) Received: from localhost ([127.0.0.1]:56498 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNdXQ-0005RA-4J for importer@patchew.org; Mon, 06 May 2019 09:20:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:32923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNdSP-0001fc-5F for qemu-devel@nongnu.org; Mon, 06 May 2019 09:15:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNdSN-0000J4-DD for qemu-devel@nongnu.org; Mon, 06 May 2019 09:15:00 -0400 Received: from mail02.asahi-net.or.jp ([202.224.55.14]:59660) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNdSN-0000Hk-3q for qemu-devel@nongnu.org; Mon, 06 May 2019 09:14:59 -0400 Received: from h61-195-96-97.vps.ablenet.jp (h61-195-96-97.vps.ablenet.jp [61.195.96.97]) (Authenticated sender: PQ4Y-STU) by mail02.asahi-net.or.jp (Postfix) with ESMTPA id BAC1C3BC9C; Mon, 6 May 2019 22:14:58 +0900 (JST) Received: from ysato.dip.jp (ZM005235.ppp.dion.ne.jp [222.8.5.235]) by h61-195-96-97.vps.ablenet.jp (Postfix) with ESMTPSA id 4604A240085; Mon, 6 May 2019 22:14:58 +0900 (JST) From: Yoshinori Sato To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 22:14:44 +0900 Message-Id: <20190506131444.120869-14-ysato@users.sourceforge.jp> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190506131444.120869-1-ysato@users.sourceforge.jp> References: <20190506131444.120869-1-ysato@users.sourceforge.jp> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 202.224.55.14 Subject: [Qemu-devel] [PATCH v9 13/13] qemu/bitops.h: Add extract8 and extract16 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, richard.henderson@linaro.org, Yoshinori Sato Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Yoshinori Sato --- include/qemu/bitops.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index 3f0926cf40..0dfd81efb2 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -301,6 +301,44 @@ static inline uint32_t extract32(uint32_t value, int s= tart, int length) } =20 /** + * extract8: + * @value: the value to extract the bit field from + * @start: the lowest bit in the bit field (numbered from 0) + * @length: the length of the bit field + * + * Extract from the 8 bit input @value the bit field specified by the + * @start and @length parameters, and return it. The bit field must + * lie entirely within the 8 bit word. It is valid to request that + * all 8 bits are returned (ie @length 8 and @start 0). + * + * Returns: the value of the bit field extracted from the input value. + */ +static inline uint8_t extract8(uint8_t value, int start, int length) +{ + assert(start >=3D 0 && length > 0 && length <=3D 8 - start); + return (value >> start) & (~0U >> (32 - length)); +} + +/** + * extract16: + * @value: the value to extract the bit field from + * @start: the lowest bit in the bit field (numbered from 0) + * @length: the length of the bit field + * + * Extract from the 16 bit input @value the bit field specified by the + * @start and @length parameters, and return it. The bit field must + * lie entirely within the 16 bit word. It is valid to request that + * all 16 bits are returned (ie @length 16 and @start 0). + * + * Returns: the value of the bit field extracted from the input value. + */ +static inline uint16_t extract16(uint32_t value, int start, int length) +{ + assert(start >=3D 0 && length > 0 && length <=3D 16 - start); + return (value >> start) & (~0U >> (32 - length)); +} + +/** * extract64: * @value: the value to extract the bit field from * @start: the lowest bit in the bit field (numbered from 0) --=20 2.11.0