Boost logo

Boost :

From: Michael Marcin (mmarcin_at_[hidden])
Date: 2007-12-05 13:53:51

I'm trying to make local modifications to bind to improve the code
generated the compiler I have to use.

I have written this small test file:

#include <boost/bind.hpp>

class tester
    struct value_type
       float x, y, z;
    typedef const value_type& const_reference;

    value_type test( const value_type& a );

tester::value_type test_bind( tester& t, tester::const_reference x )
    return boost::bind( &tester::test, &t, _1 )( x );

struct handspun
    handspun( tester& t ) : m_t(t) {}
    tester::value_type operator()( tester::const_reference x )
       return m_t.test(x);
    tester& m_t;

tester::value_type test_handspun( tester& t, tester::const_reference x )
    return handspun(t)(x);

tester::value_type test_unrolled( tester& t, tester::const_reference x )
    return t.test( x );

Checking the generated assembly this code generates essentially the same
code for test_bind and test_unrolled under VC8.

Under the compiler I have to use (RVCT 2.2 sp1) however, it generates
the following code.

_Z9test_bindR6testerRKNS_10value_typeE PROC
         PUSH {lr}
         LDR r3,|L1.152|
         LDR r12,|L1.156|
         MOV lr,r2
         LDM r3,{r2,r3} ; <Anon1>, <Anon1>
         SUB sp,sp,#0x2c
         LDRB r12,[r12,#0]
         STR r2,[sp,#0xc]
         STR r1,[sp,#8]
         ADD r2,sp,#0xc
         STR r12,[sp,#0x1c]
         STR r3,[sp,#0x10]
         STR r1,[sp,#0x14]
         LDM r2,{r2,r3,r12}
         ADD r1,sp,#0x20
         STM r1,{r2,r3,r12}
         MOV r1,#0
         LDR r3,[sp,#0x24]
         STR r1,[sp,#0x18]
         STR lr,[sp,#0x14]
         LDR r1,[sp,#0x28]
         TST r3,#1
         LDRNE r12,[sp,#0x20]
         ADD r1,r1,r3,ASR #1
         LDRNE r3,[r1,#0]
         BICNE r12,r12,#3
         LDRNE r3,[r3,r12]
         LDREQ r3,[sp,#0x20]
         MOV r2,lr
         BLX r3
         ADD sp,sp,#0x2c
         POP {pc}

_Z13test_handspunR6testerRKNS_10value_typeE PROC
         PUSH {r3,lr}
         STR r1,[sp,#0]
         BL _ZN6tester4testERKNS_10value_typeE
         POP {r12,pc}

_Z13test_unrolledR6testerRKNS_10value_typeE PROC
         B _ZN6tester4testERKNS_10value_typeE

         AREA ||.constdata||, DATA, READONLY, ALIGN=2

         DCD _ZN6tester4testERKNS_10value_typeE
         DCD 0x00000000

I want to use bind in some performance sensitive areas because I don't
want to have to get all the details of writing my functors or algorithms
right since Boost and STL have already done that for me. Unless I can
coerce my compiler into generating better code I'll have no choice but
to abandon bind for this project.

It isn't very easy for me to follow the bind sources. Does anyone have
any hints on where I might start looking?


Michael Marcin

Boost list run by bdawes at, gregod at, cpdaniel at, john at