Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // Copyright 2019-2022 Cambridge Quantum Computing | |||
2 | // | |||
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |||
4 | // you may not use this file except in compliance with the License. | |||
5 | // You may obtain a copy of the License at | |||
6 | // | |||
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |||
8 | // | |||
9 | // Unless required by applicable law or agreed to in writing, software | |||
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |||
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
12 | // See the License for the specific language governing permissions and | |||
13 | // limitations under the License. | |||
14 | ||||
15 | #include "HelperFunctions.hpp" | |||
16 | ||||
17 | namespace tket { | |||
18 | ||||
19 | 1520 | GrayCode gen_graycode(unsigned m_controls) { | ||
20 | 1520 | const unsigned n = m_controls; | ||
21 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1520 times.
|
0/1? Decision couldn't be analyzed.
|
1520 | if (m_controls == 0) return {}; |
22 |
3/6✓ Branch 2 taken 1520 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1520 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 1520 times.
✗ Branch 11 not taken.
|
7600 | GrayCode gc{{0}, {1}}; | |
23 | ||||
24 |
2/2✓ Branch 0 taken 3551 times.
✓ Branch 1 taken 1520 times.
|
2/2✓ Decision 'true' taken 3551 times.
✓ Decision 'false' taken 1520 times.
|
5071 | for (unsigned i = 2; i < (1u << n); i = i << 1) { |
25 |
2/2✓ Branch 0 taken 19500 times.
✓ Branch 1 taken 3551 times.
|
2/2✓ Decision 'true' taken 19500 times.
✓ Decision 'false' taken 3551 times.
|
23051 | for (unsigned j = 0; j < i; ++j) { |
26 |
1/2✓ Branch 2 taken 19500 times.
✗ Branch 3 not taken.
|
19500 | gc.push_back(gc[i - 1 - j]); | |
27 | } | |||
28 |
2/2✓ Branch 0 taken 19500 times.
✓ Branch 1 taken 3551 times.
|
2/2✓ Decision 'true' taken 19500 times.
✓ Decision 'false' taken 3551 times.
|
23051 | for (unsigned j = 0; j < i; ++j) { |
29 |
1/2✓ Branch 2 taken 19500 times.
✗ Branch 3 not taken.
|
19500 | gc[j].push_back(0); | |
30 | } | |||
31 |
2/2✓ Branch 0 taken 19500 times.
✓ Branch 1 taken 3551 times.
|
2/2✓ Decision 'true' taken 19500 times.
✓ Decision 'false' taken 3551 times.
|
23051 | for (unsigned j = i; j < 2 * i; ++j) { |
32 |
1/2✓ Branch 2 taken 19500 times.
✗ Branch 3 not taken.
|
19500 | gc[j].push_back(1); | |
33 | } | |||
34 | } | |||
35 | 1520 | return gc; | ||
36 | 1520 | } | ||
37 | ||||
38 | 32 | uint32_t reverse_bits(uint32_t v, unsigned w) { | ||
39 | 32 | uint32_t r = 0; | ||
40 |
2/2✓ Branch 0 taken 56 times.
✓ Branch 1 taken 32 times.
|
2/2✓ Decision 'true' taken 56 times.
✓ Decision 'false' taken 32 times.
|
88 | for (unsigned i = w; i--;) { |
41 | 56 | r |= (v & 1) << i; | ||
42 | 56 | v >>= 1; | ||
43 | } | |||
44 | 32 | return r; | ||
45 | } | |||
46 | ||||
47 | } // namespace tket | |||
48 |