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

Simplify trap handling #425

Merged
merged 1 commit into from
Sep 10, 2020
Merged

Simplify trap handling #425

merged 1 commit into from
Sep 10, 2020

Conversation

axic
Copy link
Member

@axic axic commented Jul 15, 2020

Pulled out of #219.

@codecov
Copy link

codecov bot commented Jul 15, 2020

Codecov Report

Merging #425 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #425      +/-   ##
==========================================
- Coverage   98.73%   98.72%   -0.01%     
==========================================
  Files          56       56              
  Lines        8704     8660      -44     
==========================================
- Hits         8594     8550      -44     
  Misses        110      110              

@axic
Copy link
Member Author

axic commented Jul 15, 2020

Well then let's do #219. It is a bit worrying how brittle the execution loop is to changes.

@chfast chfast changed the base branch from master to execute-return July 16, 2020 07:57
@chfast chfast requested a review from gumb0 July 16, 2020 07:57
Base automatically changed from execute-return to master July 16, 2020 15:35
@axic
Copy link
Member Author

axic commented Jul 16, 2020

What are the number after #219 was merged?

@axic axic added the refactoring Refactors a part of the codebase label Jul 16, 2020
@chfast
Copy link
Collaborator

chfast commented Jul 16, 2020

I re-benchmarked master.

v1

Comparing master2 to trap
Benchmark                                                            Time             CPU      Time Old      Time New       CPU Old       CPU New
-------------------------------------------------------------------------------------------------------------------------------------------------
fizzy/execute/blake2b/512_bytes_rounds_1_mean                     -0.0003         -0.0003            86            86            86            86
fizzy/execute/blake2b/512_bytes_rounds_16_mean                    -0.0010         -0.0010          1308          1307          1308          1307
fizzy/execute/ecpairing/onepoint_mean                             +0.0039         +0.0039        421901        423541        421904        423545
fizzy/execute/keccak256/512_bytes_rounds_1_mean                   +0.0156         +0.0156           103           104           103           104
fizzy/execute/keccak256/512_bytes_rounds_16_mean                  +0.0131         +0.0131          1507          1526          1507          1526
fizzy/execute/memset/256_bytes_mean                               -0.0015         -0.0015             7             7             7             7
fizzy/execute/memset/60000_bytes_mean                             -0.0010         -0.0010          1547          1546          1547          1546
fizzy/execute/mul256_opt0/input0_mean                             -0.0301         -0.0301            27            26            27            26
fizzy/execute/mul256_opt0/input1_mean                             -0.0128         -0.0128            27            27            27            27
fizzy/execute/sha1/512_bytes_rounds_1_mean                        -0.0005         -0.0005            90            90            90            90
fizzy/execute/sha1/512_bytes_rounds_16_mean                       +0.0006         +0.0006          1255          1256          1255          1256
fizzy/execute/sha256/512_bytes_rounds_1_mean                      -0.0030         -0.0030            91            91            91            91
fizzy/execute/sha256/512_bytes_rounds_16_mean                     +0.0013         +0.0013          1248          1250          1248          1250
fizzy/execute/micro/eli_interpreter/halt_mean                     +0.0097         +0.0097             0             0             0             0
fizzy/execute/micro/eli_interpreter/exec105_mean                  -0.0105         -0.0105             5             5             5             5
fizzy/execute/micro/factorial/10_mean                             +0.0008         +0.0008             0             0             0             0
fizzy/execute/micro/factorial/20_mean                             +0.0030         +0.0030             1             1             1             1
fizzy/execute/micro/fibonacci/24_mean                             +0.0096         +0.0096          7410          7481          7410          7481
fizzy/execute/micro/host_adler32/1_mean                           -0.0086         -0.0086             0             0             0             0
fizzy/execute/micro/host_adler32/100_mean                         -0.0144         -0.0144             3             3             3             3
fizzy/execute/micro/host_adler32/1000_mean                        -0.0174         -0.0174            30            30            30            30
fizzy/execute/micro/spinner/1_mean                                +0.0006         +0.0006             0             0             0             0
fizzy/execute/micro/spinner/1000_mean                             -0.0007         -0.0007            10            10            10            10

