blob: 8a49c775d321ab110c6d387bc011344ccb1c30df [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
25#include <premultiply.hpp>
26
27#define CHANNEL_MULTIPLIER 6
28#define BLOCK_SIZE 4
29
30void do_premultiply_float_6(const float *in_ptr,
31 const unsigned int ld_row,
32 const unsigned int ld_col,
33 float *out_ptr,
34 const unsigned int out_ld_row,
35 const unsigned int out_ld_col,
36 const unsigned int tile_rows,
37 const unsigned int tile_cols,
38 const unsigned input_channels)
39{
40 for(unsigned int i = 0; i < tile_rows; i++)
41 {
42 const float *ip2 = in_ptr + i * ld_row;
43 float *op2 = out_ptr + i * out_ld_row;
44 for(unsigned int j = 0; j < tile_cols; j++)
45 {
46 const float *ip = ip2;
47 float *op = op2;
Michael Tyler4c30de02023-07-07 12:01:32 +010048
49 unsigned int num_blocks = input_channels / BLOCK_SIZE;
50 for(unsigned int c = 0; c < num_blocks; c++)
Michael Tyler8deee9b2023-06-30 11:26:05 +010051 {
52 float vals[BLOCK_SIZE];
53 for(unsigned int v = 0; v < BLOCK_SIZE; v++)
54 {
55 vals[v] = ip[v];
56 }
57 ip += BLOCK_SIZE;
58
59 for(unsigned int v = 0; v < BLOCK_SIZE; v++)
60 {
61 for(unsigned int r = 0; r < CHANNEL_MULTIPLIER; r++)
62 {
63 op[r] = vals[v];
64 }
65 op += CHANNEL_MULTIPLIER;
66 }
67 }
Michael Tyler4c30de02023-07-07 12:01:32 +010068
69 unsigned int rem = input_channels - num_blocks * BLOCK_SIZE;
70 for(unsigned int c = 0; c < rem; c++)
71 {
72 float val = ip[c];
73 for(unsigned int r = 0; r < CHANNEL_MULTIPLIER; r++)
74 {
75 op[r] = val;
76 }
77 op += CHANNEL_MULTIPLIER;
78 }
79
Michael Tyler8deee9b2023-06-30 11:26:05 +010080 ip2 += ld_col;
81 op2 += out_ld_col;
82 }
83 }
84}