You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by "Mark Brown (JIRA)" <ji...@apache.org> on 2007/07/22 22:27:06 UTC
[jira] Created: (STDCXX-491) string::push_back() slow
string::push_back() slow
------------------------
Key: STDCXX-491
URL: https://issues.apache.org/jira/browse/STDCXX-491
Project: C++ Standard Library
Issue Type: Bug
Components: 21. Strings
Affects Versions: 4.1.3
Environment: gcc 4.1.2, Linux/x86_64
Reporter: Mark Brown
According to my timings string::push_back() in stdcxx 4.1.3 is more than twice as slow than the same function in gcc 4.1.2 on Linux x86_64:
$ time ./push_back-stdcxx 100000000
real 0m2.175s
user 0m2.004s
sys 0m0.172s
$ time ./push_back-gcc 100000000
real 0m0.924s
user 0m0.760s
sys 0m0.164s
#include <cassert>
#include <cstdlib>
#include <string>
int main (int argc, char *argv[])
{
const int N = argc < 2 ? 1 : std::atoi (argv [1]);
std::string str;
for (int i = 0; i < N; ++i)
str.push_back ('x');
assert (str.size () == std::size_t (N));
}
Comparing the generated assembly, the gcc push_back() is mostly inline but the stdcxx push_back() is not:
stdcxx:
_Z8pushbackRSsc:
.LFB449:
movq (%rdi), %rax
movl %esi, %edx
movl $1, %ecx
movsbl %dl,%r8d
xorl %edx, %edx
movq -8(%rax), %rsi
jmp _ZNSs7replaceEmmmc
gcc:
_Z8pushbackRSsc:
.LFB904:
movq %rbp, -16(%rsp)
.LCFI0:
movq %r12, -8(%rsp)
.LCFI1:
movq %rdi, %rbp
movq %rbx, -24(%rsp)
.LCFI2:
subq $24, %rsp
.LCFI3:
movq (%rdi), %rax
movl %esi, %r12d
subq $24, %rax
movq (%rax), %rbx
addq $1, %rbx
cmpq 8(%rax), %rbx
ja .L2
movl 16(%rax), %eax
testl %eax, %eax
jg .L2
.L4:
movq (%rbp), %rdx
movq -24(%rdx), %rax
movb %r12b, (%rdx,%rax)
movq (%rbp), %rax
subq $24, %rax
movl $0, 16(%rax)
movq %rbx, (%rax)
movb $0, 24(%rax,%rbx)
movq (%rsp), %rbx
movq 8(%rsp), %rbp
movq 16(%rsp), %r12
addq $24, %rsp
ret
.p2align 4,,7
.L2:
movq %rbx, %rsi
movq %rbp, %rdi
call _ZNSs7reserveEm
jmp .L4
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-491) string::push_back() slow
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-491?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12517641 ]
Martin Sebor commented on STDCXX-491:
-------------------------------------
See the following thread for the patch and a discussion:
http://www.mail-archive.com/stdcxx-dev@incubator.apache.org/msg03993.html
> string::push_back() slow
> ------------------------
>
> Key: STDCXX-491
> URL: https://issues.apache.org/jira/browse/STDCXX-491
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 21. Strings
> Affects Versions: 4.1.3
> Environment: gcc 4.1.2, Linux/x86_64
> Reporter: Mark Brown
> Assignee: Martin Sebor
>
> According to my timings string::push_back() in stdcxx 4.1.3 is more than twice as slow than the same function in gcc 4.1.2 on Linux x86_64:
> $ time ./push_back-stdcxx 100000000
> real 0m2.175s
> user 0m2.004s
> sys 0m0.172s
> $ time ./push_back-gcc 100000000
> real 0m0.924s
> user 0m0.760s
> sys 0m0.164s
> #include <cassert>
> #include <cstdlib>
> #include <string>
> int main (int argc, char *argv[])
> {
> const int N = argc < 2 ? 1 : std::atoi (argv [1]);
> std::string str;
> for (int i = 0; i < N; ++i)
> str.push_back ('x');
> assert (str.size () == std::size_t (N));
> }
> Comparing the generated assembly, the gcc push_back() is mostly inline but the stdcxx push_back() is not:
> stdcxx:
> _Z8pushbackRSsc:
> .LFB449:
> movq (%rdi), %rax
> movl %esi, %edx
> movl $1, %ecx
> movsbl %dl,%r8d
> xorl %edx, %edx
> movq -8(%rax), %rsi
> jmp _ZNSs7replaceEmmmc
> gcc:
> _Z8pushbackRSsc:
> .LFB904:
> movq %rbp, -16(%rsp)
> .LCFI0:
> movq %r12, -8(%rsp)
> .LCFI1:
> movq %rdi, %rbp
> movq %rbx, -24(%rsp)
> .LCFI2:
> subq $24, %rsp
> .LCFI3:
> movq (%rdi), %rax
> movl %esi, %r12d
> subq $24, %rax
> movq (%rax), %rbx
> addq $1, %rbx
> cmpq 8(%rax), %rbx
> ja .L2
> movl 16(%rax), %eax
> testl %eax, %eax
> jg .L2
> .L4:
> movq (%rbp), %rdx
> movq -24(%rdx), %rax
> movb %r12b, (%rdx,%rax)
> movq (%rbp), %rax
> subq $24, %rax
> movl $0, 16(%rax)
> movq %rbx, (%rax)
> movb $0, 24(%rax,%rbx)
> movq (%rsp), %rbx
> movq 8(%rsp), %rbp
> movq 16(%rsp), %r12
> addq $24, %rsp
> ret
> .p2align 4,,7
> .L2:
> movq %rbx, %rsi
> movq %rbp, %rdi
> call _ZNSs7reserveEm
> jmp .L4
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Closed: (STDCXX-491) string::push_back() slow
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-491?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Sebor closed STDCXX-491.
-------------------------------
Resolution: Fixed
Fix Version/s: 4.2
Here are the new timings obtained with Intel C++ 9.1 on Xeon E5345. We're almost twice as fast than the native C++ Standard Library (libstdc++).
$ grep "model name" /proc/cpuinfo | head -n 1 && icc --version
model name : Intel(R) Xeon(R) CPU E5345 @ 2.33GHz
icc (ICC) 9.1 20070320
Copyright (C) 1985-2007 Intel Corporation. All rights reserved.
$ cat t.cpp && make t && icc -D_REENTRANT -O2 t.cpp -pthread && time ./t 0xffffffff && time ./a.out 0xffffffff
#include <cassert>
#include <cstdlib>
#include <string>
int main (int argc, char *argv[])
{
const unsigned long N = argc < 2 ? 1 : std::strtoul (argv [1], 0, 0);
const unsigned long N0 = 1000000 < N ? N / 1000000 : 1;
const unsigned long N1 = N % 1000000;
for (unsigned long j = 0; j < N0; ++j) {
std::string str;
for (unsigned long i = 0; i < N1; ++i) {
str.push_back ('x');
}
assert (str.size () == std::size_t (N1));
}
}
icc -c -I/amd/devco/sebor/stdcxx/include/ansi -D_REENTRANT -I/amd/devco/sebor/stdcxx/include -I/build/sebor/stdcxx-icc-9.1.049-12D/include -I/amd/devco/sebor/stdcxx/examples/include -cxxlib-nostd -O2 -w1 t.cpp
icc t.o -o t -cxxlib-nostd -lpthread -L/build/sebor/stdcxx-icc-9.1.049-12D/lib -Wl,-R/build/sebor/stdcxx-icc-9.1.049-12D/lib -lstd12D -lcxaguard -lsupc++ -lm
real 0m35.937s
user 0m30.230s
sys 0m5.696s
real 0m57.159s
user 0m53.995s
sys 0m3.145s
> string::push_back() slow
> ------------------------
>
> Key: STDCXX-491
> URL: https://issues.apache.org/jira/browse/STDCXX-491
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 21. Strings
> Affects Versions: 4.1.3
> Environment: gcc 4.1.2, Linux/x86_64
> Reporter: Mark Brown
> Assignee: Martin Sebor
> Fix For: 4.2
>
>
> According to my timings string::push_back() in stdcxx 4.1.3 is more than twice as slow than the same function in gcc 4.1.2 on Linux x86_64:
> $ time ./push_back-stdcxx 100000000
> real 0m2.175s
> user 0m2.004s
> sys 0m0.172s
> $ time ./push_back-gcc 100000000
> real 0m0.924s
> user 0m0.760s
> sys 0m0.164s
> #include <cassert>
> #include <cstdlib>
> #include <string>
> int main (int argc, char *argv[])
> {
> const int N = argc < 2 ? 1 : std::atoi (argv [1]);
> std::string str;
> for (int i = 0; i < N; ++i)
> str.push_back ('x');
> assert (str.size () == std::size_t (N));
> }
> Comparing the generated assembly, the gcc push_back() is mostly inline but the stdcxx push_back() is not:
> stdcxx:
> _Z8pushbackRSsc:
> .LFB449:
> movq (%rdi), %rax
> movl %esi, %edx
> movl $1, %ecx
> movsbl %dl,%r8d
> xorl %edx, %edx
> movq -8(%rax), %rsi
> jmp _ZNSs7replaceEmmmc
> gcc:
> _Z8pushbackRSsc:
> .LFB904:
> movq %rbp, -16(%rsp)
> .LCFI0:
> movq %r12, -8(%rsp)
> .LCFI1:
> movq %rdi, %rbp
> movq %rbx, -24(%rsp)
> .LCFI2:
> subq $24, %rsp
> .LCFI3:
> movq (%rdi), %rax
> movl %esi, %r12d
> subq $24, %rax
> movq (%rax), %rbx
> addq $1, %rbx
> cmpq 8(%rax), %rbx
> ja .L2
> movl 16(%rax), %eax
> testl %eax, %eax
> jg .L2
> .L4:
> movq (%rbp), %rdx
> movq -24(%rdx), %rax
> movb %r12b, (%rdx,%rax)
> movq (%rbp), %rax
> subq $24, %rax
> movl $0, 16(%rax)
> movq %rbx, (%rax)
> movb $0, 24(%rax,%rbx)
> movq (%rsp), %rbx
> movq 8(%rsp), %rbp
> movq 16(%rsp), %r12
> addq $24, %rsp
> ret
> .p2align 4,,7
> .L2:
> movq %rbx, %rsi
> movq %rbp, %rdi
> call _ZNSs7reserveEm
> jmp .L4
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (STDCXX-491) string::push_back() slow
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-491?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Sebor updated STDCXX-491:
--------------------------------
Attachment: push_back.png
Attached graph showing benchmark results of the latest stdcxx against 4.1.3, libstdc++/gcc 4.1.2, libstdc++/Intel C++ 10.0, and STLport 5.1.3/gcc 4.1.2.
> string::push_back() slow
> ------------------------
>
> Key: STDCXX-491
> URL: https://issues.apache.org/jira/browse/STDCXX-491
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 21. Strings
> Affects Versions: 4.1.3
> Environment: gcc 4.1.2, Linux/x86_64
> Reporter: Mark Brown
> Assignee: Martin Sebor
> Fix For: 4.2
>
> Attachments: push_back.png
>
>
> According to my timings string::push_back() in stdcxx 4.1.3 is more than twice as slow than the same function in gcc 4.1.2 on Linux x86_64:
> $ time ./push_back-stdcxx 100000000
> real 0m2.175s
> user 0m2.004s
> sys 0m0.172s
> $ time ./push_back-gcc 100000000
> real 0m0.924s
> user 0m0.760s
> sys 0m0.164s
> #include <cassert>
> #include <cstdlib>
> #include <string>
> int main (int argc, char *argv[])
> {
> const int N = argc < 2 ? 1 : std::atoi (argv [1]);
> std::string str;
> for (int i = 0; i < N; ++i)
> str.push_back ('x');
> assert (str.size () == std::size_t (N));
> }
> Comparing the generated assembly, the gcc push_back() is mostly inline but the stdcxx push_back() is not:
> stdcxx:
> _Z8pushbackRSsc:
> .LFB449:
> movq (%rdi), %rax
> movl %esi, %edx
> movl $1, %ecx
> movsbl %dl,%r8d
> xorl %edx, %edx
> movq -8(%rax), %rsi
> jmp _ZNSs7replaceEmmmc
> gcc:
> _Z8pushbackRSsc:
> .LFB904:
> movq %rbp, -16(%rsp)
> .LCFI0:
> movq %r12, -8(%rsp)
> .LCFI1:
> movq %rdi, %rbp
> movq %rbx, -24(%rsp)
> .LCFI2:
> subq $24, %rsp
> .LCFI3:
> movq (%rdi), %rax
> movl %esi, %r12d
> subq $24, %rax
> movq (%rax), %rbx
> addq $1, %rbx
> cmpq 8(%rax), %rbx
> ja .L2
> movl 16(%rax), %eax
> testl %eax, %eax
> jg .L2
> .L4:
> movq (%rbp), %rdx
> movq -24(%rdx), %rax
> movb %r12b, (%rdx,%rax)
> movq (%rbp), %rax
> subq $24, %rax
> movl $0, 16(%rax)
> movq %rbx, (%rax)
> movb $0, 24(%rax,%rbx)
> movq (%rsp), %rbx
> movq 8(%rsp), %rbp
> movq 16(%rsp), %r12
> addq $24, %rsp
> ret
> .p2align 4,,7
> .L2:
> movq %rbx, %rsi
> movq %rbp, %rdi
> call _ZNSs7reserveEm
> jmp .L4
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Closed: (STDCXX-491) string::push_back() slow
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-491?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Sebor closed STDCXX-491.
-------------------------------
Resolution: Fixed
> string::push_back() slow
> ------------------------
>
> Key: STDCXX-491
> URL: https://issues.apache.org/jira/browse/STDCXX-491
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 21. Strings
> Affects Versions: 4.1.3
> Environment: gcc 4.1.2, Linux/x86_64
> Reporter: Mark Brown
> Assignee: Martin Sebor
> Fix For: 4.2
>
> Attachments: push_back.png
>
>
> According to my timings string::push_back() in stdcxx 4.1.3 is more than twice as slow than the same function in gcc 4.1.2 on Linux x86_64:
> $ time ./push_back-stdcxx 100000000
> real 0m2.175s
> user 0m2.004s
> sys 0m0.172s
> $ time ./push_back-gcc 100000000
> real 0m0.924s
> user 0m0.760s
> sys 0m0.164s
> #include <cassert>
> #include <cstdlib>
> #include <string>
> int main (int argc, char *argv[])
> {
> const int N = argc < 2 ? 1 : std::atoi (argv [1]);
> std::string str;
> for (int i = 0; i < N; ++i)
> str.push_back ('x');
> assert (str.size () == std::size_t (N));
> }
> Comparing the generated assembly, the gcc push_back() is mostly inline but the stdcxx push_back() is not:
> stdcxx:
> _Z8pushbackRSsc:
> .LFB449:
> movq (%rdi), %rax
> movl %esi, %edx
> movl $1, %ecx
> movsbl %dl,%r8d
> xorl %edx, %edx
> movq -8(%rax), %rsi
> jmp _ZNSs7replaceEmmmc
> gcc:
> _Z8pushbackRSsc:
> .LFB904:
> movq %rbp, -16(%rsp)
> .LCFI0:
> movq %r12, -8(%rsp)
> .LCFI1:
> movq %rdi, %rbp
> movq %rbx, -24(%rsp)
> .LCFI2:
> subq $24, %rsp
> .LCFI3:
> movq (%rdi), %rax
> movl %esi, %r12d
> subq $24, %rax
> movq (%rax), %rbx
> addq $1, %rbx
> cmpq 8(%rax), %rbx
> ja .L2
> movl 16(%rax), %eax
> testl %eax, %eax
> jg .L2
> .L4:
> movq (%rbp), %rdx
> movq -24(%rdx), %rax
> movb %r12b, (%rdx,%rax)
> movq (%rbp), %rax
> subq $24, %rax
> movl $0, 16(%rax)
> movq %rbx, (%rax)
> movb $0, 24(%rax,%rbx)
> movq (%rsp), %rbx
> movq 8(%rsp), %rbp
> movq 16(%rsp), %r12
> addq $24, %rsp
> ret
> .p2align 4,,7
> .L2:
> movq %rbx, %rsi
> movq %rbp, %rdi
> call _ZNSs7reserveEm
> jmp .L4
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Reopened: (STDCXX-491) string::push_back() slow
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-491?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Sebor reopened STDCXX-491:
---------------------------------
Reopened to attach file.
> string::push_back() slow
> ------------------------
>
> Key: STDCXX-491
> URL: https://issues.apache.org/jira/browse/STDCXX-491
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 21. Strings
> Affects Versions: 4.1.3
> Environment: gcc 4.1.2, Linux/x86_64
> Reporter: Mark Brown
> Assignee: Martin Sebor
> Fix For: 4.2
>
>
> According to my timings string::push_back() in stdcxx 4.1.3 is more than twice as slow than the same function in gcc 4.1.2 on Linux x86_64:
> $ time ./push_back-stdcxx 100000000
> real 0m2.175s
> user 0m2.004s
> sys 0m0.172s
> $ time ./push_back-gcc 100000000
> real 0m0.924s
> user 0m0.760s
> sys 0m0.164s
> #include <cassert>
> #include <cstdlib>
> #include <string>
> int main (int argc, char *argv[])
> {
> const int N = argc < 2 ? 1 : std::atoi (argv [1]);
> std::string str;
> for (int i = 0; i < N; ++i)
> str.push_back ('x');
> assert (str.size () == std::size_t (N));
> }
> Comparing the generated assembly, the gcc push_back() is mostly inline but the stdcxx push_back() is not:
> stdcxx:
> _Z8pushbackRSsc:
> .LFB449:
> movq (%rdi), %rax
> movl %esi, %edx
> movl $1, %ecx
> movsbl %dl,%r8d
> xorl %edx, %edx
> movq -8(%rax), %rsi
> jmp _ZNSs7replaceEmmmc
> gcc:
> _Z8pushbackRSsc:
> .LFB904:
> movq %rbp, -16(%rsp)
> .LCFI0:
> movq %r12, -8(%rsp)
> .LCFI1:
> movq %rdi, %rbp
> movq %rbx, -24(%rsp)
> .LCFI2:
> subq $24, %rsp
> .LCFI3:
> movq (%rdi), %rax
> movl %esi, %r12d
> subq $24, %rax
> movq (%rax), %rbx
> addq $1, %rbx
> cmpq 8(%rax), %rbx
> ja .L2
> movl 16(%rax), %eax
> testl %eax, %eax
> jg .L2
> .L4:
> movq (%rbp), %rdx
> movq -24(%rdx), %rax
> movb %r12b, (%rdx,%rax)
> movq (%rbp), %rax
> subq $24, %rax
> movl $0, 16(%rax)
> movq %rbx, (%rax)
> movb $0, 24(%rax,%rbx)
> movq (%rsp), %rbx
> movq 8(%rsp), %rbp
> movq 16(%rsp), %r12
> addq $24, %rsp
> ret
> .p2align 4,,7
> .L2:
> movq %rbx, %rsi
> movq %rbp, %rdi
> call _ZNSs7reserveEm
> jmp .L4
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (STDCXX-491) string::push_back() slow
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-491?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12517675 ]
Martin Sebor commented on STDCXX-491:
-------------------------------------
Here are the timings for gcc on the same machine for comparison. Interesting that the gcc-generated code is faster than Intel's own (although we're still more than 30% faster)...
$ gcc --version && g++ -m64 -O2 -D_REENTRANT -pthread t.cpp && time ./a.out 0xffffffff
gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-3)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
real 0m48.376s
user 0m45.259s
sys 0m3.104s
> string::push_back() slow
> ------------------------
>
> Key: STDCXX-491
> URL: https://issues.apache.org/jira/browse/STDCXX-491
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 21. Strings
> Affects Versions: 4.1.3
> Environment: gcc 4.1.2, Linux/x86_64
> Reporter: Mark Brown
> Assignee: Martin Sebor
> Fix For: 4.2
>
>
> According to my timings string::push_back() in stdcxx 4.1.3 is more than twice as slow than the same function in gcc 4.1.2 on Linux x86_64:
> $ time ./push_back-stdcxx 100000000
> real 0m2.175s
> user 0m2.004s
> sys 0m0.172s
> $ time ./push_back-gcc 100000000
> real 0m0.924s
> user 0m0.760s
> sys 0m0.164s
> #include <cassert>
> #include <cstdlib>
> #include <string>
> int main (int argc, char *argv[])
> {
> const int N = argc < 2 ? 1 : std::atoi (argv [1]);
> std::string str;
> for (int i = 0; i < N; ++i)
> str.push_back ('x');
> assert (str.size () == std::size_t (N));
> }
> Comparing the generated assembly, the gcc push_back() is mostly inline but the stdcxx push_back() is not:
> stdcxx:
> _Z8pushbackRSsc:
> .LFB449:
> movq (%rdi), %rax
> movl %esi, %edx
> movl $1, %ecx
> movsbl %dl,%r8d
> xorl %edx, %edx
> movq -8(%rax), %rsi
> jmp _ZNSs7replaceEmmmc
> gcc:
> _Z8pushbackRSsc:
> .LFB904:
> movq %rbp, -16(%rsp)
> .LCFI0:
> movq %r12, -8(%rsp)
> .LCFI1:
> movq %rdi, %rbp
> movq %rbx, -24(%rsp)
> .LCFI2:
> subq $24, %rsp
> .LCFI3:
> movq (%rdi), %rax
> movl %esi, %r12d
> subq $24, %rax
> movq (%rax), %rbx
> addq $1, %rbx
> cmpq 8(%rax), %rbx
> ja .L2
> movl 16(%rax), %eax
> testl %eax, %eax
> jg .L2
> .L4:
> movq (%rbp), %rdx
> movq -24(%rdx), %rax
> movb %r12b, (%rdx,%rax)
> movq (%rbp), %rax
> subq $24, %rax
> movl $0, 16(%rax)
> movq %rbx, (%rax)
> movb $0, 24(%rax,%rbx)
> movq (%rsp), %rbx
> movq 8(%rsp), %rbp
> movq 16(%rsp), %r12
> addq $24, %rsp
> ret
> .p2align 4,,7
> .L2:
> movq %rbx, %rsi
> movq %rbp, %rdi
> call _ZNSs7reserveEm
> jmp .L4
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Assigned: (STDCXX-491) string::push_back() slow
Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/STDCXX-491?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Martin Sebor reassigned STDCXX-491:
-----------------------------------
Assignee: Martin Sebor
> string::push_back() slow
> ------------------------
>
> Key: STDCXX-491
> URL: https://issues.apache.org/jira/browse/STDCXX-491
> Project: C++ Standard Library
> Issue Type: Bug
> Components: 21. Strings
> Affects Versions: 4.1.3
> Environment: gcc 4.1.2, Linux/x86_64
> Reporter: Mark Brown
> Assignee: Martin Sebor
>
> According to my timings string::push_back() in stdcxx 4.1.3 is more than twice as slow than the same function in gcc 4.1.2 on Linux x86_64:
> $ time ./push_back-stdcxx 100000000
> real 0m2.175s
> user 0m2.004s
> sys 0m0.172s
> $ time ./push_back-gcc 100000000
> real 0m0.924s
> user 0m0.760s
> sys 0m0.164s
> #include <cassert>
> #include <cstdlib>
> #include <string>
> int main (int argc, char *argv[])
> {
> const int N = argc < 2 ? 1 : std::atoi (argv [1]);
> std::string str;
> for (int i = 0; i < N; ++i)
> str.push_back ('x');
> assert (str.size () == std::size_t (N));
> }
> Comparing the generated assembly, the gcc push_back() is mostly inline but the stdcxx push_back() is not:
> stdcxx:
> _Z8pushbackRSsc:
> .LFB449:
> movq (%rdi), %rax
> movl %esi, %edx
> movl $1, %ecx
> movsbl %dl,%r8d
> xorl %edx, %edx
> movq -8(%rax), %rsi
> jmp _ZNSs7replaceEmmmc
> gcc:
> _Z8pushbackRSsc:
> .LFB904:
> movq %rbp, -16(%rsp)
> .LCFI0:
> movq %r12, -8(%rsp)
> .LCFI1:
> movq %rdi, %rbp
> movq %rbx, -24(%rsp)
> .LCFI2:
> subq $24, %rsp
> .LCFI3:
> movq (%rdi), %rax
> movl %esi, %r12d
> subq $24, %rax
> movq (%rax), %rbx
> addq $1, %rbx
> cmpq 8(%rax), %rbx
> ja .L2
> movl 16(%rax), %eax
> testl %eax, %eax
> jg .L2
> .L4:
> movq (%rbp), %rdx
> movq -24(%rdx), %rax
> movb %r12b, (%rdx,%rax)
> movq (%rbp), %rax
> subq $24, %rax
> movl $0, 16(%rax)
> movq %rbx, (%rax)
> movb $0, 24(%rax,%rbx)
> movq (%rsp), %rbx
> movq 8(%rsp), %rbp
> movq 16(%rsp), %r12
> addq $24, %rsp
> ret
> .p2align 4,,7
> .L2:
> movq %rbx, %rsi
> movq %rbp, %rdi
> call _ZNSs7reserveEm
> jmp .L4
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.