<?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 assembly cmp not working as it should after a while in Software Tuning, Performance Optimization &amp; Platform Monitoring</title>
    <link>https://community.intel.com/t5/Software-Tuning-Performance/assembly-cmp-not-working-as-it-should-after-a-while/m-p/1378101#M8043</link>
    <description>&lt;P&gt;I have this assembly code that takes two sorted arrays and merges them to one merged array without repetition:&lt;/P&gt;
&lt;PRE&gt;.global main

.section .text
main:
       lea (array1), %rax
       lea (array2), %rbx
       lea (mergedArray), %rcx
       
loop_hw1_ex3: cmp $0,(%rax) 
              je exit
              cmp $0,(%rbx) 
              je exit
              movl (%rax), %edx
              movl (%rbx), %esi
              
              leaq 4(%rbx), %rdi
              movl (%rdi), %edi
              cmp %esi,%edi # checking if there is repetition in first array 
              jne no_rep_Label_hw1
              leaq 4(%rbx), %rbx
              jmp loop_hw1_ex3
no_rep_Label_hw1:     
              leaq 4(%rax), %rdi
              movl (%rdi), %edi
              cmp %edx,%edi # checking if there is repetition in second array 
              jne no_rep_Label2_hw1
              leaq 4(%rax), %rax
              jmp loop_hw1_ex3
no_rep_Label2_hw1:    
              
              
              cmpl %edx, %esi ## main compare to sort it fails after a while
              jle  less_equal_Label_hw1
              movl %esi, (%rcx)
              leaq  4(%rcx) ,%rcx 
              leaq 4(%rbx), %rbx
              
              jg  bigger_Label_hw1
less_equal_Label_hw1:
              je rax_eq_rbx_label_hw1
              movl %edx, (%rcx)
              leaq  4(%rcx) ,%rcx 
rax_eq_rbx_label_hw1:  # there both arrays have same val so I move one forward
              leaq 4(%rax), %rax
bigger_Label_hw1:
              jmp loop_hw1_ex3
        exit:
  #this the part when one of them has ended and we only need to continue with the other one
loop2_hw1_ex3: cmp $0,(%rbx) 
               je no_loop2 
               movl (%rbx), %esi
               leaq 4(%rbx), %rdi
               movl (%rdi), %edi
               cmp %esi,%edi
               je rep_label_hw1
               movl  %esi, (%rcx)
               leaq 4(%rcx),%rcx
rep_label_hw1: leaq 4(%rbx),%rbx
               jmp loop2_hw1_ex3 
      no_loop2:
loop3_hw1_ex3: cmp $0,(%rax) 
               je no_loop3
               movl (%rax), %edx
               leaq 4(%rax), %rdi
               movl (%rdi), %edi
               cmp %edx,%edi
               je rep_label_hw1
               movl  %edx, (%rcx)
               leaq 4(%rcx),%rcx
rep_label2_hw1:leaq 4(%rax),%rax
               jmp loop3_hw1_ex3 
      no_loop3:
&lt;/PRE&gt;
&lt;P&gt;I added the whole code so that maybe you would want to run it on your machine as well.&lt;A href="https://deepmaterialpt.com/" target="_self"&gt;&amp;nbsp;&lt;/A&gt;and this is the test I'm doing:&lt;/P&gt;
&lt;PRE&gt;#test
mov $mergedArray, %rax

    
    cmpl $3938153337, 0(%rax)
    jne bad_exit

    cmpl $3921428393, 4(%rax)
    jne bad_exit

    cmpl $3860874895, 8(%rax)
    jne bad_exit

    cmpl $3793010036, 12(%rax)
    jne bad_exit

    cmpl $3728920121, 16(%rax)
    jne bad_exit

    cmpl $3652968237, 20(%rax)
    jne bad_exit

    cmpl $2810665667, 24(%rax)
    jne bad_exit

    cmpl $2734063791, 28(%rax)
    jne bad_exit

    cmpl $2534193645, 32(%rax)
    jne bad_exit

    cmpl $2311096085, 36(%rax)
    jne bad_exit#########3
syscall
bad_exit:
    movq $60, %rax
    movq $1, %rdi
    syscall
.section .data
array1: .int 3938153337, 3860874895, 3793010036, 2810665667, 2734063791, 2311096085, 2083910944, 2062799482, 2029885871, 1979220646, 1968205798, 1855504373, 1824017782, 1629103669, 1437682032, 1364807752, 1269411879, 1167414194, 838087726, 676572428, 595215934, 309552879, 114306948, 6088819, 5996561, 0
array2: .int 3938153337, 3938153337, 3921428393, 3728920121, 3652968237, 2534193645, 2046175771, 1968205798, 1925687059, 1292648006, 165804778, 0
mergedArray: .zero 34
&lt;/PRE&gt;
&lt;P&gt;so the code fail when coming to the value 2311096085 , for some reason it keeps considering every other value in the second array bigger and therefore it gets sorted the wrong way, PS: the sorting is from big to small I have debugged it on SASM but I couldn't figure what happened wrong since the values before that were sorted correctly.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Apr 2022 11:41:03 GMT</pubDate>
    <dc:creator>Richard_Son</dc:creator>
    <dc:date>2022-04-19T11:41:03Z</dc:date>
    <item>
      <title>assembly cmp not working as it should after a while</title>
      <link>https://community.intel.com/t5/Software-Tuning-Performance/assembly-cmp-not-working-as-it-should-after-a-while/m-p/1378101#M8043</link>
      <description>&lt;P&gt;I have this assembly code that takes two sorted arrays and merges them to one merged array without repetition:&lt;/P&gt;
