<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How oneAPI vectorize the given code? in Intel® oneAPI DPC++/C++ Compiler</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/How-oneAPI-vectorize-the-given-code/m-p/1365947#M1933</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am working on DPC++ on CPU backend.&lt;/P&gt;
&lt;P&gt;I have the following function:&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void Evaluate_Kernel(Creature *creatures, double *fitness_function,
                                uint32_t count, uint32_t num_vars,
                                sycl::nd_item&amp;lt;3&amp;gt; item_ct1) {
  double fitness = 0;
  for (int j = 0; j &amp;lt; num_vars; j++) {
    double pow = 127;
    for (int k = 0; k &amp;lt; j + 1; k++) {
      pow *= 7.3;
      printf("add\n");
    }
    fitness += pow;
  }
  printf("fitness: %f\n", fitness);
}&lt;/LI-CODE&gt;
&lt;P&gt;And when I see the dumped code, it has:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;0000000000407a60 &amp;lt;_Z15Evaluate_KernelP8CreaturePdjjN2cl4sycl7nd_itemILi3EEE&amp;gt;:
  407a60:	55                   	push   %rbp
  407a61:	48 89 e5             	mov    %rsp,%rbp
  407a64:	48 83 ec 40          	sub    $0x40,%rsp
  407a68:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
  407a6c:	48 89 75 f0          	mov    %rsi,-0x10(%rbp)
  407a70:	89 55 ec             	mov    %edx,-0x14(%rbp)
  407a73:	89 4d e8             	mov    %ecx,-0x18(%rbp)
  407a76:	0f 57 c0             	xorps  %xmm0,%xmm0
  407a79:	f2 0f 11 45 e0       	movsd  %xmm0,-0x20(%rbp)
  407a7e:	c7 45 dc 00 00 00 00 	movl   $0x0,-0x24(%rbp)
  407a85:	8b 45 dc             	mov    -0x24(%rbp),%eax
  407a88:	3b 45 e8             	cmp    -0x18(%rbp),%eax
  407a8b:	0f 83 73 00 00 00    	jae    407b04 &amp;lt;_Z15Evaluate_KernelP8CreaturePdjjN2cl4sycl7nd_itemILi3EEE+0xa4&amp;gt;
  407a91:	f2 0f 10 05 87 16 02 	movsd  0x21687(%rip),%xmm0        # 429120 &amp;lt;_ZTI5Timer+0x10&amp;gt;
  407a98:	00 
  407a99:	f2 0f 11 45 d0       	movsd  %xmm0,-0x30(%rbp)
  407a9e:	c7 45 cc 00 00 00 00 	movl   $0x0,-0x34(%rbp)
  407aa5:	8b 45 cc             	mov    -0x34(%rbp),%eax
  407aa8:	8b 4d dc             	mov    -0x24(%rbp),%ecx
  407aab:	83 c1 01             	add    $0x1,%ecx
  407aae:	39 c8                	cmp    %ecx,%eax
  407ab0:	0f 8d 31 00 00 00    	jge    407ae7 &amp;lt;_Z15Evaluate_KernelP8CreaturePdjjN2cl4sycl7nd_itemILi3EEE+0x87&amp;gt;
  407ab6:	f2 0f 10 05 6a 16 02 	movsd  0x2166a(%rip),%xmm0        # 429128 &amp;lt;_ZTI5Timer+0x18&amp;gt;
  407abd:	00 
  407abe:	f2 0f 59 45 d0       	mulsd  -0x30(%rbp),%xmm0
  407ac3:	f2 0f 11 45 d0       	movsd  %xmm0,-0x30(%rbp)
  407ac8:	48 bf 70 95 42 00 00 	movabs $0x429570,%rdi
  407acf:	00 00 00 
  407ad2:	b0 00                	mov    $0x0,%al
  407ad4:	e8 97 c5 ff ff       	callq  404070 &amp;lt;printf@plt&amp;gt;
  407ad9:	8b 45 cc             	mov    -0x34(%rbp),%eax
  407adc:	83 c0 01             	add    $0x1,%eax
  407adf:	89 45 cc             	mov    %eax,-0x34(%rbp)
  407ae2:	e9 be ff ff ff       	jmpq   407aa5 &amp;lt;_Z15Evaluate_KernelP8CreaturePdjjN2cl4sycl7nd_itemILi3EEE+0x45&amp;gt;
  407ae7:	f2 0f 10 45 d0       	movsd  -0x30(%rbp),%xmm0
  407aec:	f2 0f 58 45 e0       	addsd  -0x20(%rbp),%xmm0
  407af1:	f2 0f 11 45 e0       	movsd  %xmm0,-0x20(%rbp)
  407af6:	8b 45 dc             	mov    -0x24(%rbp),%eax
  407af9:	83 c0 01             	add    $0x1,%eax
  407afc:	89 45 dc             	mov    %eax,-0x24(%rbp)
  407aff:	e9 81 ff ff ff       	jmpq   407a85 &amp;lt;_Z15Evaluate_KernelP8CreaturePdjjN2cl4sycl7nd_itemILi3EEE+0x25&amp;gt;
  407b04:	f2 0f 10 45 e0       	movsd  -0x20(%rbp),%xmm0
  407b09:	48 bf 75 95 42 00 00 	movabs $0x429575,%rdi
  407b10:	00 00 00 
  407b13:	b0 01                	mov    $0x1,%al
  407b15:	e8 56 c5 ff ff       	callq  404070 &amp;lt;printf@plt&amp;gt;
  407b1a:	48 83 c4 40          	add    $0x40,%rsp
  407b1e:	5d                   	pop    %rbp
  407b1f:	c3                   	retq   &lt;/LI-CODE&gt;
