Tests/cocotb (#19)
* wip * reorg * update sv int * apb4 working * apb3 working * version bump + ignore runner warning * remove redundant check * adding log on failure * cleaning up verilator version issue * devcontainer * Fix missing libpython in GitHub Actions CI environment (#21) * Initial plan * Install libpython in GitHub Actions for cocotb tests Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: arnavsacheti <36746504+arnavsacheti@users.noreply.github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
from typing import Literal
|
||||
|
||||
|
||||
class SVInt:
|
||||
def __init__(self, value: int, width: int | None = None) -> None:
|
||||
self.value = value
|
||||
@@ -19,3 +22,27 @@ class SVInt:
|
||||
return SVInt(self.value + other.value, max(self.width, other.width))
|
||||
else:
|
||||
return SVInt(self.value + other.value, None)
|
||||
|
||||
def __sub__(self, other: "SVInt") -> "SVInt":
|
||||
if self.width is not None and other.width is not None:
|
||||
return SVInt(self.value - other.value, max(self.width, other.width))
|
||||
else:
|
||||
return SVInt(self.value - other.value, None)
|
||||
|
||||
def __len__(self) -> int:
|
||||
if self.width is not None:
|
||||
return self.width
|
||||
else:
|
||||
return self.value.bit_length()
|
||||
|
||||
def to_bytes(self, byteorder: Literal["little", "big"] = "little") -> bytes:
|
||||
byte_length = (self.value.bit_length() + 7) // 8
|
||||
return self.value.to_bytes(byte_length, byteorder)
|
||||
|
||||
def __eq__(self, other: object) -> bool:
|
||||
if not isinstance(other, SVInt):
|
||||
return NotImplemented
|
||||
return self.value == other.value and self.width == other.width
|
||||
|
||||
def __hash__(self) -> int:
|
||||
return hash((self.value, self.width))
|
||||
|
||||
Reference in New Issue
Block a user