Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EraVM][MC] Add missing variants of NOP instruction #571

Merged
merged 1 commit into from
May 29, 2024

Conversation

atrosinenko
Copy link
Collaborator

Make NOP support the remaining combinations of operands.

Reorganize the tests: add nop.(s|txt) test files similar to those for arithmetic instructions, put the test cases for nop, incsp and decsp aliases to sp-changes.(s|txt) files.

@atrosinenko
Copy link
Collaborator Author

This implements the idea proposed in #483: make the backend able to represent any nop as if it is an arithmetic instruction and understand the specific forms as nop, incsp and decsp.

After the renaming takes place, the lines

def : InstAlias<"nop${cc}\t${dst0}", (NOPrrs R0, R0, stackout:$dst0, pred:$cc)>;
def : InstAlias<"nop${cc}\t${src0}", (NOPsrr R0, stackin:$src0, R0, pred:$cc)>;
def : InstAlias<"nop${cc}",          (NOPrrr R0, R0, R0, pred:$cc)>;

will be replaced by

def : InstAlias<"incsp${cc}\t${reg}",        (NOPrrs R0, R0, R0, GR256:$reg, 0, pred:$cc)>;
def : InstAlias<"incsp${cc}\t${imm}",        (NOPrrs R0, R0, R0, R0, i16imm:$imm, pred:$cc)>;
def : InstAlias<"incsp${cc}\t${reg}+${imm}", (NOPrrs R0, R0, R0, GR256:$reg, i16imm:$imm, pred:$cc)>;

def : InstAlias<"decsp${cc}\t${reg}",        (NOPsrr R0, R0, GR256:$reg, 0, R0, pred:$cc)>;
def : InstAlias<"decsp${cc}\t${imm}",        (NOPsrr R0, R0, R0, i16imm:$imm, R0, pred:$cc)>;
def : InstAlias<"decsp${cc}\t${reg}+${imm}", (NOPsrr R0, R0, GR256:$reg, i16imm:$imm, R0, pred:$cc)>;

def : InstAlias<"nop${cc}",                  (NOPrrr R0, R0, R0, pred:$cc)>;

Note that these are not "mnemonic aliases" and not even aliases for the specific 11-bit opcode: for example

nop r0, r0, stack+=[r1 + 42]

is incsp r1 + 42, but

nop r0, r1, stack+=[r1 + 42]

is not.

@hedgar2017 Is such usage of aliases acceptable?

Copy link

github-actions bot commented May 24, 2024

Benchmark results:

