mirror of
				https://github.com/hedge-dev/XenonRecomp.git
				synced 2025-10-30 07:11:38 +00:00 
			
		
		
		
	Compare commits
	
		
			2 commits
		
	
	
		
			83a66b5cdb
			...
			257c34d7a3
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 257c34d7a3 | ||
|   | 32c2f49bec | 
					 1 changed files with 16 additions and 3 deletions
				
			
		|  | @ -2,17 +2,30 @@ | |||
| 
 | ||||
| #include <cassert> | ||||
| 
 | ||||
| #if defined(_MSC_VER)  // MSVC
 | ||||
| #include <intrin.h> | ||||
| #define BSWAP16(x) _byteswap_ushort(x) | ||||
| #define BSWAP32(x) _byteswap_ulong(x) | ||||
| #define BSWAP64(x) _byteswap_uint64(x) | ||||
| #elif defined(__GNUC__) || defined(__clang__)  // GCC or Clang
 | ||||
| #define BSWAP16(x) __builtin_bswap16(x) | ||||
| #define BSWAP32(x) __builtin_bswap32(x) | ||||
| #define BSWAP64(x) __builtin_bswap64(x) | ||||
| #else | ||||
| #error "Unsupported compiler" | ||||
| #endif | ||||
| 
 | ||||
| template<typename T> | ||||
| inline T ByteSwap(T value) | ||||
| { | ||||
|     if constexpr (sizeof(T) == 1) | ||||
|         return value; | ||||
|     else if constexpr (sizeof(T) == 2) | ||||
|         return static_cast<T>(__builtin_bswap16(static_cast<uint16_t>(value))); | ||||
|         return static_cast<T>(BSWAP16(static_cast<uint16_t>(value))); | ||||
|     else if constexpr (sizeof(T) == 4) | ||||
|         return static_cast<T>(__builtin_bswap32(static_cast<uint32_t>(value))); | ||||
|         return static_cast<T>(BSWAP32(static_cast<uint32_t>(value))); | ||||
|     else if constexpr (sizeof(T) == 8) | ||||
|         return static_cast<T>(__builtin_bswap64(static_cast<uint64_t>(value))); | ||||
|         return static_cast<T>(BSWAP64(static_cast<uint64_t>(value))); | ||||
| 
 | ||||
|     assert(false && "Unexpected byte size."); | ||||
|     return value; | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue