RE: [RFC 12/12] asm-generic: simplify asm/unaligned.h
From: David Laight <hidden>
Date: 2021-05-08 11:03:33
Also in:
lkml
From: David Laight <hidden>
Date: 2021-05-08 11:03:33
Also in:
lkml
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.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)