public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org>,
	Martin Sebor <msebor@gmail.com>,
	 Richard Biener <richard.guenther@gmail.com>,
	Jonathan Wakely <jwakely@redhat.com>,
	 Richard Sandiford <richard.sandiford@arm.com>
Subject: Re: [PATCH] define auto_vec copy ctor and assignment (PR 90904)
Date: Wed, 30 Jun 2021 14:01:46 +0200	[thread overview]
Message-ID: <CAFiYyc0NJLYvmjFCj2EMFnetwV+RcCyBtvjXsXDFV2Pfwy6hgw@mail.gmail.com> (raw)
In-Reply-To: <mptbl7n3exl.fsf@arm.com>

On Wed, Jun 30, 2021 at 11:00 AM Richard Sandiford
<richard.sandiford@arm.com> wrote:
>
> Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org> writes:
> > Note there's also array_slice<> which could be used to pass non-const
> > vec<>s that are never resized but modified - the only "valid" case of
> > passing a non-const vec<> by value.
>
> Yeah.  We'd need a new constructor for that (the current one only
> takes const vec<>&) but I agree it would be a good thing to do.
>
> I realise you weren't saying otherwise, but: array_slice<> can also be
> used for const vec<>s.  E.g. array_slice<const int> can't be resized
> or modified.
>
> I think array_slice<> is going to be more efficient as well.  E.g.:
>
> void
> f1 (vec<char> &foo)
> {
>   for (unsigned int i = 0; i < foo.length (); ++i)
>     foo[i] += 1;
> }
>
> void
> f2 (array_slice<char> foo)
> {
>   for (unsigned int i = 0; i < foo.size (); ++i)
>     foo[i] += 1;
> }
>
> gives:
>
> 000000000000d150 <f1(vec<char, va_heap, vl_ptr>&)>:
>     d150:       48 8b 07                mov    (%rdi),%rax
>     d153:       31 d2                   xor    %edx,%edx
>     d155:       48 85 c0                test   %rax,%rax
>     d158:       74 26                   je     d180 <f1(vec<char, va_heap, vl_ptr>&)+0x30>
>     d15a:       66 0f 1f 44 00 00       nopw   0x0(%rax,%rax,1)
>     d160:       3b 50 04                cmp    0x4(%rax),%edx
>     d163:       73 12                   jae    d177 <f1(vec<char, va_heap, vl_ptr>&)+0x27>
>     d165:       89 d1                   mov    %edx,%ecx
>     d167:       83 c2 01                add    $0x1,%edx
>     d16a:       80 44 08 08 01          addb   $0x1,0x8(%rax,%rcx,1)
>     d16f:       48 8b 07                mov    (%rdi),%rax
>     d172:       48 85 c0                test   %rax,%rax
>     d175:       75 e9                   jne    d160 <f1(vec<char, va_heap, vl_ptr>&)+0x10>
>     d177:       c3                      retq
>     d178:       0f 1f 84 00 00 00 00    nopl   0x0(%rax,%rax,1)
>     d17f:       00
>     d180:       c3                      retq
>
> 000000000000d190 <f2(array_slice<char>)>:
>     d190:       85 f6                   test   %esi,%esi
>     d192:       74 18                   je     d1ac <f2(array_slice<char>)+0x1c>
>     d194:       8d 46 ff                lea    -0x1(%rsi),%eax
>     d197:       48 8d 44 07 01          lea    0x1(%rdi,%rax,1),%rax
>     d19c:       0f 1f 40 00             nopl   0x0(%rax)
>     d1a0:       80 07 01                addb   $0x1,(%rdi)
>     d1a3:       48 83 c7 01             add    $0x1,%rdi
>     d1a7:       48 39 c7                cmp    %rax,%rdi
>     d1aa:       75 f4                   jne    d1a0 <f2(array_slice<char>)+0x10>
>     d1ac:       c3                      retq
>
> where f1 has to reload the length and base each iteration,
> but f2 doesn't.

Of course but that's unfair - by refrence vec<> vs. by value array_slice<>
plus char * pointer stores which destroy all TBAA ... ;)

