blob: 865ef85a13e4e8678a91e1cfa756c87551dee132 [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
34TileOperand::TileOperand(ITile &tile)
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010035 : _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 +010036{
37}
38
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010039TileOperand::TileOperand(
40 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 +010041 : _tile(operand._tile), _row_start(row_start), _row_end(row_end), _col_start(col_start), _col_end(col_end)
42{
43 CKW_ASSERT(row_start >= 0 && row_start < _tile->info().height());
44 CKW_ASSERT(row_end > row_start && row_end <= _tile->info().height());
45 CKW_ASSERT(col_start >= 0 && col_start < _tile->info().width());
46 CKW_ASSERT(col_end > col_start && col_end <= _tile->info().width());
47}
48
49TileOperand TileOperand::tile(int32_t row_start, int32_t row_end, int32_t col_start, int32_t col_end) const
50{
51 CKW_ASSERT(row_start >= 0 && _row_start + row_start < _row_end);
52 CKW_ASSERT(row_end > row_start && _row_start + row_end <= _row_end);
53 CKW_ASSERT(col_start >= 0 && _col_start + col_start < _col_end);
54 CKW_ASSERT(col_end > col_start && _col_start + col_end <= _col_end);
55
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010056 return TileOperand(*this, _row_start + row_start, _row_start + row_end, _col_start + col_start,
57 _col_start + col_end);
Viet-Hoa Docd1f03e2023-09-19 16:41:34 +010058}
59
60TileOperand TileOperand::row(int32_t row) const
61{
62 CKW_ASSERT(row >= 0 && _row_start + row < _row_end);
63
64 return tile(_row_start + row, _row_start + row + 1, _col_start, _col_end);
65}
66
67TileOperand TileOperand::scalar(int32_t row, int32_t col) const
68{
69 CKW_ASSERT(row >= 0 && _row_start + row < _row_end);
70 CKW_ASSERT(col >= 0 && _col_start + col < _col_end);
71
72 return tile(_row_start + row, _row_start + row + 1, _col_start + col, _col_start + col + 1);
73}
74
Viet-Hoa Do25d26f42023-07-20 17:31:47 +010075} // namespace ckw