How to fore compiler to keep structure of a loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





compiling the following code:

for ( i = 0; i < cnt; )
   {
    x1 = 2.0 * x - 1.;
    if ( x1 <  1.0 )
     {
     b[i] = exp( x1 ) * cos( x1 );
      i = i + 3;
      x = x*2.;
     }
    else  // if ( x1 >= 1. )
     {
     a[i] = sqrt( x1 ) * log( 1 / x1 );
      i = i + 2;
      x = x/2.;
     }
   }

with “gcc -O2 -S” generates

    jmp    .L6
.L19:
    movapd    %xmm3, %xmm0
    movsd    %xmm3, 24(%rsp)
    addl    $3, %ebx
    call    __exp_finite
    movsd    24(%rsp), %xmm3
    movsd    %xmm0, 16(%rsp)
    movapd    %xmm3, %xmm0
    call    cos
    mulsd    16(%rsp), %xmm0
    cmpl    %ebx, %r12d
    movsd    8(%rsp), %xmm2
    movapd    %xmm2, %xmm1
    movsd    %xmm0, (%r14,%rbp,8)
    jbe    .L18
.L6:
    movapd    %xmm1, %xmm2
    movsd    .LC1(%rip), %xmm4
    movl    %ebx, %ebp
    addsd    %xmm1, %xmm2
    comisd    %xmm2, %xmm4
    movapd    %xmm2, %xmm3
    movsd    %xmm2, 8(%rsp)
    subsd    .LC0(%rip), %xmm3
    ja    .L19
    movsd    .LC0(%rip), %xmm0
    sqrtsd    %xmm3, %xmm6
    movsd    %xmm1, 16(%rsp)
    addl    $2, %ebx
    divsd    %xmm3, %xmm0
    movsd    %xmm6, 8(%rsp)
    call    __log_finite
    mulsd    8(%rsp), %xmm0
    cmpl    %ebx, %r12d
    movsd    16(%rsp), %xmm1
    mulsd    .LC2(%rip), %xmm1
    movsd    %xmm0, 0(%r13,%rbp,8)
    ja    .L6
.L18:

How to force the compiler to generate assembly loop that is “similar” to the C code specified:
one entry, one exit.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux