blob: fb97cf8baf46af59ea9e73a02518ebb113ce8699 [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{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010047 if (sizeof(T) == 4 && channel_multiplier == 6)
Michael Tyler8deee9b2023-06-30 11:26:05 +010048 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010049 do_premultiply_float_6((const float *)in_ptr, ld_row, ld_col, (float *)out_ptr, out_ld_row, out_ld_col,
50 tile_rows, tile_cols, input_channels);
Michael Tyler8deee9b2023-06-30 11:26:05 +010051 }
52 else
53 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010054 for (unsigned int i = 0; i < tile_rows; i++)
Michael Tyler8deee9b2023-06-30 11:26:05 +010055 {
56 const T *ip2 = in_ptr + i * ld_row;
57 T *op2 = out_ptr + i * out_ld_row;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010058 for (unsigned int j = 0; j < tile_cols; j++)
Michael Tyler8deee9b2023-06-30 11:26:05 +010059 {
60 const T *ip = ip2;
61 T *op = op2;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010062 for (unsigned int c = 0; c < input_channels; c++)
Michael Tyler8deee9b2023-06-30 11:26:05 +010063 {
64 T val = *ip;
65 ip++;
66
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010067 for (unsigned int r = 0; r < channel_multiplier; r++)
Michael Tyler8deee9b2023-06-30 11:26:05 +010068 {
69 op[r] = val;
70 }
71 op += channel_multiplier;
72 }
73 ip2 += ld_col;
74 op2 += out_ld_col;
75 }
76 }
77 }
78}