linux-mips
[Top] [All Lists]

Re: [PATCH 2/2] netdev: octeon_mgmt: Fix structure layout for little-end

To: David Laight <David.Laight@ACULAB.COM>
Subject: Re: [PATCH 2/2] netdev: octeon_mgmt: Fix structure layout for little-endian.
From: Ralf Baechle <ralf@linux-mips.org>
Date: Thu, 27 Jun 2013 12:40:48 +0200
Cc: David Daney <ddaney.cavm@gmail.com>, netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>, linux-mips@linux-mips.org, David Daney <david.daney@cavium.com>
In-reply-to: <AE90C24D6B3A694183C094C60CF0A2F6026B729B@saturn3.aculab.com>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <1371688820-4585-1-git-send-email-ddaney.cavm@gmail.com> <1371688820-4585-3-git-send-email-ddaney.cavm@gmail.com> <AE90C24D6B3A694183C094C60CF0A2F6026B729B@saturn3.aculab.com>
Sender: linux-mips-bounce@linux-mips.org
User-agent: Mutt/1.5.21 (2010-09-15)
On Thu, Jun 20, 2013 at 10:47:57AM +0100, David Laight wrote:

> > The C ABI reverses the bitfield fill order when compiled as
> > little-endian.
> 
> No - it is completely implementation defined.
> The general concensus is not to use bitfields if you
> care at all about the bit assignments.

FWIW, bitfields often alow things to be expressed more nicely.  Just the
endian-dependent definition suck, so I came up with this little hack
for arch/mips/include/uapi/asm/inst.h:

#ifdef __MIPSEB__
#define BITFIELD_FIELD(field, more)                                     \
        field;                                                          \
        more

#elif defined(__MIPSEL__)

#define BITFIELD_FIELD(field, more)                                     \
        more                                                            \
        field;
#endif

struct i_format {                       /* signed immediate format */
        BITFIELD_FIELD(unsigned int opcode : 6,
        BITFIELD_FIELD(unsigned int rs : 5,
        BITFIELD_FIELD(unsigned int rt : 5,
        BITFIELD_FIELD(signed int simmediate : 16,
        ;))))
};

  Ralf

<Prev in Thread] Current Thread [Next in Thread>