&lt;P&gt;I am quite confused as I cannot understand what the optimized instructions do. Would anyone please give me some hints of how to understand the optimized code?&lt;/P&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Mar 2022 22:01:19 GMT</pubDate>
    <dc:creator>Roin</dc:creator>
    <dc:date>2022-03-04T22:01:19Z</dc:date>
    <item>
      <title>How oneAPI vectorize the given code?</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/How-oneAPI-vectorize-the-given-code/m-p/1365947#M1933</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am working on DPC++ on CPU backend.&lt;/P&gt;
&lt;P&gt;I have the following function:&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;void Evaluate_Kernel(Creature *creatures, double *fitness_function,
                                uint32_t count, uint32_t num_vars,
                                sycl::nd_item&amp;lt;3&amp;gt; item_ct1) {
  double fitness = 0;
  for (int j = 0; j &amp;lt; num_vars; j++) {
    double pow = 127;
    for (int k = 0; k &amp;lt; j + 1; k++) {
      pow *= 7.3;
      printf("add\n");
    }
    fitness += pow;
  }
  printf("fitness: %f\n", fitness);
}&lt;/LI-CODE&gt;
&lt;P&gt;And when I see the dumped code, it has:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;0000000000407a60 &amp;lt;_Z15Evaluate_KernelP8CreaturePdjjN2cl4sycl7nd_itemILi3EEE&amp;gt;:
  407a60:	55                   	push   %rbp
  407a61:	48 89 e5             	mov    %rsp,%rbp
  407a64:	48 83 ec 40          	sub    $0x40,%rsp
  407a68:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
  407a6c:	48 89 75 f0          	mov    %rsi,-0x10(%rbp)
  407a70:	89 55 ec             	mov    %edx,-0x14(%rbp)
  407a73:	89 4d e8             	mov    %ecx,-0x18(%rbp)
  407a76:	0f 57 c0             	xorps  %xmm0,%xmm0
  407a79:	f2 0f 11 45 e0       	movsd  %xmm0,-0x20(%rbp)
  407a7e:	c7 45 dc 00 00 00 00 	movl   $0x0,-0x24(%rbp)
  407a85:	8b 45 dc             	mov    -0x24(%rbp),%eax
  407a88:	3b 45 e8             	cmp    -0x18(%rbp),%eax
  407a8b:	0f 83 73 00 00 00    	jae    407b04 &amp;lt;_Z15Evaluate_KernelP8CreaturePdjjN2cl4sycl7nd_itemILi3EEE+0xa4&amp;gt;
  407a91:	f2 0f 10 05 87 16 02 	movsd  0x21687(%rip),%xmm0        # 429120 &amp;lt;_ZTI5Timer+0x10&amp;gt;
  407a98:	00 
  407a99:	f2 0f 11 45 d0       	movsd  %xmm0,-0x30(%rbp)
  407a9e:	c7 45 cc 00 00 00 00 	movl   $0x0,-0x34(%rbp)
  407aa5:	8b 45 cc             	mov    -0x34(%rbp),%eax
  407aa8:	8b 4d dc             	mov    -0x24(%rbp),%ecx
  407aab:	83 c1 01             	add    $0x1,%ecx
  407aae:	39 c8                	cmp    %ecx,%eax
  407ab0:	0f 8d 31 00 00 00    	jge    407ae7 &amp;lt;_Z15Evaluate_KernelP8CreaturePdjjN2cl4sycl7nd_itemILi3EEE+0x87&amp;gt;
  407ab6:	f2 0f 10 05 6a 16 02 	movsd  0x2166a(%rip),%xmm0        # 429128 &amp;lt;_ZTI5Timer+0x18&amp;gt;
  407abd:	00 
  407abe:	f2 0f 59 45 d0       	mulsd  -0x30(%rbp),%xmm0
  407ac3:	f2 0f 11 45 d0       	movsd  %xmm0,-0x30(%rbp)
  407ac8:	48 bf 70 95 42 00 00 	movabs $0x429570,%rdi
  407acf:	00 00 00 
  407ad2:	b0 00                	mov    $0x0,%al
  407ad4:	e8 97 c5 ff ff       	callq  404070 &amp;lt;printf@plt&amp;gt;
  407ad9:	8b 45 cc             	mov    -0x34(%rbp),%eax
  407adc:	83 c0 01             	add    $0x1,%eax
  407adf:	89 45 cc             	mov    %eax,-0x34(%rbp)
  407ae2:	e9 be ff ff ff       	jmpq   407aa5 &amp;lt;_Z15Evaluate_KernelP8CreaturePdjjN2cl4sycl7nd_itemILi3EEE+0x45&amp;gt;
  407ae7:	f2 0f 10 45 d0       	movsd  -0x30(%rbp),%xmm0
  407aec:	f2 0f 58 45 e0       	addsd  -0x20(%rbp),%xmm0
  407af1:	f2 0f 11 45 e0       	movsd  %xmm0,-0x20(%rbp)
  407af6:	8b 45 dc             	mov    -0x24(%rbp),%eax
  407af9:	83 c0 01             	add    $0x1,%eax
  407afc:	89 45 dc             	mov    %eax,-0x24(%rbp)
  407aff:	e9 81 ff ff ff       	jmpq   407a85 &amp;lt;_Z15Evaluate_KernelP8CreaturePdjjN2cl4sycl7nd_itemILi3EEE+0x25&amp;gt;
  407b04:	f2 0f 10 45 e0       	movsd  -0x20(%rbp),%xmm0
  407b09:	48 bf 75 95 42 00 00 	movabs $0x429575,%rdi
  407b10:	00 00 00 
  407b13:	b0 01                	mov    $0x1,%al
  407b15:	e8 56 c5 ff ff       	callq  404070 &amp;lt;printf@plt&amp;gt;
  407b1a:	48 83 c4 40          	add    $0x40,%rsp
  407b1e:	5d                   	pop    %rbp
  407b1f:	c3                   	retq   &lt;/LI-CODE&gt;
&lt;P&gt;I am quite confused as I cannot understand what the optimized instructions do. Would anyone please give me some hints of how to understand the optimized code?&lt;/P&gt;
&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 22:01:19 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-DPC-C-Compiler/How-oneAPI-vectorize-the-given-code/m-p/1365947#M1933</guid>
      <dc:creator>Roin</dc:creator>
      <dc:date>2022-03-04T22:01:19Z</dc:date>
    </item>
  </channel>
</rss>

