Debian Codegraph @

gcc/testsuite/gdc.test/compilable/sroa.d

raw
1 /* REQUIRED_ARGS: -O -release -inline
2 This compares two different ways to do a for loop. The range
3 version should SROA the VecRange struct into two register variables.
4 */
5
6 extern (C):
7
8 nothrow:
9 @nogc:
10 @safe:
11
12 alias vec_base_t = size_t; // base type of vector
13 alias vec_t = vec_base_t*;
14
15 @trusted
16 pure
17 size_t vec_index(size_t b, const vec_t vec);
18
19 @trusted
20 pure ref inout(vec_base_t) vec_numbits(inout vec_t v) { return v[-1]; }
21 @trusted
22 pure ref inout(vec_base_t) vec_dim(inout vec_t v) { return v[-2]; }
23
24 struct VecRange
25 {
26 size_t i;
27 const vec_t v;
28
29 @nogc @safe nothrow pure:
30 this(const vec_t v) { this.v = v; i = vec_index(0, v); }
31 bool empty() const { return i == vec_numbits(v); }
32 size_t front() const { return i; }
33 void popFront() { i = vec_index(i + 1, v); }
34 }
35
36 @safe
37 pure
38 uint vec_numBitsSet(const vec_t vec)
39 {
40 uint n = 0;
41 size_t length = vec_numbits(vec);
42 for (size_t i = 0; (i = vec_index(i, vec)) < length; ++i)
43 ++n;
44 return n;
45 }
46
47 @safe
48 pure
49 uint vec_numBitsSet2(const vec_t vec)
50 {
51 uint n = 0;
52 foreach (j; VecRange(vec))
53 ++n;
54 return n;
55 }