1 //---------------------------------------------------------------------------
3 //---------------------------------------------------------------------------
5 //---------------------------------------------------------------------------
10 QC_swap::QC_swap(int target1,int target2) : QCalcUnit() {
14 //---------------------------------------------------------------------------
18 void QC_swap::calc(int target1, int target2,
19 double BitsR[], double BitsI[], int NumberOfBits) {
20 unsigned int states = (1 << (NumberOfBits - 2));
21 // Sort Bits to regular order of bit index
25 QCalcUnit::swap(Bit0, Bit1);
28 for (unsigned int i = 0; i < states; i++) {
29 unsigned int ix1 = insert1(i, Bit0);
30 ix1 = insert0(ix1, Bit1);
31 unsigned int ix2 = insert0(i, Bit0);
32 ix2 = insert1(ix2, Bit1);
34 QCalcUnit::swap(BitsR[ix1], BitsR[ix2]);
35 QCalcUnit::swap(BitsI[ix1], BitsI[ix2]);
38 //---------------------------------------------------------------------------
39 void QC_swap::Calc(QBits *qBits)
41 int N = qBits->GetNumberOfQBits();
42 double *R = qBits->GetBitsR();
43 double *I = qBits->GetBitsI();
45 QC_swap::calc(TargetBit1, TargetBit2, R, I, N);
47 //---------------------------------------------------------------------------
50 QC_swap::calcmpi(int t1, int t2, double R[], double I[], int N) {
51 // Sort Bits to regular order of bit index
55 QCalcUnit::swap(Bit0, Bit1);
62 unsigned int ix0, ix1;
64 printf("Swap Gate has not been implemented yet.\n");
67 for (int i = 0; i < (1 << (N - 2)); i++)
69 // Obtain indices of state:
70 unsigned int ix1 = insert1(i, Bit0);
71 ix1 = insert0(ix1, Bit1);
72 unsigned int ix2 = insert0(i, Bit0);
73 ix2 = insert1(ix2, Bit1);
75 bool bstore = setup(R, I, ix0, ix1, r0, i0, r1, i1);
78 QCalcUnit::swap(r0, r1);
79 QCalcUnit::swap(i0, i1);
81 store(R, I, ix0, ix1, r0, i0, r1, i1);
87 //---------------------------------------------------------------------------