Re: [PATCH 1/8] kernel: add common infrastructure for unaligned access

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Harvey Harrison <harvey.harrison@xxxxxxxxx> wrote:

> +static inline u16 __get_unaligned_le16(const u8 *p)
> +{
> +	return (u16)(p[0] | p[1] << 8);
> +}

You shouldn't need these casts.  return is going to cast it anyway.

Actually, you probably _ought_ to have casts, but it should look like this:

	return (u16)p[0] | (u16)p[1] << 8;

You are shifting an 8-bit value left by 8 bits, so the compiler may be at
liberty to instruct the RHS to end up zero.

I presume the compiler is guaranteed not to merge the two memory accesses?  It
can't seem to make it do so, though I seem to remember there were cases where
it did, though I can't reproduce them.  I assume that's why you're passing in
a u8 pointer and not a u16/u32/u64 pointer.

David
--
To unsubscribe from this list: send the line "unsubscribe linux-arch" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Kernel Newbies]     [x86 Platform Driver]     [Netdev]     [Linux Wireless]     [Netfilter]     [Bugtraq]     [Linux Filesystems]     [Yosemite Discussion]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]

  Powered by Linux