v1 to v2

Comparing trap to trap2
Benchmark                                                            Time             CPU      Time Old      Time New       CPU Old       CPU New
-------------------------------------------------------------------------------------------------------------------------------------------------
fizzy/execute/blake2b/512_bytes_rounds_1_mean                     -0.0437         -0.0437            86            82            86            82
fizzy/execute/blake2b/512_bytes_rounds_16_mean                    -0.0486         -0.0486          1307          1244          1307          1244
fizzy/execute/ecpairing/onepoint_mean                             +0.0191         +0.0191        423541        431627        423545        431630
fizzy/execute/keccak256/512_bytes_rounds_1_mean                   -0.0254         -0.0254           104           102           104           102
fizzy/execute/keccak256/512_bytes_rounds_16_mean                  -0.0264         -0.0264          1526          1486          1526          1486
fizzy/execute/memset/256_bytes_mean                               -0.0017         -0.0017             7             7             7             7
fizzy/execute/memset/60000_bytes_mean                             +0.0002         +0.0002          1546          1546          1546          1546
fizzy/execute/mul256_opt0/input0_mean                             +0.0022         +0.0022            26            26            26            26
fizzy/execute/mul256_opt0/input1_mean                             -0.0138         -0.0138            27            26            27            26
fizzy/execute/sha1/512_bytes_rounds_1_mean                        -0.0034         -0.0034            90            90            90            90
fizzy/execute/sha1/512_bytes_rounds_16_mean                       -0.0026         -0.0026          1256          1253          1256          1253
fizzy/execute/sha256/512_bytes_rounds_1_mean                      +0.0309         +0.0309            91            94            91            94
fizzy/execute/sha256/512_bytes_rounds_16_mean                     +0.0322         +0.0322          1250          1290          1250          1290
fizzy/execute/micro/eli_interpreter/halt_mean                     +0.0382         +0.0382             0             0             0             0
fizzy/execute/micro/eli_interpreter/exec105_mean                  +0.0129         +0.0129             5             5             5             5
fizzy/execute/micro/factorial/10_mean                             +0.0055         +0.0055             0             0             0             0
fizzy/execute/micro/factorial/20_mean                             -0.0079         -0.0079             1             1             1             1
fizzy/execute/micro/fibonacci/24_mean                             +0.0159         +0.0159          7481          7600          7481          7600
fizzy/execute/micro/host_adler32/1_mean                           -0.0077         -0.0077             0             0             0             0
fizzy/execute/micro/host_adler32/100_mean                         +0.0041         +0.0041             3             3             3             3
fizzy/execute/micro/host_adler32/1000_mean                        +0.0060         +0.0060            30            30            30            30
fizzy/execute/micro/spinner/1_mean                                +0.0023         +0.0023             0             0             0             0
fizzy/execute/micro/spinner/1000_mean                             +0.0005         +0.0005            10            10            10            10

v1 to v3

