From patchwork Thu Sep 17 16:31:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 273457 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09867C43461 for ; Thu, 17 Sep 2020 16:33:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 87640214D8 for ; Thu, 17 Sep 2020 16:33:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fw3T342b" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 87640214D8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIwqs-0002AQ-KB for qemu-devel@archiver.kernel.org; Thu, 17 Sep 2020 12:33:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52526) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIwoa-0000Pt-7v for qemu-devel@nongnu.org; Thu, 17 Sep 2020 12:31:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:32367) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIwoY-0000ug-C9 for qemu-devel@nongnu.org; Thu, 17 Sep 2020 12:31:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600360276; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XUx+wxXE+REYjw2JhAsBHYVliaS15koys54VhdQ8whA=; b=fw3T342bUgpxT3i4dfiOHKmyClmNjM/ZlerwLCsletl5COjS336Tz6eACzr89PlalvRlu6 nWt/GfoUpERgXbGNxnSWNzQb7xMab0o0b7LmV4voI+uCFajO9c7JdyM6ns+kCX/qjGEwls I6ymrpVUou+XBmzhH799cGrX6J8ciWI= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-485-Mz6pEmXfOP2hVhhBpqo0qA-1; Thu, 17 Sep 2020 12:31:14 -0400 X-MC-Unique: Mz6pEmXfOP2hVhhBpqo0qA-1 Received: by mail-wr1-f72.google.com with SMTP id x15so1083552wrm.7 for ; Thu, 17 Sep 2020 09:31:14 -0700 (PDT) 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=XUx+wxXE+REYjw2JhAsBHYVliaS15koys54VhdQ8whA=; b=ev7o4DIkpZG5GwwgcECNKo9MMJm56YPXXbe+6JGmBXD6oxI8lUwKQ3WqSR05NvWTXO m3PpOSBesnedWyvyo8cAycz40Js7shu0WcyElyP212q/iT+EfvpJnSytfUSSs2o9pNVv iMw18M5xy2Tli1RSF1PPh1mpKv8X5JQN/Dbzgb9oj2aKtAxjrCdKyJA+M2PxTKXsz06l iGiCQx/0Z3PMccB6mIY4JCXHHk+yT0aFp8By3p5atFczM4iuLdOCtpAMy9U3UIRy/I4g MIIl4dnp0mODtpA06nrBU7yqFj3dXNLCt/qRJpOPer/n3gCKkjXgXpLBCHnzKIFbHgC7 vh+w== X-Gm-Message-State: AOAM531HXDENxYFFh6nWbCraSTyeu4WV5EFbD7YJjs0yMOobH8RjHaeZ WoWeiWMBopn7b5xCMfKLokSDHE0Cy8wHQ7ehOrwHclr4aN4I5Obk6MtbwINfwI1ScCrn9yYoLjT R2OKLHS2U3chpTdY= X-Received: by 2002:a1c:7418:: with SMTP id p24mr10866680wmc.123.1600360273214; Thu, 17 Sep 2020 09:31:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzor+7GYLXEZMyW5/heb19MinyS2qVs6aaYDwSzOhSs7jtOt1BnNonG6FCWL8PMHDRpRd7i0Q== X-Received: by 2002:a1c:7418:: with SMTP id p24mr10866656wmc.123.1600360273030; Thu, 17 Sep 2020 09:31:13 -0700 (PDT) Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id t15sm161221wrp.20.2020.09.17.09.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 09:31:12 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 1/4] qemu/bswap: Move const_le() definitions around Date: Thu, 17 Sep 2020 18:31:03 +0200 Message-Id: <20200917163106.49351-2-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200917163106.49351-1-philmd@redhat.com> References: <20200917163106.49351-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/17 02:01:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.997, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Peter Maydell , Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" As we want the cpu_to_endian() macros use the const_le() macros, move them earlier, so they are defined when we use them. Signed-off-by: Philippe Mathieu-Daudé --- include/qemu/bswap.h | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index 1d3e4c24e41..c3b4277342b 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -82,6 +82,25 @@ static inline void bswap64s(uint64_t *s) #define be_bswaps(p, size) do { *p = glue(bswap, size)(*p); } while(0) #endif +/* + * Same as cpu_to_le{16,32} described below, except that gcc will + * figure the result is a compile-time constant if you pass in a constant. + * So this can be used to initialize static variables. + */ +#if defined(HOST_WORDS_BIGENDIAN) +# define const_le32(_x) \ + ((((_x) & 0x000000ffU) << 24) | \ + (((_x) & 0x0000ff00U) << 8) | \ + (((_x) & 0x00ff0000U) >> 8) | \ + (((_x) & 0xff000000U) >> 24)) +# define const_le16(_x) \ + ((((_x) & 0x00ff) << 8) | \ + (((_x) & 0xff00) >> 8)) +#else +# define const_le32(_x) (_x) +# define const_le16(_x) (_x) +#endif + /** * Endianness conversion functions between host cpu and specified endianness. * (We list the complete set of prototypes produced by the macros below @@ -175,25 +194,6 @@ static inline uint32_t qemu_bswap_len(uint32_t value, int len) return bswap32(value) >> (32 - 8 * len); } -/* - * Same as cpu_to_le{16,32}, except that gcc will figure the result is - * a compile-time constant if you pass in a constant. So this can be - * used to initialize static variables. - */ -#if defined(HOST_WORDS_BIGENDIAN) -# define const_le32(_x) \ - ((((_x) & 0x000000ffU) << 24) | \ - (((_x) & 0x0000ff00U) << 8) | \ - (((_x) & 0x00ff0000U) >> 8) | \ - (((_x) & 0xff000000U) >> 24)) -# define const_le16(_x) \ - ((((_x) & 0x00ff) << 8) | \ - (((_x) & 0xff00) >> 8)) -#else -# define const_le32(_x) (_x) -# define const_le16(_x) (_x) -#endif - /* Unions for reinterpreting between floats and integers. */ typedef union { From patchwork Thu Sep 17 16:31:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 273456 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4F89C433E2 for ; Thu, 17 Sep 2020 16:35:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E9E1E206BE for ; Thu, 17 Sep 2020 16:35:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="er/2k1JF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9E1E206BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIwsu-0004uT-4U for qemu-devel@archiver.kernel.org; Thu, 17 Sep 2020 12:35:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIwog-0000Zj-C9 for qemu-devel@nongnu.org; Thu, 17 Sep 2020 12:31:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:48034) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIwoe-0000w0-F8 for qemu-devel@nongnu.org; Thu, 17 Sep 2020 12:31:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600360283; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZF+OqmqmstlUkr/dM0RnSgA94FV+mHcH3wKBsCU4Fw8=; b=er/2k1JFAwfgKuKgKh0SFoyDO0lz8vUkjnNV6v9T+6bUBpO/dlFtz0vgGDQmH7sTWthgE/ hQz8gzByWIY3dsXoHGzXCvCmSUq2CNV5c/LqOghhAgWrsV2cIsRzEroYIdrG6q3gML9B/r iPLmbfXheZl5GQc2Ny4pOIeSprcnJlw= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-355-74xmJuILPaO6uvovxDHoPw-1; Thu, 17 Sep 2020 12:31:19 -0400 X-MC-Unique: 74xmJuILPaO6uvovxDHoPw-1 Received: by mail-wr1-f69.google.com with SMTP id x15so1083632wrm.7 for ; Thu, 17 Sep 2020 09:31:19 -0700 (PDT) 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=ZF+OqmqmstlUkr/dM0RnSgA94FV+mHcH3wKBsCU4Fw8=; b=VLoZszw2vSoQanWERcQDtbPtv40vmrVfTeC8xMtpPPr67U7zBlbu2Em2lc+9JRYRw8 sFmxBHkP3Fg41SsRoL7CfRVUgKxZue5ZSyVorE0ehH5KvuMrP3y2JJXa4XcL0sgVuFbw F7Io1gsxsujHPpWmcFAzLOSuBj6ZHGvCKxXgSGYXbI/sQFmGwLJ3Ik1TQtzVDjYr9nr5 2xt6bwJC12bsbov3IOH1V2l2D1fMIhB0SsngyM7RNsyLZW8O61x+EzGy0s0agsK0hoJ8 Mp/cHYUVaK59zpo1rGaJAR4KHmugfxTZNNQuADskHwXTeyhPJ4YzhZzXam7GTPVqUYMb TDTg== X-Gm-Message-State: AOAM530TGgLFewzChEqPYZHNm2NvU2Sote6LKJv9w9su6GFhQ5DQqjBc WeOM/3MkQSfJZt7hhDTFSERZnVQN0RiwwbMBxK0ZQLaUyx3RCKvLaWZfrW3nsxoKoqTY8Oyo4dB jceVaRfNE1i7hBl8= X-Received: by 2002:a5d:49d2:: with SMTP id t18mr31185233wrs.99.1600360278145; Thu, 17 Sep 2020 09:31:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJk4OJfAAHKtjRC2q3Vdz8KiSyHcc881TPifcw7kwFeh6Gzk4LBfKN0go9mvWayUx4Ka9MpA== X-Received: by 2002:a5d:49d2:: with SMTP id t18mr31185212wrs.99.1600360277883; Thu, 17 Sep 2020 09:31:17 -0700 (PDT) Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id i26sm75223wmb.17.2020.09.17.09.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 09:31:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 2/4] qemu/bswap: add const_be16() and const_be32() Date: Thu, 17 Sep 2020 18:31:04 +0200 Message-Id: <20200917163106.49351-3-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200917163106.49351-1-philmd@redhat.com> References: <20200917163106.49351-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/17 02:01:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.997, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Peter Maydell , Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé We already have the const_le() macros for little endian. Implement the big-endian equivalent. Signed-off-by: Philippe Mathieu-Daudé --- include/qemu/bswap.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index c3b4277342b..6885984e00c 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -83,7 +83,7 @@ static inline void bswap64s(uint64_t *s) #endif /* - * Same as cpu_to_le{16,32} described below, except that gcc will + * Same as cpu_to_{be,le}{16,32} described below, except that gcc will * figure the result is a compile-time constant if you pass in a constant. * So this can be used to initialize static variables. */ @@ -96,11 +96,20 @@ static inline void bswap64s(uint64_t *s) # define const_le16(_x) \ ((((_x) & 0x00ff) << 8) | \ (((_x) & 0xff00) >> 8)) +# define const_be32(_x) (_x) +# define const_be16(_x) (_x) #else # define const_le32(_x) (_x) # define const_le16(_x) (_x) +# define const_be32(_x) \ + ((((_x) & 0x000000ffU) << 24) | \ + (((_x) & 0x0000ff00U) << 8) | \ + (((_x) & 0x00ff0000U) >> 8) | \ + (((_x) & 0xff000000U) >> 24)) +# define const_be16(_x) \ + ((((_x) & 0x00ff) << 8) | \ + (((_x) & 0xff00) >> 8)) #endif - /** * Endianness conversion functions between host cpu and specified endianness. * (We list the complete set of prototypes produced by the macros below From patchwork Thu Sep 17 16:31:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 305119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06F90C43461 for ; Thu, 17 Sep 2020 16:37:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5BF182078D for ; Thu, 17 Sep 2020 16:37:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ASeobSNE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5BF182078D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:52252 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIwuo-0007Gn-F0 for qemu-devel@archiver.kernel.org; Thu, 17 Sep 2020 12:37:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52572) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIwon-0000ef-Hz for qemu-devel@nongnu.org; Thu, 17 Sep 2020 12:31:35 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:47135 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIwoi-0000wD-HL for qemu-devel@nongnu.org; Thu, 17 Sep 2020 12:31:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600360287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6ZmkCbrQPhSlo4AKl7/h3xZk9pphOh2PK1eFykfuhSU=; b=ASeobSNEYMPjAa0/wUEcMUB2FYIqjfn+RDOlKR0eUZgPj1z756PATQEtHncXkM07NdTfoF EuipU2UpSXfj6uEtrzA1m81qLDtVEaNxqjjKjO3KHFHEhpTffBH42Eb+9V2s8XOlgRenvE Fw9d9BD6tlK5lPCdlTXtZA6iWHgbtx4= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-484-aeB4kjj1OCaVURN_tsjCjw-1; Thu, 17 Sep 2020 12:31:24 -0400 X-MC-Unique: aeB4kjj1OCaVURN_tsjCjw-1 Received: by mail-wr1-f70.google.com with SMTP id a10so1075880wrw.22 for ; Thu, 17 Sep 2020 09:31:24 -0700 (PDT) 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=6ZmkCbrQPhSlo4AKl7/h3xZk9pphOh2PK1eFykfuhSU=; b=S+jgpwdI38eMyg3eOXKJM274tssTJ8mEmEFa7gYSOQ9Agsr2ZTdmg+XwIxSxAbPprK PF8W2GcP0kq7IBIGXf88QjJ8SY2u7Vj1uk83TqDyOBeXwb1UHm24rS3i39/LMJJwcfzF JuTaW0Sovo/OjZNnDWWM1qj1+75a2EXXmKwVJZucOtBVSlY0/v9PfL6tpSYAB9hZKdqf kUhNRo/8uScW+sHByfUo3hugDiG4wwhwSRpP7Sk9U8Ao+yrJxvtA0/jvNGPJ83WwDqR7 yoFMx5CucnZ+clNKwTtHnCUGVSHNut1i9acoF+/bqv57WLnS8B7sL+bJu7il7M4BsoZu cJSg== X-Gm-Message-State: AOAM533GHmEan68wISmaAlmRzHdoHwqHivXPpLkU+FMWi0dXyVnv0XO6 WVbZM4hexkm0U5FA/DnPc7t1/yCf7hnTspXyLw4YxDYmM4tnPzDlo2yi2T6mrFEq/Hp4Ku2HzrG UX6hahF7ur4P+WoY= X-Received: by 2002:a5d:4710:: with SMTP id y16mr34235502wrq.203.1600360282852; Thu, 17 Sep 2020 09:31:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwapxxBJVC5uenbUEU+ecvr+hoB+fQfG/HnlNuPjZ/ihRa69d9gvA21veTVXB0QNXjsmzqkwg== X-Received: by 2002:a5d:4710:: with SMTP id y16mr34235487wrq.203.1600360282668; Thu, 17 Sep 2020 09:31:22 -0700 (PDT) Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id s80sm38921wme.41.2020.09.17.09.31.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 09:31:22 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 3/4] qemu/bswap: Add const_le64() and const_be64() Date: Thu, 17 Sep 2020 18:31:05 +0200 Message-Id: <20200917163106.49351-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200917163106.49351-1-philmd@redhat.com> References: <20200917163106.49351-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/17 09:24:35 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.997, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Peter Maydell , Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé We already have the const_endian() macros for 16-bit and 32-bit values. Implement the 64-bit equivalent macros. Signed-off-by: Philippe Mathieu-Daudé --- include/qemu/bswap.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index 6885984e00c..de256cea3ab 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -83,11 +83,20 @@ static inline void bswap64s(uint64_t *s) #endif /* - * Same as cpu_to_{be,le}{16,32} described below, except that gcc will + * Same as cpu_to_{be,le}{16,32,64} described below, except that gcc will * figure the result is a compile-time constant if you pass in a constant. * So this can be used to initialize static variables. */ #if defined(HOST_WORDS_BIGENDIAN) +# define const_le64(_x) \ + ((((_x) & 0x00000000000000ffU) << 56) | \ + (((_x) & 0x000000000000ff00U) << 40) | \ + (((_x) & 0x0000000000ff0000U) << 24) | \ + (((_x) & 0x00000000ff000000U) << 8) | \ + (((_x) & 0x000000ff00000000U) >> 8) | \ + (((_x) & 0x0000ff0000000000U) >> 24) | \ + (((_x) & 0x00ff000000000000U) >> 40) | \ + (((_x) & 0xff00000000000000U) >> 56)) # define const_le32(_x) \ ((((_x) & 0x000000ffU) << 24) | \ (((_x) & 0x0000ff00U) << 8) | \ @@ -96,11 +105,22 @@ static inline void bswap64s(uint64_t *s) # define const_le16(_x) \ ((((_x) & 0x00ff) << 8) | \ (((_x) & 0xff00) >> 8)) +# define const_be64(_x) (_x) # define const_be32(_x) (_x) # define const_be16(_x) (_x) #else +# define const_le64(_x) (_x) # define const_le32(_x) (_x) # define const_le16(_x) (_x) +# define const_be64(_x) \ + ((((_x) & 0x00000000000000ffU) << 56) | \ + (((_x) & 0x000000000000ff00U) << 40) | \ + (((_x) & 0x0000000000ff0000U) << 24) | \ + (((_x) & 0x00000000ff000000U) << 8) | \ + (((_x) & 0x000000ff00000000U) >> 8) | \ + (((_x) & 0x0000ff0000000000U) >> 24) | \ + (((_x) & 0x00ff000000000000U) >> 40) | \ + (((_x) & 0xff00000000000000U) >> 56)) # define const_be32(_x) \ ((((_x) & 0x000000ffU) << 24) | \ (((_x) & 0x0000ff00U) << 8) | \ From patchwork Thu Sep 17 16:31:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 305120 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D00FCC433E2 for ; Thu, 17 Sep 2020 16:35:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6A989206BE for ; Thu, 17 Sep 2020 16:35:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZQFF8kD2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6A989206BE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:46882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIwsx-00050z-Hu for qemu-devel@archiver.kernel.org; Thu, 17 Sep 2020 12:35:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52598) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIwor-0000g6-Hi for qemu-devel@nongnu.org; Thu, 17 Sep 2020 12:31:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52891) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kIwon-0000wM-8I for qemu-devel@nongnu.org; Thu, 17 Sep 2020 12:31:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600360290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hoKGRGT2V6fv30rJh8pJxgu9hLwQjaS3tEMU4jSGQIA=; b=ZQFF8kD2q2asTYxThS/xv6Es/xDt+5rnh2wdJT1eKYJrrfZxlBg1/Zzrkq7hXgKSJoD0Ky Bgg4OSkALmVXF+38fBLyqTC1ZR0pxBIetDVEzv0eV2RXyJs390OgexcH97CeAQRnrcdfre a/Pqd+XSLWDS88MSKGbZCK9qB+hX6FM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-227-49SMtp39My2o844oh3QTtg-1; Thu, 17 Sep 2020 12:31:29 -0400 X-MC-Unique: 49SMtp39My2o844oh3QTtg-1 Received: by mail-wm1-f69.google.com with SMTP id t8so705813wmj.6 for ; Thu, 17 Sep 2020 09:31:28 -0700 (PDT) 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=hoKGRGT2V6fv30rJh8pJxgu9hLwQjaS3tEMU4jSGQIA=; b=X86wQ4njdkALt999FGaFYbpcJcZcAnE9GAnjMgMsWLvA6m/GVvs5Tbc2ZU7gZfrNgW u9rt52epWCRMU/7+2ej6DehjhuvoiGtnGFYvu2dL62DF5q+beKmE4xo+5sl1/iYtzzmq yLb987K3oAsv+ZdJXFGC+vZyBjXuHt+jd5VYsBu+CZ69CxiOmSuDaFTS9hwTQCRpnqod HCjyIS03+pVz4aXNychvMj1lqdDYGM+OgcV+b2tcqOmFjzNy+jMazL+ljIrn+/4J+w2Q eJfROSmVyc1TZQmeLNasLvJGVmTJNNg08lrgx4WMJ6M/s1bF1GfOIZJLQTTp4PjiD3Zf Yo8Q== X-Gm-Message-State: AOAM533SIQBvLL4LItkh5rj5oO5E1SQeOiJSpGOoM2CAsvU3V4gSop68 Buf+zwSpwd0llnss2ehRdjpDHsOmh7TVIvEUKpLtuFtehTMyaoTkxCD0DZeUL9+YQr5hCbMGKwP hLqNPiqg1IxJ7CM4= X-Received: by 2002:a05:6000:12c3:: with SMTP id l3mr35041007wrx.164.1600360287755; Thu, 17 Sep 2020 09:31:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxXPAP0gqwaUGtUWZKXaggU2xICD+f79soDWmMyd2fwP1yolvt5oTi7L6fQSKK2/5UDxgx7ZA== X-Received: by 2002:a05:6000:12c3:: with SMTP id l3mr35040986wrx.164.1600360287607; Thu, 17 Sep 2020 09:31:27 -0700 (PDT) Received: from x1w.redhat.com (65.red-83-57-170.dynamicip.rima-tde.net. [83.57.170.65]) by smtp.gmail.com with ESMTPSA id b11sm154973wrt.38.2020.09.17.09.31.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Sep 2020 09:31:27 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 4/4] qemu/bswap: Let cpu_to_endian() functions handle constant expressions Date: Thu, 17 Sep 2020 18:31:06 +0200 Message-Id: <20200917163106.49351-5-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200917163106.49351-1-philmd@redhat.com> References: <20200917163106.49351-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/17 02:01:40 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.997, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: Stefan Hajnoczi , Peter Maydell , Richard Henderson , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" cpu_to_endian() and endian_to_cpu() can be extended to handle constant expressions. That way the programmer doesn't need to remember the const_X() API exists. Suggested-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daudé --- include/qemu/bswap.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/qemu/bswap.h b/include/qemu/bswap.h index de256cea3ab..8827e4760b9 100644 --- a/include/qemu/bswap.h +++ b/include/qemu/bswap.h @@ -191,12 +191,16 @@ static inline void bswap64s(uint64_t *s) #define CPU_CONVERT(endian, size, type)\ static inline type endian ## size ## _to_cpu(type v)\ {\ - return glue(endian, _bswap)(v, size);\ + return __builtin_constant_p(v) ?\ + const_ ## endian ## size(v) :\ + glue(endian, _bswap)(v, size);\ }\ \ static inline type cpu_to_ ## endian ## size(type v)\ {\ - return glue(endian, _bswap)(v, size);\ + return __builtin_constant_p(v) ?\ + const_ ## endian ## size(v) :\ + glue(endian, _bswap)(v, size);\ }\ \ static inline void endian ## size ## _to_cpus(type *p)\