Received: from eggs.gnu.org ([2001:4830:134:3::10]:33846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcf2L-00021l-Pu for qemu-devel@nongnu.org; Wed, 24 Aug 2016 16:44:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcf2K-0004TO-Qo for qemu-devel@nongnu.org; Wed, 24 Aug 2016 16:44:37 -0400 Received: from mail-yw0-x244.google.com ([2607:f8b0:4002:c05::244]:36492) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcf2K-0004TI-MO for qemu-devel@nongnu.org; Wed, 24 Aug 2016 16:44:36 -0400 Received: by mail-yw0-x244.google.com with SMTP id u134so1410868ywg.3 for ; Wed, 24 Aug 2016 13:44:36 -0700 (PDT) From: Pranith Kumar Date: Wed, 24 Aug 2016 16:44:22 -0400 Message-Id: <20160824204424.14041-2-bobby.prani@gmail.com> In-Reply-To: <20160824204424.14041-1-bobby.prani@gmail.com> References: <20160824204424.14041-1-bobby.prani@gmail.com> Subject: [Qemu-devel] [PATCH 2/3] atomics: Use __atomic_*_n() variant primitives List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, Paolo Bonzini , "Emilio G. Cota" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Peter Maydell , Richard Henderson 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. Signed-off-by: Pranith Kumar --- include/qemu/atomic.h | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index d313e6b..fc2309f 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -103,8 +103,7 @@ #define atomic_set(ptr, i) do { \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val = (i); \ - __atomic_store(ptr, &_val, __ATOMIC_RELAXED); \ + __atomic_store_n(ptr, i, __ATOMIC_RELAXED); \ } while(0) /* See above: most compilers currently treat consume and acquire the @@ -129,8 +128,7 @@ #define atomic_rcu_set(ptr, i) do { \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val = (i); \ - __atomic_store(ptr, &_val, __ATOMIC_RELEASE); \ + __atomic_store_n(ptr, i, __ATOMIC_RELEASE); \ } while(0) /* atomic_mb_read/set semantics map Java volatile variables. They are @@ -153,9 +151,8 @@ #define atomic_mb_set(ptr, i) do { \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val = (i); \ smp_wmb(); \ - __atomic_store(ptr, &_val, __ATOMIC_RELAXED); \ + __atomic_store_n(ptr, i, __ATOMIC_RELAXED); \ smp_mb(); \ } while(0) #else @@ -169,8 +166,7 @@ #define atomic_mb_set(ptr, i) do { \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof(*ptr) _val = (i); \ - __atomic_store(ptr, &_val, __ATOMIC_SEQ_CST); \ + __atomic_store_n(ptr, i, __ATOMIC_SEQ_CST); \ } while(0) #endif @@ -179,9 +175,7 @@ #define atomic_xchg(ptr, i) ({ \ QEMU_BUILD_BUG_ON(sizeof(*ptr) > sizeof(void *)); \ - typeof_strip_qual(*ptr) _new = (i), _old; \ - __atomic_exchange(ptr, &_new, &_old, __ATOMIC_SEQ_CST); \ - _old; \ + __atomic_exchange_n(ptr, i, __ATOMIC_SEQ_CST); \ }) /* Returns the eventual value, failed or not */ -- 2.9.3