From 67b7c93971748e23254c2768545c15631fc111b9 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Thu, 2 May 2013 16:24:22 +0000 Subject: Fix unaligned memory access on Sparc git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@1892 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/util/wordaccess_be_aligned.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/util/wordaccess_be_aligned.h (limited to 'lib/util/wordaccess_be_aligned.h') diff --git a/lib/util/wordaccess_be_aligned.h b/lib/util/wordaccess_be_aligned.h new file mode 100644 index 00000000..0d5809e6 --- /dev/null +++ b/lib/util/wordaccess_be_aligned.h @@ -0,0 +1,35 @@ +/*============================================================================= + This file is the part of wordaccess.h for use under with big-endian + machines that require word accesses to be word-aligned. +*===========================================================================*/ + +typedef unsigned long int wordint; +typedef unsigned char wordintBytes[sizeof(wordint)]; + +static __inline__ wordint +bytesToWordint(wordintBytes bytes) { + uint16_t const hi = *((uint16_t *) (bytes + 0)); + uint16_t const mh = *((uint16_t *) (bytes + 2)); + uint16_t const ml = *((uint16_t *) (bytes + 4)); + uint16_t const lo = *((uint16_t *) (bytes + 6)); + return + (((wordint) hi) << 48) | + (((wordint) mh) << 32) | + (((wordint) ml) << 24) | + (((wordint) lo) << 0); +} + + + +static __inline__ void +wordintToBytes(wordintBytes * const bytesP, + wordint const wordInt) { + uint16_t const hi = ((wordInt >> 48) & 0xFF) + uint16_t const mh = ((wordInt >> 32) & 0xFF); + uint16_t const ml = ((wordInt >> 24) & 0xFF); + uint16_t const lo = ((wordInt >> 0) & 0xFF); + *(uint16_t *)(bytesP + 0) = hi; + *(uint16_t *)(bytesP + 2) = mh; + *(uint16_t *)(bytesP + 4) = ml; + *(uint16_t *)(bytesP + 6) = lo; +} -- cgit 1.4.1