From b1487ee909ebd4cfc59f30d3678cb6667d4a72c8 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 26 May 1998 21:38:06 +0000 Subject: Added generic functions for unaligned data access. --- lib/unaligned.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'lib/unaligned.h') diff --git a/lib/unaligned.h b/lib/unaligned.h index 29fcee9..53e32e5 100644 --- a/lib/unaligned.h +++ b/lib/unaligned.h @@ -1,5 +1,5 @@ /* - * Unaligned Data Accesses + * Unaligned Data Accesses -- Generic Version * * (c) 1998 Martin Mares * @@ -9,4 +9,34 @@ #ifndef _BIRD_UNALIGNED_H_ #define _BIRD_UNALIGNED_H_ +#if CPU_NEEDS_ALIGN_WORD != 1 || CPU_NEEDS_ALIGN_LONG != 1 +#include +#endif + +#if CPU_NEEDS_ALIGN_WORD == 1 +#define unaligned_u16(p) (*((u16 *)(p))) +#else +static inline u16 +unaligned_u16(void *p) +{ + u16 x; + + memcpy(&x, p, sizeof(x)); + return x; +} +#endif + +#if CPU_NEEDS_ALIGN_LONG == 1 +#define unaligned_u32(p) (*((u32 *)(p))) +#else +static inline u32 +unaligned_u32(void *p) +{ + u32 x; + + memcpy(&x, p, sizeof(x)); + return x; +} +#endif + #endif -- cgit v1.2.3