[Scummvm-cvs-logs] scummvm master -> 1084f2eea67d3a7f2293392af0c7a2c1d97b1b2b

wjp wjp at usecode.org
Sun Jan 4 22:03:40 CET 2015


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
7c7bdf3543 COMMON: Swap order of functions to 16, 32, 64
1084f2eea6 COMMON: Implement MIPS SWAP_BYTES_64 in terms of SWAP_BYTES_32


Commit: 7c7bdf3543ee198b4dfbb06c9a95ea387342b56d
    https://github.com/scummvm/scummvm/commit/7c7bdf3543ee198b4dfbb06c9a95ea387342b56d
Author: Willem Jan Palenstijn (wjp at usecode.org)
Date: 2015-01-04T21:59:45+01:00

Commit Message:
COMMON: Swap order of functions to 16, 32, 64

Changed paths:
    common/endian.h



diff --git a/common/endian.h b/common/endian.h
index 9a6c0cd..9f10b63 100644
--- a/common/endian.h
+++ b/common/endian.h
@@ -71,64 +71,36 @@
 	((uint16)((((a) >>  8) & 0x00FF) | \
 	          (((a) <<  8) & 0xFF00) ))
 
-#ifdef HAVE_INT64
+
+
 /**
- * Swap the bytes in a 64 bit word in order to convert LE encoded data to BE
+ * Swap the bytes in a 16 bit word in order to convert LE encoded data to BE
  * and vice versa.
  */
 
-// machine/compiler-specific variants come first, fallback last
+// compilerspecific variants come first, fallback last
 
 // Test for GCC and if the target has the MIPS rel.2 instructions (we know the psp does)
-//
-// TODO: Fix this #if statement. It isn't changed from 32 bit. Is there a 64 bit swap instruction?
 #if defined(__GNUC__) && (defined(__psp__) || defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2))
 
