1 //---------------------------------------------------------------------------
3 //---------------------------------------------------------------------------
7 QC_ccnot::QC_ccnot(int _target, int _control1, int _control2) : QCalcUnit() {
9 ControlBit1 = _control1;
10 ControlBit2 = _control2;
12 //---------------------------------------------------------------------------
17 QC_ccnot::calc(int target, int control1, int control2,
18 double R[], double I[], int NumberOfBits) {
19 // Sort Bits to reglar order of bit number
23 if (Bit0 > Bit1) swap(Bit0, Bit1);
24 if (Bit1 > Bit2) swap(Bit1, Bit2);
25 if (Bit0 > Bit1) swap(Bit0, Bit1);
27 unsigned int states = 1 << (NumberOfBits - 3);
29 for (unsigned int i = 0; i < states; i++) {
31 ix = insert1(ix,Bit0);
32 ix = insert1(ix,Bit1);
33 ix = insert1(ix,Bit2);
35 unsigned int ix_1 = ix;
36 unsigned int ix_0 = ix & ~(1 << target); //Set TargetBit 0
37 swap(R[ix_0], R[ix_1]);
38 swap(I[ix_0], I[ix_1]);
42 //---------------------------------------------------------------------------
44 QC_ccnot::Calc(QBits *qBits) {
45 double *R = qBits->GetBitsR();//Real Part
46 double *I = qBits->GetBitsI();//Imaginary Part
47 int N = qBits->GetNumberOfQBits();
49 QC_ccnot::calc(TargetBit, ControlBit1, ControlBit2, R, I, N);
51 //---------------------------------------------------------------------------
54 QC_ccnot::calcmpi(int t1, int c1, int c2, double R[], double I[], int N) {
56 // Sort Bits to reglar order of bit number
74 unsigned int ix0, ix1;
76 for (int i = 0; i < (1 << (N - 3)); i++) {
78 ix = insert1(ix,Bit0);
79 ix = insert1(ix,Bit1);
80 ix = insert1(ix,Bit2);
81 unsigned int ix_1 = ix;
82 unsigned int ix_0 = ix & ~(1 << t1); //Set TargetBit 0
83 bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
88 store(R, I, ix0, ix1, r0, i0, r1, i1);
93 //---------------------------------------------------------------------------