RE: [RFC 12/12] asm-generic: simplify asm/unaligned.h

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

 



From: David Laight
> Sent: 08 May 2021 12:03
> 
> From: Arnd Bergmann
> > Sent: 07 May 2021 23:08
> >
> > The get_unaligned()/put_unaligned() implementations are much more complex
> > than necessary, now that all architectures use the same code.
> >
> ...
> > +#define __get_unaligned_t(type, ptr) ({						\
> > +	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
> > +	__pptr->x; 								\
> > +})
> 
> I thought gcc was likely to track through the alignment of the
> variable holding the source pointer (through any (void *) casts
> implied by inlined function calls) through to the pointer used
> for the actual access - so it would tend to issue a single
> instruction that assumed an aligned address.
> 
> I know that has caused grief trying to copy unaligned data
> to an aligned structure.
> 
> Possibly adding:
> 	asm ("" :: "+r" (__pptr)) );
> in the middle stops that assumption without generating any code.

That is the wrong asm.
You need the one where an input operand and output operand
share the same register and use it for the assignment.

I've been trying to get godbolt to do something useful.
But it seems to be stuck in C++ mode and is missing something like
sparc which definitely doesn't do misaligned accesses.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)




[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