-	FORCEINLINE uint32 SWAP_BYTES_32(const uint32 a) {
+	FORCEINLINE uint16 SWAP_BYTES_16(const uint16 a) {
 		if (__builtin_constant_p(a)) {
-			return SWAP_CONSTANT_32(a);
+			return SWAP_CONSTANT_16(a);
 		} else {
-			uint32 result;
-#	if defined(__psp__)
-			// use special allegrex instruction
-			__asm__ ("wsbw %0,%1" : "=r" (result) : "r" (a));
-#	else
-			__asm__ ("wsbh %0,%1\n"
-			         "rotr %0,%0,16" : "=r" (result) : "r" (a));
-#	endif
+			uint16 result;
+			__asm__ ("wsbh %0,%1" : "=r" (result) : "r" (a));
 			return result;
 		}
 	}
-
-// Test for GCC >= 4.3.0 as this version added the bswap builtin
-#elif GCC_ATLEAST(4, 3)
-
-	FORCEINLINE uint64 SWAP_BYTES_64(uint64 a) {
-		return __builtin_bswap64(a);
-	}
-
-#elif defined(_MSC_VER)
-
-	FORCEINLINE uint64 SWAP_BYTES_64(uint64 a) {
-		return _byteswap_uint64(a);
-	}
-
-// generic fallback
 #else
 
-	inline uint64 SWAP_BYTES_64(uint64 a) {
-		uint32 low = (uint32)a, high = (uint32)(a >> 32);
-		uint16 lowLow = (uint16)low, lowHigh = (uint16)(low >> 16),
-		       highLow = (uint16)high, highHigh = (uint16)(high >> 16);
-
-		return ((uint64)(((uint32)(uint16)((lowLow   >> 8) | (lowLow   << 8)) << 16) |
-		                          (uint16)((lowHigh  >> 8) | (lowHigh  << 8))) << 32) |
-		                (((uint32)(uint16)((highLow  >> 8) | (highLow  << 8)) << 16) |
-		                          (uint16)((highHigh >> 8) | (highHigh << 8)));
+	inline uint16 SWAP_BYTES_16(const uint16 a) {
+		return (a >> 8) | (a << 8);
 	}
 #endif
 
-#endif // HAVE_INT64
+
+
 /**
  * Swap the bytes in a 32 bit word in order to convert LE encoded data to BE
  * and vice versa.
@@ -178,32 +150,65 @@
 	}
 #endif
 
+#ifdef HAVE_INT64
 /**
- * Swap the bytes in a 16 bit word in order to convert LE encoded data to BE
+ * Swap the bytes in a 64 bit word in order to convert LE encoded data to BE
  * and vice versa.
  */
 
-// compilerspecific variants come first, fallback last
+// machine/compiler-specific variants come first, fallback last
 
 // Test for GCC and if the target has the MIPS rel.2 instructions (we know the psp does)
+//
+// TODO: Fix this #if statement. It isn't changed from 32 bit. Is there a 64 bit swap instruction?
 #if defined(__GNUC__) && (defined(__psp__) || defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2))
 
-	FORCEINLINE uint16 SWAP_BYTES_16(const uint16 a) {
+	FORCEINLINE uint32 SWAP_BYTES_32(const uint32 a) {
 		if (__builtin_constant_p(a)) {
-			return SWAP_CONSTANT_16(a);
+			return SWAP_CONSTANT_32(a);
 		} else {
-			uint16 result;
-			__asm__ ("wsbh %0,%1" : "=r" (result) : "r" (a));
+			uint32 result;
+#	if defined(__psp__)
+			// use special allegrex instruction
+			__asm__ ("wsbw %0,%1" : "=r" (result) : "r" (a));
+#	else
+			__asm__ ("wsbh %0,%1\n"
+			         "rotr %0,%0,16" : "=r" (result) : "r" (a));
+#	endif
 			return result;
 		}
 	}
+
+// Test for GCC >= 4.3.0 as this version added the bswap builtin
+#elif GCC_ATLEAST(4, 3)
+
+	FORCEINLINE uint64 SWAP_BYTES_64(uint64 a) {
+		return __builtin_bswap64(a);
+	}
+
+#elif defined(_MSC_VER)
+
+	FORCEINLINE uint64 SWAP_BYTES_64(uint64 a) {
+		return _byteswap_uint64(a);
+	}
+
+// generic fallback
 #else
 
-	inline uint16 SWAP_BYTES_16(const uint16 a) {
-		return (a >> 8) | (a << 8);
+	inline uint64 SWAP_BYTES_64(uint64 a) {
+		uint32 low = (uint32)a, high = (uint32)(a >> 32);
+		uint16 lowLow = (uint16)low, lowHigh = (uint16)(low >> 16),
+		       highLow = (uint16)high, highHigh = (uint16)(high >> 16);
+
+		return ((uint64)(((uint32)(uint16)((lowLow   >> 8) | (lowLow   << 8)) << 16) |
+		                          (uint16)((lowHigh  >> 8) | (lowHigh  << 8))) << 32) |
+		                (((uint32)(uint16)((highLow  >> 8) | (highLow  << 8)) << 16) |
+		                          (uint16)((highHigh >> 8) | (highHigh << 8)));
 	}
 #endif
 
+#endif // HAVE_INT64
+
 
 /**
  * A wrapper macro used around four character constants, like 'DATA', to


Commit: 1084f2eea67d3a7f2293392af0c7a2c1d97b1b2b
    https://github.com/scummvm/scummvm/commit/1084f2eea67d3a7f2293392af0c7a2c1d97b1b2b
Author: Willem Jan Palenstijn (wjp at usecode.org)
Date: 2015-01-04T22:00:00+01:00

Commit Message:
COMMON: Implement MIPS SWAP_BYTES_64 in terms of SWAP_BYTES_32

Changed paths:
    common/endian.h



diff --git a/common/endian.h b/common/endian.h
index 9f10b63..0c6b3db 100644
--- a/common/endian.h
+++ b/common/endian.h
@@ -160,22 +160,17 @@
 
 // Test for GCC and if the target has the MIPS rel.2 instructions (we know the psp does)
 //
-// TODO: Fix this #if statement. It isn't changed from 32 bit. Is there a 64 bit swap instruction?
 #if defined(__GNUC__) && (defined(__psp__) || defined(_MIPS_ARCH_MIPS32R2) || defined(_MIPS_ARCH_MIPS64R2))
 
-	FORCEINLINE uint32 SWAP_BYTES_32(const uint32 a) {
+	FORCEINLINE uint64 SWAP_BYTES_64(const uint64 a) {
 		if (__builtin_constant_p(a)) {
-			return SWAP_CONSTANT_32(a);
+			return SWAP_CONSTANT_64(a);
 		} else {
-			uint32 result;
-#	if defined(__psp__)
-			// use special allegrex instruction
-			__asm__ ("wsbw %0,%1" : "=r" (result) : "r" (a));
-#	else
-			__asm__ ("wsbh %0,%1\n"
-			         "rotr %0,%0,16" : "=r" (result) : "r" (a));
-#	endif
-			return result;
+			uint32 low = (uint32)a, high = (uint32)(a >> 32);
+			low = SWAP_BYTES_32(low);
+			high = SWAP_BYTES_32(high);
+
+			return (((uint64)low) << 32) | high;
 		}
 	}
 






More information about the Scummvm-git-logs mailing list