From patchwork Fri Sep 9 13:11:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Leon Alrae X-Patchwork-Id: 9323417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4942160231 for ; Fri, 9 Sep 2016 13:15:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3721329E9B for ; Fri, 9 Sep 2016 13:15:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2964329E9E; Fri, 9 Sep 2016 13:15:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A224129E9B for ; Fri, 9 Sep 2016 13:15:43 +0000 (UTC) Received: from localhost ([::1]:57939 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biLeg-0002zz-T7 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 09 Sep 2016 09:15:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33142) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biLbA-000085-3b for qemu-devel@nongnu.org; Fri, 09 Sep 2016 09:12:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1biLb5-0007xY-QH for qemu-devel@nongnu.org; Fri, 09 Sep 2016 09:12:02 -0400 Received: from mailapp01.imgtec.com ([195.59.15.196]:47086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biLb5-0007xD-Hf for qemu-devel@nongnu.org; Fri, 09 Sep 2016 09:11:59 -0400 Received: from hhmail02.hh.imgtec.org (unknown [10.100.10.20]) by Forcepoint Email with ESMTPS id 6A3F2CC339A47; Fri, 9 Sep 2016 14:11:44 +0100 (IST) Received: from hhmipssw201.hh.imgtec.org (10.100.21.117) by hhmail02.hh.imgtec.org (10.100.10.20) with Microsoft SMTP Server (TLS) id 14.3.294.0; Fri, 9 Sep 2016 14:11:47 +0100 Date: Fri, 9 Sep 2016 14:11:46 +0100 From: Leon Alrae To: Richard Henderson Message-ID: <20160909131145.GB24307@hhmipssw201.hh.imgtec.org> References: <1472935202-3342-1-git-send-email-rth@twiddle.net> <1472935202-3342-14-git-send-email-rth@twiddle.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1472935202-3342-14-git-send-email-rth@twiddle.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [10.100.21.117] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.59.15.196 Subject: Re: [Qemu-devel] [PATCH v3 13/34] tcg: Add atomic helpers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "qemu-devel@nongnu.org" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP > +#define GEN_ATOMIC_HELPER(NAME, OP, NEW) \ > +static void * const table_##NAME[16] = { \ > + [MO_8] = gen_helper_atomic_##NAME##b, \ > + [MO_16 | MO_LE] = gen_helper_atomic_##NAME##w_le, \ > + [MO_16 | MO_BE] = gen_helper_atomic_##NAME##w_be, \ > + [MO_32 | MO_LE] = gen_helper_atomic_##NAME##l_le, \ > + [MO_32 | MO_BE] = gen_helper_atomic_##NAME##l_be, \ > + [MO_64 | MO_LE] = gen_helper_atomic_##NAME##q_le, \ > + [MO_64 | MO_BE] = gen_helper_atomic_##NAME##q_be, \ > +}; \ > +void tcg_gen_atomic_##NAME##_i32 \ > + (TCGv_i32 ret, TCGv addr, TCGv_i32 val, TCGArg idx, TCGMemOp memop) \ > +{ \ > + if (parallel_cpus) { \ > + do_atomic_op_i32(ret, addr, val, idx, memop, table_##NAME); \ > + } else { \ > + do_nonatomic_op_i32(ret, addr, val, idx, memop, NEW, \ > + tcg_gen_##OP##_i32); \ > + } \ > +} \ > +void tcg_gen_atomic_##NAME##_i64 \ > + (TCGv_i64 ret, TCGv addr, TCGv_i64 val, TCGArg idx, TCGMemOp memop) \ > +{ \ > + if (parallel_cpus) { \ > + do_atomic_op_i64(ret, addr, val, idx, memop, table_##NAME); \ > + } else { \ > + do_nonatomic_op_i64(ret, addr, val, idx, memop, NEW, \ > + tcg_gen_##OP##_i64); \ > + } \ > +} > + > +GEN_ATOMIC_HELPER(fetch_add, add, 0) > +GEN_ATOMIC_HELPER(fetch_and, and, 0) > +GEN_ATOMIC_HELPER(fetch_or, or, 0) > +GEN_ATOMIC_HELPER(fetch_xor, xor, 0) > + > +GEN_ATOMIC_HELPER(add_fetch, add, 1) > +GEN_ATOMIC_HELPER(and_fetch, and, 1) > +GEN_ATOMIC_HELPER(or_fetch, or, 1) > +GEN_ATOMIC_HELPER(xor_fetch, xor, 1) This causes build errors on CentOS6.5 (where __ATOMIC_RELAXED is undefined): /user/lea/dev/qemu/tcg/tcg-op.c:2280: error: ‘gen_helper_atomic_fetch_addb’ undeclared here (not in a function) /user/lea/dev/qemu/tcg/tcg-op.c:2280: error: ‘gen_helper_atomic_fetch_addw_le’ undeclared here (not in a function) /user/lea/dev/qemu/tcg/tcg-op.c:2280: error: ‘gen_helper_atomic_fetch_addw_be’ undeclared here (not in a function) (...) The fix I've been using locally while working on enabling MTTCG for MIPS: diff --git a/include/qemu/atomic.h b/include/qemu/atomic.h index 5542416..818a5a4 100644 --- a/include/qemu/atomic.h +++ b/include/qemu/atomic.h @@ -409,22 +409,22 @@ /* Provide shorter names for GCC atomic builtins. */ #define atomic_fetch_inc(ptr) __sync_fetch_and_add(ptr, 1) #define atomic_fetch_dec(ptr) __sync_fetch_and_add(ptr, -1) -#define atomic_fetch_add __sync_fetch_and_add -#define atomic_fetch_sub __sync_fetch_and_sub -#define atomic_fetch_and __sync_fetch_and_and -#define atomic_fetch_or __sync_fetch_and_or -#define atomic_fetch_xor __sync_fetch_and_xor +#define atomic_fetch_add(ptr, n) __sync_fetch_and_add(ptr, n) +#define atomic_fetch_sub(ptr, n) __sync_fetch_and_sub(ptr, n) +#define atomic_fetch_and(ptr, n) __sync_fetch_and_and(ptr, n) +#define atomic_fetch_or(ptr, n) __sync_fetch_and_or(ptr, n) +#define atomic_fetch_xor(ptr, n) __sync_fetch_and_xor(ptr, n) #define atomic_inc_fetch(ptr) __sync_add_and_fetch(ptr, 1) #define atomic_dec_fetch(ptr) __sync_add_and_fetch(ptr, -1) -#define atomic_add_fetch __sync_add_and_fetch -#define atomic_sub_fetch __sync_sub_and_fetch -#define atomic_and_fetch __sync_and_and_fetch -#define atomic_or_fetch __sync_or_and_fetch -#define atomic_xor_fetch __sync_xor_and_fetch - -#define atomic_cmpxchg __sync_val_compare_and_swap -#define atomic_cmpxchg__nocheck atomic_cmpxchg +#define atomic_add_fetch(ptr, n) __sync_add_and_fetch(ptr, n) +#define atomic_sub_fetch(ptr, n) __sync_sub_and_fetch(ptr, n) +#define atomic_and_fetch(ptr, n) __sync_and_and_fetch(ptr, n) +#define atomic_or_fetch(ptr, n) __sync_or_and_fetch(ptr, n) +#define atomic_xor_fetch(ptr, n) __sync_xor_and_fetch(ptr, n) + +#define atomic_cmpxchg(ptr, old, new) __sync_val_compare_and_swap(ptr, old, new) +#define atomic_cmpxchg__nocheck(ptr, old, new) atomic_cmpxchg(ptr, old, new) /* And even shorter names that return void. */ #define atomic_inc(ptr) ((void) __sync_fetch_and_add(ptr, 1))