From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 81A1D383800B for ; Wed, 30 Jun 2021 09:00:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 81A1D383800B Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CE8036D; Wed, 30 Jun 2021 02:00:24 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B87473F718; Wed, 30 Jun 2021 02:00:23 -0700 (PDT) From: Richard Sandiford To: Richard Biener via Gcc-patches Mail-Followup-To: Richard Biener via Gcc-patches , Martin Sebor , Richard Biener , Jonathan Wakely , richard.sandiford@arm.com Cc: Martin Sebor , Richard Biener , Jonathan Wakely Subject: Re: [PATCH] define auto_vec copy ctor and assignment (PR 90904) References: <91545a73-12af-33b2-c6e7-119b5a21de60@gmail.com> <4d503394-4e82-1d36-41ca-34315042775b@redhat.com> <49569f1d-9856-55c7-b9e9-578bbd7c7b7a@gmail.com> <118e90d5-fb85-43ad-d0bc-66ac4d35225d@redhat.com> Date: Wed, 30 Jun 2021 10:00:22 +0100 In-Reply-To: (Richard Biener via Gcc-patches's message of "Wed, 30 Jun 2021 10:40:02 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Jun 2021 09:00:30 -0000 Richard Biener via Gcc-patches 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 can't be resized or modified. I think array_slice<> is going to be more efficient as well. E.g.: void f1 (vec &foo) { for (unsigned int i =3D 0; i < foo.length (); ++i) foo[i] +=3D 1; } void f2 (array_slice foo) { for (unsigned int i =3D 0; i < foo.size (); ++i) foo[i] +=3D 1; } gives: 000000000000d150 &)>: 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 &)+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 &)+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 &)+0x10> d177: c3 retq d178: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1) d17f: 00 d180: c3 retq 000000000000d190 )>: d190: 85 f6 test %esi,%esi d192: 74 18 je d1ac )+= 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 )+= 0x10> d1ac: c3 retq where f1 has to reload the length and base each iteration, but f2 doesn't. > 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 =E2=80=9Cdon't add stuff that isn't needed yet=E2=80=9D. :-) Thanks, Richard