| 1 | ################################################################################ |
| 2 | # |
| 3 | # Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved. |
| 4 | # |
| 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | # of this software and associated documentation files (the "Software"), to deal |
| 7 | # in the Software without restriction, including without limitation the rights |
| 8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | # copies of the Software, and to permit persons to whom the Software is |
| 10 | # furnished to do so, subject to the following conditions: |
| 11 | # |
| 12 | # The above copyright notice and this permission notice shall be included in |
| 13 | # all copies or substantial portions of the Software. |
| 14 | # |
| 15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | # SOFTWARE. |
| 22 | # |
| 23 | ################################################################################ |
| 24 | |
| 25 | from rocisa.instruction import DSStoreB8, DSStoreB8HID16, ReadWriteInstruction, \ |
| 26 | DSLoadD16HIU16, DSLoadD16HIU8, \ |
| 27 | DSLoadU8, DSLoadU16, DSStoreD16HIB16, \ |
| 28 | DSStoreB16 |
| 29 | from .Common import printExit |
| 30 | |
| 31 | from dataclasses import dataclass, field |
| 32 | from typing import Type |
| 33 | |
| 34 | ################################################################################ |
| 35 | # Memory Instruction |
| 36 | ################################################################################ |
| 37 | @dataclass |
| 38 | class MemoryInstruction: |
| 39 | inst: Type[ReadWriteInstruction] |
| 40 | numAddresses: int |
| 41 | numOffsets: int |
| 42 | offsetMultiplier: int |
| 43 | blockWidth: float |
| 44 | numBlocks: int = field(init=False) |
| 45 | totalWidth: float = field(init=False) |
| 46 | issueLatency: int = field(init=False) |
| 47 | |
| 48 | def __post_init__(self): |
| 49 | self.numBlocks = 2 if self.numAddresses > 1 or self.numOffsets > 1 else 1 |
| 50 | self.totalWidth = self.blockWidth * self.numBlocks |
| 51 | self.issueLatency = self.inst.issueLatency() |
| 52 | |
| 53 | def getInst(self, highBits=0): |
| 54 | if highBits: |
| 55 | if self.inst is DSLoadU8: |
| 56 | return DSLoadD16HIU8 |
| 57 | elif self.inst is DSLoadU16: |
| 58 | return DSLoadD16HIU16 |
| 59 | elif self.inst is DSStoreB16: |
| 60 | return DSStoreD16HIB16 |
| 61 | elif self.inst is DSStoreB8: |
| 62 | return DSStoreB8HID16 |
| 63 | else: |
| 64 | printExit(str(self.inst) + " does not support high bits instructions.") |
| 65 | |
| 66 | return self.inst |