Skip to content

Commit 3fc942c

Browse files
authored
Mandelbrot fix (hanabi1224#310)
I've deleted SIMD realization, because it seems that there is no support in D of AVX512-specific instructions currently. Previously when I've made mandelbrot - I've tried 'double8' and it worked (although in documentation only 'double4' is mentioned). I don't know how exactly LDC is figuring out it internally.
1 parent 878b06c commit 3fc942c

File tree

2 files changed

+30
-69
lines changed

2 files changed

+30
-69
lines changed

bench/algorithm/mandelbrot/1.d

Lines changed: 28 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,78 +6,39 @@ import std.digest.md;
66

77
static immutable VLEN = 8;
88

9-
version(LDC){
10-
import core.simd;
11-
alias Vec = double8;
12-
13-
pragma(inline, true):
14-
ubyte mbrot8(Vec cr, double civ) {
15-
immutable Vec ci = civ;
16-
Vec zr = 0.0;
17-
Vec zi = 0.0;
18-
Vec tr = 0.0;
19-
Vec ti = 0.0;
20-
Vec absz = 0.0;
21-
foreach(l; 0 .. 10) {
22-
foreach(k; 0 .. 5) {
23-
zi = (zr + zr) * zi + ci;
24-
zr = tr - ti + cr;
25-
tr = zr * zr;
26-
ti = zi * zi;
27-
}
28-
absz = tr + ti;
29-
bool terminate = true;
30-
foreach(i; 0 .. 8)
31-
if (absz[i] <= 4.0) {
32-
terminate = false;
33-
break;
34-
}
35-
if (terminate)
36-
return 0u;
37-
}
38-
ubyte accu;
39-
foreach(i; 0 .. VLEN)
40-
if (absz[i] <= 4.0) {
41-
accu |= 0x80 >> i;
42-
}
43-
return accu;
44-
}
45-
}
46-
else {
47-
alias Vec = double[8];
9+
alias Vec = double[8];
4810

49-
pragma(inline, true):
50-
ubyte mbrot8(Vec cr, double civ) {
51-
immutable Vec ci = civ;
52-
Vec zr = 0.0;
53-
Vec zi = 0.0;
54-
Vec tr = 0.0;
55-
Vec ti = 0.0;
56-
Vec absz = 0.0;
57-
foreach(l; 0 .. 10) {
58-
foreach(k; 0 .. 5) {
59-
zi[] = (zr[] + zr[]) * zi[] + ci[];
60-
zr[] = tr[] - ti[] + cr[];
61-
tr[] = zr[] * zr[];
62-
ti[] = zi[] * zi[];
63-
}
64-
absz[] = tr[] + ti[];
65-
bool terminate = true;
66-
foreach(i; 0 .. 8)
67-
if (absz[i] <= 4.0) {
68-
terminate = false;
69-
break;
70-
}
71-
if (terminate)
72-
return 0u;
11+
pragma(inline, true):
12+
ubyte mbrot8(Vec cr, double civ) {
13+
immutable Vec ci = civ;
14+
Vec zr = 0.0;
15+
Vec zi = 0.0;
16+
Vec tr = 0.0;
17+
Vec ti = 0.0;
18+
Vec absz = 0.0;
19+
foreach(l; 0 .. 10) {
20+
foreach(k; 0 .. 5) {
21+
zi[] = (zr[] + zr[]) * zi[] + ci[];
22+
zr[] = tr[] - ti[] + cr[];
23+
tr[] = zr[] * zr[];
24+
ti[] = zi[] * zi[];
7325
}
74-
ubyte accu;
75-
foreach(i; 0 .. VLEN)
26+
absz[] = tr[] + ti[];
27+
bool terminate = true;
28+
foreach(i; 0 .. 8)
7629
if (absz[i] <= 4.0) {
77-
accu |= 0x80 >> i;
30+
terminate = false;
31+
break;
7832
}
79-
return accu;
33+
if (terminate)
34+
return 0u;
8035
}
36+
ubyte accu;
37+
foreach(i; 0 .. VLEN)
38+
if (absz[i] <= 4.0) {
39+
accu |= 0x80 >> i;
40+
}
41+
return accu;
8142
}
8243

8344
void main(string[] args) {

bench/include/d/dub.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
"name": "app",
1010
"targetPath": "out",
1111
"dflags-dmd": ["-mcpu=avx2"],
12-
"dflags-ldc2": ["--march=broadwell"]
13-
}
12+
"dflags-ldc": ["-mattr=+avx2", "-mcpu=broadwell"]
13+
}

0 commit comments

Comments
 (0)