From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40089) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beOeC-0005T6-GS for qemu-devel@nongnu.org; Mon, 29 Aug 2016 11:38:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beOe8-0003X1-78 for qemu-devel@nongnu.org; Mon, 29 Aug 2016 11:38:51 -0400 Received: from mail-yw0-x22a.google.com ([2607:f8b0:4002:c05::22a]:33749) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beOe8-0003WX-1o for qemu-devel@nongnu.org; Mon, 29 Aug 2016 11:38:48 -0400 Received: by mail-yw0-x22a.google.com with SMTP id r9so88159696ywg.0 for ; Mon, 29 Aug 2016 08:38:47 -0700 (PDT) References: <20160824204424.14041-1-bobby.prani@gmail.com> <20160824204424.14041-2-bobby.prani@gmail.com> From: Pranith Kumar In-reply-to: Date: Mon, 29 Aug 2016 11:38:45 -0400 Message-ID: <87twe37fga.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 2/3] atomics: Use __atomic_*_n() variant primitives List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, "Emilio G. Cota" , Alex =?utf-8?Q?Benn=C3=A9e?= , Peter Maydell , Richard Henderson Paolo Bonzini writes: > On 24/08/2016 22:44, Pranith Kumar wrote: >> Use the __atomic_*_n() primitives which take the value as argument. It >> is not necessary to store the value locally before calling the >> primitive, hence saving us a stack store and load. > > If you do this, you might as well do it for __atomic_load and > __atomic_compare_exchange. However, you'd still need typeof_strip_qual > for __atomic_compare_exchange's "_old" local variable. OK, I will update the patch doing the same for load and compare exchange. > > The question is, does this actually cause a change in generated code? I > would be very surprised if it did, but then it's perfectly possible to > have a bug in GCC. It looks like it does. I tested atomic_load() with previous and the atomic_load_n() version and it generates the following code: current: mov 0x200c4a(%rip),%eax # 601030 mov %eax,-0x4(%rsp) mov -0x4(%rsp),%eax atomic_load_n(): mov 0x200c4a(%rip),%eax # 601030 So looks like it's worth it. Thanks, -- Pranith