Comparing trap to trap3
Benchmark                                                            Time             CPU      Time Old      Time New       CPU Old       CPU New
-------------------------------------------------------------------------------------------------------------------------------------------------
fizzy/execute/blake2b/512_bytes_rounds_1_mean                     -0.0338         -0.0338            86            83            86            83
fizzy/execute/blake2b/512_bytes_rounds_16_mean                    -0.0384         -0.0384          1307          1257          1307          1257
fizzy/execute/ecpairing/onepoint_mean                             +0.0003         +0.0003        423541        423678        423545        423682
fizzy/execute/keccak256/512_bytes_rounds_1_mean                   -0.0104         -0.0104           104           103           104           103
fizzy/execute/keccak256/512_bytes_rounds_16_mean                  +0.0021         +0.0021          1526          1530          1526          1530
fizzy/execute/memset/256_bytes_mean                               +0.0060         +0.0060             7             7             7             7
fizzy/execute/memset/60000_bytes_mean                             +0.0093         +0.0093          1546          1560          1546          1560
fizzy/execute/mul256_opt0/input0_mean                             +0.0347         +0.0347            26            27            26            27
fizzy/execute/mul256_opt0/input1_mean                             +0.0231         +0.0231            27            27            27            27
fizzy/execute/sha1/512_bytes_rounds_1_mean                        +0.0056         +0.0056            90            91            90            91
fizzy/execute/sha1/512_bytes_rounds_16_mean                       +0.0078         +0.0078          1256          1266          1256          1266
fizzy/execute/sha256/512_bytes_rounds_1_mean                      -0.0263         -0.0263            91            88            91            88
fizzy/execute/sha256/512_bytes_rounds_16_mean                     -0.0247         -0.0247          1250          1219          1250          1219
fizzy/execute/micro/eli_interpreter/halt_mean                     -0.0228         -0.0228             0             0             0             0
fizzy/execute/micro/eli_interpreter/exec105_mean                  +0.0135         +0.0135             5             5             5             5
fizzy/execute/micro/factorial/10_mean                             -0.0212         -0.0212             0             0             0             0
fizzy/execute/micro/factorial/20_mean                             -0.0187         -0.0187             1             1             1             1
fizzy/execute/micro/fibonacci/24_mean                             +0.0036         +0.0036          7481          7508          7481          7508
fizzy/execute/micro/host_adler32/1_mean                           +0.0023         +0.0023             0             0             0             0
fizzy/execute/micro/host_adler32/100_mean                         -0.0022         -0.0022             3             3             3             3
fizzy/execute/micro/host_adler32/1000_mean                        -0.0028         -0.0028            30            29            30            29
fizzy/execute/micro/spinner/1_mean                                +0.0134         +0.0134             0             0             0             0
fizzy/execute/micro/spinner/1000_mean                             +0.0176         +0.0176            10            10            10            10

I would go with original version 1.

@axic
Copy link
Member Author

axic commented Sep 2, 2020

@chfast are you interested remeasuring this?

@chfast
Copy link
Collaborator

chfast commented Sep 3, 2020

For the GCC10, LTO:

commit 1:

fizzy/execute/blake2b/512_bytes_rounds_1_mean                     +0.0119         +0.0119            83            84            83            84
fizzy/execute/blake2b/512_bytes_rounds_16_mean                    +0.0119         +0.0119          1258          1273          1258          1273
fizzy/execute/ecpairing/onepoint_mean                             +0.0031         +0.0031        419930        421227        419934        421232
fizzy/execute/keccak256/512_bytes_rounds_1_mean                   +0.0287         +0.0287            98           101            98           101
fizzy/execute/keccak256/512_bytes_rounds_16_mean                  +0.0267         +0.0267          1427          1466          1428          1466
fizzy/execute/memset/256_bytes_mean                               +0.0031         +0.0031             7             7             7             7
fizzy/execute/memset/60000_bytes_mean                             +0.0002         +0.0002          1559          1560          1560          1560
fizzy/execute/mul256_opt0/input0_mean                             -0.0137         -0.0137            27            26            27            26
fizzy/execute/mul256_opt0/input1_mean                             -0.0138         -0.0138            27            27            27            27
fizzy/execute/ramanujan_pi/33_runs_mean                           +0.0175         +0.0175           132           134           132           134
fizzy/execute/sha1/512_bytes_rounds_1_mean                        +0.0027         +0.0027            91            91            91            91
fizzy/execute/sha1/512_bytes_rounds_16_mean                       +0.0020         +0.0020          1261          1263          1261          1263
fizzy/execute/sha256/512_bytes_rounds_1_mean                      +0.0101         +0.0101            92            93            92            93
fizzy/execute/sha256/512_bytes_rounds_16_mean                     +0.0091         +0.0091          1267          1279          1267          1279
fizzy/execute/taylor_pi/pi_1000000_runs_mean                      -0.0005         -0.0005         41398         41378         41398         41379
fizzy/execute/micro/eli_interpreter/halt_mean                     -0.0074         -0.0074             0             0             0             0
fizzy/execute/micro/eli_interpreter/exec105_mean                  +0.0210         +0.0210             5             5             5             5
fizzy/execute/micro/factorial/10_mean                             +0.0031         +0.0031             0             0             0             0
fizzy/execute/micro/factorial/20_mean                             +0.0027         +0.0027             1             1             1             1
fizzy/execute/micro/fibonacci/24_mean                             +0.0017         +0.0017          7531          7544          7531          7544
fizzy/execute/micro/host_adler32/1_mean                           -0.0128         -0.0128             0             0             0             0
fizzy/execute/micro/host_adler32/100_mean                         -0.0025         -0.0025             3             3             3             3
fizzy/execute/micro/host_adler32/1000_mean                        -0.0045         -0.0045            30            30            30            30
fizzy/execute/micro/spinner/1_mean                                -0.0109         -0.0109             0             0             0             0
fizzy/execute/micro/spinner/1000_mean                             -0.0036         -0.0036            11            11            11            11

