// File: /workspace/github_cpp_makefile_star2_O2/Pyboon[P]sage/./Eigen/src/Core/products/GeneralMatrixMatrix.h
// Function: Eigen::internal::general_matrix_matrix_product<long, std::complex<double>, 0, false, std::complex<double>, 0, false, 0>::run(long, long, long, std::complex<double> const*, long, std::complex<double> const*, long, std::complex<double>*, long, std::complex<double>, Eigen::internal::level3_blocking<std::complex<double>, std::complex<double>>&, Eigen::internal::GemmParallelInfo<long>*)
static void run(Index rows, Index cols, Index depth,
  const LhsScalar* _lhs, Index lhsStride,
  const RhsScalar* _rhs, Index rhsStride,
  ResScalar* _res, Index resStride,
  ResScalar alpha,
  level3_blocking<LhsScalar,RhsScalar>& blocking,
  GemmParallelInfo<Index>* info = 0)
{
  typedef const_blas_data_mapper<LhsScalar, Index, LhsStorageOrder> LhsMapper;
  typedef const_blas_data_mapper<RhsScalar, Index, RhsStorageOrder> RhsMapper;
  typedef blas_data_mapper<typename Traits::ResScalar, Index, ColMajor> ResMapper;
  LhsMapper lhs(_lhs,lhsStride);
  RhsMapper rhs(_rhs,rhsStride);
  ResMapper res(_res, resStride);

  Index kc = blocking.kc();                   // cache block size along the K direction
  Index mc = (std::min)(rows,blocking.mc());  // cache block size along the M direction
  Index nc = (std::min)(cols,blocking.nc());  // cache block size along the N direction

  gemm_pack_lhs<LhsScalar, Index, LhsMapper, Traits::mr, Traits::LhsProgress, LhsStorageOrder> pack_lhs;
  gemm_pack_rhs<RhsScalar, Index, RhsMapper, Traits::nr, RhsStorageOrder> pack_rhs;
  gebp_kernel<LhsScalar, RhsScalar, Index, ResMapper, Traits::mr, Traits::nr, ConjugateLhs, ConjugateRhs> gebp;

#ifdef EIGEN_HAS_OPENMP
  if(info)
  {
    // this is the parallel version!
    int tid = omp_get_thread_num();
    int threads = omp_get_num_threads();

    LhsScalar* blockA = blocking.blockA();
    eigen_internal_assert(blockA!=0);

    std::size_t sizeB = kc*nc;
    ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, 0);

    // For each horizontal panel of the rhs, and corresponding vertical panel of the lhs...
    for(Index k=0; k<depth; k+=kc)
    {
      const Index actual_kc = (std::min)(k+kc,depth)-k; // => rows of B', and cols of the A'

      // In order to reduce the chance that a thread has to wait for the other,
      // let's start by packing B'.
      pack_rhs(blockB, rhs.getSubMapper(k,0), actual_kc, nc);

      // Pack A_k to A' in a parallel fashion:
      // each thread packs the sub block A_k,i to A'_i where i is the thread id.

      // However, before copying to A'_i, we have to make sure that no other thread is still using it,
      // i.e., we test that info[tid].users equals 0.
      // Then, we set info[tid].users to the number of threads to mark that all other threads are going to use it.
      while(info[tid].users!=0) {}
      info[tid].users += threads;

      pack_lhs(blockA+info[tid].lhs_start*actual_kc, lhs.getSubMapper(info[tid].lhs_start,k), actual_kc, info[tid].lhs_length);

      // Notify the other threads that the part A'_i is ready to go.
      info[tid].sync = k;

      // Computes C_i += A' * B' per A'_i
      for(int shift=0; shift<threads; ++shift)
      {
        int i = (tid+shift)%threads;

        // At this point we have to make sure that A'_i has been updated by the thread i,
        // we use testAndSetOrdered to mimic a volatile access.
        // However, no need to wait for the B' part which has been updated by the current thread!
        if (shift>0) {
          while(info[i].sync!=k) {
          }
        }

        gebp(res.getSubMapper(info[i].lhs_start, 0), blockA+info[i].lhs_start*actual_kc, blockB, info[i].lhs_length, actual_kc, nc, alpha);
      }

      // Then keep going as usual with the remaining B'
      for(Index j=nc; j<cols; j+=nc)
      {
        const Index actual_nc = (std::min)(j+nc,cols)-j;

        // pack B_k,j to B'
        pack_rhs(blockB, rhs.getSubMapper(k,j), actual_kc, actual_nc);

        // C_j += A' * B'
        gebp(res.getSubMapper(0, j), blockA, blockB, rows, actual_kc, actual_nc, alpha);
      }

      // Release all the sub blocks A'_i of A' for the current thread,
      // i.e., we simply decrement the number of users by 1
      for(Index i=0; i<threads; ++i)
        #pragma omp atomic
        info[i].users -= 1;
    }
  }
  else
