Skip to content

Commit 217b726

Browse files
committed
Some improvement around endianess conversion functions
1 parent 4e52ad5 commit 217b726

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*******************************************************************************
44

55
=== 1.0.44 ===
6+
* Some improvement around endianess conversion functions.
67
* Updated some basic definitions related to pointer allocation.
78

89
=== 1.0.43 ===

include/lsp-plug.in/common/endian.h

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3-
* (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
2+
* Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3+
* (C) 2025 Vladimir Sadovnikov <sadko4u@gmail.com>
44
*
55
* This file is part of lsp-common-lib
66
* Created on: 1 апр. 2020 г.
@@ -24,6 +24,7 @@
2424

2525
#include <lsp-plug.in/common/version.h>
2626
#include <lsp-plug.in/common/types.h>
27+
#include <lsp-plug.in/stdlib/string.h>
2728

2829
#define LSP_PLUG_IN_COMMON_ENDIAN_IMPL
2930
// Include unsigned functions definition
@@ -42,30 +43,42 @@
4243

4344
// Define macros
4445
#ifdef ARCH_LE
45-
#define LE_TO_CPU(x) (x)
46-
#define CPU_TO_LE(x) (x)
46+
#define LE_TO_CPU(x) (x)
47+
#define CPU_TO_LE(x) (x)
4748

48-
#define BE_TO_CPU(x) ::lsp::byte_swap(x)
49-
#define CPU_TO_BE(x) ::lsp::byte_swap(x)
49+
#define BE_TO_CPU(x) ::lsp::byte_swap(x)
50+
#define CPU_TO_BE(x) ::lsp::byte_swap(x)
5051

51-
#define VLE_TO_CPU(v, n) do {} while(false)
52-
#define CPU_TO_VLE(v, n) do {} while(false)
52+
#define VLE_TO_CPU(v, n) do {} while(false)
53+
#define CPU_TO_VLE(v, n) do {} while(false)
5354

54-
#define VBE_TO_CPU(v, n) ::lsp::byte_swap(v, n)
55-
#define CPU_TO_VBE(v, n) ::lsp::byte_swap(v, n)
55+
#define VBE_TO_CPU(v, n) ::lsp::byte_swap(v, n)
56+
#define CPU_TO_VBE(v, n) ::lsp::byte_swap(v, n)
57+
58+
#define VLE_TO_CPU_COPY(d, v, n) ::lsp::no_byte_swap_copy(d, v, n)
59+
#define CPU_TO_VLE_COPY(d, v, n) ::lsp::no_byte_swap_copy(d, v, n)
60+
61+
#define VBE_TO_CPU_COPY(d, v, n) ::lsp::byte_swap_copy(d, v, n)
62+
#define CPU_TO_VBE_COPY(d, v, n) ::lsp::byte_swap_copy(d, v, n)
5663

5764
#else
58-
#define LE_TO_CPU(x) ::lsp::byte_swap(x)
59-
#define CPU_TO_LE(x) ::lsp::byte_swap(x)
65+
#define LE_TO_CPU(x) ::lsp::byte_swap(x)
66+
#define CPU_TO_LE(x) ::lsp::byte_swap(x)
67+
68+
#define BE_TO_CPU(x) (x)
69+
#define CPU_TO_BE(x) (x)
70+
71+
#define VLE_TO_CPU(v, n) ::lsp::byte_swap(v, n)
72+
#define CPU_TO_VLE(v, n) ::lsp::byte_swap(v, n)
6073

61-
#define BE_TO_CPU(x) (x)
62-
#define CPU_TO_BE(x) (x)
74+
#define VBE_TO_CPU(v, n) do {} while(false)
75+
#define CPU_TO_VBE(v, n) do {} while(false)
6376

64-
#define VLE_TO_CPU(v, n) ::lsp::byte_swap(v, n)
65-
#define CPU_TO_VLE(v, n) ::lsp::byte_swap(v, n)
77+
#define VLE_TO_CPU_COPY(d, v, n) ::lsp::byte_swap_copy(d, v, n)
78+
#define CPU_TO_VLE_COPY(d, v, n) ::lsp::byte_swap_copy(d, v, n)
6679

67-
#define VBE_TO_CPU(v, n) do {} while(false)
68-
#define CPU_TO_VBE(v, n) do {} while(false)
80+
#define VBE_TO_CPU_COPY(d, v, n) ::lsp::no_byte_swap_copy(d, v, n)
81+
#define CPU_TO_VBE_COPY(d, v, n) ::lsp::no_byte_swap_copy(d, v, n)
6982

7083
#endif /* */
7184

@@ -121,6 +134,12 @@ namespace lsp
121134
for (size_t i=0; i<n; ++i)
122135
dst[i] = byte_swap(src[i]);
123136
}
137+
138+
template <class T>
139+
inline void no_byte_swap_copy(T *dst, const T *src, size_t n)
140+
{
141+
memcpy(dst, src, n * sizeof(T));
142+
}
124143
} /* namespace lsp */
125144

126145
#endif /* LSP_PLUG_IN_COMMON_ENDIAN_H_ */

0 commit comments

Comments
 (0)