// File: /workspace/github_cpp_makefile_star2_O2/ArashPartow[P]exprtk-extras/exprtk_prime_sieve_vectorized.cpp
// Function: void sieve_of_eratosthenes_vectorized<double>()
void sieve_of_eratosthenes_vectorized()
{
   typedef exprtk::symbol_table<T> symbol_table_t;
   typedef exprtk::expression<T>   expression_t;
   typedef exprtk::parser<T>       parser_t;

   const std::string sieve_of_eratosthenes_program =
      " var sieve[10^8] := [false];                     "
      " var m := trunc(sqrt(sieve[]));                  "
      "                                                 "
      " sieve[0] := true;                               "
      " sieve[1] := true;                               "
      "                                                 "
      " for (var i := 0; i <= m; i += 1)                "
      " {                                               "
      "    if (false == sieve[i])                       "
      "    {                                            "
      "       assign(sieve, true, i^2, sieve[] - 1, i); "
      "    }                                            "
      " };                                              "
      "                                                 "
      " var prime_count := sieve[] - sum(sieve);        "
      "                                                 "
      " prime_count == 5761455;                         ";

   symbol_table_t symbol_table;
   exprtk::rtl::vecops::package<T> vector_package;

   symbol_table.add_package(vector_package);

   expression_t expression;
   expression.register_symbol_table(symbol_table);

   parser_t parser;
   parser.compile(sieve_of_eratosthenes_program,expression);

   exprtk::timer timer;
   timer.start();

   const T result = expression.value();

   timer.stop();

   printf("Result: %8.3f\n",result);

   printf("Total time: %8.3fsec\n",timer.time());
}

// Assembly:
pushq %rbx
subq $0x12b0, %rsp           # imm = 0x12B0
leaq 0x12edec(%rip), %rsi    # 0x2410fe
leaq 0x38(%rsp), %rdi
leaq 0x1a8(%rsp), %rdx
callq 0x1122c8
leaq 0x8(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x11255c
leaq 0xad0(%rsp), %rdi
callq 0x112580
leaq 0xad0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x117d7e
leaq 0x18(%rsp), %rdi
callq 0x1129a6
leaq 0x18(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x112a06
leaq 0x58(%rsp), %rdi
pushq $0x7f
popq %rsi
callq 0x112a62
leaq 0x1a8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x112b72
leaq 0x58(%rsp), %rdi
callq 0x11318a
leaq 0x1a8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq 0x1131d2
leaq 0x58(%rsp), %rdi
movb $0x0, (%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movups %xmm0, 0x18(%rdi)
callq 0x113654
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movsd %xmm0, 0x10(%rsp)
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0x113662
leaq 0x12f056(%rip), %rdi    # 0x241440
movsd 0x10(%rsp), %xmm0
movb $0x1, %al
callq 0x110060
movq %rbx, %rdi
callq 0x113676
leaq 0x12f049(%rip), %rdi    # 0x24144f
movb $0x1, %al
callq 0x110060
leaq 0x1a8(%rsp), %rdi
callq 0x1136a8
leaq 0x18(%rsp), %rdi
callq 0x1137e2
leaq 0xad0(%rsp), %rdi
callq 0x1137f8
leaq 0x8(%rsp), %rdi
callq 0x113946
leaq 0x38(%rsp), %rdi
callq 0x1105c8
addq $0x12b0, %rsp           # imm = 0x12B0
popq %rbx
retq
jmp 0x112477
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x11318a
jmp 0x112487
jmp 0x112461
movq %rax, %rbx
jmp 0x112487
jmp 0x112468
movq %rax, %rbx
jmp 0x112491
movq %rax, %rbx
jmp 0x11249e
movq %rax, %rbx
jmp 0x1124a8
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x1136a8
leaq 0x18(%rsp), %rdi
callq 0x1137e2
leaq 0xad0(%rsp), %rdi
callq 0x1137f8
leaq 0x8(%rsp), %rdi
callq 0x113946
leaq 0x38(%rsp), %rdi
callq 0x1105c8
movq %rbx, %rdi
callq 0x110320