Skip to content

Commit

Permalink
enhanced MachineModel to support mask/zeroing differentiation for ins…
Browse files Browse the repository at this point in the history
…truction forms
  • Loading branch information
JanLJL committed Mar 17, 2020
1 parent 7120689 commit 1aa710f
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions osaca/semantics/hw_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ def _check_x86_operands(self, i_operand, operand):
if 'register' in operand:
if i_operand['class'] != 'register':
return False
return self._is_x86_reg_type(i_operand['name'], operand['register'])
return self._is_x86_reg_type(i_operand, operand['register'], consider_masking=True)
# memory
if 'memory' in operand:
if i_operand['class'] != 'memory':
Expand All @@ -546,7 +546,9 @@ def _compare_db_entries(self, operand_1, operand_2):
)
for key in operand_attributes:
try:
if operand_1[key] != operand_2[key] and not any([x == self.WILDCARD for x in [operand_1[key], operand_2[key]]]):
if operand_1[key] != operand_2[key] and not any(
[x == self.WILDCARD for x in [operand_1[key], operand_2[key]]]
):
return False
except KeyError:
return False
Expand All @@ -573,15 +575,43 @@ def _is_AArch64_reg_type(self, i_reg, reg):
return False
return True

def _is_x86_reg_type(self, i_reg_name, reg):
def _is_x86_reg_type(self, i_reg, reg, consider_masking=False):
"""Check if register type match."""
i_reg_name = i_reg if not consider_masking else i_reg['name']
# check for wildcards
if i_reg_name == self.WILDCARD or reg['name'] == self.WILDCARD:
return True
# differentiate between vector registers (mm, xmm, ymm, zmm) and others (gpr)
parser_x86 = ParserX86ATT()
if parser_x86.is_vector_register(reg):
if reg['name'].rstrip(string.digits).lower() == i_reg_name:
# Consider masking and zeroing for AVX512
if consider_masking:
mask_ok = zero_ok = True
if 'mask' in reg or 'mask' in i_reg:
# one instruction is missing the masking while the other has it
mask_ok = False
# check for wildcard
if (
(
'mask' in reg
and reg['mask'].rstrip(string.digits).lower() == i_reg.get('mask')
)
or reg.get('mask') == self.WILDCARD
or i_reg.get('mask') == self.WILDCARD
):
mask_ok = True
if bool('zeroing' in reg) ^ bool('zeroing' in i_reg):
# one instruction is missing zeroing while the other has it
zero_ok = False
# check for wildcard
if (
i_reg.get('zeroing') == self.WILDCARD
or reg.get('zeroing') == self.WILDCARD
):
zero_ok = True
if not mask_ok or not zero_ok:
return False
return True
else:
if i_reg_name == 'gpr':
Expand Down

0 comments on commit 1aa710f

Please sign in to comment.