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" |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 26 | #include "ckw/Error.h" |
| 27 | #include "src/ITile.h" |
Gunes Bayir | 2ae536a | 2023-07-05 11:39:37 +0100 | [diff] [blame] | 28 | |
| 29 | namespace ckw |
| 30 | { |
Viet-Hoa Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 31 | |
| 32 | TileOperand::TileOperand(ITile &tile) |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 33 | : _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] | 34 | { |
| 35 | } |
| 36 | |
Viet-Hoa Do | cd1f03e | 2023-09-19 16:41:34 +0100 | [diff] [blame] | 37 | TileOperand::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 | |
| 46 | TileOperand 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 | |
| 56 | TileOperand 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 | |
| 63 | TileOperand 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 Do | 25d26f4 | 2023-07-20 17:31:47 +0100 | [diff] [blame] | 71 | } // namespace ckw |