mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 10:52:56 +00:00
use compiler built-ins for byte swapping
for reference: https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html https://clang.llvm.org/docs/LanguageExtensions.html Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
cda92e3f7d
commit
8a9f064ede
1 changed files with 3 additions and 38 deletions
|
@ -36,10 +36,6 @@
|
|||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#ifdef __GLIBC__
|
||||
#include <byteswap.h>
|
||||
#endif
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
@ -165,49 +161,18 @@ template <> inline qint16 qFromBigEndian<qint16>(const uchar *src)
|
|||
*/
|
||||
template <typename T> T qbswap(const T source);
|
||||
|
||||
#ifdef __GLIBC__
|
||||
template <> inline quint64 qbswap<quint64>(const quint64 source)
|
||||
{
|
||||
return bswap_64(source);
|
||||
return __builtin_bswap64(source);
|
||||
}
|
||||
template <> inline quint32 qbswap<quint32>(const quint32 source)
|
||||
{
|
||||
return bswap_32(source);
|
||||
return __builtin_bswap32(source);
|
||||
}
|
||||
template <> inline quint16 qbswap<quint16>(const quint16 source)
|
||||
{
|
||||
return bswap_16(source);
|
||||
return __builtin_bswap16(source);
|
||||
}
|
||||
#else
|
||||
template <> inline quint64 qbswap<quint64>(const quint64 source)
|
||||
{
|
||||
return 0
|
||||
| ((source & Q_UINT64_C(0x00000000000000ff)) << 56)
|
||||
| ((source & Q_UINT64_C(0x000000000000ff00)) << 40)
|
||||
| ((source & Q_UINT64_C(0x0000000000ff0000)) << 24)
|
||||
| ((source & Q_UINT64_C(0x00000000ff000000)) << 8)
|
||||
| ((source & Q_UINT64_C(0x000000ff00000000)) >> 8)
|
||||
| ((source & Q_UINT64_C(0x0000ff0000000000)) >> 24)
|
||||
| ((source & Q_UINT64_C(0x00ff000000000000)) >> 40)
|
||||
| ((source & Q_UINT64_C(0xff00000000000000)) >> 56);
|
||||
}
|
||||
|
||||
template <> inline quint32 qbswap<quint32>(const quint32 source)
|
||||
{
|
||||
return 0
|
||||
| ((source & 0x000000ff) << 24)
|
||||
| ((source & 0x0000ff00) << 8)
|
||||
| ((source & 0x00ff0000) >> 8)
|
||||
| ((source & 0xff000000) >> 24);
|
||||
}
|
||||
|
||||
template <> inline quint16 qbswap<quint16>(const quint16 source)
|
||||
{
|
||||
return quint16( 0
|
||||
| ((source & 0x00ff) << 8)
|
||||
| ((source & 0xff00) >> 8) );
|
||||
}
|
||||
#endif // __GLIBC__
|
||||
|
||||
// signed specializations
|
||||
template <> inline qint64 qbswap<qint64>(const qint64 source)
|
||||
|
|
Loading…
Add table
Reference in a new issue