Skip to content

Commit 088a998

Browse files
authored
Merge pull request #5035 from MartinNowak/merge_stable
Merge remote-tracking branch 'upstream/stable' into merge_stable
2 parents d94442c + 7ae36bf commit 088a998

File tree

5 files changed

+62
-38
lines changed

5 files changed

+62
-38
lines changed
File renamed without changes.

std/algorithm/sorting.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ Params:
18121812
Returns: The initial range wrapped as a $(D SortedRange) with the predicate
18131813
$(D binaryFun!less).
18141814
1815-
Algorithms: $(HTTP en.wikipedia.org/wiki/Introsort) is used for unstable sorting and
1815+
Algorithms: $(HTTP en.wikipedia.org/wiki/Introsort, Introsort) is used for unstable sorting and
18161816
$(HTTP en.wikipedia.org/wiki/Timsort, Timsort) is used for stable sorting.
18171817
Each algorithm has benefits beyond stability. Introsort is generally faster but
18181818
Timsort may achieve greater speeds on data with low entropy or if predicate calls

std/digest/sha.d

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,14 @@ unittest
101101
hash1 = sha1.finish();
102102
}
103103

104-
version(D_PIC)
105-
{
106-
// Do not use (Bug9378).
107-
}
108-
else version(Win64)
104+
version(Win64)
109105
{
110106
// wrong calling convention
111107
}
112108
else version(D_InlineAsm_X86)
113109
{
114-
private version = USE_SSSE3;
110+
version (D_PIC) {} // Bugzilla 9378
111+
else private version = USE_SSSE3;
115112
}
116113
else version(D_InlineAsm_X86_64)
117114
{
@@ -216,11 +213,20 @@ struct SHA(uint hashBlockSize, uint digestSize)
216213
version(USE_SSSE3)
217214
{
218215
import core.cpuid : ssse3;
219-
import std.internal.digest.sha_SSSE3 : transformSSSE3;
216+
import std.internal.digest.sha_SSSE3 : sse3_constants=constants, transformSSSE3;
220217

221218
static void transform(uint[5]* state, const(ubyte[64])* block) pure nothrow @nogc
222219
{
223-
return ssse3 ? transformSSSE3(state, block) : transformX86(state, block);
220+
if (ssse3)
221+
{
222+
version (D_InlineAsm_X86_64)
223+
// constants as extra argument for PIC, see Bugzilla 9378
224+
transformSSSE3(state, block, &sse3_constants);
225+
else
226+
transformSSSE3(state, block);
227+
}
228+
else
229+
transformX86(state, block);
224230
}
225231
}
226232
else

std/internal/digest/sha_SSSE3.d

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
*/
1616
module std.internal.digest.sha_SSSE3;
1717

18-
version(D_PIC)
18+
version(D_InlineAsm_X86)
1919
{
20-
// Do not use (Bug9378).
21-
}
22-
else version(D_InlineAsm_X86)
23-
{
24-
private version = USE_SSSE3;
25-
private version = _32Bit;
20+
version (D_PIC) {} // Bugzilla 9378
21+
else
22+
{
23+
private version = USE_SSSE3;
24+
private version = _32Bit;
25+
}
2626
}
2727
else version(D_InlineAsm_X86_64)
2828
{
@@ -108,6 +108,7 @@ version(USE_SSSE3)
108108
private immutable string SP = "RSP";
109109
private immutable string BUFFER_PTR = "R9";
110110
private immutable string STATE_PTR = "R8";
111+
private immutable string CONSTANTS_PTR = "R10";
111112

112113
// Registers for temporary results (XMM10 and XMM11 are also used temporary)
113114
private immutable string W_TMP = "XMM8";
@@ -120,15 +121,11 @@ version(USE_SSSE3)
120121
private immutable string X_CONSTANT = "XMM13";
121122
}
122123

123-
/* The control words for the byte shuffle instruction. */
124-
align(16) private immutable uint[4] bswap_shufb_ctl =
125-
[
126-
0x0001_0203, 0x0405_0607, 0x0809_0a0b, 0x0c0d_0e0f
127-
];
128-
129-
/* The round constants. */
130-
align(16) private immutable uint[16] constants =
124+
/* The control words for the byte shuffle instruction and the round constants. */
125+
align(16) public immutable uint[20] constants =
131126
[
127+
// The control words for the byte shuffle instruction.
128+
0x0001_0203, 0x0405_0607, 0x0809_0a0b, 0x0c0d_0e0f,
132129
// Constants for round 0-19
133130
0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
134131
// Constants for round 20-39
@@ -152,10 +149,22 @@ version(USE_SSSE3)
152149
return s.idup;
153150
}
154151

152+
/** Returns the reference to the byte shuffle control word. */
153+
private nothrow pure string bswap_shufb_ctl()
154+
{
155+
version (_64Bit)
156+
return "["~CONSTANTS_PTR~"]";
157+
else
158+
return "[constants]";
159+
}
160+
155161
/** Returns the reference to constant used in round i. */
156162
private nothrow pure string constant(uint i)
157163
{
158-
return "[constants + 16*"~to_string(i/20)~"]";
164+
version (_64Bit)
165+
return "16 + 16*"~to_string(i/20)~"["~CONSTANTS_PTR~"]";
166+
else
167+
return "[constants + 16 + 16*"~to_string(i/20)~"]";
159168
}
160169

161170
/** Returns the XMM register number used in round i */
@@ -304,9 +313,9 @@ version(USE_SSSE3)
304313
{
305314
if (i == 0)
306315
{
307-
return swt3264(["movdqa "~X_SHUFFLECTL~",[bswap_shufb_ctl]",
316+
return swt3264(["movdqa "~X_SHUFFLECTL~","~bswap_shufb_ctl(),
308317
"movdqa "~X_CONSTANT~","~constant(i)],
309-
["movdqa "~X_SHUFFLECTL~",[bswap_shufb_ctl]",
318+
["movdqa "~X_SHUFFLECTL~","~bswap_shufb_ctl(),
310319
"movdqa "~X_CONSTANT~","~constant(i)]);
311320
}
312321
version(_64Bit)
@@ -589,8 +598,9 @@ version(USE_SSSE3)
589598
{
590599
/*
591600
* Parameters:
592-
* RSI contains pointer to state
593-
* RDI contains pointer to input buffer
601+
* RDX contains pointer to state
602+
* RSI contains pointer to input buffer
603+
* RDI contains pointer to constants
594604
*
595605
* Stack layout as follows:
596606
* +----------------+
@@ -610,8 +620,9 @@ version(USE_SSSE3)
610620
"push RBP",
611621
"push RBX",
612622
// Save parameters
613-
"mov "~STATE_PTR~", RSI", //pointer to state
614-
"mov "~BUFFER_PTR~", RDI", //pointer to buffer
623+
"mov "~STATE_PTR~", RDX", //pointer to state
624+
"mov "~BUFFER_PTR~", RSI", //pointer to buffer
625+
"mov "~CONSTANTS_PTR~", RDI", //pointer to constants to avoid absolute addressing
615626
// Align stack
616627
"sub RSP, 4*16+8",
617628
];
@@ -643,10 +654,17 @@ version(USE_SSSE3)
643654
}
644655
}
645656

657+
// constants as extra argument for PIC, see Bugzilla 9378
658+
import std.meta : AliasSeq;
659+
version (_64Bit)
660+
alias ExtraArgs = AliasSeq!(typeof(&constants));
661+
else
662+
alias ExtraArgs = AliasSeq!();
663+
646664
/**
647665
*
648666
*/
649-
public void transformSSSE3(uint[5]* state, const(ubyte[64])* buffer) pure nothrow @nogc
667+
public void transformSSSE3(uint[5]* state, const(ubyte[64])* buffer, ExtraArgs) pure nothrow @nogc
650668
{
651669
mixin(wrap(["naked;"] ~ prologue()));
652670
// Precalc first 4*16=64 bytes

std/traits.d

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ alias ParameterDefaultValueTuple = ParameterDefaults;
13081308

13091309

13101310
/**
1311-
Returns the attributes attached to a function $(D func).
1311+
Returns the FunctionAttribute mask for function $(D func).
13121312
13131313
See_Also:
13141314
$(LREF hasFunctionAttributes)
@@ -1503,8 +1503,8 @@ private FunctionAttribute extractAttribFlags(Attribs...)()
15031503
Checks whether a function has the given attributes attached.
15041504
15051505
Params:
1506-
func = function to check
1507-
attributes = variadic number of function attributes as strings
1506+
args = Function to check, followed by a
1507+
variadic number of function attributes as strings
15081508
15091509
Returns:
15101510
`true`, if the function has the list of attributes attached and `false` otherwise.
@@ -1513,7 +1513,7 @@ See_Also:
15131513
$(LREF functionAttributes)
15141514
*/
15151515
template hasFunctionAttributes(args...)
1516-
if (isCallable!(args[0]) && args.length > 0
1516+
if (args.length > 0 && isCallable!(args[0])
15171517
&& allSatisfy!(isSomeString, typeof(args[1 .. $])))
15181518
{
15191519
enum bool hasFunctionAttributes = {
@@ -1536,7 +1536,7 @@ unittest
15361536
static assert(hasFunctionAttributes!(func, "@safe", "pure"));
15371537
static assert(!hasFunctionAttributes!(func, "@trusted"));
15381538

1539-
// for templates types are automatically inferred
1539+
// for templates attributes are automatically inferred
15401540
bool myFunc(T)(T b)
15411541
{
15421542
return !b;
@@ -7442,7 +7442,7 @@ template isType(X...) if (X.length == 1)
74427442
* `true` if `X` is a function, `false` otherwise
74437443
*
74447444
* See_Also:
7445-
* Use $(REF isFunctionPointer) or $(REF isDelegate) for detecting those types
7445+
* Use $(LREF isFunctionPointer) or $(LREF isDelegate) for detecting those types
74467446
* respectively.
74477447
*/
74487448
template isFunction(X...) if (X.length == 1)

0 commit comments

Comments
 (0)