Skip to content

Commit 52b6e76

Browse files
committed
Fix swap modifier on commutative operations
1 parent 5ea0583 commit 52b6e76

File tree

6 files changed

+12
-9
lines changed

6 files changed

+12
-9
lines changed

src/sem/Add.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Section AddDefinition.
1212
(** {{{!
1313
describe(InstructionDoc(
1414
15-
ins=ins_arith("OpAdd", "add"),
15+
ins=ins_arith("OpAdd", "add", commutes = True),
1616
1717
summary = """
1818
Unsigned overflowing addition of two numbers modulo $2^{256}$.

src/sem/And.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Section AndDefinition.
1111
(** {{{!
1212
describe(descr_ins_generic_bitwise(
1313
abstract_name = "OpAnd",
14-
mnemonic = "and"
14+
mnemonic = "and",
15+
commutes=True
1516
))
1617
}}}
1718
*)

src/sem/Mul.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Section MulDefinition.
1414
(** {{{!
1515
describe(InstructionDoc(
1616
17-
ins=ins_arith("OpMul", "mul", hasOut2 = True),
17+
ins=ins_arith("OpMul", "mul", hasOut2 = True, commutes=True),
1818
1919
summary = """
2020
Unsigned multiplication of two numbers modulo $2^{512}$; the high and low 256

src/sem/Or.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Section OrDefinition.
1111
(** {{{!
1212
describe(descr_ins_generic_bitwise(
1313
abstract_name = "OpOr",
14-
mnemonic = "or"
14+
mnemonic = "or",
15+
commutes=True
1516
))
1617
}}}
1718
*)

src/sem/Xor.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ Section XorDefinition.
1111
(** {{{!
1212
describe(descr_ins_generic_bitwise(
1313
abstract_name = "OpXor",
14-
mnemonic = "xor"
14+
mnemonic = "xor",
15+
commutes=True
1516
))
1617
}}}
1718
*)

src/sem/_preprocess_header.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def NEAR_FAR_RET_LIKE_PREAMBLE(near_descr, near_section, far_descr, far_section)
4343
selected (see [%{near_section}]).
4444
"""
4545

46-
def ins_arith(abstract_name: str, mnemonic:str, hasOut2 = False):
46+
def ins_arith(abstract_name: str, mnemonic:str, hasOut2 = False, commutes=False):
4747
return Instruction(
4848
mnemonic = mnemonic,
4949
abstract_name = abstract_name,
50-
modifiers = [Modifier.Swap, Modifier.SetFlags],
50+
modifiers = ([Modifier.Swap] if not commutes else []) + [Modifier.SetFlags],
5151
in1 = In.Any,
5252
in2 = In.Reg,
5353
out1 = Out.Any,
@@ -83,9 +83,9 @@ def ins_affected(ins:Instruction):
8383
return ins_affected_args(ins.in1, ins.out1, ins.setFlags())
8484

8585

86-
def descr_ins_generic_bitwise(abstract_name: str, mnemonic:str, summary: Optional[str] = None, semantic: Optional[str] = None, usage : Optional[str] = None):
86+
def descr_ins_generic_bitwise(abstract_name: str, mnemonic:str, commutes=False, summary: Optional[str] = None, semantic: Optional[str] = None, usage : Optional[str] = None):
8787
return InstructionDoc(
88-
ins=ins_arith(abstract_name, mnemonic),
88+
ins=ins_arith(abstract_name, mnemonic, commutes=commutes),
8989

9090
summary = f"""
9191
Bitwise {mnemonic.upper()} of two 256-bit numbers.

0 commit comments

Comments
 (0)