Skip to content

Commit

Permalink
Added equality method to memory/register classes
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesouza committed Mar 18, 2024
1 parent 7830957 commit d8ad549
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 213 deletions.
112 changes: 98 additions & 14 deletions osaca/parser/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,101 @@ def __str__(self):
def __repr__(self):
return self.__str__()

def __eq__(self, other):
if isinstance(other, MemoryOperand):
return (
self._offset == other._offset
and self._base == other._base
and self._index == other._index
and self._scale == other._scale
and self._segment_ext == other._segment_ext
and self._mask == other._mask
and self._pre_indexed == other._pre_indexed
and self._post_indexed == other._post_indexed
and self._indexed_val == other._indexed_val
)
return False
def equals(self, other, isa):
if isa == "aarch64":
if (
# check base
(
(self.base is None and other.base is None)
or other.base == self.WILDCARD
or (isinstance(self.base, RegisterOperand) and (self.base.prefix == other.base))

Check failure on line 138 in osaca/parser/memory.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/memory.py#L138

Undefined name 'RegisterOperand' (F821)
)
# check offset
and (
self.offset == other.offset
or other.offset == self.WILDCARD
or (
self.offset is not None
and isinstance(self.offset, IdentifierOperand)

Check failure on line 146 in osaca/parser/memory.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/memory.py#L146

Undefined name 'IdentifierOperand' (F821)
and isinstance(other.offset, IdentifierOperand)

Check failure on line 147 in osaca/parser/memory.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/memory.py#L147

Undefined name 'IdentifierOperand' (F821)
)
or (
self.offset is not None
and isinstance(self.offset, ImmediateOperand)

Check failure on line 151 in osaca/parser/memory.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/memory.py#L151

Undefined name 'ImmediateOperand' (F821)
and other.offset == "imd"
)
)
# check index
and (
self.index == other.index
or other.index == self.WILDCARD
or (
self.index is not None
and self.index.prefix is not None
and self.index.prefix == other.index
)
)
# check scale
and (
self.scale == other.scale
or other.scale == self.WILDCARD
or (self.scale != 1 and other.scale != 1)
)
# check pre-indexing
and (other.pre_indexed == self.WILDCARD or self.pre_indexed == other.pre_indexed)
# check post-indexing
and (
other.post_indexed == self.WILDCARD
or self.post_indexed == other.post_indexed
or (isinstance(self.post_indexed, dict) and other.post_indexed)
)
):
return True
return False

Check failure on line 182 in osaca/parser/memory.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/memory.py#L182

Blank line contains whitespace (W293)
if isa == "x86":
if (
# check base
(
(self.base is None and other.base is None)
or other.base == self.WILDCARD
or self._is_x86_reg_type(other.base, self.base)
)
# check offset
and (
self.offset == other.offset
or other.offset == self.WILDCARD
or (
self.offset is not None
and isinstance(self.offset, IdentifierOperand)

Check failure on line 197 in osaca/parser/memory.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/memory.py#L197

Undefined name 'IdentifierOperand' (F821)
and isinstance(other.offset, IdentifierOperand)

Check failure on line 198 in osaca/parser/memory.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/memory.py#L198

Undefined name 'IdentifierOperand' (F821)
)
or (
self.offset is not None
and isinstance(self.offset, ImmediateOperand)

Check failure on line 202 in osaca/parser/memory.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/memory.py#L202

Undefined name 'ImmediateOperand' (F821)
and (
other.offset == "imd" or (other.offset is None and self.offset.value == "0")
)
)
or (isinstance(self.offset, IdentifierOperand) and other.offset == "id")

Check failure on line 207 in osaca/parser/memory.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/memory.py#L207

Undefined name 'IdentifierOperand' (F821)
)
# check index
and (
self.index == other.index
or other.index == self.WILDCARD
or (
self.index is not None
# and self.index.name != None
and self._is_x86_reg_type(other.index, self.index)
)
)
# check scale
and (
self.scale == other.scale
or other.scale == self.WILDCARD
or (self.scale != 1 and other.scale != 1)
)
):
return True
return False

Check failure on line 228 in osaca/parser/memory.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/memory.py#L228

Blank line at end of file (W391)
92 changes: 78 additions & 14 deletions osaca/parser/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,81 @@ def __str__(self):
def __repr__(self):
return self.__str__()

def __eq__(self, other):
if isinstance(other, RegisterOperand):
return (
self._name == other._name
and self._width == other._width
and self._prefix == other._prefix
and self._regtype == other._regtype
and self._lanes == other._lanes
and self._shape == other._shape
and self._index == other._index
and self._mask == other._mask
and self._zeroing == other._zeroing
)
return False
def equals(self, other, isa):
if isa == "aarch64":
# check for wildcards
if reg.prefix == self.WILDCARD or i_reg.prefix == self.WILDCARD:

Check failure on line 169 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L169

