1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-common-lib
* Created on: 1 апр. 2020 г.
*
* lsp-common-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-common-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-common-lib. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LSP_PLUG_IN_COMMON_ENDIAN_H_
#define LSP_PLUG_IN_COMMON_ENDIAN_H_
#include <lsp-plug.in/common/version.h>
#include <lsp-plug.in/common/types.h>
#define LSP_PLUG_IN_COMMON_ENDIAN_IMPL
// Include unsigned functions definition
#if defined(ARCH_X86)
#include <lsp-plug.in/common/arch/x86/endian.h>
#elif defined(ARCH_AARCH64)
#include <lsp-plug.in/common/arch/aarch64/endian.h>
#elif defined(ARCH_ARM)
#include <lsp-plug.in/common/arch/arm/endian.h>
#else
#include <lsp-plug.in/common/arch/generic/endian.h>
#endif /* defined(ARCH_X86) */
#undef LSP_PLUG_IN_COMMON_ENDIAN_IMPL
// Define macros
#ifdef ARCH_LE
#define LE_TO_CPU(x) (x)
#define CPU_TO_LE(x) (x)
#define BE_TO_CPU(x) ::lsp::byte_swap(x)
#define CPU_TO_BE(x) ::lsp::byte_swap(x)
#define VLE_TO_CPU(v, n)
#define CPU_TO_VLE(v, n)
#define VBE_TO_CPU(v, n) ::lsp::byte_swap(v, n)
#define CPU_TO_VBE(v, n) ::lsp::byte_swap(v, n)
#else
#define LE_TO_CPU(x) ::lsp::byte_swap(x)
#define CPU_TO_LE(x) ::lsp::byte_swap(x)
#define BE_TO_CPU(x) (x)
#define CPU_TO_BE(x) (x)
#define VLE_TO_CPU(v, n) ::lsp::byte_swap(v, n)
#define CPU_TO_VLE(v, n) ::lsp::byte_swap(v, n)
#define VBE_TO_CPU(v, n)
#define CPU_TO_VBE(v, n)
#endif /* */
namespace lsp
{
inline uint8_t __lsp_forced_inline byte_swap(uint8_t v)
{
return v;
}
inline int8_t __lsp_forced_inline byte_swap(int8_t v)
{
return v;
}
inline int16_t __lsp_forced_inline byte_swap(int16_t v)
{
return byte_swap(uint16_t(v));
}
inline int32_t __lsp_forced_inline byte_swap(int32_t v)
{
return byte_swap(uint32_t(v));
}
inline int64_t __lsp_forced_inline byte_swap(int64_t v)
{
return byte_swap(uint64_t(v));
}
inline void __lsp_forced_inline byte_swap(uint8_t *v, size_t n)
{
}
inline void __lsp_forced_inline byte_swap(int8_t *v, size_t n)
{
}
inline void __lsp_forced_inline byte_swap(wchar_t *v, size_t n)
{
#if defined(WCHART_16BIT)
byte_swap(reinterpret_cast<uint16_t *>(v), n);
#elif defined(WCHART_32BIT)
byte_swap(reinterpret_cast<uint32_t *>(v), n);
#else
byte_swap(reinterpret_cast<unsigned int *>(v), n);
#endif
}
}
#endif /* LSP_PLUG_IN_COMMON_ENDIAN_H_ */
|