Qrack  7.0
General classical-emulating-quantum development framework
qalu.hpp
Go to the documentation of this file.
1 //
3 // (C) Daniel Strano and the Qrack contributors 2017-2022. All rights reserved.
4 //
5 // This is a multithreaded, universal quantum register simulation, allowing
6 // (nonphysical) register cloning and direct measurement of probability and
7 // phase, to leverage what advantages classical emulation of qubits can have.
8 //
9 // Licensed under the GNU Lesser General Public License V3.
10 // See LICENSE.md in the project root or https://www.gnu.org/licenses/lgpl-3.0.en.html
11 // for details.
12 
13 #pragma once
14 
15 #include "common/qrack_types.hpp"
16 
17 namespace Qrack {
18 
19 class QAlu;
20 typedef std::shared_ptr<QAlu> QAluPtr;
21 
22 class QAlu {
23 public:
24  virtual bool M(bitLenInt qubitIndex) = 0;
25  virtual void X(bitLenInt qubitIndex) = 0;
26 
34  virtual void PhaseFlipIfLess(bitCapInt greaterPerm, bitLenInt start, bitLenInt length) = 0;
36  virtual void CPhaseFlipIfLess(bitCapInt greaterPerm, bitLenInt start, bitLenInt length, bitLenInt flagIndex) = 0;
37 
39  virtual void INC(bitCapInt toAdd, bitLenInt start, bitLenInt length) = 0;
41  virtual void DEC(bitCapInt toSub, bitLenInt start, bitLenInt length) = 0;
43  virtual void CINC(
44  bitCapInt toAdd, bitLenInt start, bitLenInt length, const bitLenInt* controls, bitLenInt controlLen) = 0;
46  virtual void CDEC(
47  bitCapInt toSub, bitLenInt start, bitLenInt length, const bitLenInt* controls, bitLenInt controlLen);
49  virtual void INCC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex);
51  virtual void DECC(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex);
53  virtual void INCDECC(bitCapInt toMod, bitLenInt start, bitLenInt length, bitLenInt carryIndex) = 0;
55  virtual void INCS(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex) = 0;
57  virtual void DECS(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex) = 0;
59  virtual void INCSC(
60  bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex);
62  virtual void INCSC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex);
64  virtual void DECSC(
65  bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex);
67  virtual void DECSC(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex);
69  virtual void INCDECSC(bitCapInt toMod, bitLenInt start, bitLenInt length, bitLenInt carryIndex) = 0;
71  virtual void INCDECSC(
72  bitCapInt toMod, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex) = 0;
74  virtual void MUL(bitCapInt toMul, bitLenInt start, bitLenInt carryStart, bitLenInt length) = 0;
76  virtual void DIV(bitCapInt toDiv, bitLenInt start, bitLenInt carryStart, bitLenInt length) = 0;
78  virtual void MULModNOut(
79  bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length) = 0;
81  virtual void IMULModNOut(
82  bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length) = 0;
84  virtual void POWModNOut(
85  bitCapInt base, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length) = 0;
87  virtual void CMUL(bitCapInt toMul, bitLenInt start, bitLenInt carryStart, bitLenInt length,
88  const bitLenInt* controls, bitLenInt controlLen) = 0;
90  virtual void CDIV(bitCapInt toDiv, bitLenInt start, bitLenInt carryStart, bitLenInt length,
91  const bitLenInt* controls, bitLenInt controlLen) = 0;
93  virtual void CMULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length,
94  const bitLenInt* controls, bitLenInt controlLen) = 0;
96  virtual void CIMULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length,
97  const bitLenInt* controls, bitLenInt controlLen) = 0;
99  virtual void CPOWModNOut(bitCapInt base, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length,
100  const bitLenInt* controls, bitLenInt controlLen) = 0;
101 
102 #if ENABLE_BCD
103 
104  virtual void INCBCD(bitCapInt toAdd, bitLenInt start, bitLenInt length) = 0;
106  virtual void DECBCD(bitCapInt toSub, bitLenInt start, bitLenInt length);
108  virtual void INCDECBCDC(bitCapInt toMod, bitLenInt start, bitLenInt length, bitLenInt carryIndex) = 0;
109 #endif
110 
169  virtual bitCapInt IndexedLDA(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart,
170  bitLenInt valueLength, const unsigned char* values, bool resetValue = true) = 0;
198  virtual bitCapInt IndexedADC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart,
199  bitLenInt valueLength, bitLenInt carryIndex, const unsigned char* values) = 0;
227  virtual bitCapInt IndexedSBC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart,
228  bitLenInt valueLength, bitLenInt carryIndex, const unsigned char* values) = 0;
235  virtual void Hash(bitLenInt start, bitLenInt length, const unsigned char* values) = 0;
236 
237 #if ENABLE_BCD
238 
240  virtual void INCBCDC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex);
241 
243  virtual void DECBCDC(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex);
244 #endif
245 
247 };
248 } // namespace Qrack
virtual void INCC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add integer (without sign, with carry)
Definition: qalu.cpp:46
Definition: qalu.hpp:22
virtual void IMULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)=0
Inverse of multiplication modulo N by integer, (out of place)
virtual void PhaseFlipIfLess(bitCapInt greaterPerm, bitLenInt start, bitLenInt length)=0
This is an expedient for an adaptive Grover&#39;s search for a function&#39;s global minimum.
virtual void CINC(bitCapInt toAdd, bitLenInt start, bitLenInt length, const bitLenInt *controls, bitLenInt controlLen)=0
Add integer (without sign, with controls)
virtual void INC(bitCapInt toAdd, bitLenInt start, bitLenInt length)=0
Add integer (without sign)
virtual bool M(bitLenInt qubitIndex)=0
virtual void INCS(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)=0
Add a classical integer to the register, with sign and without carry.
virtual void INCSC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex)
Add a classical integer to the register, with sign and with carry.
Definition: qalu.cpp:81
virtual void Hash(bitLenInt start, bitLenInt length, const unsigned char *values)=0
Transform a length of qubit register via lookup through a hash table.
virtual void DEC(bitCapInt toSub, bitLenInt start, bitLenInt length)=0
Add integer (without sign)
Definition: qalu.cpp:22
virtual void CMULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const bitLenInt *controls, bitLenInt controlLen)=0
Controlled multiplication modulo N by integer, (out of place)
virtual void DECBCD(bitCapInt toSub, bitLenInt start, bitLenInt length)
Subtract classical BCD integer (without sign)
Definition: qalu.cpp:148
virtual void CDEC(bitCapInt toSub, bitLenInt start, bitLenInt length, const bitLenInt *controls, bitLenInt controlLen)
Subtract integer (without sign, with controls)
Definition: qalu.cpp:29
virtual void INCDECSC(bitCapInt toMod, bitLenInt start, bitLenInt length, bitLenInt carryIndex)=0
Common driver method behind INCSC and DECSC (without overflow flag)
virtual void DECS(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt overflowIndex)=0
Add a classical integer to the register, with sign and without carry.
Definition: qalu.cpp:40
virtual void CMUL(bitCapInt toMul, bitLenInt start, bitLenInt carryStart, bitLenInt length, const bitLenInt *controls, bitLenInt controlLen)=0
Controlled multiplication by integer.
virtual void CPOWModNOut(bitCapInt base, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const bitLenInt *controls, bitLenInt controlLen)=0
Controlled, raise a classical base to a quantum power, modulo N, (out of place)
virtual void CPhaseFlipIfLess(bitCapInt greaterPerm, bitLenInt start, bitLenInt length, bitLenInt flagIndex)=0
The 6502 uses its carry flag also as a greater-than/less-than flag, for the CMP operation.
#define bitLenInt
Definition: qrack_types.hpp:40
virtual void INCDECBCDC(bitCapInt toMod, bitLenInt start, bitLenInt length, bitLenInt carryIndex)=0
Common driver method behind INCSC and DECSC (without overflow flag)
virtual bitCapInt IndexedADC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, const unsigned char *values)=0
Add to entangled 8 bit register state with a superposed index-offset-based read from classical memory...
virtual void X(bitLenInt qubitIndex)=0
virtual void INCBCDC(bitCapInt toAdd, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Add classical BCD integer (without sign, with carry)
Definition: qalu.cpp:155
virtual void CDIV(bitCapInt toDiv, bitLenInt start, bitLenInt carryStart, bitLenInt length, const bitLenInt *controls, bitLenInt controlLen)=0
Controlled division by power of integer.
virtual void MUL(bitCapInt toMul, bitLenInt start, bitLenInt carryStart, bitLenInt length)=0
Multiply by integer.
virtual void INCDECC(bitCapInt toMod, bitLenInt start, bitLenInt length, bitLenInt carryIndex)=0
Common driver method behind INCC and DECC (without sign, with carry)
virtual void DECSC(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt overflowIndex, bitLenInt carryIndex)
Subtract a classical integer from the register, with sign and with carry.
Definition: qalu.cpp:97
virtual void INCBCD(bitCapInt toAdd, bitLenInt start, bitLenInt length)=0
Add classical BCD integer (without sign)
virtual void CIMULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length, const bitLenInt *controls, bitLenInt controlLen)=0
Inverse of controlled multiplication modulo N by integer, (out of place)
virtual void MULModNOut(bitCapInt toMul, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)=0
Multiplication modulo N by integer, (out of place)
virtual void POWModNOut(bitCapInt base, bitCapInt modN, bitLenInt inStart, bitLenInt outStart, bitLenInt length)=0
Raise a classical base to a quantum power, modulo N, (out of place)
virtual bitCapInt IndexedLDA(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, const unsigned char *values, bool resetValue=true)=0
Set 8 bit register bits by a superposed index-offset-based read from classical memory.
virtual void DECC(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract classical integer (without sign, with carry)
Definition: qalu.cpp:62
std::shared_ptr< QAlu > QAluPtr
Definition: qalu.hpp:19
#define bitCapInt
Definition: qrack_types.hpp:51
Definition: complex16x2simd.hpp:25
virtual void DECBCDC(bitCapInt toSub, bitLenInt start, bitLenInt length, bitLenInt carryIndex)
Subtract BCD integer (without sign, with carry)
Definition: qalu.cpp:167
virtual bitCapInt IndexedSBC(bitLenInt indexStart, bitLenInt indexLength, bitLenInt valueStart, bitLenInt valueLength, bitLenInt carryIndex, const unsigned char *values)=0
Subtract from an entangled 8 bit register state with a superposed index-offset-based read from classi...
virtual void DIV(bitCapInt toDiv, bitLenInt start, bitLenInt carryStart, bitLenInt length)=0
Divide by integer.