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

baseline: Use custom instruction table #341

Merged
merged 2 commits into from
Jun 16, 2021
Merged

Conversation

chfast
Copy link
Member

@chfast chfast commented Jun 6, 2021

Previously EVMC instruction tables were used (for quick head start).
Now two EVMC tables are replaced with single one. This at least cuts memory bandwidth from 12 bytes to 4 bytes per instruction.
Changes to instruction requirements checks are minimal but the stack overflow is checked differently.
The check can be further optimized but this will be done separately.

@chfast chfast requested review from axic and gumb0 June 6, 2021 18:13
@codecov
Copy link

codecov bot commented Jun 6, 2021

Codecov Report

Merging #341 (f8900a2) into master (d81a8fd) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #341   +/-   ##
=======================================
  Coverage   99.78%   99.78%           
=======================================
  Files          29       30    +1     
  Lines        4133     4134    +1     
=======================================
+ Hits         4124     4125    +1     
  Misses          9        9           
Flag Coverage Δ
consensus 91.10% <100.00%> (+<0.01%) ⬆️
unittests 99.78% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/evmone/baseline.cpp 99.82% <100.00%> (-0.01%) ⬇️
lib/evmone/baseline_instruction_table.cpp 100.00% <100.00%> (ø)

@chfast
Copy link
Member Author

chfast commented Jun 7, 2021

Haswell 4.4 GHz, clang-12

Comparing o/b-master-v2 to o/b-itable-0
Benchmark                                                                Time             CPU      Time Old      Time New       CPU Old       CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------------
baseline/analyse/main/blake2b_huff_mean                               -0.0764         -0.0765             5             5             5             5
baseline/execute/main/blake2b_huff/empty_mean                         -0.0835         -0.0835            22            20            22            20
baseline/execute/main/blake2b_huff/2805nulls_mean                     -0.0953         -0.0953           347           314           347           314
baseline/execute/main/blake2b_huff/5610nulls_mean                     -0.1003         -0.1003           674           607           674           607
baseline/execute/main/blake2b_huff/8415nulls_mean                     -0.0933         -0.0933           980           889           980           889
baseline/execute/main/blake2b_huff/65536nulls_mean                    -0.1004         -0.1004          7638          6871          7638          6871
baseline/analyse/main/blake2b_shifts_mean                             -0.0119         -0.0119             3             3             3             3
baseline/execute/main/blake2b_shifts/2805nulls_mean                   -0.0566         -0.0566          3422          3229          3422          3229
baseline/execute/main/blake2b_shifts/5610nulls_mean                   -0.0536         -0.0536          7011          6635          7011          6635
baseline/execute/main/blake2b_shifts/8415nulls_mean                   -0.0529         -0.0529         10515          9958         10515          9958
baseline/execute/main/blake2b_shifts/65536nulls_mean                  -0.0521         -0.0521         83230         78892         83229         78891
baseline/analyse/main/sha1_divs_mean                                  +0.0124         +0.0124             1             1             1             1
baseline/execute/main/sha1_divs/empty_mean                            -0.0109         -0.0109            56            55            56            55
baseline/execute/main/sha1_divs/1351_mean                             -0.0234         -0.0234          1137          1110          1137          1111
baseline/execute/main/sha1_divs/2737_mean                             -0.0253         -0.0253          2219          2163          2219          2163
baseline/execute/main/sha1_divs/5311_mean                             -0.0248         -0.0248          4330          4223          4330          4223
baseline/execute/main/sha1_divs/65536_mean                            -0.0261         -0.0261         52758         51382         52759         51383
baseline/analyse/main/sha1_shifts_mean                                -0.0073         -0.0073             1             1             1             1
baseline/execute/main/sha1_shifts/empty_mean                          -0.0563         -0.0563            35            33            35            33
baseline/execute/main/sha1_shifts/1351_mean                           -0.0573         -0.0573           710           670           710           670
baseline/execute/main/sha1_shifts/2737_mean                           -0.0487         -0.0487          1389          1321          1389          1321
baseline/execute/main/sha1_shifts/5311_mean                           -0.0582         -0.0582          2701          2544          2701          2544
baseline/execute/main/sha1_shifts/65536_mean                          -0.0577         -0.0577         32940         31041         32940         31041
baseline/analyse/main/weierstrudel_mean                               -0.0491         -0.0491             7             7             7             7
baseline/execute/main/weierstrudel/0_mean                             +0.0070         +0.0070           179           180           179           180
baseline/execute/main/weierstrudel/1_mean                             +0.0025         +0.0024           393           394           393           394
baseline/execute/main/weierstrudel/3_mean                             +0.0013         +0.0013           610           611           610           611
baseline/execute/main/weierstrudel/9_mean                             +0.0009         +0.0009          1260          1262          1260          1262
baseline/execute/main/weierstrudel/14_mean                            -0.0014         -0.0014          1805          1802          1805          1802


if (instruction_names[op] == nullptr)
if (metrics.gas_cost < 0)
Copy link
Member

Choose a reason for hiding this comment

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

maybe

Suggested change
if (metrics.gas_cost < 0)
if (metrics.gas_cost == instr::undefined)

