public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org
Cc: Ville Voutilainen <ville.voutilainen@gmail.com>,
	gcc-patches List <gcc-patches@gcc.gnu.org>
Subject: Re: RFC: Allow moved-from strings to be non-empty
Date: Fri, 26 Oct 2018 04:42:00 -0000	[thread overview]
Message-ID: <20181025232746.GW23172@redhat.com> (raw)
In-Reply-To: <20181025231758.GV23172@redhat.com>

On 26/10/18 00:17 +0100, Jonathan Wakely wrote:
>On 26/10/18 00:42 +0200, Marc Glisse wrote:
>>On Fri, 26 Oct 2018, Ville Voutilainen wrote:
>>
>>>I would rather not introduce a behavioral difference between us and
>>>libc++.
>>
>>Why not? There are already several, and it helps find bugs. Maybe 
>>you could convince libc++ to change as well if you want to keep the 
>>behavior the same?
>
>For the libc++ string zeroing the length of a small string happens to
>be faster. See Howard's answer at the stackoverflow link I gave. He
>says:
>
>'So in summary, the setting of the source to an empty string is necessary in "long mode" to transfer ownership of the pointer, and also necessary in short mode for performance reasons to avoid a broken pipeline.'
>
>That's not the case for our SSO string, which wasn't designed from the
>ground up to make this move constructor optimal. We can choose whether
>to leave moved-from strings empty or not.
>
>I'm not persuaded that preserving portable behaviour between
>implementations is useful here. This is unspecified behaviour. I agree
>with Marc that introducing a difference helps find bugs, and teaches
>people not to rely on unspecified properties.
>
>I haven't been able to measure any performance difference, and in many
>cases the writes to the rvalue will be dead stores if the object is
>about to be destroyed anyway. But the code does look slightly better
>(caveat: I don't know what I'm talking about).
>
>Before:
>
>       leaq    16(%rdi), %rdx
>       movq    %rdi, %rax
>       movq    %rdx, (%rdi)
>       movq    (%rsi), %rcx
>       leaq    16(%rsi), %rdx
>       cmpq    %rdx, %rcx
>       je      .L5
>       movq    %rcx, (%rdi)
>       movq    16(%rsi), %rcx
>       movq    %rcx, 16(%rdi)
>.L3:
>       movq    8(%rsi), %rcx
>       movq    %rdx, (%rsi)
>       movq    $0, 8(%rsi)
>       movq    %rcx, 8(%rax)
>       movb    $0, 16(%rsi)
>       ret
>.L5:
>       movdqu  16(%rsi), %xmm0
>       movups  %xmm0, 16(%rdi)
>       jmp     .L3
>
>
>After:
>
>       leaq    16(%rdi), %rdx
>       movq    %rdi, %rax
>       movq    %rdx, (%rdi)
>       movq    8(%rsi), %rdx
>       movq    (%rsi), %rcx
>       movq    %rdx, 8(%rdi)
>       leaq    16(%rsi), %rdx
>       cmpq    %rdx, %rcx
>       je      .L5
>       movq    %rcx, (%rdi)
>       movq    16(%rsi), %rcx
>       movq    %rdx, (%rsi)
>       movq    %rcx, 16(%rdi)
>       movq    $0, 8(%rsi)
>       movb    $0, 16(%rsi)
>       ret
>.L5:
>       movdqu  16(%rsi), %xmm0
>       movups  %xmm0, 16(%rdi)
>       ret
>
>
>>>It does slightly concern me that some users might
>>>actually semantically expect a moved-from string to be empty, even
>>>though that's not guaranteed, although for non-SSO cases
>>>it *is* guaranteed.
>>
>>Is it? In debug mode, I'd be tempted to leave the string as "moved" 
>>(size 5, short string so there is no allocation).
>
>That's not a bad idea.

Although we can't do it for std::wstring and std::u32string, as their
small string buffer is *very* small.

  reply	other threads:[~2018-10-25 23:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-25 22:29 Jonathan Wakely
2018-10-25 22:34 ` Ville Voutilainen
2018-10-26  2:46   ` Marc Glisse
2018-10-26  4:41     ` Jonathan Wakely
2018-10-26  4:42       ` Jonathan Wakely [this message]
2018-10-26  7:14         ` Marc Glisse
2018-10-26 10:58           ` Jonathan Wakely
2018-10-26 10:29     ` Ville Voutilainen
2018-10-26 10:43       ` Jonathan Wakely
2018-10-26 11:02         ` Ville Voutilainen
2018-10-26 12:02           ` Marc Glisse
2018-10-27  5:19             ` Joe Buck
2018-10-27  5:20               ` Ville Voutilainen
2018-10-26  2:43 ` Marc Glisse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181025232746.GW23172@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=ville.voutilainen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).