From patchwork Thu May 23 14:00:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 165007 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp2239833ili; Thu, 23 May 2019 07:09:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqziDlTBR4IzbGkWTCgmyC18rGmNX3hxjNEndqzzMmdS4/CyIlYMgDrnsFD2hKYW2Cxie0Qh X-Received: by 2002:a17:906:9609:: with SMTP id s9mr24451030ejx.35.1558620575027; Thu, 23 May 2019 07:09:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558620575; cv=none; d=google.com; s=arc-20160816; b=gqHZkIBjK6l/6UujxFKh2Oift8NsSgxNhAEaeafjLzncRm4PQSygB9PuPGq572qkJ2 /sdDzTCvckdtaxWLctC8ou+Ez2Kz8nII6SeBYGM9pPrnKipUIUdA/8Fz5DcHvWN3qu9a X34lX/+WiP4K5xFkRzR87R45lh7LcgjwssHe4qruv3jhHxfniw6z0uTtNmPhTxj83p0V fP60IftMQNHencUeVrhPmSwftDZrxwmjR8TZaHwBAXQR4ETCAqEKG9v4h+o80p+xv+1N 6PjGfSVGuFz0u5lR8eAT+F0t7fCOc+AWfMnDe6ic6TpxzUM8N54x+WWAQbKHdCwevEro nM4w== 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:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=cN7HSsTir9LPfFs0tqL8Rk/5kniGhoqrSHsDQ6DZZvw=; b=J0LR/92SlepaywiGCJNzquQYH983tel0LjfXfER1bX/8ZTJIizHfDBI32Z2RAFoj9G iLPsNZ4DujLmkWGFK1cw7qS8Cf+Il/T+PM8R3QckkEIgHitmvpKHljAC7y4FJPw5KCsR yb4mVAPx8F/RKgf/b2e27kBmeWCAIBrhEh701Q/ubtVBXGDns0lsbDfRlLCzu0Kzo4uy lHK6st4vZNDbtRY4LWCYH4UB+4/0BYetR73naVsFm7IEgMYHXDedNMiF4Q1B9ZW2tkTH z3rVU5NJ1r92X2/bgJyGoLWa755wP2bHZBwQ2Z51CHkddZbEJquiohP4LiRC+QTpj5Rc MHVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=dE4y100d; 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 f34si7487725edf.38.2019.05.23.07.09.34 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 23 May 2019 07:09:35 -0700 (PDT) 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=dE4y100d; 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 ([127.0.0.1]:37047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hToPV-0004WC-Fp for patch@linaro.org; Thu, 23 May 2019 10:09:33 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46568) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hToHb-0006H3-JG for qemu-devel@nongnu.org; Thu, 23 May 2019 10:01:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hToHa-0004X7-Fu for qemu-devel@nongnu.org; Thu, 23 May 2019 10:01:23 -0400 Received: from mail-ua1-x931.google.com ([2607:f8b0:4864:20::931]:45267) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hToHa-0004Wf-AO for qemu-devel@nongnu.org; Thu, 23 May 2019 10:01:22 -0400 Received: by mail-ua1-x931.google.com with SMTP id n7so2198743uap.12 for ; Thu, 23 May 2019 07:01:22 -0700 (PDT) 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=cN7HSsTir9LPfFs0tqL8Rk/5kniGhoqrSHsDQ6DZZvw=; b=dE4y100dtpMKczXTvrJJVBXBif3jy1bvx73wTA/KPdkJHm7lolCvVrPRnkntqADBOf j6OV5t0TgQ1rQrkJ5P1yApNGDdhBB8U3P4p4DjADMHsTSgNVXHL9As8qEQKK4i9MqhX+ HAtAxyMGxNkxvrZeRl8aIS+54b5jAvHbE+Fzo+lOGpLNs5Z289M7qVVXCniw/oAV8KQZ cys482X7KLqLGg9nahgIpsT9oyDegfBs3fBDAio5VpfUcERraafdQu74SQz5R3Zj/s17 dHuS6k2KPGYDYq2fej7PskmF0mxXZ+0TYG5BY1MJEVkDOeHtKsXBuoS1ar0sdYxWRm+d Q0fw== 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=cN7HSsTir9LPfFs0tqL8Rk/5kniGhoqrSHsDQ6DZZvw=; b=spfAlwzWnYdKwT1ZhdjqcjNxkfVRyxv/p8oenrgz1skDIgNC4FdRLkje3sDB/hIiJC c0byyoEmvezk3sGnG8ak2UT0OvMmQWZLatmMvvoCtspwjOgNtT/OmdnKZuu8RX5HgW2h hwUydVYv/znSpZEzPWNk3zqDj+deruGHcI7FMcvQRSOK+cOsxCQ9qKmTw+1ZyVsGCW5r KVrLVek34ELKJ14vsAUSj/HTh7UWkJqUiLjtovO2UhNtwxtTQr/lB4HLIGTWdNyMwOP1 gTc9w3rQZ7DoMYM1UyUdTpdNgkiJChtuEBvaWm6laG2n0W5bNzpIyU34o1RuWcNCMcVG ildg== X-Gm-Message-State: APjAAAUlhADRm3Bq5TvMJMx3mMc0m6LGDK6BWuhqF3DojtGI/MX+fPl0 kClr8uQLNPOENXD3h81leZm6C92zR9nl0A== X-Received: by 2002:ab0:7802:: with SMTP id x2mr4428653uaq.8.1558620077120; Thu, 23 May 2019 07:01:17 -0700 (PDT) Received: from localhost.localdomain (ip-173-130-215-183.orldfl.spcsdns.net. [173.130.215.183]) by smtp.gmail.com with ESMTPSA id v133sm1984166vkv.5.2019.05.23.07.01.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 May 2019 07:01:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 10:00:55 -0400 Message-Id: <20190523140059.18548-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190523140059.18548-1-richard.henderson@linaro.org> References: <20190523140059.18548-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::931 Subject: [Qemu-devel] [PULL 09/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, Yoshinori Sato 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: <20190516055244.95559-12-ysato@users.sourceforge.jp> Signed-off-by: Richard Henderson --- include/qemu/bitops.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) -- 2.17.1 diff --git a/include/qemu/bitops.h b/include/qemu/bitops.h index 3f0926cf40..764f9d1ea0 100644 --- a/include/qemu/bitops.h +++ b/include/qemu/bitops.h @@ -300,6 +300,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