#endif // EIGEN_HAS_OPENMP
  {
    EIGEN_UNUSED_VARIABLE(info);

    // this is the sequential version!
    std::size_t sizeA = kc*mc;
    std::size_t sizeB = kc*nc;

    ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, blocking.blockA());
    ei_declare_aligned_stack_constructed_variable(RhsScalar, blockB, sizeB, blocking.blockB());

    const bool pack_rhs_once = mc!=rows && kc==depth && nc==cols;

    // For each horizontal panel of the rhs, and corresponding panel of the lhs...
    for(Index i2=0; i2<rows; i2+=mc)
    {
      const Index actual_mc = (std::min)(i2+mc,rows)-i2;

      for(Index k2=0; k2<depth; k2+=kc)
      {
        const Index actual_kc = (std::min)(k2+kc,depth)-k2;

        // OK, here we have selected one horizontal panel of rhs and one vertical panel of lhs.
        // => Pack lhs's panel into a sequential chunk of memory (L2/L3 caching)
        // Note that this panel will be read as many times as the number of blocks in the rhs's
        // horizontal panel which is, in practice, a very low number.
        pack_lhs(blockA, lhs.getSubMapper(i2,k2), actual_kc, actual_mc);

        // For each kc x nc block of the rhs's horizontal panel...
        for(Index j2=0; j2<cols; j2+=nc)
        {
          const Index actual_nc = (std::min)(j2+nc,cols)-j2;

          // We pack the rhs's block into a sequential chunk of memory (L2 caching)
          // Note that this block will be read a very high number of times, which is equal to the number of
          // micro horizontal panel of the large rhs's panel (e.g., rows/12 times).
          if((!pack_rhs_once) || i2==0)
            pack_rhs(blockB, rhs.getSubMapper(k2,j2), actual_kc, actual_nc);

          // Everything is packed, we can now call the panel * block kernel:
          gebp(res.getSubMapper(i2, j2), blockA, blockB, actual_mc, actual_kc, actual_nc, alpha);
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movsd %xmm1, -0x108(%rbp)
movsd %xmm0, -0x100(%rbp)
movq %r9, -0xb0(%rbp)
movq %r8, -0xd0(%rbp)
movq %rcx, -0xa8(%rbp)
movq %rdx, %r13
movq 0x28(%rbp), %rdx
movq 0x20(%rdx), %rcx
movq 0x10(%rdx), %rax
movq %rdx, %r14
movq 0x18(%rdx), %r12
cmpq %rdi, %rax
movq %rdi, -0x78(%rbp)
movq %rdi, %rbx
movq %rax, -0x38(%rbp)
cmovlq %rax, %rbx
cmpq %rsi, %r12
movq %rsi, -0x88(%rbp)
cmovlq %r12, %rsi
movq %rsi, -0x48(%rbp)
movq %rbx, -0x70(%rbp)
movq %rcx, -0x68(%rbp)
imulq %rcx, %rbx
movq %rbx, %rax
shrq $0x3c, %rax
je 0x1753f
callq 0x5906
movabsq $0xfffffffffffffff, %rdx # imm = 0xFFFFFFFFFFFFFFF
movq -0x48(%rbp), %r15
imulq -0x68(%rbp), %r15
movq (%r14), %rax
movq %rbx, %rdi
shlq $0x4, %rdi
movq %rax, -0x40(%rbp)
testq %rax, %rax
je 0x17573
cmpq $0x20001, %rdi          # imm = 0x20001
setae %al
xorl %ecx, %ecx
jmp 0x175b4
cmpq $0x20000, %rdi          # imm = 0x20000
ja 0x17595
movq %rsp, %rcx
addq $0x1e, %rdi
andq $-0x10, %rdi
subq %rdi, %rcx
movq %rcx, %rsp
xorl %eax, %eax
movq %rcx, -0x40(%rbp)
jmp 0x175b4
callq 0x595a
movabsq $0xfffffffffffffff, %rdx # imm = 0xFFFFFFFFFFFFFFF
xorl %ecx, %ecx
cmpq $0x0, (%r14)
movq %rax, -0x40(%rbp)
cmoveq %rax, %rcx
movb $0x1, %al
movq %rcx, -0x138(%rbp)
movq %rbx, -0x130(%rbp)
movb %al, -0x128(%rbp)
cmpq %rdx, %r15
jbe 0x175d2
callq 0x5906
movq %r14, %rbx
movq 0x8(%r14), %rax
movq %r15, %r14
shlq $0x4, %r14
testq %rax, %rax
je 0x175ed
movq %rax, -0x50(%rbp)
xorl %edi, %edi
jmp 0x17624
cmpq $0x20000, %r14          # imm = 0x20000
ja 0x1760d
movq %rsp, %rdi
leaq 0x1e(%r14), %rcx
andq $-0x10, %rcx
subq %rcx, %rdi
movq %rdi, %rsp
movq %rdi, -0x50(%rbp)
jmp 0x17624
movq %r14, %rdi
callq 0x595a
xorl %edi, %edi
cmpq $0x0, 0x8(%rbx)
movq %rax, -0x50(%rbp)
cmoveq %rax, %rdi
movq 0x20(%rbp), %r8
movq 0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movq 0x10(%rbp), %r9
cmpq -0x88(%rbp), %r12
setl %cl
movq -0x78(%rbp), %rsi
cmpq %rsi, -0x38(%rbp)
setge %dl
cmpq $0x20001, %r14          # imm = 0x20001
movq %rdi, -0x120(%rbp)
movq %r15, -0x118(%rbp)
setae -0x110(%rbp)
movq -0x68(%rbp), %rax
cmpq %r13, %rax
setne %dil
orb %dl, %dil
orb %cl, %dil
movb %dil, -0x29(%rbp)
movq -0x70(%rbp), %rcx
shlq $0x4, %rcx
movq %rcx, -0xa0(%rbp)
movq -0x48(%rbp), %rcx
imulq %rcx, %r8
shlq $0x4, %r8
movq %r8, -0xf8(%rbp)
shlq $0x4, %rax
movq %rax, -0xc0(%rbp)
imulq %rcx, %r9
shlq $0x4, %r9
movq %r9, -0xf0(%rbp)
xorl %eax, %eax
movq %r13, -0xc8(%rbp)
cmpq %rsi, %rax
jge 0x178b5
movq -0x70(%rbp), %rcx
addq %rax, %rcx
cmpq %rsi, %rcx
movq %rsi, %rdx
movq %rcx, -0xb8(%rbp)
cmovlq %rcx, %rdx
subq %rax, %rdx
movq %rdx, -0x90(%rbp)
movq %rax, %rcx
shlq $0x4, %rcx
addq -0xa8(%rbp), %rcx
movq %rcx, -0xd8(%rbp)
testq %rax, %rax
sete %al
orb -0x29(%rbp), %al
movb %al, -0x2a(%rbp)
movq -0xb0(%rbp), %rbx
xorl %eax, %eax
cmpq %r13, %rax
jge 0x1789e
movq -0x68(%rbp), %rcx
leaq (%rax,%rcx), %r14
cmpq %r13, %r14
movq %r13, %rcx
cmovlq %r14, %rcx
subq %rax, %rcx
movq -0xd0(%rbp), %rdx
imulq %rdx, %rax
shlq $0x4, %rax
addq -0xd8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq %rdx, -0x58(%rbp)
subq $0x8, %rsp
leaq -0x2d(%rbp), %rdi
movq -0x40(%rbp), %rsi
leaq -0x60(%rbp), %rdx
movq %rcx, -0x98(%rbp)
movq -0x90(%rbp), %r8
xorl %r9d, %r9d
pushq $0x0
callq 0x15370
popq %rax
popq %rcx
movq %r14, -0xe0(%rbp)
xorl %r12d, %r12d
movq -0x48(%rbp), %r13
movq %rbx, -0xe8(%rbp)
movq %rbx, -0x38(%rbp)
movq -0x80(%rbp), %r15
xorl %ebx, %ebx
movq -0x88(%rbp), %rax
cmpq %r13, %rax
movq %r13, %r14
cmovlq %rax, %r14
cmpq %rax, %rbx
jge 0x17879
addq %r12, %r14
cmpb $0x0, -0x2a(%rbp)
je 0x177f2
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
movq 0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
subq $0x8, %rsp
leaq -0x2c(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x60(%rbp), %rdx
movq -0x98(%rbp), %rcx
movq %r14, %r8
xorl %r9d, %r9d
pushq $0x0
callq 0x1044c
popq %rax
popq %rcx
movq %r15, -0x60(%rbp)
movq 0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
subq $0x30, %rsp
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rsp)
orq $-0x1, 0x10(%rsp)
movq %r14, (%rsp)
orq $-0x1, 0x8(%rsp)
leaq -0x2b(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x50(%rbp), %rcx
movq -0x90(%rbp), %r8
movq -0x98(%rbp), %r9
movsd -0x100(%rbp), %xmm0
movsd -0x108(%rbp), %xmm1
callq 0x153f2
addq $0x30, %rsp
movq -0x48(%rbp), %rax
addq %rax, %rbx
addq -0xf8(%rbp), %r15
movq -0x38(%rbp), %rcx
addq -0xf0(%rbp), %rcx
movq %rcx, -0x38(%rbp)
addq %rax, %r13
subq %rax, %r12
jmp 0x17799
movq -0xe8(%rbp), %rbx
addq -0xc0(%rbp), %rbx
movq -0xe0(%rbp), %rax
movq -0xc8(%rbp), %r13
movq -0x78(%rbp), %rsi
jmp 0x17714
movq -0xa0(%rbp), %rax
addq %rax, -0x80(%rbp)
movq -0xb8(%rbp), %rax
jmp 0x176bf
leaq -0x120(%rbp), %rdi
callq 0xe734
leaq -0x138(%rbp), %rdi
callq 0xe734
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x178de
movq %rax, %rbx
jmp 0x178f6
jmp 0x178e7
jmp 0x178e7
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0xe734
leaq -0x138(%rbp), %rdi
callq 0xe734
movq %rbx, %rdi
callq 0x3430