commit last (marks trap as unlikely)

fizzy/execute/blake2b/512_bytes_rounds_1_mean                     -0.0072         -0.0072            83            83            83            83
fizzy/execute/blake2b/512_bytes_rounds_16_mean                    -0.0018         -0.0018          1258          1256          1258          1256
fizzy/execute/ecpairing/onepoint_mean                             -0.0154         -0.0154        419930        413447        419934        413451
fizzy/execute/keccak256/512_bytes_rounds_1_mean                   +0.0444         +0.0444            98           103            98           103
fizzy/execute/keccak256/512_bytes_rounds_16_mean                  +0.0569         +0.0569          1427          1509          1428          1509
fizzy/execute/memset/256_bytes_mean                               -0.0205         -0.0205             7             7             7             7
fizzy/execute/memset/60000_bytes_mean                             -0.0249         -0.0249          1559          1521          1560          1521
fizzy/execute/mul256_opt0/input0_mean                             -0.0424         -0.0424            27            26            27            26
fizzy/execute/mul256_opt0/input1_mean                             -0.0490         -0.0490            27            26            27            26
fizzy/execute/ramanujan_pi/33_runs_mean                           +0.0204         +0.0204           132           134           132           134
fizzy/execute/sha1/512_bytes_rounds_1_mean                        +0.0143         +0.0143            91            92            91            92
fizzy/execute/sha1/512_bytes_rounds_16_mean                       +0.0153         +0.0153          1261          1280          1261          1280
fizzy/execute/sha256/512_bytes_rounds_1_mean                      -0.0083         -0.0083            92            91            92            91
fizzy/execute/sha256/512_bytes_rounds_16_mean                     -0.0087         -0.0087          1267          1256          1267          1256
fizzy/execute/taylor_pi/pi_1000000_runs_mean                      -0.0316         -0.0316         41398         40089         41398         40090
fizzy/execute/micro/eli_interpreter/halt_mean                     -0.0234         -0.0234             0             0             0             0
fizzy/execute/micro/eli_interpreter/exec105_mean                  -0.0160         -0.0160             5             5             5             5
fizzy/execute/micro/factorial/10_mean                             -0.0007         -0.0007             0             0             0             0
fizzy/execute/micro/factorial/20_mean                             -0.0112         -0.0112             1             1             1             1
fizzy/execute/micro/fibonacci/24_mean                             -0.0047         -0.0047          7531          7495          7531          7496
fizzy/execute/micro/host_adler32/1_mean                           -0.0275         -0.0275             0             0             0             0
fizzy/execute/micro/host_adler32/100_mean                         -0.0483         -0.0483             3             3             3             3
fizzy/execute/micro/host_adler32/1000_mean                        -0.0489         -0.0490            30            29            30            29
fizzy/execute/micro/spinner/1_mean                                -0.0533         -0.0533             0             0             0             0
fizzy/execute/micro/spinner/1000_mean                             -0.0707         -0.0707            11            10            11            10

So I think just using the first commit is good enough. Using [[unlikely]] should be left for later because there are more or less portable ways of implementing it. And it may not be needed with PGO.

lib/fizzy/execute.cpp Outdated Show resolved Hide resolved
@chfast chfast merged commit 5e6b32c into master Sep 10, 2020
@chfast chfast deleted the trap-handling branch September 10, 2020 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactors a part of the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants