blob: 16f26de38abd74dfa0945a17a662cd31db2a3c59 [file] [log] [blame]
Michael Tyler8deee9b2023-06-30 11:26:05 +01001/*
2 * Copyright (c) 2023 Arm Limited.
3 *
4 * SPDX-License-Identifier: MIT
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
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell 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 all
14 * 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
25void do_premultiply_float_6(const float *in_ptr,
26 const unsigned int ld_row,
27 const unsigned int ld_col,
28 float *out_ptr,
29 const unsigned int out_ld_row,
30 const unsigned int out_ld_col,
31 const unsigned int tile_rows,
32 const unsigned int tile_cols,
33 const unsigned input_channels);
34
35template <typename T>
36void do_premultiply(const T *in_ptr,
37 const unsigned int ld_row,
38 const unsigned int ld_col,
39 T *out_ptr,
40 const unsigned int out_ld_row,
41 const unsigned int out_ld_col,
42 const unsigned int tile_rows,
43 const unsigned int tile_cols,
44 const unsigned input_channels,
45 const unsigned int channel_multiplier)
46{
47 if(sizeof(T) == 4 && channel_multiplier == 6)
48 {
49 do_premultiply_float_6(
50 (const float *)in_ptr, ld_row, ld_col,
51 (float *)out_ptr, out_ld_row, out_ld_col,
52 tile_rows, tile_cols,
53 input_channels);
54 }
55 else
56 {
57 for(unsigned int i = 0; i < tile_rows; i++)
58 {
59 const T *ip2 = in_ptr + i * ld_row;
60 T *op2 = out_ptr + i * out_ld_row;
61 for(unsigned int j = 0; j < tile_cols; j++)
62 {
63 const T *ip = ip2;
64 T *op = op2;
65 for(unsigned int c = 0; c < input_channels; c++)
66 {
67 T val = *ip;
68 ip++;
69
70 for(unsigned int r = 0; r < channel_multiplier; r++)
71 {
72 op[r] = val;
73 }
74 op += channel_multiplier;
75 }
76 ip2 += ld_col;
77 op2 += out_ld_col;
78 }
79 }
80 }
81}