Gunes Bayir | 2ae536a | 2023-07-05 11:39:37 +0100 | [diff] [blame] | 1 | /* |
| 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 Bayir | 3c77606 | 2023-07-12 14:50:56 +0100 | [diff] [blame] | 25 | #include "ckw/TileOperand.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 26 | |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 27 | #include "ckw/Error.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 28 | |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 29 | #include "src/ITile.h" |
Gunes Bayir | 2ae536a | 2023-07-05 11:39:37 +0100 | [diff] [blame] | 30 | |
| 31 | namespace ckw |
| 32 | { |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 33 | |
Gunes Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame] | 34 | TileOperand::TileOperand() : _tile(nullptr), _row_start(0), _row_end(0), _col_start(0), _col_end(0) |
| 35 | { |
| 36 | } |
| 37 | |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 38 | TileOperand::TileOperand(ITile &tile) |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 39 | : _tile(&tile), _row_start(0), _row_end(tile.info().height()), _col_start(0), _col_end(tile.info().width()) |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 40 | { |
| 41 | } |
| 42 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 43 | TileOperand::TileOperand( |
| 44 | const TileOperand &operand, int32_t row_start, int32_t row_end, int32_t col_start, int32_t col_end) |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 45 | : _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 Bayir | 2b9fa59 | 2024-01-17 16:07:03 +0000 | [diff] [blame] | 53 | bool TileOperand::is_valid() const |
| 54 | { |
| 55 | return _tile != nullptr; |
| 56 | } |
| 57 | |
| 58 | const TileInfo &TileOperand::tile_info() const |
| 59 | { |
| 60 | return _tile->info(); |
| 61 | } |
| 62 | |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 63 | TileOperand 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 Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 70 | return TileOperand(*this, _row_start + row_start, _row_start + row_end, _col_start + col_start, |
| 71 | _col_start + col_end); |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | TileOperand 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 | |
| 81 | TileOperand 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 Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 89 | } // namespace ckw |