Coverage Report

Created: 2025-12-10 07:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Simd/src/Simd/SimdBaseReorder.cpp
Line
Count
Source
1
/*
2
* Simd Library (http://ermig1979.github.io/Simd).
3
*
4
* Copyright (c) 2011-2024 Yermalayeu Ihar.
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a copy
7
* of this software and associated documentation files (the "Software"), to deal
8
* in the Software without restriction, including without limitation the rights
9
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
* copies of the Software, and to permit persons to whom the Software is
11
* furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice shall be included in
14
* all copies or substantial portions of the Software.
15
*
16
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
* SOFTWARE.
23
*/
24
#include "Simd/SimdMemory.h"
25
#include "Simd/SimdReorder.h"
26
27
namespace Simd
28
{
29
    namespace Base
30
    {
31
        SIMD_INLINE void Reorder16bitX(const uint8_t * src, uint8_t * dst)
32
0
        {
33
0
            size_t value = *(size_t*)src;
34
0
#if defined (SIMD_X64_ENABLE) || defined (SIMD_ARM64_ENABLE)
35
0
            *(size_t*)dst = (value & 0xFF00FF00FF00FF00) >> 8 | (value & 0x00FF00FF00FF00FF) << 8;
36
#else
37
            *(size_t*)dst = (value & 0xFF00FF00) >> 8 | (value & 0x00FF00FF) << 8;
38
#endif
39
0
        }
40
41
        void Reorder16bit(const uint8_t * src, size_t size, uint8_t * dst)
42
0
        {
43
0
            assert(size % 2 == 0);
44
45
0
            size_t alignedSize = AlignLo(size, sizeof(size_t));
46
0
            for (size_t i = 0; i < alignedSize; i += sizeof(size_t))
47
0
                Reorder16bitX(src + i, dst + i);
48
0
            for (size_t i = alignedSize; i < size; i += 2)
49
0
                Reorder16bit(src + i, dst + i);
50
0
        }
51
52
        SIMD_INLINE void Reorder32bitX(const uint8_t * src, uint8_t * dst)
53
0
        {
54
0
#if defined (SIMD_X64_ENABLE) || defined (SIMD_ARM64_ENABLE)
55
0
            size_t value = *(size_t*)src;
56
0
            *(size_t*)dst =
57
0
                (value & 0x000000FF000000FF) << 24 | (value & 0x0000FF000000FF00) << 8 |
58
0
                (value & 0x00FF000000FF0000) >> 8 | (value & 0xFF000000FF000000) >> 24;
59
#else
60
            Reorder32bit(src, dst);
61
#endif
62
0
        }
63
64
        void Reorder32bit(const uint8_t * src, size_t size, uint8_t * dst)
65
0
        {
66
0
            assert(size % 4 == 0);
67
68
0
            size_t alignedSize = AlignLo(size, sizeof(size_t));
69
0
            for (size_t i = 0; i < alignedSize; i += sizeof(size_t))
70
0
                Reorder32bitX(src + i, dst + i);
71
0
            for (size_t i = alignedSize; i < size; i += 4)
72
0
                Reorder32bit(src + i, dst + i);
73
0
        }
74
75
        void Reorder64bit(const uint8_t * src, size_t size, uint8_t * dst)
76
0
        {
77
0
            assert(size % 8 == 0);
78
79
0
            for (size_t i = 0; i < size; i += 8)
80
0
                Reorder64bit(src + i, dst + i);
81
0
        }
82
    }
83
}