summaryrefslogtreecommitdiff
path: root/netdissect.h
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-10-16 01:39:10 -0700
committerGuy Harris <guy@alum.mit.edu>2017-10-16 01:39:10 -0700
commit2b9bfa05b690f71d08243a8089d6feacbe52b2d2 (patch)
tree442322da7c5af5ec3041d4821be7265025fecab9 /netdissect.h
parentfdd0467bcd46ea0d472111adedd21f43d6d4d15e (diff)
downloadtcpdump-2b9bfa05b690f71d08243a8089d6feacbe52b2d2.tar.gz
Check for unaligned memory access support at compile time.
Don't test at configure time; that doesn't work when cross-compiling and may be a pain to do with CMake.
Diffstat (limited to 'netdissect.h')
-rw-r--r--netdissect.h32
1 files changed, 24 insertions, 8 deletions
diff --git a/netdissect.h b/netdissect.h
index e8d1f3c2..90bc8050 100644
--- a/netdissect.h
+++ b/netdissect.h
@@ -340,7 +340,30 @@ extern void txtproto_print(netdissect_options *, const u_char *, u_int,
extern void safeputchar(netdissect_options *, const u_char);
extern void safeputs(netdissect_options *, const u_char *, const u_int);
-#ifdef LBL_ALIGN
+#if (defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(__x86_64__) || defined(_M_X64)) || \
+ (defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)) || \
+ (defined(__m68k__) && (!defined(__mc68000__) && !defined(__mc68010__))) || \
+ (defined(__ppc__) || defined(__ppc64__) || defined(_M_PPC) || defined(_ARCH_PPC) || defined(_ARCH_PPC64)) || \
+ (defined(__s390__) || defined(__s390x__) || defined(__zarch__)) || \
+ defined(__vax__)
+/*
+ * The procesor natively handles unaligned loads, so just use memcpy()
+ * and memcmp(), to enable those optimizations.
+ *
+ * XXX - are those all the x86 tests we need?
+ * XXX - do we need to worry about ARMv1 through ARMv5, which didn't
+ * support unaligned loads, and, if so, do we need to worry about all
+ * of them, or just some of them, e.g. ARMv5?
+ * XXX - are those the only 68k tests we need not to generated
+ * unaligned accesses if the target is the 68000 or 68010?
+ * XXX - are there any tests we don't need, because some definitions are for
+ * compilers that also predefine the GCC symbols?
+ * XXX - do we need to test for both 32-bit and 64-bit versions of those
+ * architectures in all cases?
+ */
+#define UNALIGNED_MEMCPY(p, q, l) memcpy((p), (q), (l))
+#define UNALIGNED_MEMCMP(p, q, l) memcmp((p), (q), (l))
+#else
/*
* The processor doesn't natively handle unaligned loads,
* and the compiler might "helpfully" optimize memcpy()
@@ -356,13 +379,6 @@ extern void unaligned_memcpy(void *, const void *, size_t);
extern int unaligned_memcmp(const void *, const void *, size_t);
#define UNALIGNED_MEMCPY(p, q, l) unaligned_memcpy((p), (q), (l))
#define UNALIGNED_MEMCMP(p, q, l) unaligned_memcmp((p), (q), (l))
-#else
-/*
- * The procesor natively handles unaligned loads, so just use memcpy()
- * and memcmp(), to enable those optimizations.
- */
-#define UNALIGNED_MEMCPY(p, q, l) memcpy((p), (q), (l))
-#define UNALIGNED_MEMCMP(p, q, l) memcmp((p), (q), (l))
#endif
#define PLURAL_SUFFIX(n) \