blob: 4a6da3d21cd5b106bcc4a34d62af24fdbf0dc9f9 [file] [log] [blame]
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +01001/*
Pablo Telloeb82fd22018-02-23 13:43:50 +00002 * Copyright (c) 2017-2018 ARM Limited.
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +01003 *
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#pragma once
25
Pablo Telloeb82fd22018-02-23 13:43:50 +000026/* As some of the merges need these headers, but are all included in the
27 * arm_gemm namespace, put these headers here. */
28#include <arm_neon.h>
29
30#include "asmlib.hpp"
31#include "utils.hpp"
32
33namespace arm_gemm
34{
35template <unsigned int width, unsigned int height, typename Tin, typename Tout>
36inline void MergeResults(Tout *out, const Tin *in, int ldc, int y0, int ymax, int x0, int xmax, const Tout alpha, const Tout beta)
37{
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010038 int full_y_blocks = (ymax - y0) / height;
Pablo Telloeb82fd22018-02-23 13:43:50 +000039 int y_remainder = (ymax - y0) % height;
40 int y_blocks = full_y_blocks + (y_remainder ? 1 : 0);
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010041
42 int full_x_blocks = (xmax - x0) / width;
Pablo Telloeb82fd22018-02-23 13:43:50 +000043 int x_remainder = (xmax - x0) % width;
44 int x_blocks = full_x_blocks + (x_remainder ? 1 : 0);
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010045
Pablo Telloeb82fd22018-02-23 13:43:50 +000046 for(int y_block = 0; y_block < y_blocks; y_block++)
47 {
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010048 int ybase = y0 + (y_block * height);
49
50 int fill_rows = (y_block < full_y_blocks) ? height : y_remainder;
51
Pablo Telloeb82fd22018-02-23 13:43:50 +000052 for(int x_block = 0; x_block < x_blocks; x_block++)
53 {
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010054 int xbase = x0 + (x_block * width);
55
56 int fill_cols = (x_block < full_x_blocks) ? width : x_remainder;
57
Pablo Telloeb82fd22018-02-23 13:43:50 +000058 for(int row = 0; row < fill_rows; row++)
59 {
60 for(int col = 0; col < fill_cols; col++)
61 {
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010062 Tout &p = out[(ybase + row) * ldc + xbase + col];
63
David Mansell4d1e8a22018-05-15 15:24:39 +010064 p = (p * beta) + (alpha * in[row * width + col]);
Moritz Pflanzerbeabe3b2017-08-31 14:56:32 +010065 }
66 }
67
68 in += (width * height);
69 }
70 }
71}
72
73#include "merges/list.hpp"
Pablo Telloeb82fd22018-02-23 13:43:50 +000074
75} // namespace arm_gemm