File: reverse.h

package info (click to toggle)
lsp-plugins 1.2.21-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 120,408 kB
  • sloc: cpp: 589,849; xml: 74,078; makefile: 13,396; php: 1,268; sh: 185
file content (126 lines) | stat: -rw-r--r-- 4,001 bytes parent folder | download
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
118
119
120
121
122
123
124
125
126
/*
 * Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
 *           (C) 2023 Vladimir Sadovnikov <sadko4u@gmail.com>
 *
 * This file is part of lsp-common-lib
 * Created on: 5 мар. 2023 г.
 *
 * 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_ARCH_GENERIC_BITS_REVERSE_H_
#define LSP_PLUG_IN_COMMON_ARCH_GENERIC_BITS_REVERSE_H_

#ifndef LSP_PLUG_IN_COMMON_BITS_IMPL
    #error "This file should not be included directly"
#endif /* LSP_PLUG_IN_COMMON_BITS_IMPL */

namespace lsp
{
    // Unsigned implementation
    inline uint8_t      reverse_bits(uint8_t src)
    {
        return lsp_rb_data[src];
    }

    inline uint16_t     reverse_bits(uint16_t v)
    {
        return (uint16_t(lsp_rb_data[v & 0xff]) << 8) | (uint16_t(lsp_rb_data[v >> 8]));
    }

    inline uint32_t     reverse_bits(uint32_t v)
    {
        return
            (uint32_t(lsp_rb_data[v >> 24])) |
            (uint32_t(lsp_rb_data[(v >> 16) & 0xff]) << 8) |
            (uint32_t(lsp_rb_data[(v >> 8) & 0xff]) << 16) |
            (uint32_t(lsp_rb_data[v & 0xff]) << 24);
    }

    inline uint64_t     reverse_bits(uint64_t v)
    {
        return
            (uint64_t(lsp_rb_data[v >> 56])) |
            (uint64_t(lsp_rb_data[(v >> 48) & 0xff]) << 8) |
            (uint64_t(lsp_rb_data[(v >> 40) & 0xff]) << 16) |
            (uint64_t(lsp_rb_data[(v >> 32) & 0xff]) << 24) |
            (uint64_t(lsp_rb_data[(v >> 24) & 0xff]) << 32) |
            (uint64_t(lsp_rb_data[(v >> 16) & 0xff]) << 40) |
            (uint64_t(lsp_rb_data[(v >> 8) & 0xff]) << 48) |
            (uint64_t(lsp_rb_data[v & 0xff]) << 56);
    }

    inline uint8_t      reverse_bits(uint8_t v, size_t count)
    {
        return reverse_bits(v) >> (sizeof(uint8_t) * 8 - count);
    }

    inline uint16_t     reverse_bits(uint16_t v, size_t count)
    {
        return reverse_bits(v) >> (sizeof(uint16_t) * 8 - count);
    }

    inline uint32_t     reverse_bits(uint32_t v, size_t count)
    {
        return reverse_bits(v) >> (sizeof(uint32_t) * 8 - count);
    }

    inline uint64_t     reverse_bits(uint64_t v, size_t count)
    {
        return reverse_bits(v) >> (sizeof(uint64_t) * 8 - count);
    }

    // Signed implementation
    inline int8_t __lsp_forced_inline      reverse_bits(int8_t v)
    {
        return reverse_bits(uint8_t(v));
    }

    inline int16_t __lsp_forced_inline     reverse_bits(int16_t v)
    {
        return reverse_bits(uint16_t(v));
    }

    inline int32_t __lsp_forced_inline     reverse_bits(int32_t v)
    {
        return reverse_bits(uint32_t(v));
    }

    inline int64_t __lsp_forced_inline     reverse_bits(int64_t v)
    {
        return reverse_bits(uint64_t(v));
    }

    inline int8_t __lsp_forced_inline      reverse_bits(int8_t v, size_t count)
    {
        return reverse_bits(uint8_t(v), count);
    }

    inline int16_t __lsp_forced_inline     reverse_bits(int16_t v, size_t count)
    {
        return reverse_bits(uint16_t(v), count);
    }

    inline int32_t __lsp_forced_inline     reverse_bits(int32_t v, size_t count)
    {
        return reverse_bits(uint32_t(v), count);
    }

    inline int64_t __lsp_forced_inline     reverse_bits(int64_t v, size_t count)
    {
        return reverse_bits(uint64_t(v), count);
    }
} /* namespace lsp */

#endif /* LSP_PLUG_IN_COMMON_ARCH_GENERIC_BITS_REVERSE_H_ */