From nobody Thu Oct 9 08:34:38 2025 Delivered-To: importer@patchew.org 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=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1582638282; cv=none; d=zohomail.com; s=zohoarc; b=aBZiwye0AF3tzdJvwk/t3M1Rsvt6fCKM0xI5ZwqsaxKvirVa+gQ0Hsij7OZ6M/fwrD2fvThsBrOWUPxMzv0j+ZSCSglO+nmWnSNOdLF2r82stWkx9l+wlt0CWf/KC+qO6L9l5hR/LOdF1z4hUksr23Ohq8fpUDU/FYEFvFgxBxM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582638282; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pTDgnQcfNCGcBS0F93StqkN1izWdDQLZMDSB8zlG3xk=; b=g8emjRfKd+0RfprIG8OzjIv4HDByTLC+DXM+3I/Jolc+y1EvaEkhnxTpti5cy3n41xcRBKb3f78yZArKELBef8wSzEkrqORpsqhiosGffpRunDWD/Nu4U9xtJzofiBdc/Rcu1DupNbYlL+jn2+qRPLVBFO4K5knUqxBNwL0Q7UA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582638282828158.24850902304388; Tue, 25 Feb 2020 05:44:42 -0800 (PST) Received: from localhost ([::1]:56320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6aVs-00016P-OS for importer@patchew.org; Tue, 25 Feb 2020 08:44:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59291) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6ZcZ-0005eu-LB for qemu-devel@nongnu.org; Tue, 25 Feb 2020 07:47:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6ZcY-0007Hx-E5 for qemu-devel@nongnu.org; Tue, 25 Feb 2020 07:47:31 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:41587) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j6ZcY-0007HO-7d for qemu-devel@nongnu.org; Tue, 25 Feb 2020 07:47:30 -0500 Received: by mail-wr1-x444.google.com with SMTP id v4so1718409wrs.8 for ; Tue, 25 Feb 2020 04:47:29 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id a9sm25082882wrn.3.2020.02.25.04.47.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 04:47:22 -0800 (PST) Received: from zen.home.arpa (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 709411FF9D; Tue, 25 Feb 2020 12:47:11 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=pTDgnQcfNCGcBS0F93StqkN1izWdDQLZMDSB8zlG3xk=; b=Imk4u4Wc32o+iCTKJ7UwXjcmaeocL5hw3ixbEtirkawjc8IAecLUHp7O7zVnbo14Zc K71H/4vPuohge6KJD9h5KvMu/oE9RYLE7+ybKL3PE9dXfqbuRbvxEdYvCl3RdVqi709V w2nlqBRUxFDMfkQQl0dor1v0a+IZZ+uF354mDT8mjGSF+YztedBgcYyFTfGmsywFdK/G F27mujrMq0PM8Ky5HrGw+VNu1SczXUuXRjHAgDnINLYSD9yfnNza3D/E7uyIUBLElOFb Xzzm1qTHKgmCPzT2S+6+eqb8hC8YdPpotiIK6tGKFaNyQfRu7bemIAGzyTN5Mu2d3HzE Xyhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pTDgnQcfNCGcBS0F93StqkN1izWdDQLZMDSB8zlG3xk=; b=mLpQZkEU7lRzoNOmKBlkaTkcx2xnc9x9wz/zSYUlMLETWLJmJCIbIEf9q2IRtdIMm3 8vW1kT/ZHcagsLOVDy9y045tP0rzJ9RGdDCBwnypvFY0/xnOH+9nghQQltfTFvQZGCnL hR3H/bHJM0nSYkD/sK1xOalZwRyRIUs1FaKDMcQkrWmzEYw90RuhCgdoEDdVGx5onL6B nqZD+TgSivx8yh1yAkN9B8495cnPvbdBDiryKF3rI4XP00L66v423r/7jibcFZ+Gdrv1 7HGFrKNvOZoMg55IrWhBHgj6Kv2tjrSj48vfx9zhFSKxFWkBHTInzAVc331caE92pYHo vVYg== X-Gm-Message-State: APjAAAWN9R80MSvanxEzOZmTLCuHXqVI3jCKZDuf0jQZD/pT6ThNOIkd AD/k7IacQ+xSab4+yeF+BZqPxw== X-Google-Smtp-Source: APXvYqwXlhlAk1DpqSNo6Oq+j63MJ5OL0/xpWMa/bWRCNQVFzSMpzIdariVmsGaXVZzIXUw8mhBkjw== X-Received: by 2002:adf:e949:: with SMTP id m9mr9185217wrn.342.1582634848552; Tue, 25 Feb 2020 04:47:28 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v3 13/19] qemu/bitops.h: Add extract8 and extract16 Date: Tue, 25 Feb 2020 12:47:04 +0000 Message-Id: <20200225124710.14152-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200225124710.14152-1-alex.bennee@linaro.org> References: <20200225124710.14152-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: fam@euphon.net, berrange@redhat.com, robert.foley@linaro.org, pbonzini@redhat.com, stefanb@linux.vnet.ibm.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , richard.henderson@linaro.org, f4bug@amsat.org, robhenry@microsoft.com, Yoshinori Sato , =?UTF-8?q?Alex=20Benn=C3=A9e?= , marcandre.lureau@redhat.com, aaron@os.amperecomputing.com, cota@braap.org, stefanha@redhat.com, kuhn.chenqun@huawei.com, peter.puhov@linaro.org, aurelien@aurel32.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Yoshinori Sato Signed-off-by: Yoshinori Sato Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20190607091116.49044-10-ysato@users.sourceforge.jp> Tested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Richard Henderson Signed-off-by: Alex Benn=C3=A9e Message-Id: <20200212130311.127515-3-ysato@users.sourceforge.jp> --- include/qemu/bitops.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index 02c1ce6a5d4..f55ce8b320b 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) return (value >> start) & (~0U >> (32 - 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 extract32(value, start, 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(uint16_t value, int start, int length) +{ + assert(start >=3D 0 && length > 0 && length <=3D 16 - start); + return extract32(value, start, length); +} + /** * extract64: * @value: the value to extract the bit field from --=20 2.20.1