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: Fix keccakf1600 implementation selection #168

Merged
merged 1 commit into from
Dec 9, 2020
Merged

Conversation

chfast
Copy link
Owner

@chfast chfast commented Dec 9, 2020

  1. On macOS __builtin_cpu_init() must be called directly because
    otherwise it will run after select_keccakf1600_implementation().
    See https://bugs.llvm.org/show_bug.cgi?id=48459.
  2. Check availability of both BMI and BMI2. Some CPUs like
    Intel E5-2697 v2 incorrectly report BMI2 being available.

@chfast chfast force-pushed the keccak_bmi_fix branch 2 times, most recently from c0a686b to b1a9e28 Compare December 9, 2020 17:19
@chfast chfast changed the title keccak: Add __builtin_cpu_init() keccak: Fix keccakf1600 implementation selection Dec 9, 2020
1. On macOS __builtin_cpu_init() must be called directly because
   otherwise it will run after select_keccakf1600_implementation().
   See https://bugs.llvm.org/show_bug.cgi?id=48459.
2. Check availability of both BMI and BMI2. Some CPUs like
   Intel E5-2697 v2 incorrectly report BMI2 being available.

Co-authored-by: yperbasis <andrey.ashikhmin@gmail.com>
// This is needed on macOS because of the bug: https://bugs.llvm.org/show_bug.cgi?id=48459.
__builtin_cpu_init();

// Check if both BMI and BMI2 are supported. Some CPUs like Intel E5-2697 v2 incorrectly
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you have some kind of bug report / errata link for this?

Copy link
Owner Author

Choose a reason for hiding this comment

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

No. This comes from experiments on CI.

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 can't even find any details spec of E5-2697 v2. I checks the assembly code generated by __builtin_cpu_supports("bmi2") and it looks correct. I also found a case where for some other Intel CPU it was reporting some features not actually available. That was fixed by BIOS update :)
Seems like a CPU bug, but no more information than this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also found a case where for some other Intel CPU it was reporting some features not actually available. That was fixed by BIOS update :)

That sounds like a new microcode was pushed to the BIOS. The microcode must be loaded on every cold start.

@codecov-io
Copy link

codecov-io commented Dec 9, 2020

Codecov Report

Merging #168 (b816354) into master (983ef72) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #168   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         1651      1652    +1     
=========================================
+ Hits          1651      1652    +1     
Flag Coverage Δ
be 89.31% <ø> (ø)
default 99.81% <100.00%> (+<0.01%) ⬆️
x86_64 89.06% <100.00%> (+<0.01%) ⬆️

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

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

@chfast chfast merged commit 2204f69 into master Dec 9, 2020
@chfast chfast deleted the keccak_bmi_fix branch December 9, 2020 19:37
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