incubator-stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Martin Sebor (JIRA)" <j...@apache.org>
Subject [jira] Updated: (STDCXX-335) std::min() suboptimal
Date Wed, 29 Aug 2007 21:52:30 GMT

     [ https://issues.apache.org/jira/browse/STDCXX-335?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Martin Sebor updated STDCXX-335:
--------------------------------

    Fix Version/s: 4.3

Not sure we'll be able to do anything about this w/o the blessing of the committee since changing
the signature of the function would be easily detectable even for fundamental types. See the
test case below. Scheduled for 4.3.

#include <cassert>
#include <algorithm>

int main ()
{
    int x = 0;
    int y = 2;
    const int &z = std::min (x, y);

    x = 1;

    assert (&z == &x);
    assert (z == 1);
}


> std::min() suboptimal
> ---------------------
>
>                 Key: STDCXX-335
>                 URL: https://issues.apache.org/jira/browse/STDCXX-335
>             Project: C++ Standard Library
>          Issue Type: Bug
>          Components: 25. Algorithms
>    Affects Versions: 4.1.3
>         Environment: gcc 3.2.3, x86 Linux
>            Reporter: Mark Brown
>             Fix For: 4.3
>
>
> I don't know if it's the compiler that's generating worse code for the stdcxx version
of min or if the function is not implemented as efficiently as it could be but the disassembly
for the two functions below shows that my_min() is one instruction shorter than test_min():
> #include <algorithm>
> int test_min (int x, int y) { return std::min (x, y); }
> int my_min (int x, int y) { return x < y ? x : y; }
> _Z8test_minii:
>         pushl   %ebp
>         movl    %esp, %ebp
>         movl    12(%ebp), %eax
>         cmpl    %eax, 8(%ebp)
>         jg      .L2
>         leal    8(%ebp), %eax   <<< extra load?
> .L4:
>         movl    (%eax), %eax
>         leave
>         ret
> _Z6my_minii:
>         pushl   %ebp
>         movl    %esp, %ebp
>         movl    12(%ebp), %eax
>         cmpl    8(%ebp), %eax
>         jle     .L6
>         movl    8(%ebp), %eax
> .L6:
>         leave
>         ret

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message