Undefined name 'reg' (F821)

Check failure on line 169 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L169

Undefined name 'i_reg' (F821)
if reg.shape is not None:

Check failure on line 170 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L170

Undefined name 'reg' (F821)
if i_reg.shape is not None and (

Check failure on line 171 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L171

Undefined name 'i_reg' (F821)
reg.shape == i_reg.shape or self.WILDCARD in (reg.shape + i_reg.shape)

Check failure on line 172 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L172

Undefined name 'reg' (F821)

Check failure on line 172 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L172

Undefined name 'i_reg' (F821)

Check failure on line 172 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L172

Undefined name 'reg' (F821)

Check failure on line 172 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L172

Undefined name 'i_reg' (F821)
):
return True
return False
return True
# check for prefix and shape
if reg.prefix != i_reg.prefix:

Check failure on line 178 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L178

Undefined name 'reg' (F821)

Check failure on line 178 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L178

Undefined name 'i_reg' (F821)
return False
if reg.shape is not None:

Check failure on line 180 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L180

Undefined name 'reg' (F821)
if i_reg.shape is not None and (

Check failure on line 181 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L181

Undefined name 'i_reg' (F821)
reg.shape == i_reg.shape or self.WILDCARD in (reg.shape + i_reg.shape)

Check failure on line 182 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L182

Undefined name 'reg' (F821)

Check failure on line 182 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L182

Undefined name 'i_reg' (F821)

Check failure on line 182 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L182

Undefined name 'reg' (F821)

Check failure on line 182 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L182

Undefined name 'i_reg' (F821)
):
return True
return False
if reg.lanes is not None:

Check failure on line 186 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L186

Undefined name 'reg' (F821)
if i_reg.lanes is not None and (

Check failure on line 187 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L187

Undefined name 'i_reg' (F821)
reg.lanes == i_reg.lanes or self.WILDCARD in (reg.lanes + i_reg.lanes)

Check failure on line 188 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L188

Undefined name 'reg' (F821)

Check failure on line 188 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L188

Undefined name 'i_reg' (F821)

Check failure on line 188 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L188

Undefined name 'reg' (F821)

Check failure on line 188 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L188

Undefined name 'i_reg' (F821)
):
return True
return False
return True
elif isa == "x86":
if reg is None:

Check failure on line 194 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L194

Undefined name 'reg' (F821)
if i_reg is None:

Check failure on line 195 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L195

Undefined name 'i_reg' (F821)
return True
return False
if isinstance(i_reg, RegisterOperand):

Check failure on line 198 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L198

Undefined name 'i_reg' (F821)
i_reg_name = i_reg.name

Check failure on line 199 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L199

Undefined name 'i_reg' (F821)
else:
i_reg_name = i_reg

Check failure on line 201 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L201

Undefined name 'i_reg' (F821)
# check for wildcards
if isinstance(reg, str):

Check failure on line 203 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L203

Undefined name 'reg' (F821)
return False
if i_reg_name is None and reg.name is None:

Check failure on line 205 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L205

Undefined name 'reg' (F821)
return True
if i_reg_name == self.WILDCARD or reg.name == self.WILDCARD:

Check failure on line 207 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L207

Undefined name 'reg' (F821)
return True
# differentiate between vector registers (mm, xmm, ymm, zmm) and others (gpr)
parser_x86 = ParserX86ATT()

Check failure on line 210 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L210

Undefined name 'ParserX86ATT' (F821)
if parser_x86.is_vector_register(reg):

Check failure on line 211 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L211

Undefined name 'reg' (F821)
if reg.name.rstrip(string.digits).lower() == i_reg_name:

Check failure on line 212 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L212

Undefined name 'reg' (F821)

Check failure on line 212 in osaca/parser/register.py

View workflow job for this annotation

GitHub Actions / Flake8

osaca/parser/register.py#L212

Undefined name 'string' (F821)
# Consider masking and zeroing for AVX512
if consider_masking:
mask_ok = zero_ok = True
if reg.mask is not None or i_reg.mask is not None:
# one instruction is missing the masking while the other has it
mask_ok = False
# check for wildcard
if (
(
reg.mask is not None
and reg.mask.rstrip(string.digits).lower() == i_reg.mask
)
or reg.mask == self.WILDCARD
or i_reg.mask == self.WILDCARD
):
mask_ok = True
if bool(reg.zeroing) ^ bool("zeroing" in i_reg):
# one instruction is missing zeroing while the other has it
zero_ok = False
# check for wildcard
if i_reg.zeroing == self.WILDCARD or reg.zeroing == self.WILDCARD:
zero_ok = True
if not mask_ok or not zero_ok:
return False
return True
else:
if reg.name.rstrip(string.digits).lower() == i_reg_name:
return True
if i_reg_name == "gpr":
return True
return False
Loading

0 comments on commit d8ad549

Please sign in to comment.