All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: virtio@lists.oasis-open.org, virtio-dev@lists.oasis-open.org
Cc: Cornelia Huck <cohuck@redhat.com>,
	Halil Pasic <pasic@linux.vnet.ibm.com>,
	Tiwei Bie <tiwei.bie@intel.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	"Dhanoa, Kully" <kully.dhanoa@intel.com>
Subject: [virtio] [PATCH v10 01/13] introduction: document bitfield notation
Date: Fri, 9 Mar 2018 23:23:29 +0200	[thread overview]
Message-ID: <1520629942-36324-2-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1520629942-36324-1-git-send-email-mst@redhat.com>

Bitfields are a useful and familiar way to specify sub-byte structure
layout. The only issue is that bitfield order isn't portable across
architectures.  Document that we list bitfields from least to
most significant one, and warn about portability issues.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 introduction.tex | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/introduction.tex b/introduction.tex
index 979881e..a4ac01d 100644
--- a/introduction.tex
+++ b/introduction.tex
@@ -157,5 +157,46 @@ in little-endian byte order.
 in big-endian byte order.
 \end{description}
 
+Some of the fields to be defined in this specification don't
+start or don't end on a byte boundary. Such fields are called bit-fields.
+A set of bit-fields is always a sub-division of an integer typed field.
+
+Bit-fields within integer fields are always listed in order,
+from the least significant to the most significant bit.  The
+bit-fields are considered unsigned integers of the specified
+width with the next in significance relationship of the bits
+preserved.
+
+For example:
+\begin{lstlisting}
+struct S {
+        be16 {
+                A : 15;
+                B : 1;
+        } x;
+        be16 y;
+};
+\end{lstlisting}
+documents the value A stored in the low 15 bit of \field{x} and
+the value B stored in the high bit of \field{x}, the 16-bit
+integer \field{x} in turn stored using the big-endian byte order
+at the beginning of the structure S,
+and being followed immediately by an unsigned integer \field{y}
+stored in big-endian byte order at an offset of 2 bytes (16 bits)
+from the beginning of the structure.
+
+Note that this notation somewhat resembles the C bitfield syntax but
+should not be naively converted to a bitfield notation for portable
+code: it matches the way bitfields are packed by C compilers on
+little-endian architectures but not the way bitfields are packed by C
+compilers on big-endian architectures.
+
+Assuming that CPU_TO_BE16 converts a 16-bit integer from a native
+CPU to the big-endian byte order, the following is the equivalent
+portable C code to generate a value to be stored into \field{x}:
+\begin{lstlisting}
+CPU_TO_BE16(B << 15 | A)
+\end{lstlisting}
+
 \newpage
 
-- 
MST


---------------------------------------------------------------------
To unsubscribe from this mail list, you must leave the OASIS TC that 
generates this mail.  Follow this link to all your TCs in OASIS at:
https://www.oasis-open.org/apps/org/workgroup/portal/my_workgroups.php 


  reply	other threads:[~2018-03-09 21:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-09 21:23 [virtio] [PATCH v10 00/13] packed ring layout spec Michael S. Tsirkin
2018-03-09 21:23 ` Michael S. Tsirkin [this message]
2018-03-09 21:23 ` [virtio] [PATCH v10 02/13] content: move 1.0 queue format out to a separate section Michael S. Tsirkin
2018-03-09 21:23 ` [virtio] [PATCH v10 03/13] content: move ring text out to a separate file Michael S. Tsirkin
2018-03-09 21:23 ` [virtio] [PATCH v10 04/13] content: move virtqueue operation description Michael S. Tsirkin
2018-03-09 21:23 ` [virtio] [PATCH v10 05/13] content: len -> used length, used ring -> vq Michael S. Tsirkin
2018-03-09 21:23 ` [virtio] [PATCH v10 07/13] content: generalize rest of text Michael S. Tsirkin
2018-03-09 21:23 ` [virtio] [PATCH v10 06/13] content: generalize transport ring part naming Michael S. Tsirkin
2018-03-09 21:23 ` [virtio] [PATCH v10 08/13] split-ring: generalize text Michael S. Tsirkin
2018-03-09 21:23 ` [virtio] [PATCH v10 10/13] packed virtqueues: more efficient virtqueue layout Michael S. Tsirkin
2018-03-09 21:23 ` [virtio] [PATCH v10 09/13] split-ring: typo: aligment Michael S. Tsirkin
2018-03-09 21:23 ` [virtio] [PATCH v10 11/13] content: in-order buffer use Michael S. Tsirkin
2018-03-09 21:23 ` [virtio] [PATCH v10 12/13] packed-ring: add in order support Michael S. Tsirkin
2018-03-09 21:23 ` [virtio] [PATCH v10 13/13] split-ring: in order feature Michael S. Tsirkin
2018-03-28  8:23   ` [virtio-dev] " Lars Ganrot
2018-03-28 14:38     ` [virtio] " Michael S. Tsirkin
2018-03-28 16:12       ` Lars Ganrot
2018-03-29 14:42         ` [virtio] " Michael S. Tsirkin
2018-03-29 18:23           ` Lars Ganrot
2018-03-29 19:12             ` [virtio] " Michael S. Tsirkin
2018-04-03  7:19               ` Lars Ganrot
2018-04-03 11:47                 ` [virtio] " Michael S. Tsirkin
2018-04-04 15:03                   ` Lars Ganrot
2018-04-04 16:07                     ` [virtio] " Michael S. Tsirkin
2018-04-05  7:18                       ` Lars Ganrot

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=1520629942-36324-2-git-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=cohuck@redhat.com \
    --cc=kully.dhanoa@intel.com \
    --cc=pasic@linux.vnet.ibm.com \
    --cc=stefanha@redhat.com \
    --cc=tiwei.bie@intel.com \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=virtio@lists.oasis-open.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.