From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58823) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHboA-0006fR-Gb for qemu-devel@nongnu.org; Mon, 27 Jun 2016 15:03:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bHbo6-0008Gr-NE for qemu-devel@nongnu.org; Mon, 27 Jun 2016 15:02:57 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:39322) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bHbo5-0008CK-CU for qemu-devel@nongnu.org; Mon, 27 Jun 2016 15:02:54 -0400 From: "Emilio G. Cota" Date: Mon, 27 Jun 2016 15:01:56 -0400 Message-Id: <1467054136-10430-11-git-send-email-cota@braap.org> In-Reply-To: <1467054136-10430-1-git-send-email-cota@braap.org> References: <1467054136-10430-1-git-send-email-cota@braap.org> Subject: [Qemu-devel] [RFC 10/30] cpu_ldst: add cpu_atomic helpers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: QEMU Developers , MTTCG Devel Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Paolo Bonzini , Richard Henderson , Sergey Fedorov , Alvise Rigo , Peter Maydell Signed-off-by: Emilio G. Cota --- include/exec/cpu_atomic_template.h | 41 +++++++++++++++++++++++++++++ include/exec/cpu_atomic_useronly_template.h | 25 ++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/include/exec/cpu_atomic_template.h b/include/exec/cpu_atomic_template.h index 13f4ffd..36c9593 100644 --- a/include/exec/cpu_atomic_template.h +++ b/include/exec/cpu_atomic_template.h @@ -54,3 +54,44 @@ glue(glue(cpu_cmpxchgo, MEMSUFFIX), _ra)(CPUArchState *env, target_ulong ptr, return ret; } #endif + +#define GEN_ATOMIC_HELPER(NAME) \ +static inline DATA_TYPE \ +glue(glue(glue(glue(cpu_atomic_, NAME), SUFFIX), MEMSUFFIX), \ + _ra)(CPUArchState *env, target_ulong ptr, DATA_TYPE val, uintptr_t ra) \ +{ \ + int page_index; \ + target_ulong addr; \ + int mmu_idx; \ + TCGMemOpIdx oi; \ + \ + addr = ptr; \ + page_index = (addr >> TARGET_PAGE_BITS) & (CPU_TLB_SIZE - 1); \ + mmu_idx = CPU_MMU_INDEX; \ + if (unlikely(env->tlb_table[mmu_idx][page_index].addr_write != \ + (addr & (TARGET_PAGE_MASK | (DATA_SIZE - 1))))) { \ + oi = make_memop_idx(SHIFT, mmu_idx); \ + return glue(glue(glue(helper_atomic_, NAME), SUFFIX), \ + MMUSUFFIX)(env, addr, val, oi, ra); \ + } else { \ + uintptr_t hostaddr = addr + \ + env->tlb_table[mmu_idx][page_index].addend; \ + \ + return glue(atomic_, NAME)((DATA_TYPE *)hostaddr, val); \ + } \ +} + +GEN_ATOMIC_HELPER(fetch_add) +GEN_ATOMIC_HELPER(fetch_sub) +GEN_ATOMIC_HELPER(fetch_and) +GEN_ATOMIC_HELPER(fetch_or) +GEN_ATOMIC_HELPER(fetch_xor) + +GEN_ATOMIC_HELPER(add_fetch) +GEN_ATOMIC_HELPER(sub_fetch) +GEN_ATOMIC_HELPER(and_fetch) +GEN_ATOMIC_HELPER(or_fetch) +GEN_ATOMIC_HELPER(xor_fetch) + +GEN_ATOMIC_HELPER(xchg) +#undef GEN_ATOMIC_HELPER diff --git a/include/exec/cpu_atomic_useronly_template.h b/include/exec/cpu_atomic_useronly_template.h index c7c0a3e..c4b447e 100644 --- a/include/exec/cpu_atomic_useronly_template.h +++ b/include/exec/cpu_atomic_useronly_template.h @@ -37,3 +37,28 @@ glue(glue(cpu_cmpxchgo, MEMSUFFIX), return ret; } #endif + +#define GEN_ATOMIC_HELPER(NAME) \ +static inline DATA_TYPE \ +glue(glue(glue(glue(cpu_atomic_, NAME), SUFFIX), MEMSUFFIX), \ + _ra)(CPUArchState *env, target_ulong ptr, DATA_TYPE val, uintptr_t ra) \ +{ \ + DATA_TYPE *hostaddr = g2h(ptr); \ + \ + return glue(atomic_, NAME)(hostaddr, val); \ +} + +GEN_ATOMIC_HELPER(fetch_add) +GEN_ATOMIC_HELPER(fetch_sub) +GEN_ATOMIC_HELPER(fetch_and) +GEN_ATOMIC_HELPER(fetch_or) +GEN_ATOMIC_HELPER(fetch_xor) + +GEN_ATOMIC_HELPER(add_fetch) +GEN_ATOMIC_HELPER(sub_fetch) +GEN_ATOMIC_HELPER(and_fetch) +GEN_ATOMIC_HELPER(or_fetch) +GEN_ATOMIC_HELPER(xor_fetch) + +GEN_ATOMIC_HELPER(xchg) +#undef GEN_ATOMIC_HELPER -- 2.5.0