&lt;PRE&gt;.global main

.section .text
main:
       lea (array1), %rax
       lea (array2), %rbx
       lea (mergedArray), %rcx
       
loop_hw1_ex3: cmp $0,(%rax) 
              je exit
              cmp $0,(%rbx) 
              je exit
              movl (%rax), %edx
              movl (%rbx), %esi
              
              leaq 4(%rbx), %rdi
              movl (%rdi), %edi
              cmp %esi,%edi # checking if there is repetition in first array 
              jne no_rep_Label_hw1
              leaq 4(%rbx), %rbx
              jmp loop_hw1_ex3
no_rep_Label_hw1:     
              leaq 4(%rax), %rdi
              movl (%rdi), %edi
              cmp %edx,%edi # checking if there is repetition in second array 
              jne no_rep_Label2_hw1
              leaq 4(%rax), %rax
              jmp loop_hw1_ex3
no_rep_Label2_hw1:    
              
              
              cmpl %edx, %esi ## main compare to sort it fails after a while
              jle  less_equal_Label_hw1
              movl %esi, (%rcx)
              leaq  4(%rcx) ,%rcx 
              leaq 4(%rbx), %rbx
              
              jg  bigger_Label_hw1
less_equal_Label_hw1:
              je rax_eq_rbx_label_hw1
              movl %edx, (%rcx)
              leaq  4(%rcx) ,%rcx 
rax_eq_rbx_label_hw1:  # there both arrays have same val so I move one forward
              leaq 4(%rax), %rax
bigger_Label_hw1:
              jmp loop_hw1_ex3
        exit:
  #this the part when one of them has ended and we only need to continue with the other one
loop2_hw1_ex3: cmp $0,(%rbx) 
               je no_loop2 
               movl (%rbx), %esi
               leaq 4(%rbx), %rdi
               movl (%rdi), %edi
               cmp %esi,%edi
               je rep_label_hw1
               movl  %esi, (%rcx)
               leaq 4(%rcx),%rcx
rep_label_hw1: leaq 4(%rbx),%rbx
               jmp loop2_hw1_ex3 
      no_loop2:
loop3_hw1_ex3: cmp $0,(%rax) 
               je no_loop3
               movl (%rax), %edx
               leaq 4(%rax), %rdi
               movl (%rdi), %edi
               cmp %edx,%edi
               je rep_label_hw1
               movl  %edx, (%rcx)
               leaq 4(%rcx),%rcx
rep_label2_hw1:leaq 4(%rax),%rax
               jmp loop3_hw1_ex3 
      no_loop3:
&lt;/PRE&gt;
&lt;P&gt;I added the whole code so that maybe you would want to run it on your machine as well.&lt;A href="https://deepmaterialpt.com/" target="_self"&gt;&amp;nbsp;&lt;/A&gt;and this is the test I'm doing:&lt;/P&gt;
&lt;PRE&gt;#test
mov $mergedArray, %rax

    
    cmpl $3938153337, 0(%rax)
    jne bad_exit

    cmpl $3921428393, 4(%rax)
    jne bad_exit

    cmpl $3860874895, 8(%rax)
    jne bad_exit

    cmpl $3793010036, 12(%rax)
    jne bad_exit

    cmpl $3728920121, 16(%rax)
    jne bad_exit

    cmpl $3652968237, 20(%rax)
    jne bad_exit

    cmpl $2810665667, 24(%rax)
    jne bad_exit

    cmpl $2734063791, 28(%rax)
    jne bad_exit

    cmpl $2534193645, 32(%rax)
    jne bad_exit

    cmpl $2311096085, 36(%rax)
    jne bad_exit#########3
syscall
bad_exit:
    movq $60, %rax
    movq $1, %rdi
    syscall
.section .data
array1: .int 3938153337, 3860874895, 3793010036, 2810665667, 2734063791, 2311096085, 2083910944, 2062799482, 2029885871, 1979220646, 1968205798, 1855504373, 1824017782, 1629103669, 1437682032, 1364807752, 1269411879, 1167414194, 838087726, 676572428, 595215934, 309552879, 114306948, 6088819, 5996561, 0
array2: .int 3938153337, 3938153337, 3921428393, 3728920121, 3652968237, 2534193645, 2046175771, 1968205798, 1925687059, 1292648006, 165804778, 0
mergedArray: .zero 34
&lt;/PRE&gt;
&lt;P&gt;so the code fail when coming to the value 2311096085 , for some reason it keeps considering every other value in the second array bigger and therefore it gets sorted the wrong way, PS: the sorting is from big to small I have debugged it on SASM but I couldn't figure what happened wrong since the values before that were sorted correctly.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Apr 2022 11:41:03 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Tuning-Performance/assembly-cmp-not-working-as-it-should-after-a-while/m-p/1378101#M8043</guid>
      <dc:creator>Richard_Son</dc:creator>
      <dc:date>2022-04-19T11:41:03Z</dc:date>
    </item>
  </channel>
</rss>

