-
-
Notifications
You must be signed in to change notification settings - Fork 754
partly fix Issue 9378 - SHA1 asm not PIC compatible #4994
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -15,14 +15,14 @@ | |
| */ | ||
| module std.internal.digest.sha_SSSE3; | ||
|
|
||
| version(D_PIC) | ||
| version(D_InlineAsm_X86) | ||
| { | ||
| // Do not use (Bug9378). | ||
| } | ||
| else version(D_InlineAsm_X86) | ||
| { | ||
| private version = USE_SSSE3; | ||
| private version = _32Bit; | ||
| version (D_PIC) {} // Bugzilla 9378 | ||
| else | ||
| { | ||
| private version = USE_SSSE3; | ||
| private version = _32Bit; | ||
| } | ||
| } | ||
| else version(D_InlineAsm_X86_64) | ||
| { | ||
|
|
@@ -108,6 +108,7 @@ version(USE_SSSE3) | |
| private immutable string SP = "RSP"; | ||
| private immutable string BUFFER_PTR = "R9"; | ||
| private immutable string STATE_PTR = "R8"; | ||
| private immutable string CONSTANTS_PTR = "R10"; | ||
|
|
||
| // Registers for temporary results (XMM10 and XMM11 are also used temporary) | ||
| private immutable string W_TMP = "XMM8"; | ||
|
|
@@ -120,15 +121,11 @@ version(USE_SSSE3) | |
| private immutable string X_CONSTANT = "XMM13"; | ||
| } | ||
|
|
||
| /* The control words for the byte shuffle instruction. */ | ||
| align(16) private immutable uint[4] bswap_shufb_ctl = | ||
| [ | ||
| 0x0001_0203, 0x0405_0607, 0x0809_0a0b, 0x0c0d_0e0f | ||
| ]; | ||
|
|
||
| /* The round constants. */ | ||
| align(16) private immutable uint[16] constants = | ||
| /* The control words for the byte shuffle instruction and the round constants. */ | ||
| align(16) public immutable uint[20] constants = | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why public?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's passed to the asm function from |
||
| [ | ||
| // The control words for the byte shuffle instruction. | ||
| 0x0001_0203, 0x0405_0607, 0x0809_0a0b, 0x0c0d_0e0f, | ||
| // Constants for round 0-19 | ||
| 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999, | ||
| // Constants for round 20-39 | ||
|
|
@@ -152,10 +149,22 @@ version(USE_SSSE3) | |
| return s.idup; | ||
| } | ||
|
|
||
| /** Returns the reference to the byte shuffle control word. */ | ||
| private nothrow pure string bswap_shufb_ctl() | ||
| { | ||
| version (_64Bit) | ||
| return "["~CONSTANTS_PTR~"]"; | ||
| else | ||
| return "[constants]"; | ||
| } | ||
|
|
||
| /** Returns the reference to constant used in round i. */ | ||
| private nothrow pure string constant(uint i) | ||
| { | ||
| return "[constants + 16*"~to_string(i/20)~"]"; | ||
| version (_64Bit) | ||
| return "16 + 16*"~to_string(i/20)~"["~CONSTANTS_PTR~"]"; | ||
| else | ||
| return "[constants + 16 + 16*"~to_string(i/20)~"]"; | ||
| } | ||
|
|
||
| /** Returns the XMM register number used in round i */ | ||
|
|
@@ -304,9 +313,9 @@ version(USE_SSSE3) | |
| { | ||
| if (i == 0) | ||
| { | ||
| return swt3264(["movdqa "~X_SHUFFLECTL~",[bswap_shufb_ctl]", | ||
| return swt3264(["movdqa "~X_SHUFFLECTL~","~bswap_shufb_ctl(), | ||
| "movdqa "~X_CONSTANT~","~constant(i)], | ||
| ["movdqa "~X_SHUFFLECTL~",[bswap_shufb_ctl]", | ||
| ["movdqa "~X_SHUFFLECTL~","~bswap_shufb_ctl(), | ||
| "movdqa "~X_CONSTANT~","~constant(i)]); | ||
| } | ||
| version(_64Bit) | ||
|
|
@@ -589,8 +598,9 @@ version(USE_SSSE3) | |
| { | ||
| /* | ||
| * Parameters: | ||
| * RSI contains pointer to state | ||
| * RDI contains pointer to input buffer | ||
| * RDX contains pointer to state | ||
| * RSI contains pointer to input buffer | ||
| * RDI contains pointer to constants | ||
| * | ||
| * Stack layout as follows: | ||
| * +----------------+ | ||
|
|
@@ -610,8 +620,9 @@ version(USE_SSSE3) | |
| "push RBP", | ||
| "push RBX", | ||
| // Save parameters | ||
| "mov "~STATE_PTR~", RSI", //pointer to state | ||
| "mov "~BUFFER_PTR~", RDI", //pointer to buffer | ||
| "mov "~STATE_PTR~", RDX", //pointer to state | ||
| "mov "~BUFFER_PTR~", RSI", //pointer to buffer | ||
| "mov "~CONSTANTS_PTR~", RDI", //pointer to constants to avoid absolute addressing | ||
| // Align stack | ||
| "sub RSP, 4*16+8", | ||
| ]; | ||
|
|
@@ -643,10 +654,17 @@ version(USE_SSSE3) | |
| } | ||
| } | ||
|
|
||
| // constants as extra argument for PIC, see Bugzilla 9378 | ||
| import std.meta : AliasSeq; | ||
| version (_64Bit) | ||
| alias ExtraArgs = AliasSeq!(typeof(&constants)); | ||
| else | ||
| alias ExtraArgs = AliasSeq!(); | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| public void transformSSSE3(uint[5]* state, const(ubyte[64])* buffer) pure nothrow @nogc | ||
| public void transformSSSE3(uint[5]* state, const(ubyte[64])* buffer, ExtraArgs) pure nothrow @nogc | ||
| { | ||
| mixin(wrap(["naked;"] ~ prologue())); | ||
| // Precalc first 4*16=64 bytes | ||
|
|
||
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.
shoud we worry that this is not covered?
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.
It's run as part of the 32-bit shared library test suite (b/c that is still PIC incompatible).