Boost logo

Boost :

Subject: Re: [boost] [iterators] Proof-of-concept for a sentinel iteratoradapter
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-05-13 12:50:06


AMDG

Kevin Sopp wrote:
> Interesting, I wrote a modified version where you can enter the string
> length and the sentinel version is consistently slower (using
> gcc-4.4.0 with -O3).
>
>
> {
> boost::timer t;
> for( unsigned i = 0; i < N; ++i )
> {
> m1 += test_strlen( text );
> }
>
> std::cout << "strlen: " << t.elapsed() << " " << m1 << std::endl;
> }
>

I'm not absolutely sure about this, but from the assembler it
looks like the call to strlen is being pulled out of the loop.

    movl 24(%esp), %eax
    movb $0, (%eax,%edx)
    call _clock
    movl %eax, 20(%esp)
    xorl %eax, %eax
    orl $-1, %ecx
    movl 24(%esp), %edi
    repne scasb // This looks like strlen
    notl %ecx
    movl 24(%esp), %eax
    leal -1(%eax,%ecx), %esi
    xorl %edi, %edi
    movl $0, 28(%esp)
    .p2align 2,,3
L11: // and the loop is here
    cmpl %esi, 24(%esp)
    je L32
    movl 24(%esp), %edx
    xorl %eax, %eax
    .p2align 2,,3
L10:
    movsbl (%edx),%ebx
    movl %eax, %ecx
    sall $6, %ecx
    leal -1640531527(%ebx,%ecx), %ebx
    movl %eax, %ecx
    shrl $2, %ecx
    leal (%ebx,%ecx), %ecx
    xorl %ecx, %eax
    incl %edx
    cmpl %esi, %edx
    jne L10
    addl %eax, 28(%esp)
    incl %edi
    cmpl $1000000, %edi
    jne L11

In Christ,
Steven Watanabe


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