>
> > But as noted array_slice<> lacks most of the vec<> API so I'm not sure
> > how awkward that option would be.  We of course can amend its API as
> > well.
>
> Yeah, that'd be good.  The current class follows the principle
> “don't add stuff that isn't needed yet”. :-)

Yes, and that's good of course.

Richard.

> Thanks,
> Richard

  reply	other threads:[~2021-06-30 12:01 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-26 23:30 Martin Sebor
2021-04-27  7:58 ` Richard Biener
2021-04-27 13:58   ` Martin Sebor
2021-04-27 14:04     ` Richard Biener
2021-04-27 15:52       ` Martin Sebor
2021-05-03 21:50         ` [PING][PATCH] " Martin Sebor
2021-05-11 20:02           ` [PING 2][PATCH] " Martin Sebor
2021-05-27 19:33             ` [PING 3][PATCH] " Martin Sebor
2021-05-27 20:53         ` [PATCH] " Jason Merrill
2021-06-01 19:56           ` Martin Sebor
2021-06-01 21:38             ` Jason Merrill
2021-06-25 20:51               ` Martin Sebor
2021-06-25 22:11                 ` Jason Merrill
2021-06-25 22:36                   ` Martin Sebor
2021-06-28  8:07                     ` Richard Biener
2021-06-28 18:07                       ` Martin Sebor
2021-06-29 10:58                         ` Richard Biener
2021-06-29 11:34                           ` Martin Jambor
2021-06-30  1:46                           ` Martin Sebor
2021-06-30  8:48                             ` Richard Biener
2021-06-30  9:29                               ` Martin Jambor
2021-07-06 15:06                             ` [PING][PATCH] " Martin Sebor
2021-07-07  7:28                               ` Richard Biener
2021-07-07 14:37                                 ` Martin Sebor
2021-07-12 11:02                                   ` Richard Biener
2021-07-13 14:08                                     ` Jonathan Wakely
2021-07-13 18:37                                       ` Jason Merrill
2021-07-13 20:02                                         ` Martin Sebor
2021-07-14  3:39                                           ` Jason Merrill
2021-07-14 10:47                                             ` Jonathan Wakely
2021-07-14 14:46                                             ` Martin Sebor
2021-07-14 16:23                                               ` Jason Merrill
2021-07-20 18:34                                                 ` Martin Sebor
2021-07-20 20:08                                                   ` Jason Merrill
2021-07-20 21:52                                                     ` Martin Sebor
2021-07-27 18:56                                                   ` Martin Sebor
2021-07-30 15:06                                                     ` Jason Merrill
2021-08-06  2:07                                                       ` Martin Sebor
2021-08-06  7:52                                                         ` Christophe Lyon
2021-08-06 12:17                                                           ` Christophe Lyon
2021-07-14 14:44                                     ` Martin Sebor
2021-06-29 14:43                         ` [PATCH] " Jason Merrill
2021-06-29 17:18                           ` Martin Sebor
2021-06-30  8:40                             ` Richard Biener
2021-06-30  9:00                               ` Richard Sandiford
2021-06-30 12:01                                 ` Richard Biener [this message]
2021-06-28  8:05                 ` Richard Biener
2021-06-29 12:30                 ` Trevor Saunders
2021-06-02  6:55             ` Richard Biener
2021-06-02 16:04               ` Martin Sebor
2021-06-03  8:29                 ` Trevor Saunders
2021-06-07  8:51                   ` Richard Biener
2021-06-07 10:33                     ` Trevor Saunders
2021-06-07 13:33                       ` Richard Biener
2021-06-07 20:34                     ` Martin Sebor
2021-06-08  3:26                       ` Trevor Saunders
2021-06-08  7:19                         ` Richard Biener
2021-06-07 22:17                   ` Martin Sebor
2021-06-08  2:41                     ` Trevor Saunders

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=CAFiYyc0NJLYvmjFCj2EMFnetwV+RcCyBtvjXsXDFV2Pfwy6hgw@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jwakely@redhat.com \
    --cc=msebor@gmail.com \
    --cc=richard.sandiford@arm.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).