18 #include "TargetConditionals.h"
19 #elif ENABLE_INTRINSICS
20 #include "immintrin.h"
29 #define _bi_compare(left, right) \
39 #if (QBCAPPOW < 7) || \
40 (defined(ENABLE_CPP_INT) && \
41 (((QBCAPPOW < 8) && defined(__SIZEOF_INT128__)) || ((QBCAPPOW > 7) && defined(BOOST_AVAILABLE))))
66 *quotient = left / right;
69 *rmndr = left % right;
72 #ifdef __SIZEOF_INT128__
76 *quotient = left / right;
79 *rmndr = (uint64_t)(left % right);
86 *quotient = left / right;
89 *rmndr = (uint32_t)(left % right);
101 return std::bit_width(n) - 1U;
102 #elif ENABLE_INTRINSICS && defined(_WIN32) && !defined(__CYGWIN__)
106 return (
bitLenInt)(
bitsInByte *
sizeof(
unsigned long long) - _lzcnt_u64((
unsigned long long)n) - 1U);
108 #elif ENABLE_INTRINSICS && !defined(__APPLE__)
110 return (
bitLenInt)(
bitsInByte *
sizeof(
unsigned int) - __builtin_clz((
unsigned int)n) - 1U);
112 return (
bitLenInt)(
bitsInByte *
sizeof(
unsigned long long) - __builtin_clzll((
unsigned long long)n) - 1U);
138 #elif (defined(__GNUC__) || defined(__clang__)) && !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR
139 return __builtin_popcount(n);
149 #if (QBCAPPOW < 7) || ((QBCAPPOW < 8) && defined(__SIZEOF_INT128__)) && defined(ENABLE_CPP_INT)
151 #elif (QBCAPPOW > 7) && defined(BOOST_AVAILABLE) && defined(ENABLE_CPP_INT)
152 inline int bi_log2(
const bitCapInt& n) {
return boost::multiprecision::msb(n); }
192 return ((start + length) > qubitCount) || ((
bitLenInt)(start + length) < start);
196 return ((start + length) > maxQPowerOcl) || ((
bitCapIntOcl)(start + length) < start);
199 const std::vector<bitLenInt>& controls,
const bitLenInt& qubitCount, std::string message)
201 std::set<bitLenInt> dupes;
202 for (
const bitLenInt& control : controls) {
203 if (control >= qubitCount) {
204 throw std::invalid_argument(message);
207 if (dupes.find(control) == dupes.end()) {
208 dupes.insert(control);
210 throw std::invalid_argument(message +
" (Found duplicate qubit indices!)");
216 unsigned char*
cl_alloc(
size_t ucharCount);
235 ? (
real1_f)std::stof(std::string(getenv(
"QRACK_QUNIT_SEPARABILITY_THRESHOLD")))
238 ? (
real1_f)std::stof(std::string(getenv(
"QRACK_QBDT_SEPARABILITY_THRESHOLD")))
241 getenv(
"QRACK_MAX_CPU_QB") ? (
bitLenInt)std::stoi(std::string(getenv(
"QRACK_MAX_CPU_QB"))) : -1;
243 ? (
bitLenInt)std::stoi(std::string(getenv(
"QRACK_MAX_PAGE_QB")))
246 ? (
bitLenInt)std::stoi(std::string(getenv(
"QRACK_MAX_PAGING_QB")))
249 (
bitLenInt)(getenv(
"QRACK_PSTRIDEPOW") ? std::stoi(std::string(getenv(
"QRACK_PSTRIDEPOW"))) : PSTRIDEPOW);
251 (size_t)(getenv(
"QRACK_QBDT_MAX_ALLOC_MB") ? std::stoi(std::string(getenv(
"QRACK_QBDT_MAX_ALLOC_MB"))) : -1);
253 (size_t)(getenv(
"QRACK_SPARSE_MAX_ALLOC_MB") ? std::stoi(std::string(getenv(
"QRACK_SPARSE_MAX_ALLOC_MB"))) : -1);
255 ? (
real1_f)std::stof(std::string(getenv(
"QRACK_SPARSE_TRUNCATION_THRESHOLD")))
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
void ThrowIfQbIdArrayIsBad(const std::vector< bitLenInt > &controls, const bitLenInt &qubitCount, std::string message)
Definition: qrack_functions.hpp:198
bitCapInt bitRegMask(const bitLenInt &start, const bitLenInt &length)
Definition: qrack_functions.hpp:170
bool isOverflowSub(bitCapInt inOutInt, bitCapInt inInt, const bitCapInt &signMask, const bitCapInt &lengthPower)
Check if a subtraction with overflow sets the flag.
Definition: functions.cpp:236
void cl_free(void *toFree)
Definition: functions.cpp:49
bool isPowerOfTwo(const bitCapInt &x)
Definition: qrack_functions.hpp:182
const real1_f _qrack_qunit_sep_thresh
Definition: qrack_functions.hpp:258
const bitLenInt QRACK_MAX_PAGING_QB_DEFAULT
Definition: qrack_functions.hpp:262
int bi_log2(const bitCapInt &n)
Definition: qrack_functions.hpp:150
unsigned char * cl_alloc(size_t ucharCount)
Definition: functions.cpp:27
void inv2x2(const complex m[4U], complex o[4U])
bitLenInt log2Ocl(bitCapIntOcl n)
Definition: qrack_functions.hpp:97
const size_t QRACK_SPARSE_MAX_KEYS
Definition: qrack_functions.hpp:270
const size_t QRACK_QBDT_MAX_ALLOC_BYTES_DEFAULT
Definition: qrack_functions.hpp:268
void U(quid sid, bitLenInt q, real1_f theta, real1_f phi, real1_f lambda)
(External API) 3-parameter unitary gate
Definition: wasm_api.cpp:1199
std::istream & operator>>(std::istream &os, QCircuitGatePtr &g)
Definition: qcircuit.cpp:38
std::complex< real1 > complex
Definition: qrack_types.hpp:140
const real1_f _qrack_qbdt_sep_thresh
Definition: qrack_functions.hpp:259
const bitLenInt PSTRIDEPOW_DEFAULT
Definition: qrack_functions.hpp:263
void mul2x2(const complex left[4U], const complex right[4U], complex out[4U])
const real1_f _qrack_sparse_thresh
Definition: qrack_functions.hpp:266
const bitLenInt QRACK_MAX_PAGE_QB_DEFAULT
Definition: qrack_functions.hpp:261
QRACK_CONST real1 FP_NORM_EPSILON
Definition: qrack_types.hpp:263
const bitLenInt QRACK_MAX_CPU_QB_DEFAULT
Definition: qrack_functions.hpp:260
void exp2x2(const complex m[4U], complex o[4U])
bitCapInt pushApartBits(const bitCapInt &perm, const std::vector< bitCapInt > &skipPowers)
Definition: functions.cpp:258
bitCapInt pow2(const bitLenInt &p)
Definition: qrack_functions.hpp:156
constexpr size_t SPARSE_KEY_BYTES
Definition: qrack_types.hpp:255
bitCapIntOcl bitRegMaskOcl(const bitLenInt &start, const bitLenInt &length)
Definition: qrack_functions.hpp:177
QRACK_CONST real1 REAL1_EPSILON
Definition: qrack_types.hpp:203
bitCapInt bitSlice(const bitLenInt &bit, const bitCapInt &source)
Definition: qrack_functions.hpp:165
bitLenInt popCountOcl(bitCapIntOcl n)
Definition: qrack_functions.hpp:134
bitCapInt pow2Mask(const bitLenInt &p)
Definition: qrack_functions.hpp:158
float real1_f
Definition: qrack_types.hpp:107
bool isOverflowAdd(bitCapInt inOutInt, bitCapInt inInt, const bitCapInt &signMask, const bitCapInt &lengthPower)
Check if an addition with overflow sets the flag.
Definition: functions.cpp:214
bitCapIntOcl intPowOcl(bitCapIntOcl base, bitCapIntOcl power)
Definition: functions.cpp:77
bool isPowerOfTwoOcl(const bitCapIntOcl &x)
Definition: qrack_functions.hpp:189
bitLenInt popCount(bitCapInt n)
Definition: qrack_functions.hpp:125
const size_t QRACK_SPARSE_MAX_ALLOC_MB_DEFAULT
Definition: qrack_functions.hpp:265
void log2x2(const complex m[4U], complex o[4U])
const size_t QRACK_SPARSE_MAX_ALLOC_BYTES_DEFAULT
Definition: qrack_functions.hpp:269
bitCapInt intPow(const bitCapInt &base, const bitCapInt &power)
Definition: functions.cpp:59
std::ostream & operator<<(std::ostream &os, const QCircuitGatePtr g)
Definition: qcircuit.cpp:17
const size_t QRACK_QBDT_MAX_ALLOC_MB_DEFAULT
Definition: qrack_functions.hpp:264
bitCapIntOcl pow2MaskOcl(const bitLenInt &p)
Definition: qrack_functions.hpp:164
bool isBadPermRange(const bitCapIntOcl &start, const bitCapIntOcl &length, const bitCapIntOcl &maxQPowerOcl)
Definition: qrack_functions.hpp:194
const bitCapInt ONE_BCI
Definition: qrack_types.hpp:141
const bitCapInt ZERO_BCI
Definition: qrack_types.hpp:142
bool isBadBitRange(const bitLenInt &start, const bitLenInt &length, const bitLenInt &qubitCount)
Definition: qrack_functions.hpp:190
bitCapIntOcl pow2Ocl(const bitLenInt &p)
Definition: qrack_functions.hpp:157
bitCapIntOcl bitSliceOcl(const bitLenInt &bit, const bitCapIntOcl &source)
Definition: qrack_functions.hpp:166
bitLenInt log2(bitCapInt n)
Definition: qrack_functions.hpp:154
half pow(half x, half y)
Power function.
Definition: half.hpp:3721
void bi_and_ip(bitCapInt *left, const bitCapInt &right)
Definition: qrack_functions.hpp:43
int bi_compare_1(const bitCapInt &left)
Definition: qrack_functions.hpp:58
int bi_and_1(const bitCapInt &left)
Definition: qrack_functions.hpp:54
void bi_xor_ip(bitCapInt *left, const bitCapInt &right)
Definition: qrack_functions.hpp:45
void bi_not_ip(bitCapInt *left)
Definition: qrack_functions.hpp:42
int bi_compare_0(const bitCapInt &left)
Definition: qrack_functions.hpp:57
int bi_compare(const bitCapInt &left, const bitCapInt &right)
Definition: qrack_functions.hpp:56
void bi_increment(bitCapInt *pBigInt, const bitCapInt &value)
Definition: qrack_functions.hpp:48
void bi_div_mod_small(const bitCapInt &left, uint32_t right, bitCapInt *quotient, uint32_t *rmndr)
Definition: qrack_functions.hpp:83
double bi_to_double(const bitCapInt &in)
Definition: qrack_functions.hpp:46
void bi_div_mod(const bitCapInt &left, const bitCapInt &right, bitCapInt *quotient, bitCapInt *rmndr)
Definition: qrack_functions.hpp:63
void bi_rshift_ip(bitCapInt *left, const size_t &right)
Definition: qrack_functions.hpp:52
void bi_decrement(bitCapInt *pBigInt, const bitCapInt &value)
Definition: qrack_functions.hpp:49
void bi_add_ip(bitCapInt *left, const bitCapInt &right)
Definition: qrack_functions.hpp:60
void bi_or_ip(bitCapInt *left, const bitCapInt &right)
Definition: qrack_functions.hpp:44
#define _bi_compare(left, right)
Definition: qrack_functions.hpp:29
void bi_sub_ip(bitCapInt *left, const bitCapInt &right)
Definition: qrack_functions.hpp:61
void bi_lshift_ip(bitCapInt *left, const size_t &right)
Definition: qrack_functions.hpp:51
#define bitsInByte
Definition: qrack_types.hpp:156
#define bitLenInt
Definition: qrack_types.hpp:41
#define bitCapInt
Definition: qrack_types.hpp:65
#define bitCapIntOcl
Definition: qrack_types.hpp:53