╔═╡ Size (-%) ╞════════════════╡ All M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════════════╡ All M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════════════╡ All M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════════════╡ All MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════════════╡ All MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════════════╡ All MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs/gas ╞══════╡ EVMInterpreter M3B3 ╞═╣
║ ADD                                69.333 ║
║ MUL                                40.400 ║
║ SUB                                69.333 ║
║ DIV                                48.800 ║
║ SDIV                               65.600 ║
║ MOD                                47.600 ║
║ SMOD                               63.200 ║
║ ADDMOD                             39.625 ║
║ MULMOD                             36.625 ║
║ EXP                                 9.667 ║
║ SIGNEXTEND                         46.400 ║
║ LT                                 73.333 ║
║ GT                                 73.333 ║
║ SLT                                97.333 ║
║ SGT                                95.333 ║
║ EQ                                 73.333 ║
║ ISZERO                             65.000 ║
║ AND                                67.333 ║
║ OR                                 69.333 ║
║ XOR                                69.333 ║
║ NOT                                61.000 ║
║ BYTE                               77.333 ║
║ SHL                                75.333 ║
║ SHR                                73.333 ║
║ SAR                                91.333 ║
║ SGT                                95.333 ║
║ SHA3                               28.519 ║
║ ADDRESS                            93.781 ║
║ BALANCE                            73.230 ║
║ ORIGIN                           1389.719 ║
║ CALLER                             93.781 ║
║ CALLVALUE                          93.781 ║
║ CALLDATALOAD                       63.333 ║
║ CALLDATASIZE                       94.000 ║
║ CALLDATACOPY                       71.533 ║
║ CODESIZE                           91.000 ║
║ CODECOPY                          145.574 ║
║ GASPRICE                         1392.438 ║
║ EXTCODESIZE                         5.149 ║
║ EXTCODECOPY                         4.667 ║
║ RETURNDATASIZE                     89.000 ║
║ RETURNDATACOPY                     55.889 ║
║ EXTCODEHASH                         9.087 ║
║ BLOCKHASH                         244.700 ║
║ COINBASE                         1392.719 ║
║ TIMESTAMP                        1389.719 ║
║ NUMBER                           1389.719 ║
║ PREVRANDAO                       1389.719 ║
║ GASLIMIT                         1395.719 ║
║ CHAINID                          1389.719 ║
║ SELFBALANCE                       641.312 ║
║ BASEFEE                          1386.719 ║
║ POP                                81.500 ║
║ MLOAD                              80.186 ║
║ MSTORE                             82.069 ║
║ MSTORE8                            89.912 ║
║ SLOAD                              27.212 ║
║ SSTORE                              9.099 ║
║ JUMP                               37.333 ║
║ JUMPI                              32.818 ║
║ PC                                 94.281 ║
║ MSIZE                             103.781 ║
║ GAS                                88.281 ║
║ JUMPDEST                          127.562 ║
║ PUSH0                              91.281 ║
║ PUSH1                              78.854 ║
║ PUSH2                              96.854 ║
║ PUSH4                             158.854 ║
║ PUSH5                             180.854 ║
║ PUSH6                             202.854 ║
║ PUSH7                             224.854 ║
║ PUSH8                             246.854 ║
║ PUSH9                             268.854 ║
║ PUSH10                            290.854 ║
║ PUSH11                            312.854 ║
║ PUSH12                            332.854 ║
║ PUSH13                            356.854 ║
║ PUSH14                            378.854 ║
║ PUSH15                            400.854 ║
║ PUSH16                            422.854 ║
║ PUSH17                            444.854 ║
║ PUSH18                            466.854 ║
║ PUSH19                            488.854 ║
║ PUSH20                            510.854 ║
║ PUSH21                            532.854 ║
║ PUSH22                            554.854 ║
║ PUSH23                            576.854 ║
║ PUSH24                            598.854 ║
║ PUSH25                            620.854 ║
║ PUSH26                            642.854 ║
║ PUSH27                            664.854 ║
║ PUSH28                            686.854 ║
║ PUSH29                            708.854 ║
║ PUSH30                            730.854 ║
║ PUSH31                            752.854 ║
║ PUSH32                            774.854 ║
║ DUP1                               63.000 ║
║ DUP2                               67.000 ║
║ DUP3                               67.000 ║
║ DUP4                               67.000 ║
║ DUP5                               67.000 ║
║ DUP6                               67.000 ║
║ DUP7                               67.000 ║
║ DUP8                               67.000 ║
║ DUP9                               67.000 ║
║ DUP10                              67.000 ║
║ DUP11                              67.000 ║
║ DUP12                              67.000 ║
║ DUP13                              65.000 ║
║ DUP14                              67.000 ║
║ DUP15                              67.000 ║
║ DUP16                              67.000 ║
║ SWAP1                              67.667 ║
║ SWAP2                              67.667 ║
║ SWAP3                              67.667 ║
║ SWAP4                              67.667 ║
║ SWAP5                              67.667 ║
║ SWAP6                              67.667 ║
║ SWAP7                              67.667 ║
║ SWAP8                              67.667 ║
║ SWAP9                              67.667 ║
║ SWAP10                             67.667 ║
║ SWAP11                             67.667 ║
║ SWAP12                             67.667 ║
║ SWAP13                             67.667 ║
║ SWAP14                             67.667 ║
║ SWAP15                             65.667 ║
║ SWAP16                             67.667 ║
║ CALL                               56.371 ║
║ STATICCALL                         53.248 ║
║ DELEGATECALL                       52.286 ║
║ CREATE                              5.046 ║
║ CREATE2                             7.067 ║
║ RETURN                              1.000 ║
║ REVERT                              1.000 ║
╠═╡ Ergs/gas (-%) ╞═╡ EVMInterpreter M3B3 ╞═╣
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                                 NaN ║
╠═╡ Cycles (-%) ╞═══╡ EVMInterpreter MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞═════╡ EVMInterpreter MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════╡ Precompiles M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════╡ Precompiles M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞════════╡ Precompiles MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞══════╡ Precompiles MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞════════╡ Precompiles MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞══════════╡ Real life M3B3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞════════╡ Real life M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life M3B3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞══════════╡ Real life MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Cycles (-%) ╞════════╡ Real life MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ Ergs (-%) ╞══════════╡ Real life MzB3 ╞═╣
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╚═══════════════════════════════════════════╝

@asl
Copy link
Collaborator

asl commented May 24, 2024

Looks reasonable to me. @sayon Will you please check the desired syntax in the tests?

Base automatically changed from eravm-mc/split-ret-like to eravm-mc/refine-ret-like May 24, 2024 18:25
@atrosinenko atrosinenko changed the base branch from eravm-mc/refine-ret-like to eravm-mc/split-ret-like May 27, 2024 08:45
Copy link
Collaborator

@hedgar2017 hedgar2017 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayon do we have a single source of truth for modifiers, where we can revamp them just like main mnemonics?

@atrosinenko
Copy link
Collaborator Author

do we have a single source of truth for modifiers

@hedgar2017 Do you mean aliases (like incsp r1, 42 -> nop r0, r0, stack+=[r1+42])? Or is it the question about to_label modifier from #567?

@sayon
Copy link

sayon commented May 27, 2024

I am making a summary of concrete syntax ATM will include everything there @hedgar2017

@atrosinenko
Copy link
Collaborator Author

@hedgar2017 Which changes are planned to this PR?

Copy link
Collaborator

@hedgar2017 hedgar2017 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atrosinenko LGTM. Our changes only touch the other PR apparently.

Make NOP support the remaining combinations of operands.

Reorganize the tests: add `nop.(s|txt)` test files similar to those for
arithmetic instructions, put the test cases for `nop`, `incsp` and
`decsp` aliases to `sp-changes.(s|txt)` files.
@atrosinenko atrosinenko merged commit 3e90ed7 into main May 29, 2024
8 checks passed
@atrosinenko atrosinenko deleted the eravm-mc/reorganize-nops branch May 29, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants