blob: 8ced6cfe3ffabbe9b4a052c2109d163c854f3586 [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"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010026
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010027#include "ckw/Error.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010029#include "src/ITile.h"
Gunes Bayir2ae536a2023-07-05 11:39:37 +010030
31namespace ckw
32{
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010033
Gunes Bayir2b9fa592024-01-17 16:07:03 +000034TileOperand::TileOperand() : _tile(nullptr), _row_start(0), _row_end(0), _col_start(0), _col_end(0)
35{
36}
37
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010038TileOperand::TileOperand(ITile &tile)
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010039 : _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 +010040{
41}
42
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010043TileOperand::TileOperand(
44 const TileOperand &operand, int32_t row_start, int32_t row_end, int32_t col_start, int32_t col_end)
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010045 : _tile(operand._tile), _row_start(row_start), _row_end(row_end), _col_start(col_start), _col_end(col_end)
46{
47 CKW_ASSERT(row_start >= 0 && row_start < _tile->info().height());
48 CKW_ASSERT(row_end > row_start && row_end <= _tile->info().height());
49 CKW_ASSERT(col_start >= 0 && col_start < _tile->info().width());
50 CKW_ASSERT(col_end > col_start && col_end <= _tile->info().width());
51}
52
Gunes Bayir2b9fa592024-01-17 16:07:03 +000053bool TileOperand::is_valid() const
54{
55 return _tile != nullptr;
56}
57
58const TileInfo &TileOperand::tile_info() const
59{
60 return _tile->info();
61}
62
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010063TileOperand TileOperand::tile(int32_t row_start, int32_t row_end, int32_t col_start, int32_t col_end) const
64{
65 CKW_ASSERT(row_start >= 0 && _row_start + row_start < _row_end);
66 CKW_ASSERT(row_end > row_start && _row_start + row_end <= _row_end);
67 CKW_ASSERT(col_start >= 0 && _col_start + col_start < _col_end);
68 CKW_ASSERT(col_end > col_start && _col_start + col_end <= _col_end);
69
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010070 return TileOperand(*this, _row_start + row_start, _row_start + row_end, _col_start + col_start,
71 _col_start + col_end);
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010072}
73
74TileOperand TileOperand::row(int32_t row) const
75{
76 CKW_ASSERT(row >= 0 && _row_start + row < _row_end);
77
78 return tile(_row_start + row, _row_start + row + 1, _col_start, _col_end);
79}
80
81TileOperand TileOperand::scalar(int32_t row, int32_t col) const
82{
83 CKW_ASSERT(row >= 0 && _row_start + row < _row_end);
84 CKW_ASSERT(col >= 0 && _col_start + col < _col_end);
85
86 return tile(_row_start + row, _row_start + row + 1, _col_start + col, _col_start + col + 1);
87}
88
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010089} // namespace ckw