From patchwork Wed Feb 26 07:39:23 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: 183903 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp2793481ile; Tue, 25 Feb 2020 23:47:55 -0800 (PST) X-Google-Smtp-Source: APXvYqz4KfiUhmMdxcnd1OHmokvMytanXSEQ29q/1OkeqzDHFiluBbtcJWcoXMX/os9E2ihqOFu6 X-Received: by 2002:ac8:76c1:: with SMTP id q1mr3808295qtr.66.1582703275274; Tue, 25 Feb 2020 23:47:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582703275; cv=none; d=google.com; s=arc-20160816; b=BqkLKJaZah7bySNaUxPgNc3AjjnEf9aAQDAhOedgZL5Y4AjS4tBOGJELHW/omfQqpK nwjvoWUk3FetpO5cgZcHFD5vy6H3OgSubTFzXVIxBI4ksWtNJrZMTLyIFlLlLmcHNEsD xRKc3k/AWYSUPpx4c3IfBYVJoZogDIidGG5GSnFI6B+vAhnzVYmazsdF4HAntgCchaxu Y0GHXR73LwG4IHPbd6NrYtJArYDStBLSJ9kNZaFmQiWFJcxzN0MbunVvurWakUrgLHPy fGRfQplIevf86dq4XehkFDLWzaa52H+vUr5zmo3/2krcDXZPapke3Sv5QO+HP2kma9Gv M5XA== 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=kDf62Cq3SJaj+O7BFzF/D+1wJBPHwNV0aNRu09HEVs4=; b=QZAFEQ9tbUCue6ZY8Z/LFMLeMXEvttYbu4crHFymYrphfQYOyv1202caBqQzw3BETW h0yrwrH/3PEUPXEYLcDY320NLh2+aX28QQ3gYfZb4MUkwvRwRMExSudM7xiGpgNaAiEE VhSwvpiLH6kqdaoxLx0EqD18oGxGfweR0yqXl1ccda6gcRFyI1bNMcvqG2iip7MNSdCL c1LaDELHI6NnBEAlivFkNZdpLMG3mJpOxs8BL9E0OonKjVR+OsMYTi8E/0VYSHLfncYM 3JF/Si+qPOIF8z3hMFSG8cTs0/QtQ3f6BZBGeGnCEbdLDGPbQzUQMLjKU2YWuursWwv2 zLzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=YTiBBSkS; 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 t12si705757qti.315.2020.02.25.23.47.55 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 25 Feb 2020 23:47:55 -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=YTiBBSkS; 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]:39460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6rQA-0006DH-Pz for patch@linaro.org; Wed, 26 Feb 2020 02:47:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:46293) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6rIO-00013L-Is for qemu-devel@nongnu.org; Wed, 26 Feb 2020 02:39:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6rIN-0002vm-8w for qemu-devel@nongnu.org; Wed, 26 Feb 2020 02:39:52 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]:38944) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j6rIN-0002uW-1U for qemu-devel@nongnu.org; Wed, 26 Feb 2020 02:39:51 -0500 Received: by mail-wm1-x32f.google.com with SMTP id c84so1840678wme.4 for ; Tue, 25 Feb 2020 23:39:50 -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=kDf62Cq3SJaj+O7BFzF/D+1wJBPHwNV0aNRu09HEVs4=; b=YTiBBSkS40uIrltuUklpXCQubhJo4ikWPs2XC3h2XFByKQSRBWc3c+lBlPXwZkvmQ8 np1I1ZACVy4dbQGXV5ZUjtapUW+HQsSoiWa59M2lWw7JqX04i3jlassDAad4MujawdDo IXC5ibNngxwBCkIle3HGBKvEFENwwXvb1uIs+ipfMKhcnDQYLT7Z4cDEf6LUnCg2djgN /NT6TCP2MYpG+mUTDCoWItl8wJTuZZkEdC9W3u4LIh2s6PLasRBVigVI7tW6XGTdUxWP uhsWEySBWMbLmbRyoieTZdZLZoq/a/b4b27UKevjhfBA1uXjkyJJujlUwLMlXlEFIUWk mekw== 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=kDf62Cq3SJaj+O7BFzF/D+1wJBPHwNV0aNRu09HEVs4=; b=Ootg+zETwWFRNLOVzWlSCW8sxdnfcK72/SIBKnHvGNuT1PN7c+Cx1VKDB1dcddOndI J91JtCs00ZJzfHz3vljZCqCmqj+ZyggejBy5kKclyVq9JHqam5mMbuLF1UU8LCI05Yly xIr2i8lTUi3cmxIDZcTarm5TiNYBE2fa/XhWBWrlxqZAJ0oONBNe+GKKX45EOSISWA3/ 8mqezGDa1pd+VLb4osle7r+/U3suTCtrYrEfCo91S9FqBfyOxUwt7m7C0wfTUo1mIBf2 DojqyxeDsJ4KdcgHR28BqQUwYkCpoU/ofdj/Q1Wg/KRfnEN/+RYQW2p6UHhuLeEfAb4T oOqQ== X-Gm-Message-State: APjAAAVF9qOqZOSRJCBKLuEm+yCWoptBEsfzsb+wCuzDz//qaQJr3A84 GF65MEeshqDA8MVRFDDBRfciPQ== X-Received: by 2002:a7b:c7d2:: with SMTP id z18mr3851636wmk.160.1582702789980; Tue, 25 Feb 2020 23:39:49 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id d17sm1700621wmb.36.2020.02.25.23.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Feb 2020 23:39:45 -0800 (PST) Received: from zen.home.arpa (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 678D41FF9D; Wed, 26 Feb 2020 07:39:30 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 13/19] qemu/bitops.h: Add extract8 and extract16 Date: Wed, 26 Feb 2020 07:39:23 +0000 Message-Id: <20200226073929.28237-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200226073929.28237-1-alex.bennee@linaro.org> References: <20200226073929.28237-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::32f 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: =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Richard Henderson , qemu-devel@nongnu.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é 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> Message-Id: <20200225124710.14152-14-alex.bennee@linaro.org> -- 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