// File: /workspace/github_c_makefile_star2_O0/jwang11[P]intel_avx_perf/matrix_int16.c
// Function: calc_avx2
void calc_avx2(void) {
  #define VLEN (256/8/sizeof(int16_t))
  const int col_aligned = col - col % VLEN;
  int16_t dst_arr[VLEN];

  __m256i op0, op1, tmp_vec;
  volatile __m256i  tgt;

  for (int i = 0; i < row; i++) {
    int16_t sum = 0;
    tgt = _mm256_setzero_si256();
    for (int j = 0; j < col_aligned; j += VLEN) {
      op0 = _mm256_load_si256((__m256i *)&mutiplier[j]);
      op1 = _mm256_load_si256((__m256i *)&mat[i][j]);
      tmp_vec = _mm256_mullo_epi16(op0, op1);
      tgt = _mm256_add_epi16(tmp_vec, tgt);
    }

    _mm256_store_epi64(&dst_arr, tgt);
    for (int k = 0; k < VLEN; k++)
      sum += dst_arr[k];

    for (int l = col_aligned; l < col; l++)
      sum += mat[i][l] * mutiplier[l];
 
    result[i] = sum;
  }
  #undef VLEN
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
andq $-0x20, %rsp
subq $0x1e0, %rsp            # imm = 0x1E0
movl $0x1000, 0xdc(%rsp) # imm = 0x1000
movl $0x0, 0x1c(%rsp)
cmpl $0x40, 0x1c(%rsp)
jge 0x1532
movw $0x0, 0x1a(%rsp)
vpxor %xmm0, %xmm0, %xmm0
vmovdqa %ymm0, 0xe0(%rsp)
vmovdqa 0xe0(%rsp), %ymm0
vmovdqa %ymm0, 0x20(%rsp)
movl $0x0, 0x14(%rsp)
cmpl $0x1000, 0x14(%rsp)     # imm = 0x1000
jge 0x1446
movslq 0x14(%rsp), %rcx
leaq 0x82cfe(%rip), %rax     # 0x84060
shlq %rcx
addq %rcx, %rax
movq %rax, 0x118(%rsp)
movq 0x118(%rsp), %rax
vmovdqa (%rax), %ymm0
vmovdqa %ymm0, 0x80(%rsp)
movslq 0x1c(%rsp), %rcx
leaq 0x2ccf(%rip), %rax      # 0x4060
shlq $0xd, %rcx
addq %rcx, %rax
movslq 0x14(%rsp), %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, 0x110(%rsp)
movq 0x110(%rsp), %rax
vmovdqa (%rax), %ymm0
vmovdqa %ymm0, 0x60(%rsp)
vmovdqa 0x80(%rsp), %ymm1
vmovdqa 0x60(%rsp), %ymm0
vmovdqa %ymm1, 0x140(%rsp)
vmovdqa %ymm0, 0x120(%rsp)
vmovdqa 0x140(%rsp), %ymm0
vmovdqa 0x120(%rsp), %ymm1
vpmullw %ymm1, %ymm0, %ymm0
vmovdqa %ymm0, 0x40(%rsp)
vmovdqa 0x40(%rsp), %ymm1
vmovdqa 0x20(%rsp), %ymm0
vmovdqa %ymm1, 0x180(%rsp)
vmovdqa %ymm0, 0x160(%rsp)
vmovdqa 0x180(%rsp), %ymm0
vmovdqa 0x160(%rsp), %ymm1
vpaddw %ymm1, %ymm0, %ymm0
vmovdqa %ymm0, 0x20(%rsp)
movslq 0x14(%rsp), %rax
addq $0x10, %rax
movl %eax, 0x14(%rsp)
jmp 0x1348
vmovdqa 0x20(%rsp), %ymm0
leaq 0xb0(%rsp), %rax
movq %rax, 0x1c8(%rsp)
vmovdqa %ymm0, 0x1a0(%rsp)
vmovdqa 0x1a0(%rsp), %ymm0
movq 0x1c8(%rsp), %rax
vmovdqa %ymm0, (%rax)
movl $0x0, 0x10(%rsp)
movslq 0x10(%rsp), %rax
cmpq $0x10, %rax
jae 0x14b3
movslq 0x10(%rsp), %rax
movswl 0xb0(%rsp,%rax,2), %ecx
movswl 0x1a(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x1a(%rsp)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x1482
movl $0x1000, 0xc(%rsp)      # imm = 0x1000
cmpl $0x1000, 0xc(%rsp)      # imm = 0x1000
jge 0x150d
movslq 0x1c(%rsp), %rcx
leaq 0x2b8f(%rip), %rax      # 0x4060
shlq $0xd, %rcx
addq %rcx, %rax
movslq 0xc(%rsp), %rcx
movswl (%rax,%rcx,2), %ecx
movslq 0xc(%rsp), %rdx
leaq 0x82b73(%rip), %rax     # 0x84060
movswl (%rax,%rdx,2), %eax
imull %eax, %ecx
movswl 0x1a(%rsp), %eax
addl %ecx, %eax
movw %ax, 0x1a(%rsp)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x14bb
movw 0x1a(%rsp), %dx
movslq 0x1c(%rsp), %rcx
leaq 0x84b42(%rip), %rax     # 0x86060
movw %dx, (%rax,%rcx,2)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x1312
movq %rbp, %rsp
popq %rbp
vzeroupper
retq
nopw (%rax,%rax)