21 #include <pmmintrin.h>
23 #include <xmmintrin.h>
26 #include <immintrin.h>
34 static const __m128
SIGNMASK = _mm_set_ps(0.0f, -0.0f, 0.0f, -0.0f);
46 inline complex2(
const std::complex<float>& cm1,
const std::complex<float>& cm2)
48 c2 = _mm_set_ps(cm2.imag(), cm2.real(), cm1.imag(), cm1.real());
50 inline complex2(
const float& r1,
const float& i1,
const float& r2,
const float& i2)
52 c2 = _mm_set_ps(i2, r2, i1, r1);
54 inline std::complex<float>
c(
const size_t& i)
const {
return complex(
f[i << 1U],
f[(i << 1U) + 1U]); }
58 c2 = _mm_add_ps(
c2, other.
c2);
64 c2 = _mm_sub_ps(
c2, other.
c2);
69 const __m128& oVal2 = other.
c2;
72 return _mm_fmadd_ps(_mm_shuffle_ps(
c2,
c2, 177), _mm_xor_ps(
SIGNMASK, _mm_shuffle_ps(oVal2, oVal2, 245)),
73 _mm_mul_ps(
c2, _mm_shuffle_ps(oVal2, oVal2, 160)));
76 _mm_mul_ps(_mm_shuffle_ps(
c2,
c2, 177), _mm_xor_ps(
SIGNMASK, _mm_shuffle_ps(oVal2, oVal2, 245))),
77 _mm_mul_ps(
c2, _mm_shuffle_ps(oVal2, oVal2, 160)));
82 const __m128& oVal2 = other.
c2;
85 c2 = _mm_fmadd_ps(_mm_shuffle_ps(
c2,
c2, 177), _mm_xor_ps(
SIGNMASK, _mm_shuffle_ps(oVal2, oVal2, 245)),
86 _mm_mul_ps(
c2, _mm_shuffle_ps(oVal2, oVal2, 160)));
89 _mm_add_ps(_mm_mul_ps(_mm_shuffle_ps(
c2,
c2, 177), _mm_xor_ps(
SIGNMASK, _mm_shuffle_ps(oVal2, oVal2, 245))),
90 _mm_mul_ps(
c2, _mm_shuffle_ps(oVal2, oVal2, 160)));
98 c2 = _mm_mul_ps(
c2, _mm_set1_ps(other));
103 inline complex2
mtrxColShuff(
const complex2& mtrxCol) {
return _mm_shuffle_ps(mtrxCol.c2, mtrxCol.c2, 177); }
104 inline complex2
matrixMul(
const complex2& mtrxCol1,
const complex2& mtrxCol2,
const complex2& mtrxCol1Shuff,
105 const complex2& mtrxCol2Shuff,
const complex2& qubit)
107 const __m128 dupeLo = _mm_shuffle_ps(qubit.c2, qubit.c2, 68);
108 const __m128 dupeHi = _mm_shuffle_ps(qubit.c2, qubit.c2, 238);
111 return _mm_add_ps(_mm_fmadd_ps(mtrxCol1Shuff.c2, _mm_xor_ps(
SIGNMASK, _mm_shuffle_ps(dupeLo, dupeLo, 245)),
112 _mm_mul_ps(mtrxCol1.c2, _mm_shuffle_ps(dupeLo, dupeLo, 160))),
113 _mm_fmadd_ps(mtrxCol2Shuff.c2, _mm_xor_ps(
SIGNMASK, _mm_shuffle_ps(dupeHi, dupeHi, 245)),
114 _mm_mul_ps(mtrxCol2.c2, _mm_shuffle_ps(dupeHi, dupeHi, 160))));
117 _mm_add_ps(_mm_mul_ps(mtrxCol1Shuff.c2, _mm_xor_ps(
SIGNMASK, _mm_shuffle_ps(dupeLo, dupeLo, 245))),
118 _mm_mul_ps(mtrxCol1.c2, _mm_shuffle_ps(dupeLo, dupeLo, 160))),
119 _mm_add_ps(_mm_mul_ps(mtrxCol2Shuff.c2, _mm_xor_ps(
SIGNMASK, _mm_shuffle_ps(dupeHi, dupeHi, 245))),
120 _mm_mul_ps(mtrxCol2.c2, _mm_shuffle_ps(dupeHi, dupeHi, 160))));
123 inline complex2
matrixMul(
const float& nrm,
const complex2& mtrxCol1,
const complex2& mtrxCol2,
124 const complex2& mtrxCol1Shuff,
const complex2& mtrxCol2Shuff,
const complex2& qubit)
126 return matrixMul(mtrxCol1, mtrxCol2, mtrxCol1Shuff, mtrxCol2Shuff, qubit) * nrm;
132 inline float norm(
const complex2& c)
134 const __m128 n = _mm_mul_ps(c.c2, c.c2);
136 __m128 shuf = _mm_movehdup_ps(n);
138 __m128 shuf = _mm_shuffle_ps(n, n, _MM_SHUFFLE(2, 3, 0, 1));
140 const __m128 sums = _mm_add_ps(n, shuf);
141 shuf = _mm_movehl_ps(shuf, sums);
142 return _mm_cvtss_f32(_mm_add_ss(sums, shuf));
GLOSSARY: bitLenInt - "bit-length integer" - unsigned integer ID of qubit position in register bitCap...
Definition: complex16x2simd.hpp:25
static const __m256d SIGNMASK
Definition: complex16x2simd.hpp:27
std::complex< real1 > complex
Definition: qrack_types.hpp:136
double norm(const complex2 &c)
Definition: complex16x2simd.hpp:122
complex2 matrixMul(const complex2 &mtrxCol1, const complex2 &mtrxCol2, const complex2 &mtrxCol1Shuff, const complex2 &mtrxCol2Shuff, const complex2 &qubit)
Definition: complex16x2simd.hpp:95
complex2 mtrxColShuff(const complex2 &mtrxCol)
Definition: complex16x2simd.hpp:94
complex2 operator*(const double &lhs, const complex2 &rhs)
Definition: complex16x2simd.hpp:120
SIMD implementation of the double precision complex vector type of 2 complex numbers,...
Definition: complex16x2simd.hpp:30
__m128 c2
Definition: complex8x2simd.hpp:40
complex2(const float &r1, const float &i1, const float &r2, const float &i2)
Definition: complex8x2simd.hpp:50
complex2 operator*(const complex2 &other) const
Definition: complex8x2simd.hpp:67
complex2(const complex2 &cm2)
Definition: complex8x2simd.hpp:45
complex2(const std::complex< float > &cm1, const std::complex< float > &cm2)
Definition: complex8x2simd.hpp:46
double f[4]
Definition: complex16x2simd.hpp:32
__m256d c2
Definition: complex16x2simd.hpp:31
complex2 operator*=(const complex2 &other)
Definition: complex8x2simd.hpp:80
complex2()
Definition: complex8x2simd.hpp:43
complex2(const __m128 &cm2)
Definition: complex8x2simd.hpp:44
complex2 operator-(const complex2 &other) const
Definition: complex8x2simd.hpp:61
complex2 operator+=(const complex2 &other)
Definition: complex8x2simd.hpp:56
complex2 operator*(const float &rhs) const
Definition: complex8x2simd.hpp:94
std::complex< float > c(const size_t &i) const
Definition: complex8x2simd.hpp:54
complex2 operator-() const
Definition: complex8x2simd.hpp:95
complex2 operator*=(const float &other)
Definition: complex8x2simd.hpp:96
complex2 operator+(const complex2 &other) const
Definition: complex8x2simd.hpp:55
complex2 operator-=(const complex2 &other)
Definition: complex8x2simd.hpp:62