blob: 3dfa2b8b2ba9bf63d63727781660f93cbfa37253 [file] [log] [blame]
Gunes Bayir2ae536a2023-07-05 11:39:37 +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
Gunes Bayir3c776062023-07-12 14:50:56 +010025#include "ckw/TileOperand.h"
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010026#include "ckw/Error.h"
27#include "src/ITile.h"
Gunes Bayir2ae536a2023-07-05 11:39:37 +010028
29namespace ckw
30{
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010031
32TileOperand::TileOperand(ITile &tile)
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010033 : _tile(&tile), _row_start(0), _row_end(tile.info().height()), _col_start(0), _col_end(tile.info().width())
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010034{
35}
36
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010037TileOperand::TileOperand(const TileOperand &operand, int32_t row_start, int32_t row_end, int32_t col_start, int32_t col_end)
38 : _tile(operand._tile), _row_start(row_start), _row_end(row_end), _col_start(col_start), _col_end(col_end)
39{
40 CKW_ASSERT(row_start >= 0 && row_start < _tile->info().height());
41 CKW_ASSERT(row_end > row_start && row_end <= _tile->info().height());
42 CKW_ASSERT(col_start >= 0 && col_start < _tile->info().width());
43 CKW_ASSERT(col_end > col_start && col_end <= _tile->info().width());
44}
45
46TileOperand TileOperand::tile(int32_t row_start, int32_t row_end, int32_t col_start, int32_t col_end) const
47{
48 CKW_ASSERT(row_start >= 0 && _row_start + row_start < _row_end);
49 CKW_ASSERT(row_end > row_start && _row_start + row_end <= _row_end);
50 CKW_ASSERT(col_start >= 0 && _col_start + col_start < _col_end);
51 CKW_ASSERT(col_end > col_start && _col_start + col_end <= _col_end);
52
53 return TileOperand(*this, _row_start + row_start, _row_start + row_end, _col_start + col_start, _col_start + col_end);
54}
55
56TileOperand TileOperand::row(int32_t row) const
57{
58 CKW_ASSERT(row >= 0 && _row_start + row < _row_end);
59
60 return tile(_row_start + row, _row_start + row + 1, _col_start, _col_end);
61}
62
63TileOperand TileOperand::scalar(int32_t row, int32_t col) const
64{
65 CKW_ASSERT(row >= 0 && _row_start + row < _row_end);
66 CKW_ASSERT(col >= 0 && _col_start + col < _col_end);
67
68 return tile(_row_start + row, _row_start + row + 1, _col_start + col, _col_start + col + 1);
69}
70
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010071} // namespace ckw