public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/44413]  New: inefficient code for std::string::compare on x86-64
@ 2010-06-04 12:15 dgohman at gmail dot com
  2010-06-04 16:52 ` [Bug libstdc++/44413] " redi at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: dgohman at gmail dot com @ 2010-06-04 12:15 UTC (permalink / raw)
  To: gcc-bugs

This code:

#include <string>
int foo(const std::string &a, const std::string &b) { return a.compare(b); }

compiles to code like this on x86-64:
[...]
        subq    %rdx, %r8
        movl    $2147483647, %eax
        cmpq    $2147483647, %r8
        jg      .L2
        movl    $-2147483648, %eax
        cmpq    $-2147483648, %r8
        cmovge  %r8d, %eax
.L2:
[...]

Since compare need only return a value greater, less, or equal to zero, the
code in _S_compare would be more efficient as simple code that just returns -1,
0, or 1 on most targets where difference_type is wider than int.


-- 
           Summary: inefficient code for std::string::compare on x86-64
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dgohman at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44413


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-06-10  0:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-04 12:15 [Bug libstdc++/44413] New: inefficient code for std::string::compare on x86-64 dgohman at gmail dot com
2010-06-04 16:52 ` [Bug libstdc++/44413] " redi at gcc dot gnu dot org
2010-06-07 14:52 ` paolo dot carlini at oracle dot com
2010-06-08 14:54 ` dgohman at gmail dot com
2010-06-08 15:09 ` paolo dot carlini at oracle dot com
2010-06-08 16:00 ` paolo dot carlini at oracle dot com
2010-06-09  9:16 ` paolo at gcc dot gnu dot org
2010-06-09 14:03 ` paolo at gcc dot gnu dot org
2010-06-09 15:14 ` paolo dot carlini at oracle dot com
2010-06-10  0:27 ` paolo dot carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).