* [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` [PATCH RFC 01/10] tools: Remove double-underscore symbols from user space byteshift functions H. Peter Anvin
` (10 subsequent siblings)
11 siblings, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
After a recent problem in the x86 tree, which seems to be the heaviest
but not the only user of these functions, I went through and did a
patchset to revamp the *user space* unaligned/endian accessor
functions. As much as I think it is downright pathetic that this
functionality still isn't part of the C standard, that is life and we
have to deal with it. Furthermore, although glibc has a pretty nice
set of functions for byte swapping in <endian.h>, taken from FreeBSD I
believe, some older systems don't support them.
This variant tries to fill in all the holes. It assumes that
<endian.h> define the functions as macros if they exist, as I don't
know any other way of probing for them without reaching for autoconf,
but that should be valid enough of an assumption in this case.
The hope is that this should give reasonable, if not optimal, code
generation on most processors, and give a hook where arch maintainers
can add their own changes if needed.
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH RFC 01/10] tools: Remove double-underscore symbols from user space byteshift functions
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` [PATCH RFC 02/10] tools: Create <tools/unaligned.h> and an unaligned subdirectory H. Peter Anvin
` (9 subsequent siblings)
11 siblings, 1 reply; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
We should not use double-underscore (or underscore-capital) symbols in
arbitrary user space code, and these include files are specifically
used for user space compilation. Furthermore, the indirection is
completely unnecessary in this case.
Also, reorder the littleendian put macros to allow the compiler to
generate better code on some architectures (stores in sequence.)
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/be_byteshift.h | 62 ++++++++++++++------------------------
tools/include/tools/le_byteshift.h | 62 ++++++++++++++------------------------
2 files changed, 44 insertions(+), 80 deletions(-)
diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h
index 84c17d836578..9850c7df2667 100644
--- a/tools/include/tools/be_byteshift.h
+++ b/tools/include/tools/be_byteshift.h
@@ -3,68 +3,50 @@
#include <stdint.h>
-static inline uint16_t __get_unaligned_be16(const uint8_t *p)
+static inline uint16_t get_unaligned_be16(const void *_p)
{
- return p[0] << 8 | p[1];
-}
+ const uint8_t *p = _p;
-static inline uint32_t __get_unaligned_be32(const uint8_t *p)
-{
- return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+ return p[0] << 8 | p[1];
}
-static inline uint64_t __get_unaligned_be64(const uint8_t *p)
+static inline uint32_t get_unaligned_be32(const void *_p)
{
- return (uint64_t)__get_unaligned_be32(p) << 32 |
- __get_unaligned_be32(p + 4);
-}
+ const uint8_t *p = _p;
-static inline void __put_unaligned_be16(uint16_t val, uint8_t *p)
-{
- *p++ = val >> 8;
- *p++ = val;
+ return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
}
-static inline void __put_unaligned_be32(uint32_t val, uint8_t *p)
+static inline uint64_t get_unaligned_be64(const void *_p)
{
- __put_unaligned_be16(val >> 16, p);
- __put_unaligned_be16(val, p + 2);
-}
+ const uint8_t *p = _p;
-static inline void __put_unaligned_be64(uint64_t val, uint8_t *p)
-{
- __put_unaligned_be32(val >> 32, p);
- __put_unaligned_be32(val, p + 4);
+ return (uint64_t)get_unaligned_be32(p) << 32 |
+ get_unaligned_be32(p + 4);
}
-static inline uint16_t get_unaligned_be16(const void *p)
+static inline void put_unaligned_be16(uint16_t val, void *_p)
{
- return __get_unaligned_be16((const uint8_t *)p);
-}
+ uint8_t *p = _p;
-static inline uint32_t get_unaligned_be32(const void *p)
-{
- return __get_unaligned_be32((const uint8_t *)p);
+ *p++ = val >> 8;
+ *p++ = val;
}
-static inline uint64_t get_unaligned_be64(const void *p)
+static inline void put_unaligned_be32(uint32_t val, void *_p)
{
- return __get_unaligned_be64((const uint8_t *)p);
-}
+ uint8_t *p = _p;
-static inline void put_unaligned_be16(uint16_t val, void *p)
-{
- __put_unaligned_be16(val, p);
+ put_unaligned_be16(val >> 16, p);
+ put_unaligned_be16(val, p + 2);
}
-static inline void put_unaligned_be32(uint32_t val, void *p)
+static inline void put_unaligned_be64(uint64_t val, void *_p)
{
- __put_unaligned_be32(val, p);
-}
+ uint8_t *p = _p;
-static inline void put_unaligned_be64(uint64_t val, void *p)
-{
- __put_unaligned_be64(val, p);
+ put_unaligned_be32(val >> 32, p);
+ put_unaligned_be32(val, p + 4);
}
#endif /* _TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h
index 8fe9f2488ec7..819ba186ede5 100644
--- a/tools/include/tools/le_byteshift.h
+++ b/tools/include/tools/le_byteshift.h
@@ -3,68 +3,50 @@
#include <stdint.h>
-static inline uint16_t __get_unaligned_le16(const uint8_t *p)
+static inline uint16_t get_unaligned_le16(const void *_p)
{
- return p[0] | p[1] << 8;
-}
+ const uint8_t *p = _p;
-static inline uint32_t __get_unaligned_le32(const uint8_t *p)
-{
- return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
+ return p[0] | p[1] << 8;
}
-static inline uint64_t __get_unaligned_le64(const uint8_t *p)
+static inline uint32_t get_unaligned_le32(const void *_p)
{
- return (uint64_t)__get_unaligned_le32(p + 4) << 32 |
- __get_unaligned_le32(p);
-}
+ const uint8_t *p = _p;
-static inline void __put_unaligned_le16(uint16_t val, uint8_t *p)
-{
- *p++ = val;
- *p++ = val >> 8;
+ return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
}
-static inline void __put_unaligned_le32(uint32_t val, uint8_t *p)
+static inline uint64_t get_unaligned_le64(const void *_p)
{
- __put_unaligned_le16(val >> 16, p + 2);
- __put_unaligned_le16(val, p);
-}
+ const uint8_t *p = _p;
-static inline void __put_unaligned_le64(uint64_t val, uint8_t *p)
-{
- __put_unaligned_le32(val >> 32, p + 4);
- __put_unaligned_le32(val, p);
+ return (uint64_t)get_unaligned_le32(p + 4) << 32 |
+ get_unaligned_le32(p);
}
-static inline uint16_t get_unaligned_le16(const void *p)
+static inline void put_unaligned_le16(uint16_t val, void *_p)
{
- return __get_unaligned_le16((const uint8_t *)p);
-}
+ uint8_t *p = _p;
-static inline uint32_t get_unaligned_le32(const void *p)
-{
- return __get_unaligned_le32((const uint8_t *)p);
+ *p++ = val;
+ *p++ = val >> 8;
}
-static inline uint64_t get_unaligned_le64(const void *p)
+static inline void put_unaligned_le32(uint32_t val, void *_p)
{
- return __get_unaligned_le64((const uint8_t *)p);
-}
+ uint8_t *p = _p;
-static inline void put_unaligned_le16(uint16_t val, void *p)
-{
- __put_unaligned_le16(val, p);
+ put_unaligned_le16(val, p);
+ put_unaligned_le16(val >> 16, p + 2);
}
-static inline void put_unaligned_le32(uint32_t val, void *p)
+static inline void put_unaligned_le64(uint64_t val, void *_p)
{
- __put_unaligned_le32(val, p);
-}
+ uint8_t *p = _p;
-static inline void put_unaligned_le64(uint64_t val, void *p)
-{
- __put_unaligned_le64(val, p);
+ put_unaligned_le32(val, p);
+ put_unaligned_le32(val >> 32, p + 4);
}
#endif /* _TOOLS_LE_BYTESHIFT_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 01/10] tools: Remove double-underscore symbols from user space byteshift functions
2014-06-10 23:13 ` [PATCH RFC 01/10] tools: Remove double-underscore symbols from user space byteshift functions H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
0 siblings, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
We should not use double-underscore (or underscore-capital) symbols in
arbitrary user space code, and these include files are specifically
used for user space compilation. Furthermore, the indirection is
completely unnecessary in this case.
Also, reorder the littleendian put macros to allow the compiler to
generate better code on some architectures (stores in sequence.)
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/be_byteshift.h | 62 ++++++++++++++------------------------
tools/include/tools/le_byteshift.h | 62 ++++++++++++++------------------------
2 files changed, 44 insertions(+), 80 deletions(-)
diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h
index 84c17d836578..9850c7df2667 100644
--- a/tools/include/tools/be_byteshift.h
+++ b/tools/include/tools/be_byteshift.h
@@ -3,68 +3,50 @@
#include <stdint.h>
-static inline uint16_t __get_unaligned_be16(const uint8_t *p)
+static inline uint16_t get_unaligned_be16(const void *_p)
{
- return p[0] << 8 | p[1];
-}
+ const uint8_t *p = _p;
-static inline uint32_t __get_unaligned_be32(const uint8_t *p)
-{
- return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+ return p[0] << 8 | p[1];
}
-static inline uint64_t __get_unaligned_be64(const uint8_t *p)
+static inline uint32_t get_unaligned_be32(const void *_p)
{
- return (uint64_t)__get_unaligned_be32(p) << 32 |
- __get_unaligned_be32(p + 4);
-}
+ const uint8_t *p = _p;
-static inline void __put_unaligned_be16(uint16_t val, uint8_t *p)
-{
- *p++ = val >> 8;
- *p++ = val;
+ return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
}
-static inline void __put_unaligned_be32(uint32_t val, uint8_t *p)
+static inline uint64_t get_unaligned_be64(const void *_p)
{
- __put_unaligned_be16(val >> 16, p);
- __put_unaligned_be16(val, p + 2);
-}
+ const uint8_t *p = _p;
-static inline void __put_unaligned_be64(uint64_t val, uint8_t *p)
-{
- __put_unaligned_be32(val >> 32, p);
- __put_unaligned_be32(val, p + 4);
+ return (uint64_t)get_unaligned_be32(p) << 32 |
+ get_unaligned_be32(p + 4);
}
-static inline uint16_t get_unaligned_be16(const void *p)
+static inline void put_unaligned_be16(uint16_t val, void *_p)
{
- return __get_unaligned_be16((const uint8_t *)p);
-}
+ uint8_t *p = _p;
-static inline uint32_t get_unaligned_be32(const void *p)
-{
- return __get_unaligned_be32((const uint8_t *)p);
+ *p++ = val >> 8;
+ *p++ = val;
}
-static inline uint64_t get_unaligned_be64(const void *p)
+static inline void put_unaligned_be32(uint32_t val, void *_p)
{
- return __get_unaligned_be64((const uint8_t *)p);
-}
+ uint8_t *p = _p;
-static inline void put_unaligned_be16(uint16_t val, void *p)
-{
- __put_unaligned_be16(val, p);
+ put_unaligned_be16(val >> 16, p);
+ put_unaligned_be16(val, p + 2);
}
-static inline void put_unaligned_be32(uint32_t val, void *p)
+static inline void put_unaligned_be64(uint64_t val, void *_p)
{
- __put_unaligned_be32(val, p);
-}
+ uint8_t *p = _p;
-static inline void put_unaligned_be64(uint64_t val, void *p)
-{
- __put_unaligned_be64(val, p);
+ put_unaligned_be32(val >> 32, p);
+ put_unaligned_be32(val, p + 4);
}
#endif /* _TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h
index 8fe9f2488ec7..819ba186ede5 100644
--- a/tools/include/tools/le_byteshift.h
+++ b/tools/include/tools/le_byteshift.h
@@ -3,68 +3,50 @@
#include <stdint.h>
-static inline uint16_t __get_unaligned_le16(const uint8_t *p)
+static inline uint16_t get_unaligned_le16(const void *_p)
{
- return p[0] | p[1] << 8;
-}
+ const uint8_t *p = _p;
-static inline uint32_t __get_unaligned_le32(const uint8_t *p)
-{
- return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
+ return p[0] | p[1] << 8;
}
-static inline uint64_t __get_unaligned_le64(const uint8_t *p)
+static inline uint32_t get_unaligned_le32(const void *_p)
{
- return (uint64_t)__get_unaligned_le32(p + 4) << 32 |
- __get_unaligned_le32(p);
-}
+ const uint8_t *p = _p;
-static inline void __put_unaligned_le16(uint16_t val, uint8_t *p)
-{
- *p++ = val;
- *p++ = val >> 8;
+ return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
}
-static inline void __put_unaligned_le32(uint32_t val, uint8_t *p)
+static inline uint64_t get_unaligned_le64(const void *_p)
{
- __put_unaligned_le16(val >> 16, p + 2);
- __put_unaligned_le16(val, p);
-}
+ const uint8_t *p = _p;
-static inline void __put_unaligned_le64(uint64_t val, uint8_t *p)
-{
- __put_unaligned_le32(val >> 32, p + 4);
- __put_unaligned_le32(val, p);
+ return (uint64_t)get_unaligned_le32(p + 4) << 32 |
+ get_unaligned_le32(p);
}
-static inline uint16_t get_unaligned_le16(const void *p)
+static inline void put_unaligned_le16(uint16_t val, void *_p)
{
- return __get_unaligned_le16((const uint8_t *)p);
-}
+ uint8_t *p = _p;
-static inline uint32_t get_unaligned_le32(const void *p)
-{
- return __get_unaligned_le32((const uint8_t *)p);
+ *p++ = val;
+ *p++ = val >> 8;
}
-static inline uint64_t get_unaligned_le64(const void *p)
+static inline void put_unaligned_le32(uint32_t val, void *_p)
{
- return __get_unaligned_le64((const uint8_t *)p);
-}
+ uint8_t *p = _p;
-static inline void put_unaligned_le16(uint16_t val, void *p)
-{
- __put_unaligned_le16(val, p);
+ put_unaligned_le16(val, p);
+ put_unaligned_le16(val >> 16, p + 2);
}
-static inline void put_unaligned_le32(uint32_t val, void *p)
+static inline void put_unaligned_le64(uint64_t val, void *_p)
{
- __put_unaligned_le32(val, p);
-}
+ uint8_t *p = _p;
-static inline void put_unaligned_le64(uint64_t val, void *p)
-{
- __put_unaligned_le64(val, p);
+ put_unaligned_le32(val, p);
+ put_unaligned_le32(val >> 32, p + 4);
}
#endif /* _TOOLS_LE_BYTESHIFT_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 02/10] tools: Create <tools/unaligned.h> and an unaligned subdirectory
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` [PATCH RFC 01/10] tools: Remove double-underscore symbols from user space byteshift functions H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access H. Peter Anvin
` (8 subsequent siblings)
11 siblings, 1 reply; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Create <tools/unaligned.h> and create an unaligned subdirectory for
specific implementations -- currently including the existing
be_byteshift.h and le_byteshift.h.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
arch/x86/boot/compressed/mkpiggy.c | 2 +-
arch/x86/boot/tools/build.c | 2 +-
arch/x86/tools/relocs.h | 2 +-
scripts/sortextable.c | 3 +-
tools/include/tools/be_byteshift.h | 52 ----------------------------
tools/include/tools/le_byteshift.h | 52 ----------------------------
tools/include/tools/unaligned.h | 2 ++
tools/include/tools/unaligned/be_byteshift.h | 52 ++++++++++++++++++++++++++++
tools/include/tools/unaligned/le_byteshift.h | 52 ++++++++++++++++++++++++++++
tools/usb/ffs-test.c | 2 +-
10 files changed, 111 insertions(+), 110 deletions(-)
delete mode 100644 tools/include/tools/be_byteshift.h
delete mode 100644 tools/include/tools/le_byteshift.h
create mode 100644 tools/include/tools/unaligned.h
create mode 100644 tools/include/tools/unaligned/be_byteshift.h
create mode 100644 tools/include/tools/unaligned/le_byteshift.h
diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index b669ab65bf6c..dc009d80dd34 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -29,7 +29,7 @@
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
-#include <tools/le_byteshift.h>
+#include <tools/unaligned.h>
int main(int argc, char *argv[])
{
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index 1a2f2121cada..010892234f94 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -33,7 +33,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
-#include <tools/le_byteshift.h>
+#include <tools/unaligned.h>
typedef unsigned char u8;
typedef unsigned short u16;
diff --git a/arch/x86/tools/relocs.h b/arch/x86/tools/relocs.h
index f59590645b68..69ae4d2b121c 100644
--- a/arch/x86/tools/relocs.h
+++ b/arch/x86/tools/relocs.h
@@ -14,7 +14,7 @@
#define USE_BSD
#include <endian.h>
#include <regex.h>
-#include <tools/le_byteshift.h>
+#include <tools/unaligned.h>
void die(char *fmt, ...);
diff --git a/scripts/sortextable.c b/scripts/sortextable.c
index cc49062acdee..a17a7dbd8dce 100644
--- a/scripts/sortextable.c
+++ b/scripts/sortextable.c
@@ -28,8 +28,7 @@
#include <string.h>
#include <unistd.h>
-#include <tools/be_byteshift.h>
-#include <tools/le_byteshift.h>
+#include <tools/unaligned.h>
#ifndef EM_ARCOMPACT
#define EM_ARCOMPACT 93
diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h
deleted file mode 100644
index 9850c7df2667..000000000000
--- a/tools/include/tools/be_byteshift.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#ifndef _TOOLS_BE_BYTESHIFT_H
-#define _TOOLS_BE_BYTESHIFT_H
-
-#include <stdint.h>
-
-static inline uint16_t get_unaligned_be16(const void *_p)
-{
- const uint8_t *p = _p;
-
- return p[0] << 8 | p[1];
-}
-
-static inline uint32_t get_unaligned_be32(const void *_p)
-{
- const uint8_t *p = _p;
-
- return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
-}
-
-static inline uint64_t get_unaligned_be64(const void *_p)
-{
- const uint8_t *p = _p;
-
- return (uint64_t)get_unaligned_be32(p) << 32 |
- get_unaligned_be32(p + 4);
-}
-
-static inline void put_unaligned_be16(uint16_t val, void *_p)
-{
- uint8_t *p = _p;
-
- *p++ = val >> 8;
- *p++ = val;
-}
-
-static inline void put_unaligned_be32(uint32_t val, void *_p)
-{
- uint8_t *p = _p;
-
- put_unaligned_be16(val >> 16, p);
- put_unaligned_be16(val, p + 2);
-}
-
-static inline void put_unaligned_be64(uint64_t val, void *_p)
-{
- uint8_t *p = _p;
-
- put_unaligned_be32(val >> 32, p);
- put_unaligned_be32(val, p + 4);
-}
-
-#endif /* _TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h
deleted file mode 100644
index 819ba186ede5..000000000000
--- a/tools/include/tools/le_byteshift.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#ifndef _TOOLS_LE_BYTESHIFT_H
-#define _TOOLS_LE_BYTESHIFT_H
-
-#include <stdint.h>
-
-static inline uint16_t get_unaligned_le16(const void *_p)
-{
- const uint8_t *p = _p;
-
- return p[0] | p[1] << 8;
-}
-
-static inline uint32_t get_unaligned_le32(const void *_p)
-{
- const uint8_t *p = _p;
-
- return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
-}
-
-static inline uint64_t get_unaligned_le64(const void *_p)
-{
- const uint8_t *p = _p;
-
- return (uint64_t)get_unaligned_le32(p + 4) << 32 |
- get_unaligned_le32(p);
-}
-
-static inline void put_unaligned_le16(uint16_t val, void *_p)
-{
- uint8_t *p = _p;
-
- *p++ = val;
- *p++ = val >> 8;
-}
-
-static inline void put_unaligned_le32(uint32_t val, void *_p)
-{
- uint8_t *p = _p;
-
- put_unaligned_le16(val, p);
- put_unaligned_le16(val >> 16, p + 2);
-}
-
-static inline void put_unaligned_le64(uint64_t val, void *_p)
-{
- uint8_t *p = _p;
-
- put_unaligned_le32(val, p);
- put_unaligned_le32(val >> 32, p + 4);
-}
-
-#endif /* _TOOLS_LE_BYTESHIFT_H */
diff --git a/tools/include/tools/unaligned.h b/tools/include/tools/unaligned.h
new file mode 100644
index 000000000000..f89c089b6148
--- /dev/null
+++ b/tools/include/tools/unaligned.h
@@ -0,0 +1,2 @@
+#include <tools/unaligned/le_byteshift.h>
+#include <tools/unaligned/be_byteshift.h>
diff --git a/tools/include/tools/unaligned/be_byteshift.h b/tools/include/tools/unaligned/be_byteshift.h
new file mode 100644
index 000000000000..9850c7df2667
--- /dev/null
+++ b/tools/include/tools/unaligned/be_byteshift.h
@@ -0,0 +1,52 @@
+#ifndef _TOOLS_BE_BYTESHIFT_H
+#define _TOOLS_BE_BYTESHIFT_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_be16(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return p[0] << 8 | p[1];
+}
+
+static inline uint32_t get_unaligned_be32(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+}
+
+static inline uint64_t get_unaligned_be64(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return (uint64_t)get_unaligned_be32(p) << 32 |
+ get_unaligned_be32(p + 4);
+}
+
+static inline void put_unaligned_be16(uint16_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ *p++ = val >> 8;
+ *p++ = val;
+}
+
+static inline void put_unaligned_be32(uint32_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ put_unaligned_be16(val >> 16, p);
+ put_unaligned_be16(val, p + 2);
+}
+
+static inline void put_unaligned_be64(uint64_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ put_unaligned_be32(val >> 32, p);
+ put_unaligned_be32(val, p + 4);
+}
+
+#endif /* _TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/unaligned/le_byteshift.h b/tools/include/tools/unaligned/le_byteshift.h
new file mode 100644
index 000000000000..819ba186ede5
--- /dev/null
+++ b/tools/include/tools/unaligned/le_byteshift.h
@@ -0,0 +1,52 @@
+#ifndef _TOOLS_LE_BYTESHIFT_H
+#define _TOOLS_LE_BYTESHIFT_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_le16(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return p[0] | p[1] << 8;
+}
+
+static inline uint32_t get_unaligned_le32(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
+}
+
+static inline uint64_t get_unaligned_le64(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return (uint64_t)get_unaligned_le32(p + 4) << 32 |
+ get_unaligned_le32(p);
+}
+
+static inline void put_unaligned_le16(uint16_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ *p++ = val;
+ *p++ = val >> 8;
+}
+
+static inline void put_unaligned_le32(uint32_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ put_unaligned_le16(val, p);
+ put_unaligned_le16(val >> 16, p + 2);
+}
+
+static inline void put_unaligned_le64(uint64_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ put_unaligned_le32(val, p);
+ put_unaligned_le32(val >> 32, p + 4);
+}
+
+#endif /* _TOOLS_LE_BYTESHIFT_H */
diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c
index fe1e66b6ef40..39695d18b3e7 100644
--- a/tools/usb/ffs-test.c
+++ b/tools/usb/ffs-test.c
@@ -36,7 +36,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
-#include <tools/le_byteshift.h>
+#include <tools/unaligned.h>
#include "../../include/uapi/linux/usb/functionfs.h"
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 02/10] tools: Create <tools/unaligned.h> and an unaligned subdirectory
2014-06-10 23:13 ` [PATCH RFC 02/10] tools: Create <tools/unaligned.h> and an unaligned subdirectory H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
0 siblings, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Create <tools/unaligned.h> and create an unaligned subdirectory for
specific implementations -- currently including the existing
be_byteshift.h and le_byteshift.h.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
arch/x86/boot/compressed/mkpiggy.c | 2 +-
arch/x86/boot/tools/build.c | 2 +-
arch/x86/tools/relocs.h | 2 +-
scripts/sortextable.c | 3 +-
tools/include/tools/be_byteshift.h | 52 ----------------------------
tools/include/tools/le_byteshift.h | 52 ----------------------------
tools/include/tools/unaligned.h | 2 ++
tools/include/tools/unaligned/be_byteshift.h | 52 ++++++++++++++++++++++++++++
tools/include/tools/unaligned/le_byteshift.h | 52 ++++++++++++++++++++++++++++
tools/usb/ffs-test.c | 2 +-
10 files changed, 111 insertions(+), 110 deletions(-)
delete mode 100644 tools/include/tools/be_byteshift.h
delete mode 100644 tools/include/tools/le_byteshift.h
create mode 100644 tools/include/tools/unaligned.h
create mode 100644 tools/include/tools/unaligned/be_byteshift.h
create mode 100644 tools/include/tools/unaligned/le_byteshift.h
diff --git a/arch/x86/boot/compressed/mkpiggy.c b/arch/x86/boot/compressed/mkpiggy.c
index b669ab65bf6c..dc009d80dd34 100644
--- a/arch/x86/boot/compressed/mkpiggy.c
+++ b/arch/x86/boot/compressed/mkpiggy.c
@@ -29,7 +29,7 @@
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
-#include <tools/le_byteshift.h>
+#include <tools/unaligned.h>
int main(int argc, char *argv[])
{
diff --git a/arch/x86/boot/tools/build.c b/arch/x86/boot/tools/build.c
index 1a2f2121cada..010892234f94 100644
--- a/arch/x86/boot/tools/build.c
+++ b/arch/x86/boot/tools/build.c
@@ -33,7 +33,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
-#include <tools/le_byteshift.h>
+#include <tools/unaligned.h>
typedef unsigned char u8;
typedef unsigned short u16;
diff --git a/arch/x86/tools/relocs.h b/arch/x86/tools/relocs.h
index f59590645b68..69ae4d2b121c 100644
--- a/arch/x86/tools/relocs.h
+++ b/arch/x86/tools/relocs.h
@@ -14,7 +14,7 @@
#define USE_BSD
#include <endian.h>
#include <regex.h>
-#include <tools/le_byteshift.h>
+#include <tools/unaligned.h>
void die(char *fmt, ...);
diff --git a/scripts/sortextable.c b/scripts/sortextable.c
index cc49062acdee..a17a7dbd8dce 100644
--- a/scripts/sortextable.c
+++ b/scripts/sortextable.c
@@ -28,8 +28,7 @@
#include <string.h>
#include <unistd.h>
-#include <tools/be_byteshift.h>
-#include <tools/le_byteshift.h>
+#include <tools/unaligned.h>
#ifndef EM_ARCOMPACT
#define EM_ARCOMPACT 93
diff --git a/tools/include/tools/be_byteshift.h b/tools/include/tools/be_byteshift.h
deleted file mode 100644
index 9850c7df2667..000000000000
--- a/tools/include/tools/be_byteshift.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#ifndef _TOOLS_BE_BYTESHIFT_H
-#define _TOOLS_BE_BYTESHIFT_H
-
-#include <stdint.h>
-
-static inline uint16_t get_unaligned_be16(const void *_p)
-{
- const uint8_t *p = _p;
-
- return p[0] << 8 | p[1];
-}
-
-static inline uint32_t get_unaligned_be32(const void *_p)
-{
- const uint8_t *p = _p;
-
- return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
-}
-
-static inline uint64_t get_unaligned_be64(const void *_p)
-{
- const uint8_t *p = _p;
-
- return (uint64_t)get_unaligned_be32(p) << 32 |
- get_unaligned_be32(p + 4);
-}
-
-static inline void put_unaligned_be16(uint16_t val, void *_p)
-{
- uint8_t *p = _p;
-
- *p++ = val >> 8;
- *p++ = val;
-}
-
-static inline void put_unaligned_be32(uint32_t val, void *_p)
-{
- uint8_t *p = _p;
-
- put_unaligned_be16(val >> 16, p);
- put_unaligned_be16(val, p + 2);
-}
-
-static inline void put_unaligned_be64(uint64_t val, void *_p)
-{
- uint8_t *p = _p;
-
- put_unaligned_be32(val >> 32, p);
- put_unaligned_be32(val, p + 4);
-}
-
-#endif /* _TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/le_byteshift.h b/tools/include/tools/le_byteshift.h
deleted file mode 100644
index 819ba186ede5..000000000000
--- a/tools/include/tools/le_byteshift.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#ifndef _TOOLS_LE_BYTESHIFT_H
-#define _TOOLS_LE_BYTESHIFT_H
-
-#include <stdint.h>
-
-static inline uint16_t get_unaligned_le16(const void *_p)
-{
- const uint8_t *p = _p;
-
- return p[0] | p[1] << 8;
-}
-
-static inline uint32_t get_unaligned_le32(const void *_p)
-{
- const uint8_t *p = _p;
-
- return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
-}
-
-static inline uint64_t get_unaligned_le64(const void *_p)
-{
- const uint8_t *p = _p;
-
- return (uint64_t)get_unaligned_le32(p + 4) << 32 |
- get_unaligned_le32(p);
-}
-
-static inline void put_unaligned_le16(uint16_t val, void *_p)
-{
- uint8_t *p = _p;
-
- *p++ = val;
- *p++ = val >> 8;
-}
-
-static inline void put_unaligned_le32(uint32_t val, void *_p)
-{
- uint8_t *p = _p;
-
- put_unaligned_le16(val, p);
- put_unaligned_le16(val >> 16, p + 2);
-}
-
-static inline void put_unaligned_le64(uint64_t val, void *_p)
-{
- uint8_t *p = _p;
-
- put_unaligned_le32(val, p);
- put_unaligned_le32(val >> 32, p + 4);
-}
-
-#endif /* _TOOLS_LE_BYTESHIFT_H */
diff --git a/tools/include/tools/unaligned.h b/tools/include/tools/unaligned.h
new file mode 100644
index 000000000000..f89c089b6148
--- /dev/null
+++ b/tools/include/tools/unaligned.h
@@ -0,0 +1,2 @@
+#include <tools/unaligned/le_byteshift.h>
+#include <tools/unaligned/be_byteshift.h>
diff --git a/tools/include/tools/unaligned/be_byteshift.h b/tools/include/tools/unaligned/be_byteshift.h
new file mode 100644
index 000000000000..9850c7df2667
--- /dev/null
+++ b/tools/include/tools/unaligned/be_byteshift.h
@@ -0,0 +1,52 @@
+#ifndef _TOOLS_BE_BYTESHIFT_H
+#define _TOOLS_BE_BYTESHIFT_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_be16(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return p[0] << 8 | p[1];
+}
+
+static inline uint32_t get_unaligned_be32(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
+}
+
+static inline uint64_t get_unaligned_be64(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return (uint64_t)get_unaligned_be32(p) << 32 |
+ get_unaligned_be32(p + 4);
+}
+
+static inline void put_unaligned_be16(uint16_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ *p++ = val >> 8;
+ *p++ = val;
+}
+
+static inline void put_unaligned_be32(uint32_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ put_unaligned_be16(val >> 16, p);
+ put_unaligned_be16(val, p + 2);
+}
+
+static inline void put_unaligned_be64(uint64_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ put_unaligned_be32(val >> 32, p);
+ put_unaligned_be32(val, p + 4);
+}
+
+#endif /* _TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/unaligned/le_byteshift.h b/tools/include/tools/unaligned/le_byteshift.h
new file mode 100644
index 000000000000..819ba186ede5
--- /dev/null
+++ b/tools/include/tools/unaligned/le_byteshift.h
@@ -0,0 +1,52 @@
+#ifndef _TOOLS_LE_BYTESHIFT_H
+#define _TOOLS_LE_BYTESHIFT_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_le16(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return p[0] | p[1] << 8;
+}
+
+static inline uint32_t get_unaligned_le32(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24;
+}
+
+static inline uint64_t get_unaligned_le64(const void *_p)
+{
+ const uint8_t *p = _p;
+
+ return (uint64_t)get_unaligned_le32(p + 4) << 32 |
+ get_unaligned_le32(p);
+}
+
+static inline void put_unaligned_le16(uint16_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ *p++ = val;
+ *p++ = val >> 8;
+}
+
+static inline void put_unaligned_le32(uint32_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ put_unaligned_le16(val, p);
+ put_unaligned_le16(val >> 16, p + 2);
+}
+
+static inline void put_unaligned_le64(uint64_t val, void *_p)
+{
+ uint8_t *p = _p;
+
+ put_unaligned_le32(val, p);
+ put_unaligned_le32(val >> 32, p + 4);
+}
+
+#endif /* _TOOLS_LE_BYTESHIFT_H */
diff --git a/tools/usb/ffs-test.c b/tools/usb/ffs-test.c
index fe1e66b6ef40..39695d18b3e7 100644
--- a/tools/usb/ffs-test.c
+++ b/tools/usb/ffs-test.c
@@ -36,7 +36,7 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
-#include <tools/le_byteshift.h>
+#include <tools/unaligned.h>
#include "../../include/uapi/linux/usb/functionfs.h"
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
` (2 preceding siblings ...)
2014-06-10 23:13 ` [PATCH RFC 02/10] tools: Create <tools/unaligned.h> and an unaligned subdirectory H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:25 ` Andy Lutomirski
2014-06-10 23:13 ` [PATCH RFC 04/10] tools: Add packed struct method for unaligned references H. Peter Anvin
` (7 subsequent siblings)
11 siblings, 2 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
For architectures which handle unaligned references transparently.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned/be_direct.h | 48 +++++++++++++++++++++++++++++++
tools/include/tools/unaligned/le_direct.h | 48 +++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+)
create mode 100644 tools/include/tools/unaligned/be_direct.h
create mode 100644 tools/include/tools/unaligned/le_direct.h
diff --git a/tools/include/tools/unaligned/be_direct.h b/tools/include/tools/unaligned/be_direct.h
new file mode 100644
index 000000000000..10a9b8229003
--- /dev/null
+++ b/tools/include/tools/unaligned/be_direct.h
@@ -0,0 +1,48 @@
+#ifndef _TOOLS_BE_DIRECT_H
+#define _TOOLS_BE_DIRECT_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_be16(const void *_p)
+{
+ const uint16_t *p = _p;
+
+ return *p;
+}
+
+static inline uint32_t get_unaligned_be32(const void *_p)
+{
+ const uint32_t *p = _p;
+
+ return *p;
+}
+
+static inline uint64_t get_unaligned_be64(const void *_p)
+{
+ const uint64_t *p = _p;
+
+ return *p;
+}
+
+static inline void put_unaligned_be16(uint16_t val, void *_p)
+{
+ uint16_t *p = _p;
+
+ *p = val;
+}
+
+static inline void put_unaligned_be32(uint32_t val, void *_p)
+{
+ uint32_t *p = _p;
+
+ *p = val;
+}
+
+static inline void put_unaligned_be64(uint64_t val, void *_p)
+{
+ uint64_t *p = _p;
+
+ *p = val;
+}
+
+#endif /* _TOOLS_BE_DIRECT_H */
diff --git a/tools/include/tools/unaligned/le_direct.h b/tools/include/tools/unaligned/le_direct.h
new file mode 100644
index 000000000000..6353dfd04fd7
--- /dev/null
+++ b/tools/include/tools/unaligned/le_direct.h
@@ -0,0 +1,48 @@
+#ifndef _TOOLS_LE_DIRECT_H
+#define _TOOLS_LE_DIRECT_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_le16(const void *_p)
+{
+ const uint16_t *p = _p;
+
+ return *p;
+}
+
+static inline uint32_t get_unaligned_le32(const void *_p)
+{
+ const uint32_t *p = _p;
+
+ return *p;
+}
+
+static inline uint64_t get_unaligned_le64(const void *_p)
+{
+ const uint64_t *p = _p;
+
+ return *p;
+}
+
+static inline void put_unaligned_le16(uint16_t val, void *_p)
+{
+ uint16_t *p = _p;
+
+ *p = val;
+}
+
+static inline void put_unaligned_le32(uint32_t val, void *_p)
+{
+ uint32_t *p = _p;
+
+ *p = val;
+}
+
+static inline void put_unaligned_le64(uint64_t val, void *_p)
+{
+ uint64_t *p = _p;
+
+ *p = val;
+}
+
+#endif /* _TOOLS_LE_DIRECT_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access
2014-06-10 23:13 ` [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:25 ` Andy Lutomirski
1 sibling, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
For architectures which handle unaligned references transparently.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned/be_direct.h | 48 +++++++++++++++++++++++++++++++
tools/include/tools/unaligned/le_direct.h | 48 +++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+)
create mode 100644 tools/include/tools/unaligned/be_direct.h
create mode 100644 tools/include/tools/unaligned/le_direct.h
diff --git a/tools/include/tools/unaligned/be_direct.h b/tools/include/tools/unaligned/be_direct.h
new file mode 100644
index 000000000000..10a9b8229003
--- /dev/null
+++ b/tools/include/tools/unaligned/be_direct.h
@@ -0,0 +1,48 @@
+#ifndef _TOOLS_BE_DIRECT_H
+#define _TOOLS_BE_DIRECT_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_be16(const void *_p)
+{
+ const uint16_t *p = _p;
+
+ return *p;
+}
+
+static inline uint32_t get_unaligned_be32(const void *_p)
+{
+ const uint32_t *p = _p;
+
+ return *p;
+}
+
+static inline uint64_t get_unaligned_be64(const void *_p)
+{
+ const uint64_t *p = _p;
+
+ return *p;
+}
+
+static inline void put_unaligned_be16(uint16_t val, void *_p)
+{
+ uint16_t *p = _p;
+
+ *p = val;
+}
+
+static inline void put_unaligned_be32(uint32_t val, void *_p)
+{
+ uint32_t *p = _p;
+
+ *p = val;
+}
+
+static inline void put_unaligned_be64(uint64_t val, void *_p)
+{
+ uint64_t *p = _p;
+
+ *p = val;
+}
+
+#endif /* _TOOLS_BE_DIRECT_H */
diff --git a/tools/include/tools/unaligned/le_direct.h b/tools/include/tools/unaligned/le_direct.h
new file mode 100644
index 000000000000..6353dfd04fd7
--- /dev/null
+++ b/tools/include/tools/unaligned/le_direct.h
@@ -0,0 +1,48 @@
+#ifndef _TOOLS_LE_DIRECT_H
+#define _TOOLS_LE_DIRECT_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_le16(const void *_p)
+{
+ const uint16_t *p = _p;
+
+ return *p;
+}
+
+static inline uint32_t get_unaligned_le32(const void *_p)
+{
+ const uint32_t *p = _p;
+
+ return *p;
+}
+
+static inline uint64_t get_unaligned_le64(const void *_p)
+{
+ const uint64_t *p = _p;
+
+ return *p;
+}
+
+static inline void put_unaligned_le16(uint16_t val, void *_p)
+{
+ uint16_t *p = _p;
+
+ *p = val;
+}
+
+static inline void put_unaligned_le32(uint32_t val, void *_p)
+{
+ uint32_t *p = _p;
+
+ *p = val;
+}
+
+static inline void put_unaligned_le64(uint64_t val, void *_p)
+{
+ uint64_t *p = _p;
+
+ *p = val;
+}
+
+#endif /* _TOOLS_LE_DIRECT_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access
2014-06-10 23:13 ` [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
@ 2014-06-10 23:25 ` Andy Lutomirski
2014-06-10 23:30 ` H. Peter Anvin
1 sibling, 1 reply; 33+ messages in thread
From: Andy Lutomirski @ 2014-06-10 23:25 UTC (permalink / raw)
To: H. Peter Anvin
Cc: Sam Ravnborg, linux-kernel@vger.kernel.org,
linux-kbuild@vger.kernel.org, linux-arch, Andrew Morton,
Ingo Molnar, Thomas Gleixner
On Tue, Jun 10, 2014 at 4:13 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> For architectures which handle unaligned references transparently.
Shouldn't these depend on host endianness?
--Andy
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access
2014-06-10 23:25 ` Andy Lutomirski
@ 2014-06-10 23:30 ` H. Peter Anvin
2014-06-10 23:30 ` H. Peter Anvin
2014-06-10 23:33 ` Andy Lutomirski
0 siblings, 2 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:30 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Sam Ravnborg, linux-kernel@vger.kernel.org,
linux-kbuild@vger.kernel.org, linux-arch, Andrew Morton,
Ingo Molnar, Thomas Gleixner
On 06/10/2014 04:25 PM, Andy Lutomirski wrote:
> On Tue, Jun 10, 2014 at 4:13 PM, H. Peter Anvin <hpa@zytor.com> wrote:
>> For architectures which handle unaligned references transparently.
>
> Shouldn't these depend on host endianness?
>
See further down the series for how these end up being invoked.
-hpa
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access
2014-06-10 23:30 ` H. Peter Anvin
@ 2014-06-10 23:30 ` H. Peter Anvin
2014-06-10 23:33 ` Andy Lutomirski
1 sibling, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:30 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Sam Ravnborg, linux-kernel@vger.kernel.org,
linux-kbuild@vger.kernel.org, linux-arch, Andrew Morton,
Ingo Molnar, Thomas Gleixner
On 06/10/2014 04:25 PM, Andy Lutomirski wrote:
> On Tue, Jun 10, 2014 at 4:13 PM, H. Peter Anvin <hpa@zytor.com> wrote:
>> For architectures which handle unaligned references transparently.
>
> Shouldn't these depend on host endianness?
>
See further down the series for how these end up being invoked.
-hpa
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access
2014-06-10 23:30 ` H. Peter Anvin
2014-06-10 23:30 ` H. Peter Anvin
@ 2014-06-10 23:33 ` Andy Lutomirski
2014-06-10 23:33 ` Andy Lutomirski
2014-06-10 23:41 ` H. Peter Anvin
1 sibling, 2 replies; 33+ messages in thread
From: Andy Lutomirski @ 2014-06-10 23:33 UTC (permalink / raw)
To: H. Peter Anvin
Cc: Sam Ravnborg, linux-kernel@vger.kernel.org,
linux-kbuild@vger.kernel.org, linux-arch, Andrew Morton,
Ingo Molnar, Thomas Gleixner
On Tue, Jun 10, 2014 at 4:30 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 06/10/2014 04:25 PM, Andy Lutomirski wrote:
>> On Tue, Jun 10, 2014 at 4:13 PM, H. Peter Anvin <hpa@zytor.com> wrote:
>>> For architectures which handle unaligned references transparently.
>>
>> Shouldn't these depend on host endianness?
>>
>
> See further down the series for how these end up being invoked.
>
Ah, sneaky.
Would it make sense to put a comment in this file (and similar files)
indicating that they must only be included on architectures of the
appropriate endianness?
--Andy
> -hpa
>
>
--
Andy Lutomirski
AMA Capital Management, LLC
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access
2014-06-10 23:33 ` Andy Lutomirski
@ 2014-06-10 23:33 ` Andy Lutomirski
2014-06-10 23:41 ` H. Peter Anvin
1 sibling, 0 replies; 33+ messages in thread
From: Andy Lutomirski @ 2014-06-10 23:33 UTC (permalink / raw)
To: H. Peter Anvin
Cc: Sam Ravnborg, linux-kernel@vger.kernel.org,
linux-kbuild@vger.kernel.org, linux-arch, Andrew Morton,
Ingo Molnar, Thomas Gleixner
On Tue, Jun 10, 2014 at 4:30 PM, H. Peter Anvin <hpa@zytor.com> wrote:
> On 06/10/2014 04:25 PM, Andy Lutomirski wrote:
>> On Tue, Jun 10, 2014 at 4:13 PM, H. Peter Anvin <hpa@zytor.com> wrote:
>>> For architectures which handle unaligned references transparently.
>>
>> Shouldn't these depend on host endianness?
>>
>
> See further down the series for how these end up being invoked.
>
Ah, sneaky.
Would it make sense to put a comment in this file (and similar files)
indicating that they must only be included on architectures of the
appropriate endianness?
--Andy
> -hpa
>
>
--
Andy Lutomirski
AMA Capital Management, LLC
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access
2014-06-10 23:33 ` Andy Lutomirski
2014-06-10 23:33 ` Andy Lutomirski
@ 2014-06-10 23:41 ` H. Peter Anvin
1 sibling, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:41 UTC (permalink / raw)
To: Andy Lutomirski
Cc: Sam Ravnborg, linux-kernel@vger.kernel.org,
linux-kbuild@vger.kernel.org, linux-arch, Andrew Morton,
Ingo Molnar, Thomas Gleixner
On 06/10/2014 04:33 PM, Andy Lutomirski wrote:
>
> Ah, sneaky.
>
> Would it make sense to put a comment in this file (and similar files)
> indicating that they must only be included on architectures of the
> appropriate endianness?
>
That might make sense, yes, although I don't think we do that for the
kernel variants.
-hpa
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH RFC 04/10] tools: Add packed struct method for unaligned references
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
` (3 preceding siblings ...)
2014-06-10 23:13 ` [PATCH RFC 03/10] tools: Add le_direct/be_direct methods for unaligned access H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` [PATCH RFC 05/10] tools: Add <endian.h> libc support " H. Peter Anvin
` (6 subsequent siblings)
11 siblings, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
gcc can generate code for unaligned references using a packed struct
on nearly all architectures.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned/be_struct.h | 60 +++++++++++++++++++++++++++++++
tools/include/tools/unaligned/le_struct.h | 60 +++++++++++++++++++++++++++++++
2 files changed, 120 insertions(+)
create mode 100644 tools/include/tools/unaligned/be_struct.h
create mode 100644 tools/include/tools/unaligned/le_struct.h
diff --git a/tools/include/tools/unaligned/be_struct.h b/tools/include/tools/unaligned/be_struct.h
new file mode 100644
index 000000000000..27b73bdf5a86
--- /dev/null
+++ b/tools/include/tools/unaligned/be_struct.h
@@ -0,0 +1,60 @@
+#ifndef _TOOLS_BE_STRUCT_H
+#define _TOOLS_BE_STRUCT_H
+
+#include <stdint.h>
+
+struct _packed_u16_struct {
+ uint16_t v;
+} __attribute__((packed));
+
+struct _packed_u32_struct {
+ uint32_t v;
+} __attribute__((packed));
+
+struct _packed_u64_struct {
+ uint64_t v;
+} __attribute__((packed));
+
+static inline uint16_t get_unaligned_be16(const void *_p)
+{
+ const struct _packed_u16_struct *p = _p;
+
+ return p->v;
+}
+
+static inline uint32_t get_unaligned_be32(const void *_p)
+{
+ const struct _packed_u32_struct *p = _p;
+
+ return p->v;
+}
+
+static inline uint64_t get_unaligned_be64(const void *_p)
+{
+ const struct _packed_u64_struct *p = _p;
+
+ return p->v;
+}
+
+static inline void put_unaligned_be16(uint16_t val, void *_p)
+{
+ struct _packed_u16_struct *p = _p;
+
+ p->v = val;
+}
+
+static inline void put_unaligned_be32(uint32_t val, void *_p)
+{
+ struct _packed_u32_struct *p = _p;
+
+ p->v = val;
+}
+
+static inline void put_unaligned_be64(uint64_t val, void *_p)
+{
+ struct _packed_u64_struct *p = _p;
+
+ p->v = val;
+}
+
+#endif /* _TOOLS_BE_STRUCT_H */
diff --git a/tools/include/tools/unaligned/le_struct.h b/tools/include/tools/unaligned/le_struct.h
new file mode 100644
index 000000000000..281b03b8f316
--- /dev/null
+++ b/tools/include/tools/unaligned/le_struct.h
@@ -0,0 +1,60 @@
+#ifndef _TOOLS_LE_STRUCT_H
+#define _TOOLS_LE_STRUCT_H
+
+#include <stdint.h>
+
+struct _packed_u16_struct {
+ uint16_t v;
+} __attribute__((packed));
+
+struct _packed_u32_struct {
+ uint32_t v;
+} __attribute__((packed));
+
+struct _packed_u64_struct {
+ uint64_t v;
+} __attribute__((packed));
+
+static inline uint16_t get_unaligned_le16(const void *_p)
+{
+ const struct _packed_u16_struct *p = _p;
+
+ return p->v;
+}
+
+static inline uint32_t get_unaligned_le32(const void *_p)
+{
+ const struct _packed_u32_struct *p = _p;
+
+ return p->v;
+}
+
+static inline uint64_t get_unaligned_le64(const void *_p)
+{
+ const struct _packed_u64_struct *p = _p;
+
+ return p->v;
+}
+
+static inline void put_unaligned_le16(uint16_t val, void *_p)
+{
+ struct _packed_u16_struct *p = _p;
+
+ p->v = val;
+}
+
+static inline void put_unaligned_le32(uint32_t val, void *_p)
+{
+ struct _packed_u32_struct *p = _p;
+
+ p->v = val;
+}
+
+static inline void put_unaligned_le64(uint64_t val, void *_p)
+{
+ struct _packed_u64_struct *p = _p;
+
+ p->v = val;
+}
+
+#endif /* _TOOLS_LE_STRUCT_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 05/10] tools: Add <endian.h> libc support for unaligned references
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
` (4 preceding siblings ...)
2014-06-10 23:13 ` [PATCH RFC 04/10] tools: Add packed struct method for unaligned references H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` [PATCH RFC 06/10] tools: Add gcc __builtin_bswap*() " H. Peter Anvin
` (5 subsequent siblings)
11 siblings, 1 reply; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Add support for the <endian.h> byteswap macros for unaligned
references.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned/be_endian.h | 40 +++++++++++++++++++++++++++++++
tools/include/tools/unaligned/le_endian.h | 40 +++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+)
create mode 100644 tools/include/tools/unaligned/be_endian.h
create mode 100644 tools/include/tools/unaligned/le_endian.h
diff --git a/tools/include/tools/unaligned/be_endian.h b/tools/include/tools/unaligned/be_endian.h
new file mode 100644
index 000000000000..4106c082855e
--- /dev/null
+++ b/tools/include/tools/unaligned/be_endian.h
@@ -0,0 +1,40 @@
+#ifndef _TOOLS_BE_ENDIAN_H
+#define _TOOLS_BE_ENDIAN_H
+
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE 1
+#endif
+#include <endian.h>
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_be16(const void *_p)
+{
+ return be16toh(get_unaligned_le16(_p));
+}
+
+static inline uint32_t get_unaligned_be32(const void *_p)
+{
+ return be32toh(get_unaligned_le32(_p));
+}
+
+static inline uint64_t get_unaligned_be64(const void *_p)
+{
+ return be64toh(get_unaligned_le64(_p));
+}
+
+static inline void put_unaligned_be16(uint16_t val, void *_p)
+{
+ put_unaligned_le16(htobe16(val), _p);
+}
+
+static inline void put_unaligned_be32(uint32_t val, void *_p)
+{
+ put_unaligned_le32(htobe32(val), _p);
+}
+
+static inline void put_unaligned_be64(uint64_t val, void *_p)
+{
+ put_unaligned_le64(htobe64(val), _p);
+}
+
+#endif /* _TOOLS_BE_ENDIAN_H */
diff --git a/tools/include/tools/unaligned/le_endian.h b/tools/include/tools/unaligned/le_endian.h
new file mode 100644
index 000000000000..0429f1b29250
--- /dev/null
+++ b/tools/include/tools/unaligned/le_endian.h
@@ -0,0 +1,40 @@
+#ifndef _TOOLS_LE_ENDIAN_H
+#define _TOOLS_LE_ENDIAN_H
+
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE 1
+#endif
+#include <endian.h>
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_le16(const void *_p)
+{
+ return le16toh(get_unaligned_be16(_p));
+}
+
+static inline uint32_t get_unaligned_le32(const void *_p)
+{
+ return le32toh(get_unaligned_be32(_p));
+}
+
+static inline uint64_t get_unaligned_le64(const void *_p)
+{
+ return le64toh(get_unaligned_be64(_p));
+}
+
+static inline void put_unaligned_le16(uint16_t val, void *_p)
+{
+ put_unaligned_be16(htole16(val), _p);
+}
+
+static inline void put_unaligned_le32(uint32_t val, void *_p)
+{
+ put_unaligned_be32(htole32(val), _p);
+}
+
+static inline void put_unaligned_le64(uint64_t val, void *_p)
+{
+ put_unaligned_be64(htole64(val), _p);
+}
+
+#endif /* _TOOLS_LE_ENDIAN_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 05/10] tools: Add <endian.h> libc support for unaligned references
2014-06-10 23:13 ` [PATCH RFC 05/10] tools: Add <endian.h> libc support " H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
0 siblings, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Add support for the <endian.h> byteswap macros for unaligned
references.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned/be_endian.h | 40 +++++++++++++++++++++++++++++++
tools/include/tools/unaligned/le_endian.h | 40 +++++++++++++++++++++++++++++++
2 files changed, 80 insertions(+)
create mode 100644 tools/include/tools/unaligned/be_endian.h
create mode 100644 tools/include/tools/unaligned/le_endian.h
diff --git a/tools/include/tools/unaligned/be_endian.h b/tools/include/tools/unaligned/be_endian.h
new file mode 100644
index 000000000000..4106c082855e
--- /dev/null
+++ b/tools/include/tools/unaligned/be_endian.h
@@ -0,0 +1,40 @@
+#ifndef _TOOLS_BE_ENDIAN_H
+#define _TOOLS_BE_ENDIAN_H
+
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE 1
+#endif
+#include <endian.h>
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_be16(const void *_p)
+{
+ return be16toh(get_unaligned_le16(_p));
+}
+
+static inline uint32_t get_unaligned_be32(const void *_p)
+{
+ return be32toh(get_unaligned_le32(_p));
+}
+
+static inline uint64_t get_unaligned_be64(const void *_p)
+{
+ return be64toh(get_unaligned_le64(_p));
+}
+
+static inline void put_unaligned_be16(uint16_t val, void *_p)
+{
+ put_unaligned_le16(htobe16(val), _p);
+}
+
+static inline void put_unaligned_be32(uint32_t val, void *_p)
+{
+ put_unaligned_le32(htobe32(val), _p);
+}
+
+static inline void put_unaligned_be64(uint64_t val, void *_p)
+{
+ put_unaligned_le64(htobe64(val), _p);
+}
+
+#endif /* _TOOLS_BE_ENDIAN_H */
diff --git a/tools/include/tools/unaligned/le_endian.h b/tools/include/tools/unaligned/le_endian.h
new file mode 100644
index 000000000000..0429f1b29250
--- /dev/null
+++ b/tools/include/tools/unaligned/le_endian.h
@@ -0,0 +1,40 @@
+#ifndef _TOOLS_LE_ENDIAN_H
+#define _TOOLS_LE_ENDIAN_H
+
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE 1
+#endif
+#include <endian.h>
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_le16(const void *_p)
+{
+ return le16toh(get_unaligned_be16(_p));
+}
+
+static inline uint32_t get_unaligned_le32(const void *_p)
+{
+ return le32toh(get_unaligned_be32(_p));
+}
+
+static inline uint64_t get_unaligned_le64(const void *_p)
+{
+ return le64toh(get_unaligned_be64(_p));
+}
+
+static inline void put_unaligned_le16(uint16_t val, void *_p)
+{
+ put_unaligned_be16(htole16(val), _p);
+}
+
+static inline void put_unaligned_le32(uint32_t val, void *_p)
+{
+ put_unaligned_be32(htole32(val), _p);
+}
+
+static inline void put_unaligned_le64(uint64_t val, void *_p)
+{
+ put_unaligned_be64(htole64(val), _p);
+}
+
+#endif /* _TOOLS_LE_ENDIAN_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 06/10] tools: Add gcc __builtin_bswap*() support for unaligned references
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
` (5 preceding siblings ...)
2014-06-10 23:13 ` [PATCH RFC 05/10] tools: Add <endian.h> libc support " H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` [PATCH RFC 07/10] tools: Remove leading underscores from header guards H. Peter Anvin
` (4 subsequent siblings)
11 siblings, 1 reply; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Add support for gcc __builtin_bswap*() for byteswapping unaligned
references.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned/be_bswap.h | 36 ++++++++++++++++++++++++++++++++
tools/include/tools/unaligned/le_bswap.h | 36 ++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
create mode 100644 tools/include/tools/unaligned/be_bswap.h
create mode 100644 tools/include/tools/unaligned/le_bswap.h
diff --git a/tools/include/tools/unaligned/be_bswap.h b/tools/include/tools/unaligned/be_bswap.h
new file mode 100644
index 000000000000..9e8d1e91fe0e
--- /dev/null
+++ b/tools/include/tools/unaligned/be_bswap.h
@@ -0,0 +1,36 @@
+#ifndef _TOOLS_BE_BSWAP_H
+#define _TOOLS_BE_BSWAP_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_be16(const void *_p)
+{
+ return __builtin_bswap16(get_unaligned_le16(_p));
+}
+
+static inline uint32_t get_unaligned_be32(const void *_p)
+{
+ return __builtin_bswap32(get_unaligned_le32(_p));
+}
+
+static inline uint64_t get_unaligned_be64(const void *_p)
+{
+ return __builtin_bswap64(get_unaligned_le64(_p));
+}
+
+static inline void put_unaligned_be16(uint16_t val, void *_p)
+{
+ put_unaligned_le16(__builtin_bswap16(val), _p);
+}
+
+static inline void put_unaligned_be32(uint32_t val, void *_p)
+{
+ put_unaligned_le32(__builtin_bswap32(val), _p);
+}
+
+static inline void put_unaligned_be64(uint64_t val, void *_p)
+{
+ put_unaligned_le64(__builtin_bswap64(val), _p);
+}
+
+#endif /* _TOOLS_BE_BSWAP_H */
diff --git a/tools/include/tools/unaligned/le_bswap.h b/tools/include/tools/unaligned/le_bswap.h
new file mode 100644
index 000000000000..9c70415fa782
--- /dev/null
+++ b/tools/include/tools/unaligned/le_bswap.h
@@ -0,0 +1,36 @@
+#ifndef _TOOLS_LE_BSWAP_H
+#define _TOOLS_LE_BSWAP_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_le16(const void *_p)
+{
+ return __builtin_bswap16(get_unaligned_be16(_p));
+}
+
+static inline uint32_t get_unaligned_le32(const void *_p)
+{
+ return __builtin_bswap32(get_unaligned_be32(_p));
+}
+
+static inline uint64_t get_unaligned_le64(const void *_p)
+{
+ return __builtin_bswap64(get_unaligned_be64(_p));
+}
+
+static inline void put_unaligned_le16(uint16_t val, void *_p)
+{
+ put_unaligned_be16(__builtin_bswap16(val), _p);
+}
+
+static inline void put_unaligned_le32(uint32_t val, void *_p)
+{
+ put_unaligned_be32(__builtin_bswap32(val), _p);
+}
+
+static inline void put_unaligned_le64(uint64_t val, void *_p)
+{
+ put_unaligned_be64(__builtin_bswap64(val), _p);
+}
+
+#endif /* _TOOLS_LE_BSWAP_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 06/10] tools: Add gcc __builtin_bswap*() support for unaligned references
2014-06-10 23:13 ` [PATCH RFC 06/10] tools: Add gcc __builtin_bswap*() " H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
0 siblings, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Add support for gcc __builtin_bswap*() for byteswapping unaligned
references.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned/be_bswap.h | 36 ++++++++++++++++++++++++++++++++
tools/include/tools/unaligned/le_bswap.h | 36 ++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
create mode 100644 tools/include/tools/unaligned/be_bswap.h
create mode 100644 tools/include/tools/unaligned/le_bswap.h
diff --git a/tools/include/tools/unaligned/be_bswap.h b/tools/include/tools/unaligned/be_bswap.h
new file mode 100644
index 000000000000..9e8d1e91fe0e
--- /dev/null
+++ b/tools/include/tools/unaligned/be_bswap.h
@@ -0,0 +1,36 @@
+#ifndef _TOOLS_BE_BSWAP_H
+#define _TOOLS_BE_BSWAP_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_be16(const void *_p)
+{
+ return __builtin_bswap16(get_unaligned_le16(_p));
+}
+
+static inline uint32_t get_unaligned_be32(const void *_p)
+{
+ return __builtin_bswap32(get_unaligned_le32(_p));
+}
+
+static inline uint64_t get_unaligned_be64(const void *_p)
+{
+ return __builtin_bswap64(get_unaligned_le64(_p));
+}
+
+static inline void put_unaligned_be16(uint16_t val, void *_p)
+{
+ put_unaligned_le16(__builtin_bswap16(val), _p);
+}
+
+static inline void put_unaligned_be32(uint32_t val, void *_p)
+{
+ put_unaligned_le32(__builtin_bswap32(val), _p);
+}
+
+static inline void put_unaligned_be64(uint64_t val, void *_p)
+{
+ put_unaligned_le64(__builtin_bswap64(val), _p);
+}
+
+#endif /* _TOOLS_BE_BSWAP_H */
diff --git a/tools/include/tools/unaligned/le_bswap.h b/tools/include/tools/unaligned/le_bswap.h
new file mode 100644
index 000000000000..9c70415fa782
--- /dev/null
+++ b/tools/include/tools/unaligned/le_bswap.h
@@ -0,0 +1,36 @@
+#ifndef _TOOLS_LE_BSWAP_H
+#define _TOOLS_LE_BSWAP_H
+
+#include <stdint.h>
+
+static inline uint16_t get_unaligned_le16(const void *_p)
+{
+ return __builtin_bswap16(get_unaligned_be16(_p));
+}
+
+static inline uint32_t get_unaligned_le32(const void *_p)
+{
+ return __builtin_bswap32(get_unaligned_be32(_p));
+}
+
+static inline uint64_t get_unaligned_le64(const void *_p)
+{
+ return __builtin_bswap64(get_unaligned_be64(_p));
+}
+
+static inline void put_unaligned_le16(uint16_t val, void *_p)
+{
+ put_unaligned_be16(__builtin_bswap16(val), _p);
+}
+
+static inline void put_unaligned_le32(uint32_t val, void *_p)
+{
+ put_unaligned_be32(__builtin_bswap32(val), _p);
+}
+
+static inline void put_unaligned_le64(uint64_t val, void *_p)
+{
+ put_unaligned_be64(__builtin_bswap64(val), _p);
+}
+
+#endif /* _TOOLS_LE_BSWAP_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 07/10] tools: Remove leading underscores from header guards
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
` (6 preceding siblings ...)
2014-06-10 23:13 ` [PATCH RFC 06/10] tools: Add gcc __builtin_bswap*() " H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` [PATCH RFC 08/10] tools: Move unaligned common infrastructure into <tools/unaligned.h> H. Peter Anvin
` (3 subsequent siblings)
11 siblings, 1 reply; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Underscore-capital symbols belong to the implementation, i.e. the
libc, and we are not it.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned/be_bswap.h | 6 +++---
tools/include/tools/unaligned/be_byteshift.h | 6 +++---
tools/include/tools/unaligned/be_direct.h | 6 +++---
tools/include/tools/unaligned/be_endian.h | 6 +++---
tools/include/tools/unaligned/be_struct.h | 6 +++---
tools/include/tools/unaligned/le_bswap.h | 6 +++---
tools/include/tools/unaligned/le_byteshift.h | 6 +++---
tools/include/tools/unaligned/le_direct.h | 6 +++---
tools/include/tools/unaligned/le_endian.h | 6 +++---
tools/include/tools/unaligned/le_struct.h | 6 +++---
10 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/tools/include/tools/unaligned/be_bswap.h b/tools/include/tools/unaligned/be_bswap.h
index 9e8d1e91fe0e..5e63da922d23 100644
--- a/tools/include/tools/unaligned/be_bswap.h
+++ b/tools/include/tools/unaligned/be_bswap.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_BE_BSWAP_H
-#define _TOOLS_BE_BSWAP_H
+#ifndef TOOLS_BE_BSWAP_H
+#define TOOLS_BE_BSWAP_H
#include <stdint.h>
@@ -33,4 +33,4 @@ static inline void put_unaligned_be64(uint64_t val, void *_p)
put_unaligned_le64(__builtin_bswap64(val), _p);
}
-#endif /* _TOOLS_BE_BSWAP_H */
+#endif /* TOOLS_BE_BSWAP_H */
diff --git a/tools/include/tools/unaligned/be_byteshift.h b/tools/include/tools/unaligned/be_byteshift.h
index 9850c7df2667..068a5a8b47b2 100644
--- a/tools/include/tools/unaligned/be_byteshift.h
+++ b/tools/include/tools/unaligned/be_byteshift.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_BE_BYTESHIFT_H
-#define _TOOLS_BE_BYTESHIFT_H
+#ifndef TOOLS_BE_BYTESHIFT_H
+#define TOOLS_BE_BYTESHIFT_H
#include <stdint.h>
@@ -49,4 +49,4 @@ static inline void put_unaligned_be64(uint64_t val, void *_p)
put_unaligned_be32(val, p + 4);
}
-#endif /* _TOOLS_BE_BYTESHIFT_H */
+#endif /* TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/unaligned/be_direct.h b/tools/include/tools/unaligned/be_direct.h
index 10a9b8229003..4f446856aa84 100644
--- a/tools/include/tools/unaligned/be_direct.h
+++ b/tools/include/tools/unaligned/be_direct.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_BE_DIRECT_H
-#define _TOOLS_BE_DIRECT_H
+#ifndef TOOLS_BE_DIRECT_H
+#define TOOLS_BE_DIRECT_H
#include <stdint.h>
@@ -45,4 +45,4 @@ static inline void put_unaligned_be64(uint64_t val, void *_p)
*p = val;
}
-#endif /* _TOOLS_BE_DIRECT_H */
+#endif /* TOOLS_BE_DIRECT_H */
diff --git a/tools/include/tools/unaligned/be_endian.h b/tools/include/tools/unaligned/be_endian.h
index 4106c082855e..52ee4a47e23c 100644
--- a/tools/include/tools/unaligned/be_endian.h
+++ b/tools/include/tools/unaligned/be_endian.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_BE_ENDIAN_H
-#define _TOOLS_BE_ENDIAN_H
+#ifndef TOOLS_BE_ENDIAN_H
+#define TOOLS_BE_ENDIAN_H
#ifndef _BSD_SOURCE
# define _BSD_SOURCE 1
@@ -37,4 +37,4 @@ static inline void put_unaligned_be64(uint64_t val, void *_p)
put_unaligned_le64(htobe64(val), _p);
}
-#endif /* _TOOLS_BE_ENDIAN_H */
+#endif /* TOOLS_BE_ENDIAN_H */
diff --git a/tools/include/tools/unaligned/be_struct.h b/tools/include/tools/unaligned/be_struct.h
index 27b73bdf5a86..2543fee4acda 100644
--- a/tools/include/tools/unaligned/be_struct.h
+++ b/tools/include/tools/unaligned/be_struct.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_BE_STRUCT_H
-#define _TOOLS_BE_STRUCT_H
+#ifndef TOOLS_BE_STRUCT_H
+#define TOOLS_BE_STRUCT_H
#include <stdint.h>
@@ -57,4 +57,4 @@ static inline void put_unaligned_be64(uint64_t val, void *_p)
p->v = val;
}
-#endif /* _TOOLS_BE_STRUCT_H */
+#endif /* TOOLS_BE_STRUCT_H */
diff --git a/tools/include/tools/unaligned/le_bswap.h b/tools/include/tools/unaligned/le_bswap.h
index 9c70415fa782..199b42a7b862 100644
--- a/tools/include/tools/unaligned/le_bswap.h
+++ b/tools/include/tools/unaligned/le_bswap.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_LE_BSWAP_H
-#define _TOOLS_LE_BSWAP_H
+#ifndef TOOLS_LE_BSWAP_H
+#define TOOLS_LE_BSWAP_H
#include <stdint.h>
@@ -33,4 +33,4 @@ static inline void put_unaligned_le64(uint64_t val, void *_p)
put_unaligned_be64(__builtin_bswap64(val), _p);
}
-#endif /* _TOOLS_LE_BSWAP_H */
+#endif /* TOOLS_LE_BSWAP_H */
diff --git a/tools/include/tools/unaligned/le_byteshift.h b/tools/include/tools/unaligned/le_byteshift.h
index 819ba186ede5..dfd5d42b9783 100644
--- a/tools/include/tools/unaligned/le_byteshift.h
+++ b/tools/include/tools/unaligned/le_byteshift.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_LE_BYTESHIFT_H
-#define _TOOLS_LE_BYTESHIFT_H
+#ifndef TOOLS_LE_BYTESHIFT_H
+#define TOOLS_LE_BYTESHIFT_H
#include <stdint.h>
@@ -49,4 +49,4 @@ static inline void put_unaligned_le64(uint64_t val, void *_p)
put_unaligned_le32(val >> 32, p + 4);
}
-#endif /* _TOOLS_LE_BYTESHIFT_H */
+#endif /* TOOLS_LE_BYTESHIFT_H */
diff --git a/tools/include/tools/unaligned/le_direct.h b/tools/include/tools/unaligned/le_direct.h
index 6353dfd04fd7..17b773284edd 100644
--- a/tools/include/tools/unaligned/le_direct.h
+++ b/tools/include/tools/unaligned/le_direct.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_LE_DIRECT_H
-#define _TOOLS_LE_DIRECT_H
+#ifndef TOOLS_LE_DIRECT_H
+#define TOOLS_LE_DIRECT_H
#include <stdint.h>
@@ -45,4 +45,4 @@ static inline void put_unaligned_le64(uint64_t val, void *_p)
*p = val;
}
-#endif /* _TOOLS_LE_DIRECT_H */
+#endif /* TOOLS_LE_DIRECT_H */
diff --git a/tools/include/tools/unaligned/le_endian.h b/tools/include/tools/unaligned/le_endian.h
index 0429f1b29250..bc8c2d41be0e 100644
--- a/tools/include/tools/unaligned/le_endian.h
+++ b/tools/include/tools/unaligned/le_endian.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_LE_ENDIAN_H
-#define _TOOLS_LE_ENDIAN_H
+#ifndef TOOLS_LE_ENDIAN_H
+#define TOOLS_LE_ENDIAN_H
#ifndef _BSD_SOURCE
# define _BSD_SOURCE 1
@@ -37,4 +37,4 @@ static inline void put_unaligned_le64(uint64_t val, void *_p)
put_unaligned_be64(htole64(val), _p);
}
-#endif /* _TOOLS_LE_ENDIAN_H */
+#endif /* TOOLS_LE_ENDIAN_H */
diff --git a/tools/include/tools/unaligned/le_struct.h b/tools/include/tools/unaligned/le_struct.h
index 281b03b8f316..f6f271a5824b 100644
--- a/tools/include/tools/unaligned/le_struct.h
+++ b/tools/include/tools/unaligned/le_struct.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_LE_STRUCT_H
-#define _TOOLS_LE_STRUCT_H
+#ifndef TOOLS_LE_STRUCT_H
+#define TOOLS_LE_STRUCT_H
#include <stdint.h>
@@ -57,4 +57,4 @@ static inline void put_unaligned_le64(uint64_t val, void *_p)
p->v = val;
}
-#endif /* _TOOLS_LE_STRUCT_H */
+#endif /* TOOLS_LE_STRUCT_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 07/10] tools: Remove leading underscores from header guards
2014-06-10 23:13 ` [PATCH RFC 07/10] tools: Remove leading underscores from header guards H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
0 siblings, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Underscore-capital symbols belong to the implementation, i.e. the
libc, and we are not it.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned/be_bswap.h | 6 +++---
tools/include/tools/unaligned/be_byteshift.h | 6 +++---
tools/include/tools/unaligned/be_direct.h | 6 +++---
tools/include/tools/unaligned/be_endian.h | 6 +++---
tools/include/tools/unaligned/be_struct.h | 6 +++---
tools/include/tools/unaligned/le_bswap.h | 6 +++---
tools/include/tools/unaligned/le_byteshift.h | 6 +++---
tools/include/tools/unaligned/le_direct.h | 6 +++---
tools/include/tools/unaligned/le_endian.h | 6 +++---
tools/include/tools/unaligned/le_struct.h | 6 +++---
10 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/tools/include/tools/unaligned/be_bswap.h b/tools/include/tools/unaligned/be_bswap.h
index 9e8d1e91fe0e..5e63da922d23 100644
--- a/tools/include/tools/unaligned/be_bswap.h
+++ b/tools/include/tools/unaligned/be_bswap.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_BE_BSWAP_H
-#define _TOOLS_BE_BSWAP_H
+#ifndef TOOLS_BE_BSWAP_H
+#define TOOLS_BE_BSWAP_H
#include <stdint.h>
@@ -33,4 +33,4 @@ static inline void put_unaligned_be64(uint64_t val, void *_p)
put_unaligned_le64(__builtin_bswap64(val), _p);
}
-#endif /* _TOOLS_BE_BSWAP_H */
+#endif /* TOOLS_BE_BSWAP_H */
diff --git a/tools/include/tools/unaligned/be_byteshift.h b/tools/include/tools/unaligned/be_byteshift.h
index 9850c7df2667..068a5a8b47b2 100644
--- a/tools/include/tools/unaligned/be_byteshift.h
+++ b/tools/include/tools/unaligned/be_byteshift.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_BE_BYTESHIFT_H
-#define _TOOLS_BE_BYTESHIFT_H
+#ifndef TOOLS_BE_BYTESHIFT_H
+#define TOOLS_BE_BYTESHIFT_H
#include <stdint.h>
@@ -49,4 +49,4 @@ static inline void put_unaligned_be64(uint64_t val, void *_p)
put_unaligned_be32(val, p + 4);
}
-#endif /* _TOOLS_BE_BYTESHIFT_H */
+#endif /* TOOLS_BE_BYTESHIFT_H */
diff --git a/tools/include/tools/unaligned/be_direct.h b/tools/include/tools/unaligned/be_direct.h
index 10a9b8229003..4f446856aa84 100644
--- a/tools/include/tools/unaligned/be_direct.h
+++ b/tools/include/tools/unaligned/be_direct.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_BE_DIRECT_H
-#define _TOOLS_BE_DIRECT_H
+#ifndef TOOLS_BE_DIRECT_H
+#define TOOLS_BE_DIRECT_H
#include <stdint.h>
@@ -45,4 +45,4 @@ static inline void put_unaligned_be64(uint64_t val, void *_p)
*p = val;
}
-#endif /* _TOOLS_BE_DIRECT_H */
+#endif /* TOOLS_BE_DIRECT_H */
diff --git a/tools/include/tools/unaligned/be_endian.h b/tools/include/tools/unaligned/be_endian.h
index 4106c082855e..52ee4a47e23c 100644
--- a/tools/include/tools/unaligned/be_endian.h
+++ b/tools/include/tools/unaligned/be_endian.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_BE_ENDIAN_H
-#define _TOOLS_BE_ENDIAN_H
+#ifndef TOOLS_BE_ENDIAN_H
+#define TOOLS_BE_ENDIAN_H
#ifndef _BSD_SOURCE
# define _BSD_SOURCE 1
@@ -37,4 +37,4 @@ static inline void put_unaligned_be64(uint64_t val, void *_p)
put_unaligned_le64(htobe64(val), _p);
}
-#endif /* _TOOLS_BE_ENDIAN_H */
+#endif /* TOOLS_BE_ENDIAN_H */
diff --git a/tools/include/tools/unaligned/be_struct.h b/tools/include/tools/unaligned/be_struct.h
index 27b73bdf5a86..2543fee4acda 100644
--- a/tools/include/tools/unaligned/be_struct.h
+++ b/tools/include/tools/unaligned/be_struct.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_BE_STRUCT_H
-#define _TOOLS_BE_STRUCT_H
+#ifndef TOOLS_BE_STRUCT_H
+#define TOOLS_BE_STRUCT_H
#include <stdint.h>
@@ -57,4 +57,4 @@ static inline void put_unaligned_be64(uint64_t val, void *_p)
p->v = val;
}
-#endif /* _TOOLS_BE_STRUCT_H */
+#endif /* TOOLS_BE_STRUCT_H */
diff --git a/tools/include/tools/unaligned/le_bswap.h b/tools/include/tools/unaligned/le_bswap.h
index 9c70415fa782..199b42a7b862 100644
--- a/tools/include/tools/unaligned/le_bswap.h
+++ b/tools/include/tools/unaligned/le_bswap.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_LE_BSWAP_H
-#define _TOOLS_LE_BSWAP_H
+#ifndef TOOLS_LE_BSWAP_H
+#define TOOLS_LE_BSWAP_H
#include <stdint.h>
@@ -33,4 +33,4 @@ static inline void put_unaligned_le64(uint64_t val, void *_p)
put_unaligned_be64(__builtin_bswap64(val), _p);
}
-#endif /* _TOOLS_LE_BSWAP_H */
+#endif /* TOOLS_LE_BSWAP_H */
diff --git a/tools/include/tools/unaligned/le_byteshift.h b/tools/include/tools/unaligned/le_byteshift.h
index 819ba186ede5..dfd5d42b9783 100644
--- a/tools/include/tools/unaligned/le_byteshift.h
+++ b/tools/include/tools/unaligned/le_byteshift.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_LE_BYTESHIFT_H
-#define _TOOLS_LE_BYTESHIFT_H
+#ifndef TOOLS_LE_BYTESHIFT_H
+#define TOOLS_LE_BYTESHIFT_H
#include <stdint.h>
@@ -49,4 +49,4 @@ static inline void put_unaligned_le64(uint64_t val, void *_p)
put_unaligned_le32(val >> 32, p + 4);
}
-#endif /* _TOOLS_LE_BYTESHIFT_H */
+#endif /* TOOLS_LE_BYTESHIFT_H */
diff --git a/tools/include/tools/unaligned/le_direct.h b/tools/include/tools/unaligned/le_direct.h
index 6353dfd04fd7..17b773284edd 100644
--- a/tools/include/tools/unaligned/le_direct.h
+++ b/tools/include/tools/unaligned/le_direct.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_LE_DIRECT_H
-#define _TOOLS_LE_DIRECT_H
+#ifndef TOOLS_LE_DIRECT_H
+#define TOOLS_LE_DIRECT_H
#include <stdint.h>
@@ -45,4 +45,4 @@ static inline void put_unaligned_le64(uint64_t val, void *_p)
*p = val;
}
-#endif /* _TOOLS_LE_DIRECT_H */
+#endif /* TOOLS_LE_DIRECT_H */
diff --git a/tools/include/tools/unaligned/le_endian.h b/tools/include/tools/unaligned/le_endian.h
index 0429f1b29250..bc8c2d41be0e 100644
--- a/tools/include/tools/unaligned/le_endian.h
+++ b/tools/include/tools/unaligned/le_endian.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_LE_ENDIAN_H
-#define _TOOLS_LE_ENDIAN_H
+#ifndef TOOLS_LE_ENDIAN_H
+#define TOOLS_LE_ENDIAN_H
#ifndef _BSD_SOURCE
# define _BSD_SOURCE 1
@@ -37,4 +37,4 @@ static inline void put_unaligned_le64(uint64_t val, void *_p)
put_unaligned_be64(htole64(val), _p);
}
-#endif /* _TOOLS_LE_ENDIAN_H */
+#endif /* TOOLS_LE_ENDIAN_H */
diff --git a/tools/include/tools/unaligned/le_struct.h b/tools/include/tools/unaligned/le_struct.h
index 281b03b8f316..f6f271a5824b 100644
--- a/tools/include/tools/unaligned/le_struct.h
+++ b/tools/include/tools/unaligned/le_struct.h
@@ -1,5 +1,5 @@
-#ifndef _TOOLS_LE_STRUCT_H
-#define _TOOLS_LE_STRUCT_H
+#ifndef TOOLS_LE_STRUCT_H
+#define TOOLS_LE_STRUCT_H
#include <stdint.h>
@@ -57,4 +57,4 @@ static inline void put_unaligned_le64(uint64_t val, void *_p)
p->v = val;
}
-#endif /* _TOOLS_LE_STRUCT_H */
+#endif /* TOOLS_LE_STRUCT_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 08/10] tools: Move unaligned common infrastructure into <tools/unaligned.h>
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
` (7 preceding siblings ...)
2014-06-10 23:13 ` [PATCH RFC 07/10] tools: Remove leading underscores from header guards H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` [PATCH RFC 09/10] tools: Add common infrastructure for byte swapping H. Peter Anvin
` (2 subsequent siblings)
11 siblings, 1 reply; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Move common includes and infrastructure into <tools/unaligned.h>.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned.h | 34 ++++++++++++++++++++++++++++
tools/include/tools/unaligned/be_bswap.h | 2 --
tools/include/tools/unaligned/be_byteshift.h | 2 --
tools/include/tools/unaligned/be_direct.h | 2 --
tools/include/tools/unaligned/be_endian.h | 6 -----
tools/include/tools/unaligned/be_struct.h | 14 ------------
tools/include/tools/unaligned/le_bswap.h | 2 --
tools/include/tools/unaligned/le_byteshift.h | 2 --
tools/include/tools/unaligned/le_direct.h | 2 --
tools/include/tools/unaligned/le_endian.h | 6 -----
tools/include/tools/unaligned/le_struct.h | 12 ----------
11 files changed, 34 insertions(+), 50 deletions(-)
diff --git a/tools/include/tools/unaligned.h b/tools/include/tools/unaligned.h
index f89c089b6148..a3d43989bd25 100644
--- a/tools/include/tools/unaligned.h
+++ b/tools/include/tools/unaligned.h
@@ -1,2 +1,36 @@
+#ifndef TOOLS_UNALIGNED_H
+#define TOOLS_UNALIGNED_H
+
+#include <stdint.h>
+
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE 1
+#endif
+#include <endian.h>
+
+#ifdef __GNUC__
+
+struct _packed_u16_struct {
+ uint16_t v;
+} __attribute__((packed));
+
+struct _packed_u32_struct {
+ uint32_t v;
+} __attribute__((packed));
+
+struct _packed_u64_struct {
+ uint64_t v;
+} __attribute__((packed));
+
+#define TOOLS_UNALIGNED_GCC ((__GNUC__ << 16) + (__GNUC_MINOR__ << 8) + __GNUC_PATCHLEVEL__)
+
+#else
+
+#define TOOLS_UNALIGNED_GCC 0
+
+#endif /* __GNUC__ */
+
#include <tools/unaligned/le_byteshift.h>
#include <tools/unaligned/be_byteshift.h>
+
+#endif /* TOOLS_UNALIGNED_H */
diff --git a/tools/include/tools/unaligned/be_bswap.h b/tools/include/tools/unaligned/be_bswap.h
index 5e63da922d23..72855d3af5f2 100644
--- a/tools/include/tools/unaligned/be_bswap.h
+++ b/tools/include/tools/unaligned/be_bswap.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_BE_BSWAP_H
#define TOOLS_BE_BSWAP_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
return __builtin_bswap16(get_unaligned_le16(_p));
diff --git a/tools/include/tools/unaligned/be_byteshift.h b/tools/include/tools/unaligned/be_byteshift.h
index 068a5a8b47b2..ee0ff62c63cc 100644
--- a/tools/include/tools/unaligned/be_byteshift.h
+++ b/tools/include/tools/unaligned/be_byteshift.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_BE_BYTESHIFT_H
#define TOOLS_BE_BYTESHIFT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
const uint8_t *p = _p;
diff --git a/tools/include/tools/unaligned/be_direct.h b/tools/include/tools/unaligned/be_direct.h
index 4f446856aa84..1ce1c4a94a01 100644
--- a/tools/include/tools/unaligned/be_direct.h
+++ b/tools/include/tools/unaligned/be_direct.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_BE_DIRECT_H
#define TOOLS_BE_DIRECT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
const uint16_t *p = _p;
diff --git a/tools/include/tools/unaligned/be_endian.h b/tools/include/tools/unaligned/be_endian.h
index 52ee4a47e23c..bed93fd0c88b 100644
--- a/tools/include/tools/unaligned/be_endian.h
+++ b/tools/include/tools/unaligned/be_endian.h
@@ -1,12 +1,6 @@
#ifndef TOOLS_BE_ENDIAN_H
#define TOOLS_BE_ENDIAN_H
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE 1
-#endif
-#include <endian.h>
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
return be16toh(get_unaligned_le16(_p));
diff --git a/tools/include/tools/unaligned/be_struct.h b/tools/include/tools/unaligned/be_struct.h
index 2543fee4acda..127ecfdc1ac0 100644
--- a/tools/include/tools/unaligned/be_struct.h
+++ b/tools/include/tools/unaligned/be_struct.h
@@ -1,20 +1,6 @@
#ifndef TOOLS_BE_STRUCT_H
#define TOOLS_BE_STRUCT_H
-#include <stdint.h>
-
-struct _packed_u16_struct {
- uint16_t v;
-} __attribute__((packed));
-
-struct _packed_u32_struct {
- uint32_t v;
-} __attribute__((packed));
-
-struct _packed_u64_struct {
- uint64_t v;
-} __attribute__((packed));
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
const struct _packed_u16_struct *p = _p;
diff --git a/tools/include/tools/unaligned/le_bswap.h b/tools/include/tools/unaligned/le_bswap.h
index 199b42a7b862..f9717b7e072d 100644
--- a/tools/include/tools/unaligned/le_bswap.h
+++ b/tools/include/tools/unaligned/le_bswap.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_LE_BSWAP_H
#define TOOLS_LE_BSWAP_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
return __builtin_bswap16(get_unaligned_be16(_p));
diff --git a/tools/include/tools/unaligned/le_byteshift.h b/tools/include/tools/unaligned/le_byteshift.h
index dfd5d42b9783..bf54188b5210 100644
--- a/tools/include/tools/unaligned/le_byteshift.h
+++ b/tools/include/tools/unaligned/le_byteshift.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_LE_BYTESHIFT_H
#define TOOLS_LE_BYTESHIFT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
const uint8_t *p = _p;
diff --git a/tools/include/tools/unaligned/le_direct.h b/tools/include/tools/unaligned/le_direct.h
index 17b773284edd..b599020be21f 100644
--- a/tools/include/tools/unaligned/le_direct.h
+++ b/tools/include/tools/unaligned/le_direct.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_LE_DIRECT_H
#define TOOLS_LE_DIRECT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
const uint16_t *p = _p;
diff --git a/tools/include/tools/unaligned/le_endian.h b/tools/include/tools/unaligned/le_endian.h
index bc8c2d41be0e..a412af39eda9 100644
--- a/tools/include/tools/unaligned/le_endian.h
+++ b/tools/include/tools/unaligned/le_endian.h
@@ -1,12 +1,6 @@
#ifndef TOOLS_LE_ENDIAN_H
#define TOOLS_LE_ENDIAN_H
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE 1
-#endif
-#include <endian.h>
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
return le16toh(get_unaligned_be16(_p));
diff --git a/tools/include/tools/unaligned/le_struct.h b/tools/include/tools/unaligned/le_struct.h
index f6f271a5824b..b1ac490dcb3f 100644
--- a/tools/include/tools/unaligned/le_struct.h
+++ b/tools/include/tools/unaligned/le_struct.h
@@ -3,18 +3,6 @@
#include <stdint.h>
-struct _packed_u16_struct {
- uint16_t v;
-} __attribute__((packed));
-
-struct _packed_u32_struct {
- uint32_t v;
-} __attribute__((packed));
-
-struct _packed_u64_struct {
- uint64_t v;
-} __attribute__((packed));
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
const struct _packed_u16_struct *p = _p;
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 08/10] tools: Move unaligned common infrastructure into <tools/unaligned.h>
2014-06-10 23:13 ` [PATCH RFC 08/10] tools: Move unaligned common infrastructure into <tools/unaligned.h> H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
0 siblings, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Move common includes and infrastructure into <tools/unaligned.h>.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned.h | 34 ++++++++++++++++++++++++++++
tools/include/tools/unaligned/be_bswap.h | 2 --
tools/include/tools/unaligned/be_byteshift.h | 2 --
tools/include/tools/unaligned/be_direct.h | 2 --
tools/include/tools/unaligned/be_endian.h | 6 -----
tools/include/tools/unaligned/be_struct.h | 14 ------------
tools/include/tools/unaligned/le_bswap.h | 2 --
tools/include/tools/unaligned/le_byteshift.h | 2 --
tools/include/tools/unaligned/le_direct.h | 2 --
tools/include/tools/unaligned/le_endian.h | 6 -----
tools/include/tools/unaligned/le_struct.h | 12 ----------
11 files changed, 34 insertions(+), 50 deletions(-)
diff --git a/tools/include/tools/unaligned.h b/tools/include/tools/unaligned.h
index f89c089b6148..a3d43989bd25 100644
--- a/tools/include/tools/unaligned.h
+++ b/tools/include/tools/unaligned.h
@@ -1,2 +1,36 @@
+#ifndef TOOLS_UNALIGNED_H
+#define TOOLS_UNALIGNED_H
+
+#include <stdint.h>
+
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE 1
+#endif
+#include <endian.h>
+
+#ifdef __GNUC__
+
+struct _packed_u16_struct {
+ uint16_t v;
+} __attribute__((packed));
+
+struct _packed_u32_struct {
+ uint32_t v;
+} __attribute__((packed));
+
+struct _packed_u64_struct {
+ uint64_t v;
+} __attribute__((packed));
+
+#define TOOLS_UNALIGNED_GCC ((__GNUC__ << 16) + (__GNUC_MINOR__ << 8) + __GNUC_PATCHLEVEL__)
+
+#else
+
+#define TOOLS_UNALIGNED_GCC 0
+
+#endif /* __GNUC__ */
+
#include <tools/unaligned/le_byteshift.h>
#include <tools/unaligned/be_byteshift.h>
+
+#endif /* TOOLS_UNALIGNED_H */
diff --git a/tools/include/tools/unaligned/be_bswap.h b/tools/include/tools/unaligned/be_bswap.h
index 5e63da922d23..72855d3af5f2 100644
--- a/tools/include/tools/unaligned/be_bswap.h
+++ b/tools/include/tools/unaligned/be_bswap.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_BE_BSWAP_H
#define TOOLS_BE_BSWAP_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
return __builtin_bswap16(get_unaligned_le16(_p));
diff --git a/tools/include/tools/unaligned/be_byteshift.h b/tools/include/tools/unaligned/be_byteshift.h
index 068a5a8b47b2..ee0ff62c63cc 100644
--- a/tools/include/tools/unaligned/be_byteshift.h
+++ b/tools/include/tools/unaligned/be_byteshift.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_BE_BYTESHIFT_H
#define TOOLS_BE_BYTESHIFT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
const uint8_t *p = _p;
diff --git a/tools/include/tools/unaligned/be_direct.h b/tools/include/tools/unaligned/be_direct.h
index 4f446856aa84..1ce1c4a94a01 100644
--- a/tools/include/tools/unaligned/be_direct.h
+++ b/tools/include/tools/unaligned/be_direct.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_BE_DIRECT_H
#define TOOLS_BE_DIRECT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
const uint16_t *p = _p;
diff --git a/tools/include/tools/unaligned/be_endian.h b/tools/include/tools/unaligned/be_endian.h
index 52ee4a47e23c..bed93fd0c88b 100644
--- a/tools/include/tools/unaligned/be_endian.h
+++ b/tools/include/tools/unaligned/be_endian.h
@@ -1,12 +1,6 @@
#ifndef TOOLS_BE_ENDIAN_H
#define TOOLS_BE_ENDIAN_H
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE 1
-#endif
-#include <endian.h>
-#include <stdint.h>
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
return be16toh(get_unaligned_le16(_p));
diff --git a/tools/include/tools/unaligned/be_struct.h b/tools/include/tools/unaligned/be_struct.h
index 2543fee4acda..127ecfdc1ac0 100644
--- a/tools/include/tools/unaligned/be_struct.h
+++ b/tools/include/tools/unaligned/be_struct.h
@@ -1,20 +1,6 @@
#ifndef TOOLS_BE_STRUCT_H
#define TOOLS_BE_STRUCT_H
-#include <stdint.h>
-
-struct _packed_u16_struct {
- uint16_t v;
-} __attribute__((packed));
-
-struct _packed_u32_struct {
- uint32_t v;
-} __attribute__((packed));
-
-struct _packed_u64_struct {
- uint64_t v;
-} __attribute__((packed));
-
static inline uint16_t get_unaligned_be16(const void *_p)
{
const struct _packed_u16_struct *p = _p;
diff --git a/tools/include/tools/unaligned/le_bswap.h b/tools/include/tools/unaligned/le_bswap.h
index 199b42a7b862..f9717b7e072d 100644
--- a/tools/include/tools/unaligned/le_bswap.h
+++ b/tools/include/tools/unaligned/le_bswap.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_LE_BSWAP_H
#define TOOLS_LE_BSWAP_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
return __builtin_bswap16(get_unaligned_be16(_p));
diff --git a/tools/include/tools/unaligned/le_byteshift.h b/tools/include/tools/unaligned/le_byteshift.h
index dfd5d42b9783..bf54188b5210 100644
--- a/tools/include/tools/unaligned/le_byteshift.h
+++ b/tools/include/tools/unaligned/le_byteshift.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_LE_BYTESHIFT_H
#define TOOLS_LE_BYTESHIFT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
const uint8_t *p = _p;
diff --git a/tools/include/tools/unaligned/le_direct.h b/tools/include/tools/unaligned/le_direct.h
index 17b773284edd..b599020be21f 100644
--- a/tools/include/tools/unaligned/le_direct.h
+++ b/tools/include/tools/unaligned/le_direct.h
@@ -1,8 +1,6 @@
#ifndef TOOLS_LE_DIRECT_H
#define TOOLS_LE_DIRECT_H
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
const uint16_t *p = _p;
diff --git a/tools/include/tools/unaligned/le_endian.h b/tools/include/tools/unaligned/le_endian.h
index bc8c2d41be0e..a412af39eda9 100644
--- a/tools/include/tools/unaligned/le_endian.h
+++ b/tools/include/tools/unaligned/le_endian.h
@@ -1,12 +1,6 @@
#ifndef TOOLS_LE_ENDIAN_H
#define TOOLS_LE_ENDIAN_H
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE 1
-#endif
-#include <endian.h>
-#include <stdint.h>
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
return le16toh(get_unaligned_be16(_p));
diff --git a/tools/include/tools/unaligned/le_struct.h b/tools/include/tools/unaligned/le_struct.h
index f6f271a5824b..b1ac490dcb3f 100644
--- a/tools/include/tools/unaligned/le_struct.h
+++ b/tools/include/tools/unaligned/le_struct.h
@@ -3,18 +3,6 @@
#include <stdint.h>
-struct _packed_u16_struct {
- uint16_t v;
-} __attribute__((packed));
-
-struct _packed_u32_struct {
- uint32_t v;
-} __attribute__((packed));
-
-struct _packed_u64_struct {
- uint64_t v;
-} __attribute__((packed));
-
static inline uint16_t get_unaligned_le16(const void *_p)
{
const struct _packed_u16_struct *p = _p;
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 09/10] tools: Add common infrastructure for byte swapping
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
` (8 preceding siblings ...)
2014-06-10 23:13 ` [PATCH RFC 08/10] tools: Move unaligned common infrastructure into <tools/unaligned.h> H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` [PATCH RFC 10/10] tools: Use reasonable defaults for the default access H. Peter Anvin
2014-06-11 19:21 ` [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions Sam Ravnborg
11 siblings, 1 reply; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Common selection infrastructure for picking the best byte swap method.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned/be_swap.h | 15 +++++++++++++++
tools/include/tools/unaligned/le_swap.h | 15 +++++++++++++++
2 files changed, 30 insertions(+)
create mode 100644 tools/include/tools/unaligned/be_swap.h
create mode 100644 tools/include/tools/unaligned/le_swap.h
diff --git a/tools/include/tools/unaligned/be_swap.h b/tools/include/tools/unaligned/be_swap.h
new file mode 100644
index 000000000000..f0effb8fc6ca
--- /dev/null
+++ b/tools/include/tools/unaligned/be_swap.h
@@ -0,0 +1,15 @@
+#ifndef TOOLS_BE_SWAP_H
+#define TOOLS_BE_SWAP_H
+
+#ifdef htole64
+/* Prefer the <endian.h> infrastructure if it exists */
+# include <tools/unaligned/be_endian.h>
+#elif TOOLS_UNALIGNED_GCC >= 0x040800
+/* This version of gcc is new enough to have __builtin_bswap*() */
+# include <tools/unaligned/be_bswap.h>
+#else
+/* This always works */
+# include <tools/unaligned/be_byteshift.h>
+#endif
+
+#endif /* TOOLS_BE_SWAP_H */
diff --git a/tools/include/tools/unaligned/le_swap.h b/tools/include/tools/unaligned/le_swap.h
new file mode 100644
index 000000000000..8952723c1dff
--- /dev/null
+++ b/tools/include/tools/unaligned/le_swap.h
@@ -0,0 +1,15 @@
+#ifndef TOOLS_LE_SWAP_H
+#define TOOLS_LE_SWAP_H
+
+#ifdef htobe64
+/* Prefer the <endian.h> infrastructure if it exists */
+# include <tools/unaligned/le_endian.h>
+#elif TOOLS_UNALIGNED_GCC >= 0x040800
+/* This version of gcc is new enough to have __builtin_bswap*() */
+# include <tools/unaligned/le_bswap.h>
+#else
+/* This always works */
+# include <tools/unaligned/le_byteshift.h>
+#endif
+
+#endif /* TOOLS_LE_SWAP_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 09/10] tools: Add common infrastructure for byte swapping
2014-06-10 23:13 ` [PATCH RFC 09/10] tools: Add common infrastructure for byte swapping H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
0 siblings, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
Common selection infrastructure for picking the best byte swap method.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned/be_swap.h | 15 +++++++++++++++
tools/include/tools/unaligned/le_swap.h | 15 +++++++++++++++
2 files changed, 30 insertions(+)
create mode 100644 tools/include/tools/unaligned/be_swap.h
create mode 100644 tools/include/tools/unaligned/le_swap.h
diff --git a/tools/include/tools/unaligned/be_swap.h b/tools/include/tools/unaligned/be_swap.h
new file mode 100644
index 000000000000..f0effb8fc6ca
--- /dev/null
+++ b/tools/include/tools/unaligned/be_swap.h
@@ -0,0 +1,15 @@
+#ifndef TOOLS_BE_SWAP_H
+#define TOOLS_BE_SWAP_H
+
+#ifdef htole64
+/* Prefer the <endian.h> infrastructure if it exists */
+# include <tools/unaligned/be_endian.h>
+#elif TOOLS_UNALIGNED_GCC >= 0x040800
+/* This version of gcc is new enough to have __builtin_bswap*() */
+# include <tools/unaligned/be_bswap.h>
+#else
+/* This always works */
+# include <tools/unaligned/be_byteshift.h>
+#endif
+
+#endif /* TOOLS_BE_SWAP_H */
diff --git a/tools/include/tools/unaligned/le_swap.h b/tools/include/tools/unaligned/le_swap.h
new file mode 100644
index 000000000000..8952723c1dff
--- /dev/null
+++ b/tools/include/tools/unaligned/le_swap.h
@@ -0,0 +1,15 @@
+#ifndef TOOLS_LE_SWAP_H
+#define TOOLS_LE_SWAP_H
+
+#ifdef htobe64
+/* Prefer the <endian.h> infrastructure if it exists */
+# include <tools/unaligned/le_endian.h>
+#elif TOOLS_UNALIGNED_GCC >= 0x040800
+/* This version of gcc is new enough to have __builtin_bswap*() */
+# include <tools/unaligned/le_bswap.h>
+#else
+/* This always works */
+# include <tools/unaligned/le_byteshift.h>
+#endif
+
+#endif /* TOOLS_LE_SWAP_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 10/10] tools: Use reasonable defaults for the default access
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
` (9 preceding siblings ...)
2014-06-10 23:13 ` [PATCH RFC 09/10] tools: Add common infrastructure for byte swapping H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
2014-06-10 23:13 ` H. Peter Anvin
2014-06-11 19:21 ` [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions Sam Ravnborg
11 siblings, 1 reply; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
By default, as long as we are using gcc, use struct access for the
native byte order and byte swap it for the reverse byte order. This
works well on most gcc targets. If we are not compiling with gcc,
then we cannot assume that struct access is safe, and so fall back to
the most generic portable form ([bl]e_byteshift.h).
However, there are some architectures on which this generates poor
code even with gcc, and so some architectures may want to implement
specific overrides in this header file.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned.h | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/tools/include/tools/unaligned.h b/tools/include/tools/unaligned.h
index a3d43989bd25..1ef19a1ca9b4 100644
--- a/tools/include/tools/unaligned.h
+++ b/tools/include/tools/unaligned.h
@@ -30,7 +30,21 @@ struct _packed_u64_struct {
#endif /* __GNUC__ */
-#include <tools/unaligned/le_byteshift.h>
-#include <tools/unaligned/be_byteshift.h>
+#if defined(__GNUC__) && (__BYTE_ORDER == __LITTLE_ENDIAN)
+
+# include <tools/unaligned/le_struct.h>
+# include <tools/unaligned/be_swap.h>
+
+#elif defined(__GNUC__) && (__BYTE_ORDER == __BIG_ENDIAN)
+
+# include <tools/unaligned/be_struct.h>
+# include <tools/unaligned/le_swap.h>
+
+#else /* No idea what we actually are dealing with */
+
+# include <tools/unaligned/be_byteshift.h>
+# include <tools/unaligned/le_byteshift.h>
+
+#endif
#endif /* TOOLS_UNALIGNED_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* [PATCH RFC 10/10] tools: Use reasonable defaults for the default access
2014-06-10 23:13 ` [PATCH RFC 10/10] tools: Use reasonable defaults for the default access H. Peter Anvin
@ 2014-06-10 23:13 ` H. Peter Anvin
0 siblings, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-10 23:13 UTC (permalink / raw)
To: Sam Ravnborg, linux-kernel, linux-kbuild, linux-arch
Cc: Andy Lutomirski, Andrew Morton, Ingo Molnar, Thomas Gleixner,
H. Peter Anvin
By default, as long as we are using gcc, use struct access for the
native byte order and byte swap it for the reverse byte order. This
works well on most gcc targets. If we are not compiling with gcc,
then we cannot assume that struct access is safe, and so fall back to
the most generic portable form ([bl]e_byteshift.h).
However, there are some architectures on which this generates poor
code even with gcc, and so some architectures may want to implement
specific overrides in this header file.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
tools/include/tools/unaligned.h | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/tools/include/tools/unaligned.h b/tools/include/tools/unaligned.h
index a3d43989bd25..1ef19a1ca9b4 100644
--- a/tools/include/tools/unaligned.h
+++ b/tools/include/tools/unaligned.h
@@ -30,7 +30,21 @@ struct _packed_u64_struct {
#endif /* __GNUC__ */
-#include <tools/unaligned/le_byteshift.h>
-#include <tools/unaligned/be_byteshift.h>
+#if defined(__GNUC__) && (__BYTE_ORDER == __LITTLE_ENDIAN)
+
+# include <tools/unaligned/le_struct.h>
+# include <tools/unaligned/be_swap.h>
+
+#elif defined(__GNUC__) && (__BYTE_ORDER == __BIG_ENDIAN)
+
+# include <tools/unaligned/be_struct.h>
+# include <tools/unaligned/le_swap.h>
+
+#else /* No idea what we actually are dealing with */
+
+# include <tools/unaligned/be_byteshift.h>
+# include <tools/unaligned/le_byteshift.h>
+
+#endif
#endif /* TOOLS_UNALIGNED_H */
--
1.9.3
^ permalink raw reply related [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions
2014-06-10 23:13 [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions H. Peter Anvin
` (10 preceding siblings ...)
2014-06-10 23:13 ` [PATCH RFC 10/10] tools: Use reasonable defaults for the default access H. Peter Anvin
@ 2014-06-11 19:21 ` Sam Ravnborg
2014-06-11 19:21 ` Sam Ravnborg
2014-06-11 21:52 ` H. Peter Anvin
11 siblings, 2 replies; 33+ messages in thread
From: Sam Ravnborg @ 2014-06-11 19:21 UTC (permalink / raw)
To: H. Peter Anvin
Cc: linux-kernel, linux-kbuild, linux-arch, Andy Lutomirski,
Andrew Morton, Ingo Molnar, Thomas Gleixner
On Tue, Jun 10, 2014 at 04:13:04PM -0700, H. Peter Anvin wrote:
> After a recent problem in the x86 tree, which seems to be the heaviest
> but not the only user of these functions, I went through and did a
> patchset to revamp the *user space* unaligned/endian accessor
> functions. As much as I think it is downright pathetic that this
> functionality still isn't part of the C standard, that is life and we
> have to deal with it. Furthermore, although glibc has a pretty nice
> set of functions for byte swapping in <endian.h>, taken from FreeBSD I
> believe, some older systems don't support them.
>
> This variant tries to fill in all the holes. It assumes that
> <endian.h> define the functions as macros if they exist, as I don't
> know any other way of probing for them without reaching for autoconf,
> but that should be valid enough of an assumption in this case.
>
> The hope is that this should give reasonable, if not optimal, code
> generation on most processors, and give a hook where arch maintainers
> can add their own changes if needed.
This looks like a very complex solution to a simple problem.
We want a shared implementation of the *user space*
unaligned/endian accessor functions.
But do we really want *fast* versions for our use?
This is not a new libc that should generate optimal code,
but only something were we want to provide e working
implmentation for use in our user-space tools.
A much simpler approach without any fallback to arch specific
version etc. is everything we need.
Sam
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions
2014-06-11 19:21 ` [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions Sam Ravnborg
@ 2014-06-11 19:21 ` Sam Ravnborg
2014-06-11 21:52 ` H. Peter Anvin
1 sibling, 0 replies; 33+ messages in thread
From: Sam Ravnborg @ 2014-06-11 19:21 UTC (permalink / raw)
To: H. Peter Anvin
Cc: linux-kernel, linux-kbuild, linux-arch, Andy Lutomirski,
Andrew Morton, Ingo Molnar, Thomas Gleixner
On Tue, Jun 10, 2014 at 04:13:04PM -0700, H. Peter Anvin wrote:
> After a recent problem in the x86 tree, which seems to be the heaviest
> but not the only user of these functions, I went through and did a
> patchset to revamp the *user space* unaligned/endian accessor
> functions. As much as I think it is downright pathetic that this
> functionality still isn't part of the C standard, that is life and we
> have to deal with it. Furthermore, although glibc has a pretty nice
> set of functions for byte swapping in <endian.h>, taken from FreeBSD I
> believe, some older systems don't support them.
>
> This variant tries to fill in all the holes. It assumes that
> <endian.h> define the functions as macros if they exist, as I don't
> know any other way of probing for them without reaching for autoconf,
> but that should be valid enough of an assumption in this case.
>
> The hope is that this should give reasonable, if not optimal, code
> generation on most processors, and give a hook where arch maintainers
> can add their own changes if needed.
This looks like a very complex solution to a simple problem.
We want a shared implementation of the *user space*
unaligned/endian accessor functions.
But do we really want *fast* versions for our use?
This is not a new libc that should generate optimal code,
but only something were we want to provide e working
implmentation for use in our user-space tools.
A much simpler approach without any fallback to arch specific
version etc. is everything we need.
Sam
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions
2014-06-11 19:21 ` [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions Sam Ravnborg
2014-06-11 19:21 ` Sam Ravnborg
@ 2014-06-11 21:52 ` H. Peter Anvin
2014-06-11 21:52 ` H. Peter Anvin
2014-06-13 20:04 ` Sam Ravnborg
1 sibling, 2 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-11 21:52 UTC (permalink / raw)
To: Sam Ravnborg
Cc: linux-kernel, linux-kbuild, linux-arch, Andy Lutomirski,
Andrew Morton, Ingo Molnar, Thomas Gleixner
On 06/11/2014 12:21 PM, Sam Ravnborg wrote:
> On Tue, Jun 10, 2014 at 04:13:04PM -0700, H. Peter Anvin wrote:
>> After a recent problem in the x86 tree, which seems to be the heaviest
>> but not the only user of these functions, I went through and did a
>> patchset to revamp the *user space* unaligned/endian accessor
>> functions. As much as I think it is downright pathetic that this
>> functionality still isn't part of the C standard, that is life and we
>> have to deal with it. Furthermore, although glibc has a pretty nice
>> set of functions for byte swapping in <endian.h>, taken from FreeBSD I
>> believe, some older systems don't support them.
>>
>> This variant tries to fill in all the holes. It assumes that
>> <endian.h> define the functions as macros if they exist, as I don't
>> know any other way of probing for them without reaching for autoconf,
>> but that should be valid enough of an assumption in this case.
>>
>> The hope is that this should give reasonable, if not optimal, code
>> generation on most processors, and give a hook where arch maintainers
>> can add their own changes if needed.
>
> This looks like a very complex solution to a simple problem.
> We want a shared implementation of the *user space*
> unaligned/endian accessor functions.
> But do we really want *fast* versions for our use?
>
> This is not a new libc that should generate optimal code,
> but only something were we want to provide e working
> implmentation for use in our user-space tools.
>
> A much simpler approach without any fallback to arch specific
> version etc. is everything we need.
It doesn't matter so much for things that are just done for the kernel
compile, no, but there are some tools that are built to be used as
standalone things, and it could matter there.
Please note that the code currently doesn't have any arch-specific bits
at all... the code is somewhat complex in part because it is very
generic and handles several levels of fallback. It *can* get
arch-specific overrides if it matters, but the intent is that it
shouldn't be necessary in the vast majority of the cases.
-hpa
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions
2014-06-11 21:52 ` H. Peter Anvin
@ 2014-06-11 21:52 ` H. Peter Anvin
2014-06-13 20:04 ` Sam Ravnborg
1 sibling, 0 replies; 33+ messages in thread
From: H. Peter Anvin @ 2014-06-11 21:52 UTC (permalink / raw)
To: Sam Ravnborg
Cc: linux-kernel, linux-kbuild, linux-arch, Andy Lutomirski,
Andrew Morton, Ingo Molnar, Thomas Gleixner
On 06/11/2014 12:21 PM, Sam Ravnborg wrote:
> On Tue, Jun 10, 2014 at 04:13:04PM -0700, H. Peter Anvin wrote:
>> After a recent problem in the x86 tree, which seems to be the heaviest
>> but not the only user of these functions, I went through and did a
>> patchset to revamp the *user space* unaligned/endian accessor
>> functions. As much as I think it is downright pathetic that this
>> functionality still isn't part of the C standard, that is life and we
>> have to deal with it. Furthermore, although glibc has a pretty nice
>> set of functions for byte swapping in <endian.h>, taken from FreeBSD I
>> believe, some older systems don't support them.
>>
>> This variant tries to fill in all the holes. It assumes that
>> <endian.h> define the functions as macros if they exist, as I don't
>> know any other way of probing for them without reaching for autoconf,
>> but that should be valid enough of an assumption in this case.
>>
>> The hope is that this should give reasonable, if not optimal, code
>> generation on most processors, and give a hook where arch maintainers
>> can add their own changes if needed.
>
> This looks like a very complex solution to a simple problem.
> We want a shared implementation of the *user space*
> unaligned/endian accessor functions.
> But do we really want *fast* versions for our use?
>
> This is not a new libc that should generate optimal code,
> but only something were we want to provide e working
> implmentation for use in our user-space tools.
>
> A much simpler approach without any fallback to arch specific
> version etc. is everything we need.
It doesn't matter so much for things that are just done for the kernel
compile, no, but there are some tools that are built to be used as
standalone things, and it could matter there.
Please note that the code currently doesn't have any arch-specific bits
at all... the code is somewhat complex in part because it is very
generic and handles several levels of fallback. It *can* get
arch-specific overrides if it matters, but the intent is that it
shouldn't be necessary in the vast majority of the cases.
-hpa
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions
2014-06-11 21:52 ` H. Peter Anvin
2014-06-11 21:52 ` H. Peter Anvin
@ 2014-06-13 20:04 ` Sam Ravnborg
2014-06-13 20:04 ` Sam Ravnborg
1 sibling, 1 reply; 33+ messages in thread
From: Sam Ravnborg @ 2014-06-13 20:04 UTC (permalink / raw)
To: H. Peter Anvin
Cc: linux-kernel, linux-kbuild, linux-arch, Andy Lutomirski,
Andrew Morton, Ingo Molnar, Thomas Gleixner
> >
> > A much simpler approach without any fallback to arch specific
> > version etc. is everything we need.
>
> It doesn't matter so much for things that are just done for the kernel
> compile, no, but there are some tools that are built to be used as
> standalone things, and it could matter there.
Which tools require 452 lines of codes for a simple set of
le/be wrappers?
In other words - which tool will benefit from the addition speedup
this amount of code gives?
If I as a naive user look in unaligned.h I do not even see
a prototype of the available methods. I am thrown to a directory
with no less than 12 files.
The le_direct.h´+ be_direct.h files seems unused.
So again - why is it not enaough to provide only le_byteshift.h
+ the be counterpart?
Sam
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH RFC 00/10] tools: Revamp the unaligned endian access functions
2014-06-13 20:04 ` Sam Ravnborg
@ 2014-06-13 20:04 ` Sam Ravnborg
0 siblings, 0 replies; 33+ messages in thread
From: Sam Ravnborg @ 2014-06-13 20:04 UTC (permalink / raw)
To: H. Peter Anvin
Cc: linux-kernel, linux-kbuild, linux-arch, Andy Lutomirski,
Andrew Morton, Ingo Molnar, Thomas Gleixner
> >
> > A much simpler approach without any fallback to arch specific
> > version etc. is everything we need.
>
> It doesn't matter so much for things that are just done for the kernel
> compile, no, but there are some tools that are built to be used as
> standalone things, and it could matter there.
Which tools require 452 lines of codes for a simple set of
le/be wrappers?
In other words - which tool will benefit from the addition speedup
this amount of code gives?
If I as a naive user look in unaligned.h I do not even see
a prototype of the available methods. I am thrown to a directory
with no less than 12 files.
The le_direct.h´+ be_direct.h files seems unused.
So again - why is it not enaough to provide only le_byteshift.h
+ the be counterpart?
Sam
^ permalink raw reply [flat|nested] 33+ messages in thread