From patchwork Fri May 17 04:51:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 164393 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp1705931ili; Thu, 16 May 2019 21:57:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqy3P7R96N/Y0P58xN2edhxTHc+oDuFxAN4u2xiyTGXhKv/uGpg0dVwE02LCEKiCNiAOlSew X-Received: by 2002:a05:6402:14d1:: with SMTP id f17mr55086989edx.20.1558069070481; Thu, 16 May 2019 21:57:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558069070; cv=none; d=google.com; s=arc-20160816; b=XMy7cTPRG7btEV6oNI2+WejUJ/Q6r+q9DrBbufPR1srqr3hQrgDesY5a/1+//2oNXn isryrXLpSOR0F7iQxZVpRGwjPjR/1/slt81tbOHijIzKTlIPenpCFhlbNn7mUdZRBzlF 23X2mF9PZDlK3CzZn6EbjzaCpwVYm+Wug/Ahdo2hlnQ1gwOJE2CS6W4UYcaL5PcAENZO MrKvuelro3t53KYCbjJwuE7uScFvfyR0rYPbW0h4X8xJwoe00op6s7eAdJ/kz97JTewh vmrtVKowUvLhlgnsd/cgZlX8Hi9NBHuzGDmzWNG1MuYBgtibbxH/4xQkYP38TRgLsQzG lZ+g== 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=Lh9SWts69Baomhby75JWGgMIQfmaTAYqMWQtMXPucJMT9dj/tY+hjTaqGqVjw7KfNv v/e0h+M1UmMhm/ziBxCnb9p3zo/OEbLPRKI9r59QeXRlIkDOQ3yT1JhQHW6kaJ0e5Kw7 4hzDaoloYZ5hnbW5Cy+H/waEETfGUh7f8CXTGibEv4Xj8geknOrrpOKnWvRTS/3y9qQG gwNwkmhMHU3FhhYF4zhVpLkh63kxGMduNLHJ4fz+4V4pFFTDTGGHTGke8tDLlljxm8kz UpfOGYM0+6SgNJMVojhTYJp+PhSlIxb9vCkYjshFNRUzLsNczezyAN4ZoPqW3AZTP581 Defw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pIaRtA4q; 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 f39si1663315edd.8.2019.05.16.21.57.50 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 16 May 2019 21:57:50 -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=pIaRtA4q; 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]:42322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRUwH-0002w0-Bc for patch@linaro.org; Fri, 17 May 2019 00:57:49 -0400 Received: from eggs.gnu.org ([209.51.188.92]:59609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hRUqV-0006Dr-F0 for qemu-devel@nongnu.org; Fri, 17 May 2019 00:51:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hRUqU-0007lv-6E for qemu-devel@nongnu.org; Fri, 17 May 2019 00:51:51 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:45235) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hRUqT-0007lP-Vn for qemu-devel@nongnu.org; Fri, 17 May 2019 00:51:50 -0400 Received: by mail-pl1-x641.google.com with SMTP id a5so2720452pls.12 for ; Thu, 16 May 2019 21:51:49 -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=pIaRtA4qvbeSiGPTGFA/MJugbq0Bd6ZTWwoii1QRgfQ7hDU00qFqWd7XvvinDwOEQI HdBT2MZ2Q+y/CLI4NrOA9v1Z0UK+EOfIIODayCkd7m+Fjt4pMBumrwZNS0Ziu2WD0C4A K2K7XgN3epof0Owh7WxiFGn2TsZf2AN0W7pVgu/NcHtqDimTWNYa/bvwnqY8Tqrtt4C/ tuTFRbM/YnE/1qBo2L4ukctONlGhsjLA/hz2BSg7l/iV0t0lWKFbx5Tj/+83MIvlzeH6 A1d6JaEHLQvgxOSg6kSKGDagvoPHhq4vNmhJASoz1hgIs4AOgMObXdTpENPecw1OMTLq u/lw== 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=p3IYrK9HGyrUtdVANvCxmbj0gSABcaRrzcj1KOXl6wO82/+sExcOW9okplAvcW7TJ/ w4BSartPYp+5Z8C4bUKem7AyoNz9MG8BKJRmkAqYGEkkW6UdhZIY0Hjn+zUPH2HFxGBZ q/XQVSl0dR2V2IMwc70E3QWP0V8TQo8VJwAAItmdTGZx2sE0fgR0jBkODdiuP1RKjtkx uq6scrfEw9aQ7DO4BCyoySoqBr1aLG4f0wq+z22EXsh4n6ioeyORX12z2aCEozyDQ2TU LXwkpChEFdTCn8bm+EF+GxuTH83vtNIvBWe2GGlMeCDYEpCS54Hu8eFMCwxUpfvkqB6D x47g== X-Gm-Message-State: APjAAAUzkn/ufQuUfIdXtlVAQ+y/Ub5WixrcL+1dJK/IP/YAa+sAjfyr 0YJNXsTBSDyKZ5xy9F6ebfDR89RjtEU= X-Received: by 2002:a17:902:1126:: with SMTP id d35mr18803100pla.82.1558068708774; Thu, 16 May 2019 21:51:48 -0700 (PDT) Received: from localhost.localdomain (97-113-13-231.tukw.qwest.net. [97.113.13.231]) by smtp.gmail.com with ESMTPSA id 132sm7709625pga.79.2019.05.16.21.51.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 21:51:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 16 May 2019 21:51:32 -0700 Message-Id: <20190517045136.3509-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190517045136.3509-1-richard.henderson@linaro.org> References: <20190517045136.3509-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::641 Subject: [Qemu-devel] [PATCH v14 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: philmd@redhat.com, ysato@users.sourceforge.jp 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