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][ELF] Fix emission of jump tables #534

Merged
merged 1 commit into from May 14, 2024
Merged

Conversation

atrosinenko
Copy link
Collaborator

The generic implementation tries to emit jump table entries as 256-bit pointers, which triggers an assertion in MCFixupKind::getKindForSize.

This commit adds custom implementation of emitJumpTableInfo for EraVM, based on emitJumpTableInfo and emitJumpTableEntry functions from the AsmPrinter class that emits 16-bit labels and takes scaling by 8 into account.

@atrosinenko
Copy link
Collaborator Author

@akiramenai According to llvm/test/CodeGen/EraVM/jumptable.ll, jump tables are emitted to asm as a sequence of .cell @LABEL_NAME and used via const-operand. Does the standalone assembler emit these .cells as instruction indexes (i.e. byte offsets divided by 8)?

Copy link

github-actions bot commented May 8, 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                               0.000 ║
╠═╡ 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                                67.667 ║
║ MUL                                39.400 ║
║ SUB                                67.667 ║
║ DIV                                47.800 ║
║ SDIV                               64.600 ║
║ MOD                                46.600 ║
║ SMOD                               62.200 ║
║ ADDMOD                             39.000 ║
║ MULMOD                             36.000 ║
║ EXP                                 9.283 ║
║ SIGNEXTEND                         45.400 ║
║ LT                                 71.667 ║
║ GT                                 71.667 ║
║ SLT                                95.667 ║
║ SGT                                93.667 ║
║ EQ                                 71.667 ║
║ ISZERO                             63.333 ║
║ AND                                65.667 ║
║ OR                                 67.667 ║
║ XOR                                67.667 ║
║ NOT                                59.333 ║
║ BYTE                               75.667 ║
║ SHL                                73.667 ║
║ SHR                                71.667 ║
║ SAR                                89.667 ║
║ SGT                                93.667 ║
║ SHA3                               28.307 ║
║ ADDRESS                            91.000 ║
║ BALANCE                            73.180 ║
║ ORIGIN                           1443.875 ║
║ CALLER                             91.000 ║
║ CALLVALUE                          91.000 ║
║ BLOCKHASH                         244.450 ║
║ COINBASE                         1440.875 ║
║ TIMESTAMP                        1434.875 ║
║ NUMBER                           1434.875 ║
║ PREVRANDAO                       1434.875 ║
║ GASLIMIT                         1440.875 ║
║ CHAINID                          1428.875 ║
║ SELFBALANCE                       640.200 ║
║ BASEFEE                          1431.875 ║
║ POP                                79.000 ║
║ MLOAD                              75.611 ║
║ MSTORE                             77.389 ║
║ MSTORE8                            84.796 ║
║ SLOAD                              29.201 ║
║ SSTORE                              4.998 ║
║ JUMP                               37.333 ║
║ JUMPI                              32.818 ║
║ PC                                 91.500 ║
║ MSIZE                             101.000 ║
║ GAS                                85.500 ║
║ JUMPDEST                          122.000 ║
║ RETURN                              1.000 ║
║ REVERT                              1.000 ║
╠═╡ Ergs/gas (-%) ╞═╡ EVMInterpreter M3B3 ╞═╣
╚═══════════════════════════════════════════╝

╔═╡ Size (-%) ╞═════╡ EVMInterpreter MzB3 ╞═╗
║ Mean                                0.000 ║
║ Best                                0.000 ║
║ Worst                               0.000 ║
║ Total                               0.000 ║
╠═╡ 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 ║
╚═══════════════════════════════════════════╝

@atrosinenko atrosinenko force-pushed the eravm-mc/null-pointer-elf branch 2 times, most recently from a28cc70 to 7e335a0 Compare May 13, 2024 13:25
@atrosinenko atrosinenko marked this pull request as ready for review May 13, 2024 13:32
@atrosinenko atrosinenko changed the title Draft: [EraVM][ELF] Fix emission of jump tables [EraVM][ELF] Fix emission of jump tables May 13, 2024
@atrosinenko
Copy link
Collaborator Author

atrosinenko commented May 13, 2024

Here are some useful links:

Base automatically changed from eravm-mc/null-pointer-elf to main May 13, 2024 16:39
@asl asl force-pushed the eravm-mc/elf-jump-tables branch from da11b19 to dbfdfa8 Compare May 13, 2024 16:39
The generic implementation tries to emit jump table entries as 256-bit
pointers, which triggers an assertion in MCFixupKind::getKindForSize.

This commit adds custom implementation of emitJumpTableInfo for EraVM,
based on emitJumpTableInfo and emitJumpTableEntry functions from the
AsmPrinter class that emits 16-bit labels and takes scaling by 8 into
account.
@atrosinenko atrosinenko merged commit ea1483c into main May 14, 2024
8 checks passed
@atrosinenko atrosinenko deleted the eravm-mc/elf-jump-tables branch May 14, 2024 13:20
@atrosinenko atrosinenko linked an issue May 22, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ELF] UNREACHABLE: "Invalid generic fixup size!"
2 participants