[rtems commit] v850 - byte swap instructions not available on all multilibs

Joel Sherrill joel at rtems.org
Tue Jun 12 22:54:41 UTC 2012


Module:    rtems
Branch:    master
Commit:    1364eb9935cb6911598436a5cc5ca5c2705f088e
Changeset: http://git.rtems.org/rtems/commit/?id=1364eb9935cb6911598436a5cc5ca5c2705f088e

Author:    Joel Sherrill <joel.sherrill at oarcorp.com>
Date:      Tue Jun 12 17:57:35 2012 -0500

v850 - byte swap instructions not available on all multilibs

---

 cpukit/score/cpu/v850/rtems/score/cpu.h  |   31 ++++++++++++++++++++++++-----
 cpukit/score/cpu/v850/rtems/score/v850.h |    9 +++++++-
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/cpukit/score/cpu/v850/rtems/score/cpu.h b/cpukit/score/cpu/v850/rtems/score/cpu.h
index 591af00..875f160 100644
--- a/cpukit/score/cpu/v850/rtems/score/cpu.h
+++ b/cpukit/score/cpu/v850/rtems/score/cpu.h
@@ -1154,10 +1154,23 @@ static inline uint32_t CPU_swap_u32(
   uint32_t value
 )
 {
-  unsigned int v, swapped;
+  unsigned int swapped;
 
-  v = value;
-  __asm__ __volatile__ ("bsw %0, %1" : "=r" (v), "=&r" (swapped) );
+  #if (V850_HAS_BYTE_SWAP_INSTRUCTION == 1)
+    unsigned int v;
+
+    v = value;
+    __asm__ __volatile__ ("bsw %0, %1" : "=r" (v), "=&r" (swapped) );
+  #else
+    uint32_t byte1, byte2, byte3, byte4;
+
+    byte4 = (value >> 24) & 0xff;
+    byte3 = (value >> 16) & 0xff;
+    byte2 = (value >> 8)  & 0xff;
+    byte1 =  value        & 0xff;
+
+    swapped = (byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4;
+  #endif
   return swapped;
 }
 
@@ -1174,10 +1187,16 @@ static inline uint32_t CPU_swap_u32(
  */
 static inline uint16_t CPU_swap_u16( uint16_t value )
 {
-  unsigned int v, swapped;
+  unsigned int swapped;
+
+  #if (V850_HAS_BYTE_SWAP_INSTRUCTION == 1)
+    unsigned int v;
 
-  v = value;
-  __asm__ __volatile__ ("bsh %0, %1" : "=r" (v), "=&r" (swapped) );
+    v = value;
+    __asm__ __volatile__ ("bsh %0, %1" : "=r" (v), "=&r" (swapped) );
+  #else
+    swapped = ((value & 0xff) << 8) | ((value >> 8) & 0xff);
+  #endif
   return swapped;
 }
 
diff --git a/cpukit/score/cpu/v850/rtems/score/v850.h b/cpukit/score/cpu/v850/rtems/score/v850.h
index b76ddbc..3e9bec5 100644
--- a/cpukit/score/cpu/v850/rtems/score/v850.h
+++ b/cpukit/score/cpu/v850/rtems/score/v850.h
@@ -40,30 +40,37 @@ extern "C" {
  */
 #define CPU_MODEL_NAME  "rtems_multilib"
 #define V850_HAS_FPU 0
+#define V850_HAS_BYTE_SWAP_INSTRUCTION 0
 
 #elif defined(__v850e2v3__)
 #define CPU_MODEL_NAME  "v850e2v3"
 #define V850_HAS_FPU 1
+#define V850_HAS_BYTE_SWAP_INSTRUCTION 1
 
 #elif defined(__v850e2__)
 #define CPU_MODEL_NAME  "v850e2"
 #define V850_HAS_FPU 0
+#define V850_HAS_BYTE_SWAP_INSTRUCTION 1
 
 #elif defined(__v850es__)
 #define CPU_MODEL_NAME  "v850es"
 #define V850_HAS_FPU 0
+#define V850_HAS_BYTE_SWAP_INSTRUCTION 1
 
 #elif defined(__v850e1__)
 #define CPU_MODEL_NAME  "v850e1"
 #define V850_HAS_FPU 0
+#define V850_HAS_BYTE_SWAP_INSTRUCTION 1
 
 #elif defined(__v850e__)
 #define CPU_MODEL_NAME  "v850e"
 #define V850_HAS_FPU 0
+#define V850_HAS_BYTE_SWAP_INSTRUCTION 1
 
 #else
 #define CPU_MODEL_NAME  "v850"
-#define V850_HAS_FPU     0
+#define V850_HAS_FPU 0
+#define V850_HAS_BYTE_SWAP_INSTRUCTION 0
 
 #endif
 




More information about the vc mailing list