// File: /workspace/github_cpp_makefile_star2_O1/Kingsford-Group[P]ghost2/include/Eigen/src/Core/products/GeneralMatrixMatrix.h
// Function: Eigen::internal::general_matrix_matrix_product<long, double, 0, false, double, 0, false, 0>::run(long, long, long, double const*, long, double const*, long, double*, long, double, Eigen::internal::level3_blocking<double, 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)
{
  const_blas_data_mapper<LhsScalar, Index, LhsStorageOrder> lhs(_lhs,lhsStride);
  const_blas_data_mapper<RhsScalar, Index, RhsStorageOrder> rhs(_rhs,rhsStride);

  typedef gebp_traits<LhsScalar,RhsScalar> Traits;

  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 = blocking.nc(); // cache block size along the N direction

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

#ifdef EIGEN_HAS_OPENMP
  if(info)
  {
    // this is the parallel version!
    Index tid = omp_get_thread_num();
    Index threads = omp_get_num_threads();
    
    std::size_t sizeA = kc*mc;
    std::size_t sizeW = kc*Traits::WorkSpaceFactor;
    ei_declare_aligned_stack_constructed_variable(LhsScalar, blockA, sizeA, 0);
    ei_declare_aligned_stack_constructed_variable(RhsScalar, w, sizeW, 0);
    
    RhsScalar* blockB = blocking.blockB();
    eigen_internal_assert(blockB!=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 A'.
      pack_lhs(blockA, &lhs(0,k), lhsStride, actual_kc, mc);

      // Pack B_k to B' in a parallel fashion:
      // each thread packs the sub block B_k,j to B'_j where j is the thread id.

      // However, before copying to B'_j, 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_rhs(blockB+info[tid].rhs_start*actual_kc, &rhs(k,info[tid].rhs_start), rhsStride, actual_kc, info[tid].rhs_length);

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

      // Computes C_i += A' * B' per B'_j
      for(Index shift=0; shift<threads; ++shift)
      {
        Index j = (tid+shift)%threads;

        // At this point we have to make sure that B'_j has been updated by the thread j,
        // 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[j].sync!=k) {}

        gebp(res+info[j].rhs_start*resStride, resStride, blockA, blockB+info[j].rhs_start*actual_kc, mc, actual_kc, info[j].rhs_length, alpha, -1,-1,0,0, w);
      }

      // Then keep going as usual with the remaining A'
      for(Index i=mc; i<rows; i+=mc)
      {
        const Index actual_mc = (std::min)(i+mc,rows)-i;

        // pack A_i,k to A'
        pack_lhs(blockA, &lhs(i,k), lhsStride, actual_kc, actual_mc);

        // C_i += A' * B'
        gebp(res+i, resStride, blockA, blockB, actual_mc, actual_kc, cols, alpha, -1,-1,0,0, w);
      }

      // Release all the sub blocks B'_j of B' for the current thread,
      // i.e., we simply decrement the number of users by 1
      for(Index j=0; j<threads; ++j)
        #pragma omp atomic
        --(info[j].users);
    }
  }
  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*cols;
    std::size_t sizeW = kc*Traits::WorkSpaceFactor;

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

    // For each horizontal panel of the rhs, and corresponding panel of the lhs...
    // (==GEMM_VAR1)
    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 rhs's panel into a sequential chunk of memory (L2 caching)
      // Note that this panel will be read as many times as the number of blocks in the lhs's
      // vertical panel which is, in practice, a very low number.
      pack_rhs(blockB, &rhs(k2,0), rhsStride, actual_kc, cols);

      // For each mc x kc block of the lhs's vertical panel...
      // (==GEPP_VAR1)
      for(Index i2=0; i2<rows; i2+=mc)
      {
        const Index actual_mc = (std::min)(i2+mc,rows)-i2;

        // We pack the lhs's block into a sequential chunk of memory (L1 caching)
        // Note that this block will be read a very high number of times, which is equal to the number of
        // micro vertical panel of the large rhs's panel (e.g., cols/4 times).
        pack_lhs(blockA, &lhs(i2,k2), lhsStride, actual_kc, actual_mc);

        // Everything is packed, we can now call the block * panel kernel:
        gebp(res+i2, resStride, blockA, blockB, actual_mc, actual_kc, cols, alpha, -1, -1, 0, 0, blockW);
      }
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movsd %xmm0, -0xe0(%rbp)
movq %r9, -0xc0(%rbp)
movq %r8, -0xa8(%rbp)
movq %rcx, %r12
movq %rsi, -0x88(%rbp)
movq 0x28(%rbp), %rbx
movq 0x18(%rbx), %r14
movq 0x28(%rbx), %rcx
cmpq %rdi, %r14
movq %rdi, -0xf0(%rbp)
cmovgeq %rdi, %r14
movq %r14, -0x80(%rbp)
movq %rcx, -0x38(%rbp)
imulq %rcx, %r14
movq %r14, %rax
shrq $0x3d, %rax
jne 0x42183
movq %rdx, %r13
movq (%rbx), %rax
testq %rax, %rax
je 0x41e16
movq %rax, -0x70(%rbp)
movq $0x0, -0x50(%rbp)
jmp 0x41e58
leaq (,%r14,8), %rdi
cmpq $0x9c4, %r14            # imm = 0x9C4
ja 0x41e42
movq %rsp, %rcx
addq $0xf, %rdi
andq $-0x10, %rdi
subq %rdi, %rcx
movq %rcx, %rsp
movq %rcx, -0x50(%rbp)
movq %rcx, -0x70(%rbp)
jmp 0x41e58
callq 0xd750
movq %rax, -0x70(%rbp)
movq %rax, -0x50(%rbp)
testq %rax, %rax
je 0x42183
movabsq $0x1fffffffffffffff, %rax # imm = 0x1FFFFFFFFFFFFFFF
movq -0x38(%rbp), %r15
imulq -0x88(%rbp), %r15
cmpq %rax, %r15
ja 0x421b1
movq 0x8(%rbx), %rax
movq %rax, -0x58(%rbp)
testq %rax, %rax
je 0x41e8e
movq $0x0, -0x48(%rbp)
jmp 0x41ed0
leaq (,%r15,8), %rdi
cmpq $0x9c4, %r15            # imm = 0x9C4
ja 0x41eba
movq %rsp, %rcx
addq $0xf, %rdi
andq $-0x10, %rdi
subq %rdi, %rcx
movq %rcx, %rsp
movq %rcx, -0x48(%rbp)
movq %rcx, -0x58(%rbp)
jmp 0x41ed0
callq 0xd750
movq %rax, -0x58(%rbp)
movq %rax, -0x48(%rbp)
testq %rax, %rax
je 0x4220d
movabsq $0x1c00000000000000, %rax # imm = 0x1C00000000000000
testq %rax, -0x38(%rbp)
jne 0x421df
movq 0x10(%rbx), %rax
movq %rax, -0x78(%rbp)
testq %rax, %rax
movq %r14, -0x68(%rbp)
movq %r15, -0x60(%rbp)
je 0x41f03
movq $0x0, -0x40(%rbp)
jmp 0x41f45
movq -0x38(%rbp), %rdi
shlq $0x6, %rdi
cmpq $0x4e20, %rdi           # imm = 0x4E20
ja 0x41f2f
movq %rsp, %rcx
addq $0xf, %rdi
andq $-0x10, %rdi
subq %rdi, %rcx
movq %rcx, %rsp
movq %rcx, -0x40(%rbp)
movq %rcx, -0x78(%rbp)
jmp 0x41f45
callq 0xd750
movq %rax, -0x78(%rbp)
movq %rax, -0x40(%rbp)
testq %rax, %rax
je 0x4223b
movq -0x38(%rbp), %rax
shlq $0x6, %rax
movq %rax, -0xa0(%rbp)
testq %r13, %r13
jle 0x42135
movq -0x38(%rbp), %rax
imulq -0xa8(%rbp), %rax
shlq $0x3, %rax
movq %rax, -0xb0(%rbp)
movq -0x80(%rbp), %rax
leaq (,%rax,8), %rax
movq %rax, -0xd8(%rbp)
xorl %eax, %eax
xorps %xmm0, %xmm0
movq %r13, -0xb8(%rbp)
movq -0x70(%rbp), %r15
movq -0x38(%rbp), %rcx
addq %rax, %rcx
cmpq %r13, %rcx
movq %rcx, -0xd0(%rbp)
cmovlq %rcx, %r13
subq %rax, %r13
movq -0xc0(%rbp), %rcx
leaq (%rcx,%rax,8), %rdx
subq $0x10, %rsp
movups %xmm0, (%rsp)
leaq -0x2a(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq 0x10(%rbp), %rcx
movq %r13, -0xe8(%rbp)
movq %r13, %r8
movq -0x88(%rbp), %r9
callq 0x422d2
addq $0x10, %rsp
movq 0x18(%rbp), %rdx
xorl %r13d, %r13d
movq -0x80(%rbp), %r14
movq %r12, -0xc8(%rbp)
xorl %ecx, %ecx
movq -0xf0(%rbp), %rax
cmpq %r14, %rax
movq %r14, %rbx
cmovlq %rax, %rbx
cmpq %rax, %rcx
jge 0x4210d
addq %r13, %rbx
subq $0x10, %rsp
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
leaq -0x2b(%rbp), %rdi
movq %rdx, -0xf8(%rbp)
movq %r15, %rsi
movq %r14, -0x90(%rbp)
movq %r12, %rdx
movq %rcx, -0x98(%rbp)
movq -0xa8(%rbp), %rcx
movq -0xe8(%rbp), %r14
movq %r14, %r8
movq %rbx, %r9
callq 0x4242c
movq -0xf8(%rbp), %rsi
movq -0x98(%rbp), %rcx
movq -0x90(%rbp), %rdx
addq $0x10, %rsp
movq -0x80(%rbp), %rax
addq %rax, %rcx
movq %rcx, -0x98(%rbp)
movq -0xd8(%rbp), %rcx
addq %rcx, %r12
addq %rax, %rdx
subq %rax, %r13
leaq (%rsi,%rcx), %rax
movq %rax, -0x90(%rbp)
subq $0x40, %rsp
movq -0x78(%rbp), %rax
movq %rax, 0x30(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rsp)
movq $-0x1, %rax
movq %rax, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq -0x88(%rbp), %rax
movq %rax, 0x8(%rsp)
movq %r14, (%rsp)
leaq -0x29(%rbp), %rdi
movq %rdx, %r14
movq 0x20(%rbp), %rdx
movq %r15, %rcx
movq -0x58(%rbp), %r8
movq %rbx, %r9
movsd -0xe0(%rbp), %xmm0
callq 0x4254a
movq -0x98(%rbp), %rcx
addq $0x40, %rsp
movq -0x90(%rbp), %rdx
jmp 0x41ffc
movq -0xc8(%rbp), %r12
addq -0xb0(%rbp), %r12
movq -0xb8(%rbp), %r13
movq -0xd0(%rbp), %rax
cmpq %r13, %rax
xorps %xmm0, %xmm0
jl 0x41f97
cmpq $0x4e21, -0xa0(%rbp) # imm = 0x4E21
jb 0x4214b
movq -0x40(%rbp), %rdi
callq 0xd660
cmpq $0x9c5, -0x60(%rbp)     # imm = 0x9C5
movq -0x68(%rbp), %rbx
jb 0x42162
movq -0x48(%rbp), %rdi
callq 0xd660
cmpq $0x9c5, %rbx            # imm = 0x9C5
jb 0x42174
movq -0x50(%rbp), %rdi
callq 0xd660
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x8, %edi
callq 0xd260
movq 0x36ddc(%rip), %rcx     # 0x78f70
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x36dfe(%rip), %rsi     # 0x78fa0
movq 0x36d97(%rip), %rdx     # 0x78f40
movq %rax, %rdi
callq 0xd990
movl $0x8, %edi
callq 0xd260
movq 0x36dae(%rip), %rcx     # 0x78f70
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x36dd0(%rip), %rsi     # 0x78fa0
movq 0x36d69(%rip), %rdx     # 0x78f40
movq %rax, %rdi
callq 0xd990
movl $0x8, %edi
callq 0xd260
movq 0x36d80(%rip), %rcx     # 0x78f70
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x36da2(%rip), %rsi     # 0x78fa0
movq 0x36d3b(%rip), %rdx     # 0x78f40
movq %rax, %rdi
callq 0xd990
movl $0x8, %edi
callq 0xd260
movq 0x36d52(%rip), %rcx     # 0x78f70
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x36d74(%rip), %rsi     # 0x78fa0
movq 0x36d0d(%rip), %rdx     # 0x78f40
movq %rax, %rdi
callq 0xd990
movl $0x8, %edi
callq 0xd260
movq 0x36d24(%rip), %rcx     # 0x78f70
addq $0x10, %rcx
movq %rcx, (%rax)
movq 0x36d46(%rip), %rsi     # 0x78fa0
movq 0x36cdf(%rip), %rdx     # 0x78f40
movq %rax, %rdi
callq 0xd990
movq %rax, %rbx
movq -0x68(%rbp), %r14
movq -0x60(%rbp), %r15
jmp 0x422a5
jmp 0x4227d
movq %rax, %rbx
jmp 0x422a5
movq %rax, %rbx
jmp 0x422b7
jmp 0x42284
movq %rax, %rbx
cmpq $0x4e21, -0xa0(%rbp) # imm = 0x4E21
movq -0x68(%rbp), %r14
movq -0x60(%rbp), %r15
jb 0x422a5
movq -0x40(%rbp), %rdi
callq 0xd660
cmpq $0x9c5, %r15            # imm = 0x9C5
jb 0x422b7
movq -0x48(%rbp), %rdi
callq 0xd660
cmpq $0x9c5, %r14            # imm = 0x9C5
jb 0x422c9
movq -0x50(%rbp), %rdi
callq 0xd660
movq %rbx, %rdi
callq 0xd9c0
nop