Coverage Report

Created: 2026-07-12 07:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/Simd/src/Simd/SimdBaseSynetQuantizedShuffle.cpp
Line
Count
Source
1
/*
2
* Simd Library (http://ermig1979.github.io/Simd).
3
*
4
* Copyright (c) 2011-2025 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/SimdSynetQuantizeLinear.h"
25
26
namespace Simd
27
{
28
#if defined(SIMD_SYNET_ENABLE)
29
    namespace Base
30
    {
31
        void SynetQuantizedShuffleLayerForwardNchw0(const uint8_t* src0, int bias0, float norm0, size_t srcC0, const uint8_t* src1, int bias1, float norm1, size_t srcC1, size_t spatial, uint8_t* dst0, uint8_t* dst1, float scale, int zero)
32
0
        {
33
0
            size_t dstC = (srcC0 + srcC1) / 2;
34
0
            size_t cd = 0;
35
0
            for (size_t cs = 0; cs < srcC0; cs += 2, cd += 1)
36
0
            {
37
0
                for (size_t s = 0; s < spatial; ++s)
38
0
                    dst0[s] = DequantizeQuantizeLinear(src0[s], bias0, norm0, scale, zero, 0, 255);
39
0
                src0 += spatial;
40
0
                dst0 += spatial;
41
0
                for (size_t s = 0; s < spatial; ++s)
42
0
                    dst1[s] = DequantizeQuantizeLinear(src0[s], bias0, norm0, scale, zero, 0, 255);
43
0
                src0 += spatial;
44
0
                dst1 += spatial;
45
0
            }
46
0
            for (size_t cs = 0; cs < srcC1; cs += 2, cd += 1)
47
0
            {
48
0
                for (size_t s = 0; s < spatial; ++s)
49
0
                    dst0[s] = DequantizeQuantizeLinear(src1[s], bias1, norm1, scale, zero, 0, 255);
50
0
                src1 += spatial;
51
0
                dst0 += spatial;
52
0
                for (size_t s = 0; s < spatial; ++s)
53
0
                    dst1[s] = DequantizeQuantizeLinear(src1[s], bias1, norm1, scale, zero, 0, 255);
54
0
                src1 += spatial;
55
0
                dst1 += spatial;
56
0
            }        
57
0
        }
58
59
        void SynetQuantizedShuffleLayerForwardNhwc0(const uint8_t* src0, int bias0, float norm0, size_t srcC0, const uint8_t* src1, int bias1, float norm1, size_t srcC1, size_t spatial, uint8_t* dst0, uint8_t* dst1, float scale, int zero)
60
0
        {
61
0
            size_t dstC = (srcC0 + srcC1) / 2;
62
0
            for (size_t s = 0; s < spatial; ++s)
63
0
            {
64
0
                size_t cd = 0;
65
0
                for (size_t cs = 0; cs < srcC0; cs += 2, cd += 1)
66
0
                {
67
0
                    dst0[cd] = DequantizeQuantizeLinear(src0[cs + 0], bias0, norm0, scale, zero, 0, 255);
68
0
                    dst1[cd] = DequantizeQuantizeLinear(src0[cs + 1], bias0, norm0, scale, zero, 0, 255);
69
0
                }
70
0
                for (size_t cs = 0; cs < srcC1; cs += 2, cd += 1)
71
0
                {
72
0
                    dst0[cd] = DequantizeQuantizeLinear(src1[cs + 0], bias1, norm1, scale, zero, 0, 255);
73
0
                    dst1[cd] = DequantizeQuantizeLinear(src1[cs + 1], bias1, norm1, scale, zero, 0, 255);
74
0
                }
75
0
                src0 += srcC0;
76
0
                src1 += srcC1;
77
0
                dst0 += dstC;
78
0
                dst1 += dstC;
79
0
            }
80
81
0
        }
82
83
        void SynetQuantizedShuffleLayerForwardNchw1(const uint8_t* src0, int bias0, float norm0, size_t srcC0, const uint8_t* src1, int bias1, float norm1, size_t srcC1, size_t spatial, uint8_t* dst0, uint8_t* dst1, float scale, int zero)
84
0
        {
85
0
            size_t dstC = (srcC0 + srcC1) / 2;
86
0
            size_t cs = 0;
87
0
            for (size_t cd = 0; cd < srcC0; cs += 1, cd += 2)
88
0
            {
89
0
                for (size_t s = 0; s < spatial; ++s)
90
0
                    dst0[s] = DequantizeQuantizeLinear(src0[s], bias0, norm0, scale, zero, 0, 255);
91
0
                src0 += spatial;
92
0
                dst0 += spatial;
93
0
                for (size_t s = 0; s < spatial; ++s)
94
0
                    dst0[s] = DequantizeQuantizeLinear(src1[s], bias1, norm1, scale, zero, 0, 255);
95
0
                src1 += spatial;
96
0
                dst0 += spatial;
97
0
            }
98
0
            for (size_t cd = 0; cd < srcC1; cs += 1, cd += 2)
99
0
            {
100
0
                for (size_t s = 0; s < spatial; ++s)
101
0
                    dst1[s] = DequantizeQuantizeLinear(src0[s], bias0, norm0, scale, zero, 0, 255);
102
0
                src0 += spatial;
103
0
                dst1 += spatial;
104
0
                for (size_t s = 0; s < spatial; ++s)
105
0
                    dst1[s] = DequantizeQuantizeLinear(src1[s], bias1, norm1, scale, zero, 0, 255);
106
0
                src1 += spatial;
107
0
                dst1 += spatial;
108
0
            }
109
0
        }
110
111
        void SynetQuantizedShuffleLayerForwardNhwc1(const uint8_t* src0, int bias0, float norm0, size_t srcC0, const uint8_t* src1, int bias1, float norm1, size_t srcC1, size_t spatial, uint8_t* dst0, uint8_t* dst1, float scale, int zero)
112
0
        {
113
0
            size_t dstC = (srcC0 + srcC1) / 2;
114
0
            for (size_t s = 0; s < spatial; ++s)
115
0
            {
116
0
                size_t cs = 0;
117
0
                for (size_t cd = 0; cd < srcC0; cd += 2, cs += 1)
118
0
                {
119
0
                    dst0[cd + 0] = DequantizeQuantizeLinear(src0[cs], bias0, norm0, scale, zero, 0, 255);
120
0
                    dst0[cd + 1] = DequantizeQuantizeLinear(src1[cs], bias1, norm1, scale, zero, 0, 255);
121
0
                }
122
0
                for (size_t cd = 0; cd < srcC1; cd += 2, cs += 1)
123
0
                {
124
0
                    dst1[cd + 0] = DequantizeQuantizeLinear(src0[cs], bias0, norm0, scale, zero, 0, 255);
125
0
                    dst1[cd + 1] = DequantizeQuantizeLinear(src1[cs], bias1, norm1, scale, zero, 0, 255);
126
0
                }
127
0
                src0 += dstC;
128
0
                src1 += dstC;
129
0
                dst0 += srcC0;
130
0
                dst1 += srcC1;
131
0
            }
132
0
        }
133
134
        void SynetQuantizedShuffleLayerForward(const uint8_t* src0, int bias0, const float* norm0, size_t srcC0, const uint8_t* src1, int bias1, const float* norm1, size_t srcC1,
135
            size_t spatial, uint8_t* dst0, uint8_t* dst1, const float* scale, int zero, SimdTensorFormatType format, int shuffleType)
136
0
        {
137
0
            size_t dstC = (srcC0 + srcC1) / 2;
138
0
            switch (shuffleType)
139
0
            {
140
0
            case 0:
141
0
                if (format == SimdTensorFormatNhwc)
142
0
                    SynetQuantizedShuffleLayerForwardNhwc0(src0, bias0, *norm0, srcC0, src1, bias1, *norm1, srcC1, spatial, dst0, dst1, *scale, zero);
143
0
                else
144
0
                    SynetQuantizedShuffleLayerForwardNchw0(src0, bias0, *norm0, srcC0, src1, bias1, *norm1, srcC1, spatial, dst0, dst1, *scale, zero);
145
0
                break;
146
0
            case 1:
147
0
                if (format == SimdTensorFormatNhwc)
148
0
                    SynetQuantizedShuffleLayerForwardNhwc1(src0, bias0, *norm0, srcC0, src1, bias1, *norm1, srcC1, spatial, dst0, dst1, *scale, zero);
149
0
                else
150
0
                    SynetQuantizedShuffleLayerForwardNchw1(src0, bias0, *norm0, srcC0, src1, bias1, *norm1, srcC1, spatial, dst0, dst1, *scale, zero);
151
0
                break;
152
0
            }
153
0
        }
154
    }
155
#endif
156
}