const auto gas_cost = instr::gas_costs<Rev>[i];
t.gas_cost = gas_cost; // Include instr::undefined in the table.
t.stack_height_required = instr::traits[i].stack_height_required;
t.can_overflow_stack = instr::traits[i].stack_height_change > 0;
Copy link
Member

Choose a reason for hiding this comment

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

Could add

static_assert(instr::traits[i].stack_height_change <= 1);

because the stack overflow check now assumes this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done with assert().

@@ -0,0 +1,21 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2020 The evmone Authors.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2020 The evmone Authors.
// Copyright 2021 The evmone Authors.

Copy link
Member Author

Choose a reason for hiding this comment

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

These commits are from December 2020 :)

@chfast chfast force-pushed the baseline_instruction_table branch from d53494e to f5c2f1d Compare June 10, 2021 07:28
@chfast chfast force-pushed the baseline_instruction_table branch from f5c2f1d to f8900a2 Compare June 15, 2021 09:04
@chfast
Copy link
Member Author

chfast commented Jun 16, 2021

New benchmarks for execute only:

Comparing o/b-master to o/b-itable
Benchmark                                                                Time             CPU      Time Old      Time New       CPU Old       CPU New
-----------------------------------------------------------------------------------------------------------------------------------------------------
baseline/execute/main/blake2b_huff/empty_mean                         -0.0347         -0.0347            15            15            15            15
baseline/execute/main/blake2b_huff/2805nulls_mean                     -0.0385         -0.0386           330           317           330           317
baseline/execute/main/blake2b_huff/5610nulls_mean                     -0.0231         -0.0231           641           626           641           626
baseline/execute/main/blake2b_huff/8415nulls_mean                     -0.0304         -0.0304           939           910           939           910
baseline/execute/main/blake2b_huff/65536nulls_mean                    -0.0336         -0.0336          7300          7055          7300          7055
baseline/execute/main/blake2b_shifts/2805nulls_mean                   -0.0363         -0.0363          3160          3045          3160          3045
baseline/execute/main/blake2b_shifts/5610nulls_mean                   -0.0390         -0.0390          6278          6033          6278          6033
baseline/execute/main/blake2b_shifts/8415nulls_mean                   -0.0435         -0.0435          9426          9016          9426          9016
baseline/execute/main/blake2b_shifts/65536nulls_mean                  -0.0432         -0.0432         72934         69784         72934         69784
baseline/execute/main/sha1_divs/empty_mean                            -0.0150         -0.0150            54            53            54            53
baseline/execute/main/sha1_divs/1351_mean                             -0.0137         -0.0137          1124          1109          1124          1109
baseline/execute/main/sha1_divs/2737_mean                             -0.0126         -0.0126          2196          2168          2196          2168
baseline/execute/main/sha1_divs/5311_mean                             -0.0096         -0.0096          4273          4232          4273          4232
baseline/execute/main/sha1_divs/65536_mean                            -0.0132         -0.0132         52287         51598         52287         51598
baseline/execute/main/sha1_shifts/empty_mean                          -0.0222         -0.0222            33            32            33            32
baseline/execute/main/sha1_shifts/1351_mean                           -0.0184         -0.0184           696           684           696           684
baseline/execute/main/sha1_shifts/2737_mean                           -0.0180         -0.0180          1357          1333          1357          1333
baseline/execute/main/sha1_shifts/5311_mean                           -0.0213         -0.0213          2655          2598          2655          2598
baseline/execute/main/sha1_shifts/65536_mean                          -0.0203         -0.0203         32332         31677         32332         31677
baseline/execute/main/weierstrudel/0_mean                             -0.0389         -0.0389           169           163           169           163
baseline/execute/main/weierstrudel/1_mean                             -0.0215         -0.0215           380           371           380           371
baseline/execute/main/weierstrudel/3_mean                             -0.0214         -0.0214           594           582           594           582
baseline/execute/main/weierstrudel/9_mean                             -0.0210         -0.0210          1235          1209          1235          1209
baseline/execute/main/weierstrudel/14_mean                            -0.0216         -0.0216          1771          1733          1771          1733
baseline/execute/micro/beginsub_push1s_0xffff_mean                    -0.0009         -0.0009             0             0             0             0
baseline/execute/micro/beginsubs_0xffff_mean                          +0.0006         +0.0006             0             0             0             0
baseline/execute/micro/jumpdests_0xffff_mean                          -0.1046         -0.1046           108            97           108            97
baseline/execute/micro/loop_with_many_jumpdests_mean                  -0.1177         -0.1177         13273         11711         13273         11711
baseline/execute/micro/push1s_0xffff_mean                             -0.0001         -0.0001             0             0             0             0
baseline/execute/micro/push32s_0xffff_mean                            -0.0000         -0.0000             0             0             0             0
baseline/execute/micro/zeros_0xffff_mean                              +0.0005         +0.0005             0             0             0             0

@chfast chfast merged commit c84c429 into master Jun 16, 2021
@chfast chfast deleted the baseline_instruction_table branch June 16, 2021 07:58
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.

2 participants