From patchwork Thu Feb 13 22:51:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 183442 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp1083640ile; Thu, 13 Feb 2020 14:59:31 -0800 (PST) X-Google-Smtp-Source: APXvYqwbwTdSE0TKZNvJfqzfEqKyItBfUpN5SOpk+/kB1khV5JtQby68JUeF7usBOLN66NuBTkrV X-Received: by 2002:ad4:55ec:: with SMTP id bu12mr13934161qvb.107.1581634770925; Thu, 13 Feb 2020 14:59:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581634770; cv=none; d=google.com; s=arc-20160816; b=w3IM+l5oyNmgZ+NV25eZRN+v6OAWj7EGneM0D3St29Pzmf7IMtXq9asMS2lpKseETr q1El/ufsHOzT5WqHZHIVxrJE/vVmsTACPZe4LybHvS9YteEVm8R5l9ce+PsWAyjwzTLU T8sVSks92p4wekfGbFJMmFPPAuYzSIbsREI/LJziIvULNyNS/RbR0frHX0+tM10HUCu2 cTji/JEajK5Glr6ltkQ3Gkh3iH2C2UgHr12e4dy6qqrohUv/tKjGqVsFjVYnBo7fw8ef v/IuGQF8fFJmeAwyrdoVMKAdQDOdadIHeTssEz+uoNuaENCWmMDLNnubkNZfvQa/yNVP E5lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=pTDgnQcfNCGcBS0F93StqkN1izWdDQLZMDSB8zlG3xk=; b=dm0BrbgyEp/gh+jjO0CnvSLp1GsPi3TH1B1ABdP9gK3pSM1wsV3gbH4Tb95/p/rDps SUUnNAwCJJI4jKCh8BqdoUdHm5XJ8pLJW8MIIyEyFwAPUo80XzoyQEMqeYJ0NVHDLz1f zO0X7UgtWXPbM7VkO1IzrGGzNSr5m7EsYCEZUEoLNg+qvWSD50hUbjip7KRSDJmgKxjS iNp5arMECqyeiIz5xHfhCmkUBdO2J5NXWGt191j3sOtA5ilb9g2HxQuWHR1i3i82gBls lkssaoW7K51rTdCrHIFvWlEWFqwKv742cnz18O3RcJRppvgyFR9p2HkMP4EMtLS3u1qR mqbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wAupu899; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id v65si2049163qkb.32.2020.02.13.14.59.30 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 13 Feb 2020 14:59:30 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=wAupu899; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2NSE-0000W4-FP for patch@linaro.org; Thu, 13 Feb 2020 17:59:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39859) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2NKP-0004uO-7e for qemu-devel@nongnu.org; Thu, 13 Feb 2020 17:51:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2NKO-0003vM-24 for qemu-devel@nongnu.org; Thu, 13 Feb 2020 17:51:25 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:40769) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j2NKN-0003tQ-Ri for qemu-devel@nongnu.org; Thu, 13 Feb 2020 17:51:23 -0500 Received: by mail-wm1-x343.google.com with SMTP id t14so8602003wmi.5 for ; Thu, 13 Feb 2020 14:51:23 -0800 (PST) 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=wAupu8999iU8ZRq1G6J3JcmKXOduih0GNkOBGU3ni68xoP8+uPPS5+YSa8E3zPgXnm otIcsd1RLkFtjO/WQgTGFQ87JgkQKDON13YYXpWczg4flAvw6siU2do8bIaK0pvzyd+H eE4qnH6HBb+26NabTWniFZtwsuc0GHBXEocjvVrvZKKv4LynsAKHEWi39slHJva7JX9p PukP2w9xK/vhMBzTY6kUK3fLKdAJfb92dtyufGPSSi7bwsVJYfTKescrR66MzuFK2+gV CvXRry5q2gtf/P2+nWZKJLRMQcYIhdPKAvxx8avZMgWCGfyMd6uaYR8eS8IqePKYkqA3 Mbzg== 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=rWNItzBjqvBWAYl425myw6qG8v8ZSbQB2BRT9G43UUVm7nqmY6qe/61kY5v5LyK4S3 MI6dq5ZpkTdTDfyya20KXxZvqAXEpsTNIaJGX/5Ca/6q3CpWURhj7KTTe4XcDCe772Zs khZFKkf7t7KeVNdBQua7qzAi7THTIe/jfauSZpVsXQr8vp4Q/Jkl4r5UWDW5k4XhJiRn NEUPpru2CZPiqbhDacHQ1Je4qybZEKkScqiYQWKGPnLNH31esg9n43tMC+kLvow9M/bK xn0SKwNFSSPcbW6eJY4eGFYH6CfyldaN7nxCiBW7DT7KRTLFx5slSAEar8GbJUUYlNFf OVYg== X-Gm-Message-State: APjAAAXoO5YQ3znXTaPpLc3nd0OLGFefDqB0q7GaCCdEsU+Uc8Nz5d31 5dWdJwAwRGXQ8JN1RkaEHyxG/g== X-Received: by 2002:a1c:688a:: with SMTP id d132mr304265wmc.189.1581634282829; Thu, 13 Feb 2020 14:51:22 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id 133sm5011722wme.32.2020.02.13.14.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2020 14:51:20 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C1CC41FF9D; Thu, 13 Feb 2020 22:51:10 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 13/19] qemu/bitops.h: Add extract8 and extract16 Date: Thu, 13 Feb 2020 22:51:03 +0000 Message-Id: <20200213225109.13120-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200213225109.13120-1-alex.bennee@linaro.org> References: <20200213225109.13120-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::343 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_M?= =?utf-8?q?athieu-Daud=C3=A9?= , richard.henderson@linaro.org, f4bug@amsat.org, robhenry@microsoft.com, Yoshinori Sato , =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= , 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+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Yoshinori Sato Signed-off-by: Yoshinori Sato Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20190607091116.49044-10-ysato@users.sourceforge.jp> Tested-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson Signed-off-by: Alex Bennée Message-Id: <20200212130311.127515-3-ysato@users.sourceforge.jp> --- include/qemu/bitops.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) -- 2.20.1 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 start, int length) return (value >> start) & (~0U >> (32 - length)); } +/** + * 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 >= 0 && length > 0 && length <= 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 >= 0 && length > 0 && length <= 16 - start); + return extract32(value, start, length); +} + /** * extract64: * @value: the value to extract the bit field from