diff options
| author | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2020-10-19 00:52:24 +0200 |
| commit | be933ef2241d79558f91796cc5b3a161f72ebf9c (patch) | |
| tree | fe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/EndianSwap.h | |
| parent | 5f8335c1e49ce108ef3481863833c98efa00411b (diff) | |
| download | kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2 kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip | |
sync with upstream
Diffstat (limited to 'xbmc/utils/EndianSwap.h')
| -rw-r--r-- | xbmc/utils/EndianSwap.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/xbmc/utils/EndianSwap.h b/xbmc/utils/EndianSwap.h new file mode 100644 index 0000000..0b02689 --- /dev/null +++ b/xbmc/utils/EndianSwap.h | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (C) 2005-2018 Team Kodi | ||
| 3 | * This file is part of Kodi - https://kodi.tv | ||
| 4 | * | ||
| 5 | * SPDX-License-Identifier: GPL-2.0-or-later | ||
| 6 | * See LICENSES/README.md for more information. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #pragma once | ||
| 10 | |||
| 11 | /* Endian_SwapXX functions taken from SDL (SDL_endian.h) */ | ||
| 12 | |||
| 13 | #ifdef TARGET_POSIX | ||
| 14 | #include <inttypes.h> | ||
| 15 | #elif TARGET_WINDOWS | ||
| 16 | #define __inline__ __inline | ||
| 17 | #include <stdint.h> | ||
| 18 | #endif | ||
| 19 | |||
| 20 | |||
| 21 | /* Set up for C function definitions, even when using C++ */ | ||
| 22 | #ifdef __cplusplus | ||
| 23 | extern "C" { | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #if defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__)) | ||
| 27 | static __inline__ uint16_t Endian_Swap16(uint16_t x) | ||
| 28 | { | ||
| 29 | uint16_t result; | ||
| 30 | |||
| 31 | __asm__("rlwimi %0,%2,8,16,23" : "=&r" (result) : "0" (x >> 8), "r" (x)); | ||
| 32 | return result; | ||
| 33 | } | ||
| 34 | |||
| 35 | static __inline__ uint32_t Endian_Swap32(uint32_t x) | ||
| 36 | { | ||
| 37 | uint32_t result; | ||
| 38 | |||
| 39 | __asm__("rlwimi %0,%2,24,16,23" : "=&r" (result) : "0" (x>>24), "r" (x)); | ||
| 40 | __asm__("rlwimi %0,%2,8,8,15" : "=&r" (result) : "0" (result), "r" (x)); | ||
| 41 | __asm__("rlwimi %0,%2,24,0,7" : "=&r" (result) : "0" (result), "r" (x)); | ||
| 42 | return result; | ||
| 43 | } | ||
| 44 | #else | ||
| 45 | static __inline__ uint16_t Endian_Swap16(uint16_t x) { | ||
| 46 | return((x<<8)|(x>>8)); | ||
| 47 | } | ||
| 48 | |||
| 49 | static __inline__ uint32_t Endian_Swap32(uint32_t x) { | ||
| 50 | return((x<<24)|((x<<8)&0x00FF0000)|((x>>8)&0x0000FF00)|(x>>24)); | ||
| 51 | } | ||
| 52 | #endif | ||
| 53 | |||
| 54 | static __inline__ uint64_t Endian_Swap64(uint64_t x) { | ||
| 55 | uint32_t hi, lo; | ||
| 56 | |||
| 57 | /* Separate into high and low 32-bit values and swap them */ | ||
| 58 | lo = (uint32_t)(x&0xFFFFFFFF); | ||
| 59 | x >>= 32; | ||
| 60 | hi = (uint32_t)(x&0xFFFFFFFF); | ||
| 61 | x = Endian_Swap32(lo); | ||
| 62 | x <<= 32; | ||
| 63 | x |= Endian_Swap32(hi); | ||
| 64 | return(x); | ||
| 65 | |||
| 66 | } | ||
| 67 | |||
| 68 | void Endian_Swap16_buf(uint16_t *dst, uint16_t *src, int w); | ||
| 69 | |||
| 70 | #ifndef WORDS_BIGENDIAN | ||
| 71 | #define Endian_SwapLE16(X) (X) | ||
| 72 | #define Endian_SwapLE32(X) (X) | ||
| 73 | #define Endian_SwapLE64(X) (X) | ||
| 74 | #define Endian_SwapBE16(X) Endian_Swap16(X) | ||
| 75 | #define Endian_SwapBE32(X) Endian_Swap32(X) | ||
| 76 | #define Endian_SwapBE64(X) Endian_Swap64(X) | ||
| 77 | #else | ||
| 78 | #define Endian_SwapLE16(X) Endian_Swap16(X) | ||
| 79 | #define Endian_SwapLE32(X) Endian_Swap32(X) | ||
| 80 | #define Endian_SwapLE64(X) Endian_Swap64(X) | ||
| 81 | #define Endian_SwapBE16(X) (X) | ||
| 82 | #define Endian_SwapBE32(X) (X) | ||
| 83 | #define Endian_SwapBE64(X) (X) | ||
| 84 | #endif | ||
| 85 | |||
| 86 | /* Ends C function definitions when using C++ */ | ||
| 87 | #ifdef __cplusplus | ||
| 88 | } | ||
| 89 | #endif | ||
| 90 | |||
