Use compiler intrinsics for byte swapping
This commit is contained in:
@@ -97,8 +97,7 @@ else()
|
||||
"archutils/Unix/GetSysInfo.h"
|
||||
"archutils/Unix/RunningUnderValgrind.h"
|
||||
"archutils/Unix/SignalHandler.h"
|
||||
"archutils/Unix/SpecialDirs.h"
|
||||
"archutils/Common/gcc_byte_swaps.h")
|
||||
"archutils/Unix/SpecialDirs.h")
|
||||
if(X11_FOUND)
|
||||
list(APPEND SMDATA_OS_SRC "archutils/Unix/X11Helper.cpp")
|
||||
list(APPEND SMDATA_OS_HPP "archutils/Unix/X11Helper.h")
|
||||
|
||||
+7
-28
@@ -204,35 +204,14 @@ namespace Endian
|
||||
#endif
|
||||
}
|
||||
|
||||
/* We only have unsigned swaps; byte swapping a signed value doesn't make sense.
|
||||
*
|
||||
* Platform-specific, optimized versions are defined in arch_setup, with the names
|
||||
* ArchSwap32, ArchSwap24, and ArchSwap16; we define them to their real names here,
|
||||
* to force inclusion of this file when swaps are in use (to prevent different dependencies
|
||||
* on different systems).
|
||||
*/
|
||||
#ifdef HAVE_BYTE_SWAPS
|
||||
#define Swap32 ArchSwap32
|
||||
#define Swap24 ArchSwap24
|
||||
#define Swap16 ArchSwap16
|
||||
#ifdef _WIN32
|
||||
#define Swap32(n) _byteswap_ulong(n)
|
||||
#define Swap24(n) _byteswap_ulong(n) >> 8
|
||||
#define Swap16(n) _byteswap_ushort(n)
|
||||
#else
|
||||
inline std::uint32_t Swap32( std::uint32_t n )
|
||||
{
|
||||
return (n >> 24) |
|
||||
((n >> 8) & 0x0000FF00) |
|
||||
((n << 8) & 0x00FF0000) |
|
||||
(n << 24);
|
||||
}
|
||||
|
||||
inline std::uint32_t Swap24( std::uint32_t n )
|
||||
{
|
||||
return Swap32( n ) >> 8; // xx223344 -> 443322xx -> 00443322
|
||||
}
|
||||
|
||||
inline std::uint16_t Swap16( std::uint16_t n )
|
||||
{
|
||||
return (n >> 8) | (n << 8);
|
||||
}
|
||||
#define Swap32(n) __builtin_bswap32(n)
|
||||
#define Swap24(n) __builtin_bswap32(n) >> 8
|
||||
#define Swap16(n) __builtin_bswap16(n)
|
||||
#endif
|
||||
|
||||
inline std::uint32_t Swap32LE( std::uint32_t n ) { return Endian::little ? n : Swap32( n ); }
|
||||
|
||||
+1
-1
@@ -17,7 +17,6 @@
|
||||
#include "arch/ArchHooks/ArchHooks.h"
|
||||
#include "arch/LoadingWindow/LoadingWindow.h"
|
||||
#include "arch/Dialog/Dialog.h"
|
||||
#include <ctime>
|
||||
|
||||
#include "ProductInfo.h"
|
||||
|
||||
@@ -71,6 +70,7 @@
|
||||
#include "ver.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
#ifndef GCC_BYTE_SWAPS_H
|
||||
#define GCC_BYTE_SWAPS_H
|
||||
|
||||
#if defined(CPU_X86)
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
inline std::uint32_t ArchSwap32( std::uint32_t n )
|
||||
{
|
||||
asm(
|
||||
"xchg %b0, %h0\n"
|
||||
"rorl $16, %0\n"
|
||||
"xchg %b0, %h0":
|
||||
"=q" (n): "0" (n) );
|
||||
return n;
|
||||
}
|
||||
|
||||
inline std::uint32_t ArchSwap24( std::uint32_t n )
|
||||
{
|
||||
asm(
|
||||
"xchg %b0, %h0\n"
|
||||
"rorl $16, %0\n"
|
||||
"xchg %b0, %h0\n"
|
||||
"shrl $8, %0\n":
|
||||
"=q" (n): "0" (n) );
|
||||
return n;
|
||||
}
|
||||
|
||||
inline std::uint16_t ArchSwap16( std::uint16_t n )
|
||||
{
|
||||
asm(
|
||||
"xchg %b0, %h0\n":
|
||||
"=q" (n): "0" (n) );
|
||||
return n;
|
||||
}
|
||||
|
||||
#define HAVE_BYTE_SWAPS
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*
|
||||
* (c) 2004 Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
@@ -29,12 +29,6 @@ extern "C" int sm_main( int argc, char *argv[] );
|
||||
# define __MACOSX__
|
||||
#endif
|
||||
|
||||
#include <libkern/OSByteOrder.h>
|
||||
#define ArchSwap32(n) OSSwapInt32((n))
|
||||
#define ArchSwap24(n) (ArchSwap32((n)) >> 8)
|
||||
#define ArchSwap16(n) OSSwapInt16((n))
|
||||
#define HAVE_BYTE_SWAPS
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#undef MACHINE
|
||||
#endif
|
||||
|
||||
#include "archutils/Common/gcc_byte_swaps.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
@@ -82,10 +82,6 @@ void my_usleep( unsigned long usec );
|
||||
#define CRASH_HANDLER
|
||||
#endif
|
||||
|
||||
#define ArchSwap32(n) _byteswap_ulong(n)
|
||||
#define ArchSwap24(n) _byteswap_ulong(n) >> 8
|
||||
#define ArchSwap16(n) _byteswap_ushort(n)
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
/* Make sure everyone has min and max: */
|
||||
#include <algorithm>
|
||||
|
||||
/* Everything will need string for one reason or another: */
|
||||
#include <string>
|
||||
|
||||
/* Branch optimizations: */
|
||||
#if defined(__GNUC__)
|
||||
#define likely(x) (__builtin_expect(!!(x), 1))
|
||||
|
||||
Reference in New Issue
Block a user