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

keccak: Optimize Keccak with BMI extension #162

Merged
merged 6 commits into from
Dec 8, 2020
Merged

keccak: Optimize Keccak with BMI extension #162

merged 6 commits into from
Dec 8, 2020

Conversation

chfast
Copy link
Owner

@chfast chfast commented Dec 7, 2020

Using BMI and BMI2 instruction set extensions makes Keccak 25% faster.

seed/1                                        -0.2469           377           284
seed/10                                       -0.2487          3765          2829
seed/100                                      -0.2503         37665         28237
seed/1000                                     -0.2485        375719        282340
seed/10000                                    -0.2481       3756911       2824889
light_cache/1                                 -0.1995           452           362
create_context/1                              -0.2063           459           364
create_context/333                            -0.2065          1741          1382
ethash_calculate_dataset_item_512             -0.0511          4065          3857
ethash_calculate_dataset_item_1024            -0.0765          5127          4735
ethash_calculate_dataset_item_2048            -0.1976         10539          8456
ethash_hash/0                                 -0.0276          1160          1128
ethash_hash/10                                -0.0153          1453          1430
verify                                        -0.0250        519861        506889
keccakf1600                                   +0.0008           368           368
keccakf1600_bmi                               -0.0004           276           276
keccakf1600_best                              -0.0000           276           276
keccak256/32                                  -0.2469           377           284
keccak256/64                                  -0.2509           381           285
keccak256/128                                 -0.2498           382           286
keccak256/135                                 -0.2437           382           289
keccak256/136                                 -0.2492           747           561
keccak512/32                                  -0.2523           382           285
keccak512/64                                  -0.2560           386           287
keccak512/71                                  -0.2564           389           289
keccak512/72                                  -0.2492           747           561
keccak512/142                                 -0.2459           752           567
keccak512/143                                 -0.2461           752           567
keccak512/144                                 -0.2490          1116           838

@codecov-io
Copy link

codecov-io commented Dec 7, 2020

Codecov Report

Merging #162 (1e0b5b2) into master (17d8e1c) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #162   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           22        22           
  Lines         1643      1652    +9     
=========================================
+ Hits          1643      1652    +9     
Flag Coverage Δ
be 89.32% <100.00%> (+0.01%) ⬆️
default 99.81% <75.00%> (-0.19%) ⬇️
x86_64 89.06% <66.66%> (-0.19%) ⬇️

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

Impacted Files Coverage Δ
lib/keccak/keccakf1600.c 100.00% <100.00%> (ø)

@chfast chfast force-pushed the keccak_bmi branch 5 times, most recently from 8845b2c to 010e9fe Compare December 8, 2020 09:17
@chfast chfast marked this pull request as ready for review December 8, 2020 10:27
typedef void (*ethash_keccakf1600_func)(uint64_t[25]);

/// The pointer to the Keccak-f[1600] function implementation.
extern ethash_keccakf1600_func ethash_keccakf1600;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe instead of exposing global variable it would look simpler to have another wrapper function like ethash_keccakf1600_best or something

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or just ethash_keccakf1600 that would call ethash_keccakf1600_best function pointer inside

Copy link
Owner Author

Choose a reason for hiding this comment

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

I considered this, but that mean call + indirect call instead of just indirect call.
Anyway, don't want to expose keccakf1600 any more. It is convenient for benchmarking only so I will either expose these under some macro KECCAK_EXPORT_INTERNALS or will just use keccak256(nullptr, 0). I'm not sure why I exposed these in the first place.

But I don't want to do it here.

@chfast chfast merged commit c370341 into master Dec 8, 2020
@chfast chfast deleted the keccak_bmi branch December 8, 2020 14:41
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.

3 participants