summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-03-29 05:30:25 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-03-29 05:30:25 +0000
commite754b16f4b64920d581b4eba90e776c7fd4b920b (patch)
treebce9172adef330b8eaca871705b1c25dbec61f6b
parent62e0a516a085de93ec0fc50cfff6e346d80ccebb (diff)
downloadrockbox-e754b16f4b64920d581b4eba90e776c7fd4b920b.zip
rockbox-e754b16f4b64920d581b4eba90e776c7fd4b920b.tar.gz
rockbox-e754b16f4b64920d581b4eba90e776c7fd4b920b.tar.bz2
rockbox-e754b16f4b64920d581b4eba90e776c7fd4b920b.tar.xz
Add an asm swap_odd_even32 to SH and ARM. Have the byteswapping functions take and return intxx_t data types.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12956 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/export/system.h70
-rw-r--r--firmware/target/coldfire/system-target.h10
2 files changed, 49 insertions, 31 deletions
diff --git a/firmware/export/system.h b/firmware/export/system.h
index f5829d7..5aabb86 100644
--- a/firmware/export/system.h
+++ b/firmware/export/system.h
@@ -248,29 +248,29 @@ static inline int set_irq_level(int level)
return i;
}
-static inline unsigned short swap16(unsigned short value)
+static inline uint16_t swap16(uint16_t value)
/*
result[15..8] = value[ 7..0];
result[ 7..0] = value[15..8];
*/
{
- unsigned short result;
+ uint16_t result;
asm volatile ("swap.b\t%1,%0" : "=r"(result) : "r"(value));
return result;
}
-static inline unsigned long SWAW32(unsigned long value)
+static inline uint32_t SWAW32(uint32_t value)
/*
result[31..16] = value[15.. 0];
result[15.. 0] = value[31..16];
*/
{
- unsigned long result;
+ uint32_t result;
asm volatile ("swap.w\t%1,%0" : "=r"(result) : "r"(value));
return result;
}
-static inline unsigned long swap32(unsigned long value)
+static inline uint32_t swap32(uint32_t value)
/*
result[31..24] = value[ 7.. 0];
result[23..16] = value[15.. 8];
@@ -284,6 +284,18 @@ static inline unsigned long swap32(unsigned long value)
return value;
}
+static inline uint32_t swap_odd_even32(uint32_t value)
+{
+ /*
+ result[31..24],[15.. 8] = value[23..16],[ 7.. 0]
+ result[23..16],[ 7.. 0] = value[31..24],[15.. 8]
+ */
+ asm volatile ("swap.b\t%0,%0\n"
+ "swap.w\t%0,%0\n"
+ "swap.b\t%0,%0\n"
+ "swap.w\t%0,%0\n" : "+r"(value));
+}
+
#define invalidate_icache()
#elif defined(CPU_ARM)
@@ -313,7 +325,7 @@ static inline unsigned long swap32(unsigned long value)
#endif
-static inline unsigned short swap16(unsigned short value)
+static inline uint16_t swap16(uint16_t value)
/*
result[15..8] = value[ 7..0];
result[ 7..0] = value[15..8];
@@ -322,7 +334,7 @@ static inline unsigned short swap16(unsigned short value)
return (value >> 8) | (value << 8);
}
-static inline unsigned long swap32(unsigned long value)
+static inline uint32_t swap32(uint32_t value)
/*
result[31..24] = value[ 7.. 0];
result[23..16] = value[15.. 8];
@@ -330,7 +342,7 @@ static inline unsigned long swap32(unsigned long value)
result[ 7.. 0] = value[31..24];
*/
{
- unsigned int tmp;
+ uint32_t tmp;
asm volatile (
"eor %1, %0, %0, ror #16 \n\t"
@@ -342,6 +354,24 @@ static inline unsigned long swap32(unsigned long value)
return value;
}
+static inline uint32_t swap_odd_even32(uint32_t value)
+{
+ /*
+ result[31..24],[15.. 8] = value[23..16],[ 7.. 0]
+ result[23..16],[ 7.. 0] = value[31..24],[15.. 8]
+ */
+ uint32_t tmp;
+
+ asm volatile ( /* ABCD */
+ "bic %1, %0, #0x00ff00 \n\t" /* AB.D */
+ "bic %0, %0, #0xff0000 \n\t" /* A.CD */
+ "mov %0, %0, lsr #8 \n\t" /* .A.C */
+ "orr %0, %0, %1, lsl #8 \n\t" /* B.D.|.A.C */
+ : "+r" (value), "=r" (tmp) /* BADC */
+ );
+ return value;
+}
+
#define HIGHEST_IRQ_LEVEL (1)
static inline int set_irq_level(int level)
@@ -396,21 +426,9 @@ void irq_disable_int(int n);
#endif
-#ifndef CPU_COLDFIRE
-static inline unsigned long swap_odd_even32(unsigned long value)
-{
- /*
- result[31..24],[15.. 8] = value[23..16],[ 7.. 0]
- result[23..16],[ 7.. 0] = value[31..24],[15.. 8]
- */
- unsigned long t = value & 0xff00ff00;
- return (t >> 8) | ((t ^ value) << 8);
-}
-#endif
-
#else /* SIMULATOR */
-static inline unsigned short swap16(unsigned short value)
+static inline uint16_t swap16(uint16_t value)
/*
result[15..8] = value[ 7..0];
result[ 7..0] = value[15..8];
@@ -419,7 +437,7 @@ static inline unsigned short swap16(unsigned short value)
return (value >> 8) | (value << 8);
}
-static inline unsigned long swap32(unsigned long value)
+static inline uint32_t swap32(uint32_t value)
/*
result[31..24] = value[ 7.. 0];
result[23..16] = value[15.. 8];
@@ -427,18 +445,18 @@ static inline unsigned long swap32(unsigned long value)
result[ 7.. 0] = value[31..24];
*/
{
- unsigned long hi = swap16(value >> 16);
- unsigned long lo = swap16(value & 0xffff);
+ uint32_t hi = swap16(value >> 16);
+ uint32_t lo = swap16(value & 0xffff);
return (lo << 16) | hi;
}
-static inline unsigned long swap_odd_even32(unsigned long value)
+static inline uint32_t swap_odd_even32(uint32_t value)
{
/*
result[31..24],[15.. 8] = value[23..16],[ 7.. 0]
result[23..16],[ 7.. 0] = value[31..24],[15.. 8]
*/
- unsigned long t = value & 0xff00ff00;
+ uint32_t t = value & 0xff00ff00;
return (t >> 8) | ((t ^ value) << 8);
}
diff --git a/firmware/target/coldfire/system-target.h b/firmware/target/coldfire/system-target.h
index c707843..06589ae 100644
--- a/firmware/target/coldfire/system-target.h
+++ b/firmware/target/coldfire/system-target.h
@@ -78,7 +78,7 @@ static inline int set_irq_level(int level)
return oldlevel;
}
-static inline unsigned short swap16(unsigned short value)
+static inline uint16_t swap16(uint16_t value)
/*
result[15..8] = value[ 7..0];
result[ 7..0] = value[15..8];
@@ -87,7 +87,7 @@ static inline unsigned short swap16(unsigned short value)
return (value >> 8) | (value << 8);
}
-static inline unsigned long SWAW32(unsigned long value)
+static inline uint32_t SWAW32(uint32_tg value)
/*
result[31..16] = value[15.. 0];
result[15.. 0] = value[31..16];
@@ -97,7 +97,7 @@ static inline unsigned long SWAW32(unsigned long value)
return value;
}
-static inline unsigned long swap32(unsigned long value)
+static inline uint32_t swap32(uint32_t value)
/*
result[31..24] = value[ 7.. 0];
result[23..16] = value[15.. 8];
@@ -105,7 +105,7 @@ static inline unsigned long swap32(unsigned long value)
result[ 7.. 0] = value[31..24];
*/
{
- unsigned long mask = 0x00FF00FF;
+ uint32_t mask = 0x00FF00FF;
asm ( /* val = ABCD */
"and.l %[val],%[mask] \n" /* mask = .B.D */
"eor.l %[mask],%[val] \n" /* val = A.C. */
@@ -120,7 +120,7 @@ static inline unsigned long swap32(unsigned long value)
return value;
}
-static inline unsigned long swap_odd_even32(unsigned long value)
+static inline uint32_t swap_odd_even32(uint32_t value)
{
/*
result[31..24],[15.. 8] = value[23..16],[ 7.. 0]