Re: Being more careful about iospace accesses..

From: Kai Henningsen
Date: Sat Sep 18 2004 - 08:08:29 EST


torvalds@xxxxxxxx (Linus Torvalds) wrote on 16.09.04 in <Pine.LNX.4.58.0409160652460.2333@xxxxxxxxxxxxxxx>:

> On Thu, 16 Sep 2004, David Woodhouse wrote:
>
> > On Wed, 2004-09-15 at 16:26 -0700, Linus Torvalds wrote:
> > > - if you want to go outside that bitwise type, you have to convert it
> > > properly first. For example, if you want to add a constant to a
> > > __le16 type, you can do so, but you have to use the proper sequence:
> > >
> > > __le16 sum, a, b;
> > >
> > > sum = a + b; /* INVALID! "warning: incompatible types for operation
> > > (+)" */ sum = cpu_to_le16(le16_to_cpu(a) + le16_to_cpu(b)); /* Ok */
> > >
> > > See?
> >
> > Yeah right, that latter case is _so_ much more readable
>
> It's not about readability.
>
> It's about the first case being WRONG!

... in general.

And on the machines where it works (le machines), I'd certainly expect
those conversion functions to be trivially eliminated by the compiler (ie,
they're either trivial macros or trivial inline functions).

> > I'd really quite like to see the real compiler know about endianness,
> > too.

Well, these day, optimizers often can recognize the usual endianness
conversion idioms, so the compiler still gets a chance at inserting your
load-with-swap or whatever.

MfG Kai
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/