@@ -26,6 +26,16 @@ namespace qsim {
26
26
*/
27
27
class SimulatorBase {
28
28
protected:
29
+ // The follwoing template parameters are used for functions below.
30
+ // H - the number of high (target) qubits.
31
+ // L - the number of low (target) qubits.
32
+ // R - SIMD register width in floats.
33
+
34
+ // Fills the table of masks (ms) that is used to calculate base state indices
35
+ // and the table of offset indices (xss) that is used to access the state
36
+ // vector entries in matrix-vector multiplication functions. This function is
37
+ // used in simulator_basic.h, simulator_sse.h and simulator_avx.h (no bmi2
38
+ // version).
29
39
template <unsigned H, unsigned L = 0 >
30
40
static void FillIndices (unsigned num_qubits, const std::vector<unsigned >& qs,
31
41
uint64_t * ms, uint64_t * xss) {
@@ -50,6 +60,7 @@ class SimulatorBase {
50
60
}
51
61
}
52
62
63
+ // Fills gate matrix entries for gates with low qubits.
53
64
template <unsigned H, unsigned L, unsigned R, typename fp_type>
54
65
static void FillMatrix (unsigned qmaskl, const fp_type* matrix, fp_type* w) {
55
66
constexpr unsigned gsize = 1 << (H + L);
@@ -78,6 +89,8 @@ class SimulatorBase {
78
89
}
79
90
}
80
91
92
+ // Fills gate matrix entries for controlled gates with high target qubits
93
+ // and low control qubits.
81
94
template <unsigned H, unsigned R, typename fp_type>
82
95
static void FillControlledMatrixH (uint64_t cvalsl, uint64_t cmaskl,
83
96
const fp_type* matrix, fp_type* w) {
@@ -103,6 +116,8 @@ class SimulatorBase {
103
116
}
104
117
}
105
118
119
+ // Fills gate matrix entries for controlled gates with low target qubits
120
+ // and low control qubits.
106
121
template <unsigned H, unsigned L, unsigned R, typename fp_type>
107
122
static void FillControlledMatrixL (uint64_t cvalsl, uint64_t cmaskl,
108
123
unsigned qmaskl, const fp_type* matrix,
@@ -135,6 +150,27 @@ class SimulatorBase {
135
150
}
136
151
}
137
152
153
+ /*
154
+ The GetMasks* functions below provide various masks and related values.
155
+ GetMasks1, GetMasks2, GetMasks3, GetMasks4, GetMasks5 and GetMasks6 are
156
+ used in simulator_avx.h (BMI2 version) and in simulator_avx512.h. GetMasks7,
157
+ GetMasks8, GetMasks9, GetMasks10 and GetMasks11 are used in simulator_avx.h
158
+ (no BMI2 version) and in simulator_sse.h.
159
+
160
+ imaskh - inverted mask of high qubits (high control and target qubits).
161
+ qmaskh - mask of high qubits (high target qubits).
162
+ cvalsh - control bit values of high control qubits placed in correct
163
+ positions.
164
+ cvalsl - control bit values of low control qubits placed in correct positions.
165
+ cmaskh - mask of high control qubits.
166
+ cmaskl - mask of low control qubits.
167
+ qmaskl - mask of low qubits (low target qubits).
168
+ cl - the number of low control qubits.
169
+
170
+ Note that imaskh, qmaskh and cvalsh are multiplied by two in GetMasks1,
171
+ GetMasks2, GetMasks3, GetMasks4, GetMasks5 and GetMasks6.
172
+ */
173
+
138
174
struct Masks1 {
139
175
uint64_t imaskh;
140
176
uint64_t qmaskh;
@@ -423,15 +459,19 @@ class SimulatorBase {
423
459
return {cvalsh, cmaskh, cvalsl, cmaskl, qmaskl};
424
460
}
425
461
462
+ struct Masks11 {
463
+ unsigned qmaskl;
464
+ };
465
+
426
466
template <unsigned L>
427
- static unsigned GetQMask (const std::vector<unsigned >& qs) {
467
+ static Masks11 GetMasks11 (const std::vector<unsigned >& qs) {
428
468
unsigned qmaskl = 0 ;
429
469
430
470
for (unsigned i = 0 ; i < L; ++i) {
431
471
qmaskl |= 1 << qs[i];
432
472
}
433
473
434
- return qmaskl;
474
+ return { qmaskl} ;
435
475
}
436
476
437
477
template <unsigned R>
0 commit comments