This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [Patch] Nathan's improvements to basic_string
On Fri, Jun 13, 2003 at 02:59:34PM -0700, Nathan Myers wrote:
>
> I did some testing on a 1.4 GHz Opteron, which generally seems
> comparable to a 2.4GHz P4.
>
> -O0 -02 -O3
> no patch 3.8 2.9 2.9
> with patch 2.3 0.7 0.6
>
> (Note that times varied as much as 20% on an unloaded system.)
(Apparently our version of the kernel and our CPU stepping, together,
have time-measurement anomalies that account for the fluctuations.)
> The gains aren't as dramatic as on p4. The compiler seems much
> better at teasing performance out of the p4, or maybe the p4 needs
> a lot more hand-holding to give reasonable performance, and does
> much worse with unoptimized code than the opteron.
Actually, it appears now that the difference is because the lock/add
overhead on p4 is worse than on k8, but I don't know anything about
Paolo's chipset vs. the k8's hypertransport bus.
I diffed the assembly output, attached below. The difference at -O3
is entirely attributable to eliminating the lock/add on string creation,
and branching past the lock/decrement/test below. (I added the first
lock/add back in, just to see, and that took up half the difference.)
A lock/add seems to cost 11.6 ns, or 14 cycles, on this hardware when
there is no contention. I need to try this with both processors hitting
the refcount and see what happens. (Ick, threads.)
Nathan Myers
ncm-nospam@cantrip.org
--- str-nopatchO3.s Tue Jun 17 12:11:01 2003
+++ str-patchO3.s Tue Jun 17 12:03:03 2003
@@ -31,14 +31,11 @@
.L23:
.L27:
.L30:
.L34:
.L37:
-#APP
- lock; addl $1,_ZNSs20_S_empty_rep_storageE+16(%rip)
-#NO_APP
- movq $_ZNSs20_S_empty_rep_storageE+24, (%rdx)
+ movq $_ZNSs4_Rep20_S_empty_rep_storageE+24, (%rdx)
decq %rax
addq $8, %rdx
.L5:
.L40:
.L49:
@@ -62,13 +59,15 @@
cmpq %rbp, %r13
je .L102
.L161:
.L106:
subq $8, %rbp
- movl %ebx, %ecx
movq (%rbp), %rdx
leaq -24(%rdx), %rdi
+ cmpq $_ZNSs4_Rep20_S_empty_rep_storageE, %rdi
+ je .L156
+ movl %ebx, %ecx
#APP
lock; xaddl %ecx,-8(%rdx)
#NO_APP
testl %ecx, %ecx
jg .L156