// File: /workspace/github_cpp_makefile_star2_O2/kaityo256[P]lj_simd/force_soa.cpp
// Function: force_avx2()
void
force_avx2(void) {
  const int pn = particle_number;
  const v4df vzero = _mm256_set_pd(0, 0, 0, 0);
  const v4df vcl2 = _mm256_set_pd(CL2, CL2, CL2, CL2);
  const v4df vc24 = _mm256_set_pd(24 * dt, 24 * dt, 24 * dt, 24 * dt);
  const v4df vc48 = _mm256_set_pd(48 * dt, 48 * dt, 48 * dt, 48 * dt);
  for (int i = 0; i < pn; i++) {
    const double qix = q[X][i];
    const double qiy = q[Y][i];
    const double qiz = q[Z][i];
    const int np = number_of_partners[i];
    double pfx = 0;
    double pfy = 0;
    double pfz = 0;
    const int kp = pointer[i];
    const v4df vqix = _mm256_set_pd(q[X][i], q[X][i], q[X][i], q[X][i]);
    const v4df vqiy = _mm256_set_pd(q[Y][i], q[Y][i], q[Y][i], q[Y][i]);
    const v4df vqiz = _mm256_set_pd(q[Z][i], q[Z][i], q[Z][i], q[Z][i]);

    for (int k = 0; k < (np / 4) * 4; k += 4) {
      const int j_1 = sorted_list[kp + k];
      const int j_2 = sorted_list[kp + k + 1];
      const int j_3 = sorted_list[kp + k + 2];
      const int j_4 = sorted_list[kp + k + 3];

      const v4df vqjx = _mm256_set_pd(q[X][j_1], q[X][j_2], q[X][j_3], q[X][j_4]);
      const v4df vqjy = _mm256_set_pd(q[Y][j_1], q[Y][j_2], q[Y][j_3], q[Y][j_4]);
      const v4df vqjz = _mm256_set_pd(q[Z][j_1], q[Z][j_2], q[Z][j_3], q[Z][j_4]);

      const v4df vdx = vqjx - vqix;
      const v4df vdy = vqjy - vqiy;
      const v4df vdz = vqjz - vqiz;
      const v4df vr2 = vdx * vdx + vdy * vdy + vdz * vdz;
      const v4df vr6 = vr2 * vr2 * vr2;
      v4df vdf = (vc24 * vr6 - vc48) / (vr6 * vr6 * vr2);
      const v4df mask = vcl2 - vr2;
      vdf = _mm256_blendv_pd(vdf, vzero, mask);
      v4df vdfx = vdf * vdx;
      v4df vdfy = vdf * vdy;
      v4df vdfz = vdf * vdz;
      double *dfx = (double *)(&vdfx);
      double *dfy = (double *)(&vdfy);
      double *dfz = (double *)(&vdfz);

      pfx += dfx[3];
      pfy += dfy[3];
      pfz += dfz[3];

      p[X][j_1] -= dfx[3];
      p[Y][j_1] -= dfy[3];
      p[Z][j_1] -= dfz[3];

      pfx += dfx[2];
      pfy += dfy[2];
      pfz += dfz[2];
      p[X][j_2] -= dfx[2];
      p[Y][j_2] -= dfy[2];
      p[Z][j_2] -= dfz[2];

      pfx += dfx[1];
      pfy += dfy[1];
      pfz += dfz[1];
      p[X][j_3] -= dfx[1];
      p[Y][j_3] -= dfy[1];
      p[Z][j_3] -= dfz[1];

      pfx += dfx[0];
      pfy += dfy[0];
      pfz += dfz[0];
      p[X][j_4] -= dfx[0];
      p[Y][j_4] -= dfy[0];
      p[Z][j_4] -= dfz[0];
    }
    p[X][i] += pfx;
    p[Y][i] += pfy;
    p[Z][i] += pfz;
    for (int k = (np / 4) * 4; k < np; k++) {
      const int j = sorted_list[kp + k];
      double dx = q[X][j] - qix;
      double dy = q[Y][j] - qiy;
      double dz = q[Z][j] - qiz;
      double r2 = (dx * dx + dy * dy + dz * dz);
      if (r2 > CL2) continue;
      double r6 = r2 * r2 * r2;
      double df = ((24.0 * r6 - 48.0) / (r6 * r6 * r2)) * dt;
      p[X][i] += df * dx;
      p[Y][i] += df * dy;
      p[Z][i] += df * dz;
      p[X][j] -= df * dx;
      p[Y][j] -= df * dy;
      p[Z][j] -= df * dz;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
vbroadcastsd 0x22c1(%rip), %ymm0 # 0x4048
vbroadcastsd 0x22c0(%rip), %ymm1 # 0x4050
vbroadcastsd 0x22a7(%rip), %ymm2 # 0x4040
vmovsd 0x229f(%rip), %xmm4     # 0x4040
vmovsd 0x227f(%rip), %xmm5     # 0x4028
vmovsd 0x227d(%rip), %xmm20    # 0x4030
vmovsd 0x227b(%rip), %xmm21    # 0x4038
movl 0x19f4d4d(%rip), %eax   # 0x19f6b10
leaq 0x18ad46(%rip), %r8     # 0x18cb10
movl $0x4, %r11d
leaq 0x7a16349(%rip), %rbx   # 0x7a18120
vxorpd %xmm3, %xmm3, %xmm3
leaq 0xdbfd2e(%rip), %r14    # 0xdc1b10
xorl %edi, %edi
movl %eax, %ecx
sarl $0x1f, %ecx
andnl %eax, %ecx, %esi
cmpq %rsi, %rdi
je 0x2227
leaq 0x19f4d22(%rip), %rax   # 0x19f6b20
vbroadcastsd (%r8,%rdi,8), %ymm8
vbroadcastsd 0x30d400(%r8,%rdi,8), %ymm9
vbroadcastsd 0x61a800(%r8,%rdi,8), %ymm10
vxorpd %xmm11, %xmm11, %xmm11
vxorpd %xmm12, %xmm12, %xmm12
vxorpd %xmm13, %xmm13, %xmm13
xorl %r12d, %r12d
movslq (%rax,%rdi,4), %rcx
leaq 0x7708eeb(%rip), %rax   # 0x770ad20
movslq (%rax,%rdi,4), %r15
movl %ecx, %eax
cltd
idivl %r11d
leaq 0xc(%rbx,%r15,4), %rdx
shll $0x2, %eax
cltq
cmpq %rax, %r12
jge 0x20ee
movslq (%rdx,%r12,4), %r13
movslq -0x8(%rdx,%r12,4), %r9
movslq -0xc(%rdx,%r12,4), %r10
movslq -0x4(%rdx,%r12,4), %rbp
vmovapd %ymm0, %ymm19
addq $0x4, %r12
vmovsd (%r8,%r9,8), %xmm14
vmovsd (%r8,%r13,8), %xmm15
vmovsd 0x30d400(%r8,%r13,8), %xmm16
vmovsd 0x61a800(%r8,%r13,8), %xmm17
vmovsd (%r14,%r10,8), %xmm23
vmovhpd (%r8,%r10,8), %xmm14, %xmm14 # xmm14 = xmm14[0],mem[0]
vmovhpd (%r8,%rbp,8), %xmm15, %xmm15 # xmm15 = xmm15[0],mem[0]
vmovhpd 0x30d400(%r8,%rbp,8), %xmm16, %xmm16 # xmm16 = xmm16[0],mem[0]
vmovhpd 0x61a800(%r8,%rbp,8), %xmm17, %xmm17 # xmm17 = xmm17[0],mem[0]
vinsertf128 $0x1, %xmm14, %ymm15, %ymm14
vmovsd 0x30d400(%r8,%r9,8), %xmm15
vmovhpd 0x30d400(%r8,%r10,8), %xmm15, %xmm15 # xmm15 = xmm15[0],mem[0]
vsubpd %ymm8, %ymm14, %ymm14
vinsertf32x4 $0x1, %xmm15, %ymm16, %ymm15
vmovsd 0x61a800(%r8,%r9,8), %xmm16
vmovhpd 0x61a800(%r8,%r10,8), %xmm16, %xmm16 # xmm16 = xmm16[0],mem[0]
vsubpd %ymm9, %ymm15, %ymm15
vinsertf32x4 $0x1, %xmm16, %ymm17, %ymm16
vmulpd %ymm15, %ymm15, %ymm17
vsubpd %ymm10, %ymm16, %ymm16
vfmadd231pd %ymm14, %ymm14, %ymm17 # ymm17 = (ymm14 * ymm14) + ymm17
vfmadd231pd %ymm16, %ymm16, %ymm17 # ymm17 = (ymm16 * ymm16) + ymm17
vmulpd %ymm17, %ymm17, %ymm18
vsubpd %ymm17, %ymm2, %ymm7
vmulpd %ymm18, %ymm17, %ymm18
vfmadd213pd %ymm1, %ymm18, %ymm19 # ymm19 = (ymm18 * ymm19) + ymm1
vmulpd %ymm18, %ymm18, %ymm18
vmulpd %ymm18, %ymm17, %ymm18
vdivpd %ymm18, %ymm19, %ymm6
vblendvpd %ymm7, %ymm3, %ymm6, %ymm6
vmulpd %ymm6, %ymm14, %ymm7
vmulpd %ymm6, %ymm15, %ymm14
vmulpd %ymm16, %ymm6, %ymm6
vextractf128 $0x1, %ymm7, %xmm15
vextractf32x4 $0x1, %ymm14, %xmm17
vextractf32x4 $0x1, %ymm6, %xmm19
vshufpd $0x1, %xmm15, %xmm15, %xmm16 # xmm16 = xmm15[1,0]
vshufpd $0x1, %xmm17, %xmm17, %xmm18 # xmm18 = xmm17[1,0]
vshufpd $0x1, %xmm19, %xmm19, %xmm22 # xmm22 = xmm19[1,0]
vaddsd %xmm16, %xmm13, %xmm13
vsubsd %xmm16, %xmm23, %xmm16
vaddsd %xmm18, %xmm12, %xmm12
vaddsd %xmm22, %xmm11, %xmm11
vmovsd %xmm16, (%r14,%r10,8)
vaddsd %xmm13, %xmm15, %xmm13
vaddsd %xmm12, %xmm17, %xmm12
vaddsd %xmm11, %xmm19, %xmm11
vmovsd 0x30d400(%r14,%r10,8), %xmm16
vsubsd %xmm18, %xmm16, %xmm16
vmovsd %xmm16, 0x30d400(%r14,%r10,8)
vmovsd 0x61a800(%r14,%r10,8), %xmm16
vsubsd %xmm22, %xmm16, %xmm16
vmovsd %xmm16, 0x61a800(%r14,%r10,8)
vmovsd (%r14,%r9,8), %xmm16
vsubsd %xmm15, %xmm16, %xmm15
vshufpd $0x1, %xmm14, %xmm14, %xmm16 # xmm16 = xmm14[1,0]
vaddsd %xmm12, %xmm16, %xmm12
vmovsd %xmm15, (%r14,%r9,8)
vmovsd 0x30d400(%r14,%r9,8), %xmm15
vaddsd %xmm12, %xmm14, %xmm12
vsubsd %xmm17, %xmm15, %xmm15
vshufpd $0x1, %xmm6, %xmm6, %xmm17 # xmm17 = xmm6[1,0]
vaddsd %xmm11, %xmm17, %xmm11
vmovsd %xmm15, 0x30d400(%r14,%r9,8)
vmovsd 0x61a800(%r14,%r9,8), %xmm15
vaddsd %xmm6, %xmm11, %xmm11
vsubsd %xmm19, %xmm15, %xmm15
vmovsd %xmm15, 0x61a800(%r14,%r9,8)
vshufpd $0x1, %xmm7, %xmm7, %xmm15 # xmm15 = xmm7[1,0]
vmovsd (%r14,%rbp,8), %xmm18
vaddsd %xmm13, %xmm15, %xmm13
vaddsd %xmm7, %xmm13, %xmm13
vsubsd %xmm15, %xmm18, %xmm15
vmovsd %xmm15, (%r14,%rbp,8)
vmovsd 0x30d400(%r14,%rbp,8), %xmm15
vsubsd %xmm16, %xmm15, %xmm15
vmovsd %xmm15, 0x30d400(%r14,%rbp,8)
vmovsd 0x61a800(%r14,%rbp,8), %xmm15
vsubsd %xmm17, %xmm15, %xmm15
vmovsd %xmm15, 0x61a800(%r14,%rbp,8)
vmovsd (%r14,%r13,8), %xmm15
vsubsd %xmm7, %xmm15, %xmm7
vmovsd %xmm7, (%r14,%r13,8)
vmovsd 0x30d400(%r14,%r13,8), %xmm7
vsubsd %xmm14, %xmm7, %xmm7
vmovsd %xmm7, 0x30d400(%r14,%r13,8)
vmovsd 0x61a800(%r14,%r13,8), %xmm7
vsubsd %xmm6, %xmm7, %xmm6
vmovsd %xmm6, 0x61a800(%r14,%r13,8)
jmp 0x1e49
vaddsd (%r14,%rdi,8), %xmm13, %xmm13
addq %rax, %r15
leaq (%rbx,%r15,4), %rdx
vmovsd %xmm13, (%r14,%rdi,8)
vaddsd 0x30d400(%r14,%rdi,8), %xmm12, %xmm12
vmovsd %xmm12, 0x30d400(%r14,%rdi,8)
vaddsd 0x61a800(%r14,%rdi,8), %xmm11, %xmm11
vmovsd %xmm11, 0x61a800(%r14,%rdi,8)
cmpq %rcx, %rax
jge 0x221f
movslq (%rdx), %r9
vmovsd 0x30d400(%r8,%r9,8), %xmm11
vmovsd (%r8,%r9,8), %xmm6
vmovsd 0x61a800(%r8,%r9,8), %xmm7
vsubsd %xmm9, %xmm11, %xmm12
vsubsd %xmm8, %xmm6, %xmm13
vsubsd %xmm10, %xmm7, %xmm11
vmulsd %xmm12, %xmm12, %xmm14
vfmadd231sd %xmm13, %xmm13, %xmm14 # xmm14 = (xmm13 * xmm13) + xmm14
vfmadd231sd %xmm11, %xmm11, %xmm14 # xmm14 = (xmm11 * xmm11) + xmm14
vucomisd %xmm4, %xmm14
ja 0x2213
vmulsd %xmm14, %xmm14, %xmm6
vmovapd %xmm5, %xmm7
vmulsd %xmm6, %xmm14, %xmm6
vfmadd213sd %xmm20, %xmm6, %xmm7 # xmm7 = (xmm6 * xmm7) + xmm20
vmulsd %xmm6, %xmm6, %xmm6
vmulsd %xmm6, %xmm14, %xmm6
vdivsd %xmm6, %xmm7, %xmm6
vmovsd (%r14,%rdi,8), %xmm7
vmulsd %xmm21, %xmm6, %xmm6
vfmadd231sd %xmm13, %xmm6, %xmm7 # xmm7 = (xmm6 * xmm13) + xmm7
vmovsd %xmm7, (%r14,%rdi,8)
vmovsd 0x30d400(%r14,%rdi,8), %xmm7
vfmadd231sd %xmm12, %xmm6, %xmm7 # xmm7 = (xmm6 * xmm12) + xmm7
vmovsd %xmm7, 0x30d400(%r14,%rdi,8)
vmovsd 0x61a800(%r14,%rdi,8), %xmm7
vfmadd231sd %xmm11, %xmm6, %xmm7 # xmm7 = (xmm6 * xmm11) + xmm7
vmovsd %xmm7, 0x61a800(%r14,%rdi,8)
vfnmadd213sd (%r14,%r9,8), %xmm6, %xmm13 # xmm13 = -(xmm6 * xmm13) + mem
vmovsd %xmm13, (%r14,%r9,8)
vfnmadd213sd 0x30d400(%r14,%r9,8), %xmm6, %xmm12 # xmm12 = -(xmm6 * xmm12) + mem
vmovsd %xmm12, 0x30d400(%r14,%r9,8)
vfnmadd213sd 0x61a800(%r14,%r9,8), %xmm6, %xmm11 # xmm11 = -(xmm6 * xmm11) + mem
vmovsd %xmm11, 0x61a800(%r14,%r9,8)
incq %rax
addq $0x4, %rdx
jmp 0x2129
incq %rdi
jmp 0x1dee
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
vzeroupper
retq