Boost logo

Boost :

From: Michael Marcin (mmarcin_at_[hidden])
Date: 2007-06-20 12:00:42


Thorsten Ottosen wrote:
> Michael Marcin skrev:
>> Hi,
>>
>> I have a problem with my compiler (ARM's RVCT 2.2.1).
>> It is not generating optimal code for ptr_containers, specifically
>> I've been looking at ptr_vector.
>> I love using ptr_containers to convery ownership but I rely on them
>> being zero overhead over std::vector with explicit delete loops for
>> at least simple operations like a for each loop.
>>
>> I would hope these 2 files (attached) would generate identical
>> assembly for the foo function but they are not even close (attached
>> as txt).
>>
>> I know there are a lot of compilers that are a lot smarter than this
>> one. Unfortunately I'm stuck with this one so I need to teach this
>> compiler to generate better code (by modifying the ptr_container
>> library) or stop using ptr_containers (cry).
>
> Hi Michael,
>
> Some compilers have a problem doing near-perfect inlining,
> which can be a real killer.
>
> I'll try to investigate this.
>

I appreciate it.
If you have things you'd like me to try out I can compile them and send you
the mixed assembly output.

One thing I noticed is that it seems to fail to eliminate the return value
copy of the void_ptr_iterator::base call. Accessing iter_ directly
(unfortunately) produces much better code but still not the best.

                  _Z3foov PROC ; foo()
;;;14 void foo()
;;;15 {
000000 490d LDR r1,|L1.56|
000002 b50c PUSH {r2,r3,lr}
000004 6848 LDR r0,[r1,#4]
000006 9001 STR r0,[sp,#4] ;181
000008 6808 LDR r0,[r1,#0]
00000a e005 B |L1.24|
                  |L1.12|
00000c 6800 LDR r0,[r0,#0]
00000e 6801 LDR r1,[r0,#0]
000010 1c49 ADDS r1,r1,#1
000012 6001 STR r1,[r0,#0]
000014 9800 LDR r0,[sp,#0]
000016 1d00 ADDS r0,r0,#4
                  |L1.24|
000018 9901 LDR r1,[sp,#4]
00001a 9000 STR r0,[sp,#0]
00001c 4288 CMP r0,r1
00001e d1f5 BNE |L1.12|
000020 bd0c POP {r2,r3,pc} ;186
;;;16 boost::ptr_vector<b>::iterator iend = x.end();
;;;17 for( boost::ptr_vector<b>::iterator it = x.begin(); it != iend;
++it )
;;;18 {
;;;19 b& b_ = *it;
;;;20 b_.bar();
;;;21 }
;;;22 }
                          ENDP

Thanks,

Michael Marcin


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk