qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: Farhan Ali <alifm@linux.vnet.ibm.com>, qemu-devel@nongnu.org
Cc: borntraeger@de.ibm.com, thuth@redhat.com, cohuck@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 1/2] virtio-gpu: Handle endian conversion
Date: Fri, 15 Sep 2017 09:31:20 +0200	[thread overview]
Message-ID: <1505460680.18776.1.camel@redhat.com> (raw)
In-Reply-To: <f6c9e7ec8ad585ce7c8f401aae2ec1fddf157fd7.1505403478.git.alifm@linux.vnet.ibm.com>

  Hi,

> +static void
> +virtio_gpu_ctrl_hdr_bswap_cpu(struct virtio_gpu_ctrl_hdr *hdr)
> +{
> +    hdr->type =  le32_to_cpu(hdr->type);
> +    hdr->flags = le32_to_cpu(hdr->flags);
> +    hdr->fence_id = le64_to_cpu(hdr->fence_id);
> +    hdr->ctx_id = le32_to_cpu(hdr->ctx_id);
> +    hdr->padding = le32_to_cpu(hdr->padding);
> +}
> +
> +static void
> +virtio_gpu_ctrl_hdr_bswap_le(struct virtio_gpu_ctrl_hdr *hdr)
> +{
> +    hdr->type =  cpu_to_le32(hdr->type);
> +    hdr->flags = cpu_to_le32(hdr->flags);
> +    hdr->fence_id = cpu_to_le64(hdr->fence_id);
> +    hdr->ctx_id = cpu_to_le32(hdr->ctx_id);
> +    hdr->padding = cpu_to_le32(hdr->padding);
> +}

These two functions do exactly the same thing because cpu_to_le32 and
le32_to_cpu are the same operation.  The two variants only exist to
make the code more readable.  So this isn't needed twice.  I'd suggest
to just call the functions "*_bswap" and drop any _le or _cpu postfix. 
Note that there are also variants for in-place swapping.

Have a look at the comments in include/qemu/bswap.h

> +
> +static void virtio_gpu_bswap_cpu_32(void *ptr,
> +                                    size_t size)
> +{

#ifdef HOST_WORDS_BIGENDIAN

> +    size_t i;
> +    struct virtio_gpu_ctrl_hdr *hdr = (struct virtio_gpu_ctrl_hdr *)
> ptr;
> +
> +    virtio_gpu_ctrl_hdr_bswap_cpu(hdr);
> +
> +    i = sizeof(struct virtio_gpu_ctrl_hdr);
> +    while (i < size) {
> +        *(uint32_t *)(ptr + i) = le32_to_cpu(*(uint32_t *)(ptr +
> i));
> +        i = i + sizeof(uint32_t);
> +    }

#endif

I suspect the compiler isn't clever enough to figure the whole function
is a nop on little endian hosts.

cheers,
  Gerd

  reply	other threads:[~2017-09-15  7:31 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-14 15:55 [Qemu-devel] [PATCH v2 0/2] Virtio GPU for S390 Farhan Ali
2017-09-14 15:55 ` [Qemu-devel] [PATCH v2 1/2] virtio-gpu: Handle endian conversion Farhan Ali
2017-09-15  7:31   ` Gerd Hoffmann [this message]
2017-09-15 12:56     ` Farhan Ali
2017-09-14 15:55 ` [Qemu-devel] [PATCH v2 2/2] virtio-gpu-ccw: Create a virtio gpu device for the ccw bus Farhan Ali
2017-09-15  7:40   ` Thomas Huth
2017-09-15 12:57     ` Farhan Ali

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=1505460680.18776.1.camel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=alifm@linux.vnet.ibm.com \
    --cc=borntraeger@de.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.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).