simple pointer loop regression?

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

 



I compiled this simple test function with both g++ 4.5.1 and g++-4.6
(2010-10-16 snapshot):

   void test (int *b, int *e, int stride)
   {
     for (int *p = b; p != e; p += stride)
       *p = 1;
   }

Using compiler options "-O2 -march=core2 -S".

I got the following asm output;

g++ 4.5.1:

   .globl test(int*, int*, int)
   test(int*, int*, int):
           cmpq    %rsi, %rdi
           je      .L1
           movslq  %edx, %rax
           salq    $2, %rax
   .L3:
           movl    $1, (%rdi)
           addq    %rax, %rdi
           cmpq    %rdi, %rsi
           jne     .L3
   .L1:
           rep
           ret


g++-4.6 (2010-10-16 snapshot):

   test(int*, int*, int):
           cmpq    %rsi, %rdi
           je      .L1
           movslq  %edx, %rdx
           salq    $2, %rdx
           movq    %rdx, %rcx
           addq    %rdx, %rdi
           negq    %rcx
           jmp     .L3
   .L4:
           movq    %rax, %rdi
   .L3:
           movl    $1, (%rdi,%rcx)
           leaq    (%rdi,%rdx), %rax
           cmpq    %rdi, %rsi
           jne     .L4
   .L1:
           rep
           ret


The latter seems to be not as nice, at least at first glance, doing
more data shuffling, and using more, and more complex, instructions in
the inner loop.

Is this likely to be a bug, or is there some more subtle explanation?

Thanks,

-Miles


-- 
Politeness, n. The most acceptable hypocrisy.


[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