-
Notifications
You must be signed in to change notification settings - Fork 43
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
Runtime detection of CPU features #53
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
628233f
Build and link both accelerated and generic code
Julow 750dcf7
Check CPU features at runtime
Julow b4a5919
Adjust Cipher_block.accelerated
Julow e37a0f2
Remove MIRAGE_CRYPTO_ACCELERATE build-time env variable
Julow d241360
Enable acceleration depending on architecture
Julow 96c057d
Reimplement detection of CPU features, Don't use Cpuid
Julow aa3019e
minor fixes, use cpuid detection from mirage-crypto (detect_cpu_featu…
hannesm 1b6d08a
avoid link error on travis (+mirage-xen)
hannesm 33312c7
cpuid is no longer a dependency
hannesm c939b96
address @Julow review comment
hannesm f0e30f4
use -DENTROPY
hannesm 20f429e
Ensure detection is done in the right order
Julow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
(executables | ||
(names cfg) | ||
(libraries dune-configurator cpuid)) | ||
(libraries dune-configurator)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "mirage_crypto.h" | ||
|
||
#ifdef __mc_detect_features__ | ||
|
||
#include <cpuid.h> | ||
|
||
struct _mc_cpu_features mc_detected_cpu_features = { 0 }; | ||
|
||
CAMLprim value | ||
mc_detect_cpu_features (__unit ()) { | ||
unsigned int sig = 0, eax = 0, ebx = 0, ecx = 0, edx = 0; | ||
|
||
int max = __get_cpuid_max(0, &sig); | ||
|
||
if (max < 1) return Val_unit; | ||
|
||
__cpuid(1, eax, ebx, ecx, edx); | ||
if (ecx & bit_PCLMUL) | ||
mc_detected_cpu_features.pclmul = 1; | ||
if (ecx & bit_SSSE3) | ||
mc_detected_cpu_features.ssse3 = 1; | ||
if (ecx & bit_AES) | ||
mc_detected_cpu_features.aesni = 1; | ||
if (ecx & bit_RDRND) | ||
mc_detected_cpu_features.rdrand = 1; | ||
|
||
if (max > 7) { | ||
__cpuid_count(7, 0, eax, ebx, ecx, edx); | ||
if (ebx & bit_RDSEED) | ||
mc_detected_cpu_features.rdseed = 1; | ||
} | ||
|
||
return Val_unit; | ||
} | ||
|
||
#else /* __mc_detect_features__ */ | ||
|
||
CAMLprim value | ||
mc_detect_cpu_features (__unit ()) { | ||
return Val_unit; | ||
} | ||
|
||
#endif /* __mc_detect_features__ */ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just two lines below, the
accelerate_flags
should be passed -- i.e only on x86 platform, not on arm (this is as far as I can tell what cpuid would have done as well)... or am I misguided and ARM nowadays supports-mssse3 -maes -mpclmul
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering the same. Fixed !
Should it be passed for
amd64
andx86
? It seems onlyx86_64
was selected inmirage-crypto.h
. I removed that check so we have only one place to worry about this.