[PATCH] test-suite: Add support for unaligned read32bit and write32bit

robert lytton robert at xmos.com
Fri Feb 14 11:05:53 PST 2014


  Hi Daniel,
  added 'BE' to function names as suggested
  Robert

Hi ddunbar,

http://llvm-reviews.chandlerc.com/D2648

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2648?vs=6745&id=7136#toc

Files:
  MultiSource/Applications/ALAC/decode/ag_enc.c
  MultiSource/Applications/ALAC/encode/ag_enc.c

Index: MultiSource/Applications/ALAC/decode/ag_enc.c
===================================================================
--- MultiSource/Applications/ALAC/decode/ag_enc.c
+++ MultiSource/Applications/ALAC/decode/ag_enc.c
@@ -54,6 +54,9 @@
 #define ALWAYS_INLINE
 #endif
 
+#ifdef __XS1B__
+#define UNALIGNED_MEM_ACCESS_NOT_SUPPORTED
+#endif
 
 /*	And on the subject of the CodeWarrior x86 compiler and inlining, I reworked a lot of this
 	to help the compiler out.   In many cases this required manual inlining or a macro.  Sorry
@@ -98,7 +101,8 @@
 	return result;	
 }
 
-static inline uint32_t ALWAYS_INLINE read32bit( uint8_t * buffer )
+#ifdef UNALIGNED_MEM_ACCESS_NOT_SUPPORTED
+static inline uint32_t ALWAYS_INLINE readBE32bit( uint8_t * buffer )
 {
 	// embedded CPUs typically can't read unaligned 32-bit words so just read the bytes
 	uint32_t		value;
@@ -107,6 +111,26 @@
 			 ((uint32_t)buffer[2] << 8) | (uint32_t)buffer[3];
 	return value;
 }
+static inline void ALWAYS_INLINE writeBE32bit( uint8_t * buffer, uint32_t value )
+{
+        // embedded CPUs typically can't write unaligned 32-bit words so just write the bytes
+        buffer[0] = (value >> 24) & 0xff;
+        buffer[1] = (value >> 16) & 0xff;
+        buffer[2] = (value >> 8) & 0xff;
+        buffer[3] = value & 0xff;
+}
+#else
+static inline uint32_t ALWAYS_INLINE readBE32bit( uint8_t * buffer )
+{
+        uint32_t *i = (uint32_t *)buffer;
+        return Swap32NtoB( *i );
+}
+static inline void ALWAYS_INLINE writeBE32bit( uint8_t * buffer, uint32_t value )
+{
+        uint32_t *i = (uint32_t *)buffer;
+        *i = Swap32BtoN( value );
+}
+#endif
 
 #if PRAGMA_MARK
 #pragma mark -
@@ -193,8 +217,7 @@
 
 	//Assert( numBits <= 32 );
 
-	curr = *i;
-	curr = Swap32NtoB( curr );
+	curr = readBE32bit((uint8_t*) i);
 
 	shift = 32 - (bitPos & 7) - numBits;
 
@@ -204,7 +227,7 @@
 	value  = (value << shift) & mask;
 	value |= curr & ~mask;
 	
-	*i = Swap32BtoN( value );
+	writeBE32bit((uint8_t*) i, value);
 }
 
 
@@ -218,8 +241,7 @@
 	
 	//Assert(numBits <= 32);
 
-	curr = *i;
-	curr = Swap32NtoB( curr );
+	curr = readBE32bit((uint8_t*) i);
 
 	if (shiftvalue < 0)
 	{
@@ -243,7 +265,7 @@
 		w |= curr & ~mask;
 	}
 	
-	*i = Swap32BtoN( w );
+	writeBE32bit((uint8_t*) i, w);
 }
 
 
Index: MultiSource/Applications/ALAC/encode/ag_enc.c
===================================================================
--- MultiSource/Applications/ALAC/encode/ag_enc.c
+++ MultiSource/Applications/ALAC/encode/ag_enc.c
@@ -54,6 +54,9 @@
 #define ALWAYS_INLINE
 #endif
 
+#ifdef __XS1B__
+#define UNALIGNED_MEM_ACCESS_NOT_SUPPORTED
+#endif
 
 /*	And on the subject of the CodeWarrior x86 compiler and inlining, I reworked a lot of this
 	to help the compiler out.   In many cases this required manual inlining or a macro.  Sorry
@@ -98,7 +101,8 @@
 	return result;	
 }
 
-static inline uint32_t ALWAYS_INLINE read32bit( uint8_t * buffer )
+#ifdef UNALIGNED_MEM_ACCESS_NOT_SUPPORTED
+static inline uint32_t ALWAYS_INLINE readBE32bit( uint8_t * buffer )
 {
 	// embedded CPUs typically can't read unaligned 32-bit words so just read the bytes
 	uint32_t		value;
@@ -107,6 +111,26 @@
 			 ((uint32_t)buffer[2] << 8) | (uint32_t)buffer[3];
 	return value;
 }
+static inline void ALWAYS_INLINE writeBE32bit( uint8_t * buffer, uint32_t value )
+{
+        // embedded CPUs typically can't write unaligned 32-bit words so just write the bytes
+        buffer[0] = (value >> 24) & 0xff;
+        buffer[1] = (value >> 16) & 0xff;
+        buffer[2] = (value >> 8) & 0xff;
+        buffer[3] = value & 0xff;
+}
+#else
+static inline uint32_t ALWAYS_INLINE readBE32bit( uint8_t * buffer )
+{
+        uint32_t *i = (uint32_t *)buffer;
+        return Swap32NtoB( *i );
+}
+static inline void ALWAYS_INLINE writeBE32bit( uint8_t * buffer, uint32_t value )
+{
+        uint32_t *i = (uint32_t *)buffer;
+        *i = Swap32BtoN( value );
+}
+#endif
 
 #if PRAGMA_MARK
 #pragma mark -
@@ -193,8 +217,7 @@
 
 	//Assert( numBits <= 32 );
 
-	curr = *i;
-	curr = Swap32NtoB( curr );
+	curr = readBE32bit((uint8_t*) i);
 
 	shift = 32 - (bitPos & 7) - numBits;
 
@@ -204,7 +227,7 @@
 	value  = (value << shift) & mask;
 	value |= curr & ~mask;
 	
-	*i = Swap32BtoN( value );
+	writeBE32bit((uint8_t*) i, value);
 }
 
 
@@ -218,8 +241,7 @@
 	
 	//Assert(numBits <= 32);
 
-	curr = *i;
-	curr = Swap32NtoB( curr );
+	curr = readBE32bit((uint8_t*) i);
 
 	if (shiftvalue < 0)
 	{
@@ -243,7 +265,7 @@
 		w |= curr & ~mask;
 	}
 	
-	*i = Swap32BtoN( w );
+	writeBE32bit((uint8_t*) i, w);
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2648.2.patch
Type: text/x-patch
Size: 4548 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140214/70c714e3/attachment.bin>


More information about the llvm-commits mailing list