qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Halil Pasic <pasic@linux.ibm.com>
To: Thomas Huth <thuth@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Dmitry Fleytman" <dmitry.fleytman@gmail.com>,
	"open list:Overall KVM CPUs" <kvm@vger.kernel.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eric Farman" <farman@linux.ibm.com>,
	"Jason Wang" <jasowang@redhat.com>,
	"Bin Meng" <bin.meng@windriver.com>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	qemu-devel@nongnu.org, "Peter Xu" <peterx@redhat.com>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Yanan Wang" <wangyanan55@huawei.com>,
	"Max Filippov" <jcmvbkbc@gmail.com>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Daniel Henrique Barboza" <danielhb413@gmail.com>,
	"Vikram Garhwal" <fnu.vikram@xilinx.com>,
	"open list:virtio-blk" <qemu-block@nongnu.org>,
	"David Hildenbrand" <david@redhat.com>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	marcandre.lureau@redhat.com,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>,
	"Artyom Tarasenko" <atar4qemu@gmail.com>,
	"Pavel Pisa" <pisa@cmp.felk.cvut.cz>,
	"Huacai Chen" <chenhuacai@kernel.org>,
	"Aleksandar Rikalo" <aleksandar.rikalo@syrmia.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Greg Kurz" <groug@kaod.org>,
	"open list:S390 SCLP-backed..." <qemu-s390x@nongnu.org>,
	"open list:ARM PrimeCell and..." <qemu-arm@nongnu.org>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Palmer Dabbelt" <palmer@dabbelt.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"open list:RISC-V TCG CPUs" <qemu-riscv@nongnu.org>,
	"Cornelia Huck" <cohuck@redhat.com>,
	"Laurent Vivier" <laurent@vivier.eu>,
	"Coiby Xu" <Coiby.Xu@gmail.com>,
	"open list:PowerPC TCG CPUs" <qemu-ppc@nongnu.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Aurelien Jarno" <aurelien@aurel32.net>
Subject: Re: [PATCH 10/27] Replace config-time define HOST_WORDS_BIGENDIAN
Date: Wed, 16 Mar 2022 12:15:35 +0100	[thread overview]
Message-ID: <20220316121535.16631f9c.pasic@linux.ibm.com> (raw)
In-Reply-To: <9c101703-6aff-4188-a56a-8114281f75f4@redhat.com>

On Wed, 16 Mar 2022 11:28:59 +0100
Thomas Huth <thuth@redhat.com> wrote:

> On 16/03/2022 10.53, marcandre.lureau@redhat.com wrote:
> > From: Marc-André Lureau <marcandre.lureau@redhat.com>
> > 
> > Replace a config-time define with a compile time condition
> > define (compatible with clang and gcc) that must be declared prior to
> > its usage. This avoids having a global configure time define, but also
> > prevents from bad usage, if the config header wasn't included before.
> > 
> > This can help to make some code independent from qemu too.
> > 
> > gcc supports __BYTE_ORDER__ from about 4.6 and clang from 3.2.
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---  
> [...]
> > @@ -188,7 +188,7 @@ CPU_CONVERT(le, 64, uint64_t)
> >    * a compile-time constant if you pass in a constant.  So this can be
> >    * used to initialize static variables.
> >    */
> > -#if defined(HOST_WORDS_BIGENDIAN)
> > +#if HOST_BIG_ENDIAN
> >   # define const_le32(_x)                          \
> >       ((((_x) & 0x000000ffU) << 24) |              \
> >        (((_x) & 0x0000ff00U) <<  8) |              \
> > @@ -211,7 +211,7 @@ typedef union {
> >   
> >   typedef union {
> >       float64 d;
> > -#if defined(HOST_WORDS_BIGENDIAN)
> > +#if HOST_BIG_ENDIAN
> >       struct {
> >           uint32_t upper;
> >           uint32_t lower;
> > @@ -235,7 +235,7 @@ typedef union {
> >   
> >   typedef union {
> >       float128 q;
> > -#if defined(HOST_WORDS_BIGENDIAN)
> > +#if HOST_BIG_ENDIAN
> >       struct {
> >           uint32_t upmost;
> >           uint32_t upper;
> > diff --git a/include/qemu/compiler.h b/include/qemu/compiler.h
> > index 0a5e67fb970e..7fdd88adb368 100644
> > --- a/include/qemu/compiler.h
> > +++ b/include/qemu/compiler.h
> > @@ -7,6 +7,8 @@
> >   #ifndef COMPILER_H
> >   #define COMPILER_H
> >   
> > +#define HOST_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)  
> 
> Why don't you do it this way instead:
> 
> #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> #define HOST_WORDS_BIGENDIAN 1
> #endif
> 
> ... that way you could avoid the churn in all the other files?
> 

I guess "prevents from bad usage, if the config header wasn't included
before" from the commit message is the answer to that question. I agree
that it is more robust. If we keep the #if defined we really can't
differentiate between "not defined because not big-endian" and "not
defined because the appropriate header was not included."


  reply	other threads:[~2022-03-16 11:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16  9:53 [PATCH 10/27] Replace config-time define HOST_WORDS_BIGENDIAN marcandre.lureau
2022-03-16 10:28 ` Thomas Huth
2022-03-16 11:15   ` Halil Pasic [this message]
2022-03-16 11:20     ` Marc-André Lureau
2022-03-16 11:22     ` Thomas Huth
2022-03-16 11:31 ` Halil Pasic
2022-03-16 13:04 ` Philippe Mathieu-Daudé
2022-03-16 13:09   ` Marc-André Lureau
2022-03-16 13:11   ` Philippe Mathieu-Daudé
2022-03-17 11:31 ` Cédric Le Goater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220316121535.16631f9c.pasic@linux.ibm.com \
    --to=pasic@linux.ibm.com \
    --cc=Coiby.Xu@gmail.com \
    --cc=aleksandar.rikalo@syrmia.com \
    --cc=alex.bennee@linaro.org \
    --cc=alistair.francis@wdc.com \
    --cc=atar4qemu@gmail.com \
    --cc=aurelien@aurel32.net \
    --cc=bin.meng@windriver.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=chenhuacai@kernel.org \
    --cc=clg@kaod.org \
    --cc=cohuck@redhat.com \
    --cc=danielhb413@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=dmitry.fleytman@gmail.com \
    --cc=eduardo@habkost.net \
    --cc=f4bug@amsat.org \
    --cc=farman@linux.ibm.com \
    --cc=fnu.vikram@xilinx.com \
    --cc=groug@kaod.org \
    --cc=jasowang@redhat.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=laurent@vivier.eu \
    --cc=marcandre.lureau@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=mst@redhat.com \
    --cc=palmer@dabbelt.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=pisa@cmp.felk.cvut.cz \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=wangyanan55@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).