From patchwork Tue May 17 22:32:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 96066 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 23020B6EE7 for ; Wed, 18 May 2011 08:38:15 +1000 (EST) Received: from localhost ([::1]:52228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QMSu4-00056w-Bm for incoming@patchwork.ozlabs.org; Tue, 17 May 2011 18:38:12 -0400 Received: from eggs.gnu.org ([140.186.70.92]:50785) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QMSqJ-0007OV-29 for qemu-devel@nongnu.org; Tue, 17 May 2011 18:34:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QMSqH-0000Tu-TF for qemu-devel@nongnu.org; Tue, 17 May 2011 18:34:19 -0400 Received: from mail-ey0-f173.google.com ([209.85.215.173]:53774) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QMSqH-0000MT-Mr for qemu-devel@nongnu.org; Tue, 17 May 2011 18:34:17 -0400 Received: by mail-ey0-f173.google.com with SMTP id 6so338540eyb.4 for ; Tue, 17 May 2011 15:34:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=8m0p1vDEjHjSVw/ZoOmP9chdSFJpUFCU1xX6qgRR1IU=; b=WGUOSAh5I83c8FXbWx7MmFl0iiw7p9/zptYLY0HPK9NNULlVzh3oqfFTlxQyMpy+kw iidE6BCqEQbbRTgJMPLrwPtO1TGgpi/1+EVrwPdtdZbKNIAje1a+Hdsu0eb0PVRODsgK TEZd0MIM2RA7u3kPedI1cKafRJkVun0ubsk/E= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=P7tBVHApqQyA4a9rLmXrNZRTJzKTZZrnXpcrfyDLThhA+0RLzTm57/Gr4qGlJT4QPA TsEFczobyVBfjhz9suXIoyPYLvKf9ta4T70kWqGHO51Ehl9bSElDbgsUIlGm66+oqS/C 8+sm8KZotHn3gENWZiJfEFTejpHVec97rabGU= Received: by 10.213.98.211 with SMTP id r19mr1368982ebn.41.1305671657282; Tue, 17 May 2011 15:34:17 -0700 (PDT) Received: from octofox.metropolis ([188.134.19.124]) by mx.google.com with ESMTPS id y10sm694466eeh.14.2011.05.17.15.34.14 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 May 2011 15:34:16 -0700 (PDT) Received: by octofox.metropolis (sSMTP sendmail emulation); Wed, 18 May 2011 02:34:13 +0400 From: Max Filippov To: qemu-devel@nongnu.org Date: Wed, 18 May 2011 02:32:45 +0400 Message-Id: <1305671572-5899-20-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1305671572-5899-1-git-send-email-jcmvbkbc@gmail.com> References: <1305671572-5899-1-git-send-email-jcmvbkbc@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.215.173 Cc: Max Filippov Subject: [Qemu-devel] [PATCH 19/26] target-xtensa: implement loop option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org See ISA, 4.3.2 for details. Operations that change LEND SR value invalidate TBs at the old and at the new LEND. LEND value at TB compilation time is considered constant and loop instruction is generated based on this value. Invalidation may be avoided for the TB at the old LEND address, since looping code verifies actual LEND value. Invalidation may be avoided for the TB at the new LEND address if there's a way to associate LEND address with TB at compilation time and later verify that it doesn't change. Signed-off-by: Max Filippov --- RFC -> PATCH changes: - add XTENSA_TBFLAG_EXCM, use it in loop ending check; --- target-xtensa/cpu.h | 8 +++++ target-xtensa/helpers.h | 1 + target-xtensa/op_helper.c | 11 +++++++ target-xtensa/translate.c | 65 +++++++++++++++++++++++++++++++++++++++----- 4 files changed, 77 insertions(+), 8 deletions(-) diff --git a/target-xtensa/cpu.h b/target-xtensa/cpu.h index 223535c..026b854 100644 --- a/target-xtensa/cpu.h +++ b/target-xtensa/cpu.h @@ -106,6 +106,9 @@ enum { }; enum { + LBEG = 0, + LEND = 1, + LCOUNT = 2, SAR = 3, SCOMPARE1 = 12, WINDOW_BASE = 72, @@ -257,12 +260,17 @@ static inline int cpu_mmu_index(CPUState *env) return xtensa_get_cring(env) != 0; } +#define XTENSA_TBFLAG_EXCM 0x1 + static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc, target_ulong *cs_base, int *flags) { *pc = env->pc; *cs_base = 0; *flags = 0; + if (env->sregs[PS] & PS_EXCM) { + *flags |= XTENSA_TBFLAG_EXCM; + } } #include "cpu-all.h" diff --git a/target-xtensa/helpers.h b/target-xtensa/helpers.h index 0971fde..7babf73 100644 --- a/target-xtensa/helpers.h +++ b/target-xtensa/helpers.h @@ -12,6 +12,7 @@ DEF_HELPER_1(rotw, void, i32) DEF_HELPER_2(window_check, void, i32, i32) DEF_HELPER_0(restore_owb, void) DEF_HELPER_1(movsp, void, i32) +DEF_HELPER_1(wsr_lend, void, i32) DEF_HELPER_0(dump_state, void) #include "def-helper.h" diff --git a/target-xtensa/op_helper.c b/target-xtensa/op_helper.c index 61d82cf..3a0fa01 100644 --- a/target-xtensa/op_helper.c +++ b/target-xtensa/op_helper.c @@ -280,6 +280,17 @@ void HELPER(movsp)(uint32_t pc) } } +void HELPER(wsr_lend)(uint32_t v) +{ + if (env->sregs[LEND] != v) { + tb_invalidate_phys_page_range( + env->sregs[LEND] - 1, env->sregs[LEND], 0); + env->sregs[LEND] = v; + tb_invalidate_phys_page_range( + env->sregs[LEND] - 1, env->sregs[LEND], 0); + } +} + void HELPER(dump_state)(void) { cpu_dump_state(env, stderr, fprintf, 0); diff --git a/target-xtensa/translate.c b/target-xtensa/translate.c index 323d67b..e5e4ce7 100644 --- a/target-xtensa/translate.c +++ b/target-xtensa/translate.c @@ -46,6 +46,7 @@ typedef struct DisasContext { uint32_t pc; uint32_t next_pc; int mem_idx; + uint32_t lend; int is_jmp; int singlestep_enabled; @@ -64,6 +65,9 @@ static TCGv_i32 cpu_UR[256]; #include "gen-icount.h" static const char * const sregnames[256] = { + [LBEG] = "LBEG", + [LEND] = "LEND", + [LCOUNT] = "LCOUNT", [SAR] = "SAR", [SCOMPARE1] = "SCOMPARE1", [WINDOW_BASE] = "WINDOW_BASE", @@ -237,13 +241,35 @@ static void gen_callwi(DisasContext *dc, int callinc, uint32_t dest, int slot) tcg_temp_free(tmp); } +static void gen_check_loop_end(DisasContext *dc, int slot) +{ + if (option_enabled(dc, XTENSA_OPTION_LOOP) && + !(dc->tb->flags & XTENSA_TBFLAG_EXCM) && + dc->next_pc == dc->lend) { + int label = gen_new_label(); + + tcg_gen_brcondi_i32(TCG_COND_NE, cpu_SR[LEND], dc->next_pc, label); + tcg_gen_brcondi_i32(TCG_COND_EQ, cpu_SR[LCOUNT], 0, label); + tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_SR[LCOUNT], 1); + gen_jump(dc, cpu_SR[LBEG]); + gen_set_label(label); + gen_jumpi(dc, dc->next_pc, slot); + } +} + +static void gen_jumpi_check_loop_end(DisasContext *dc, int slot) +{ + gen_check_loop_end(dc, slot); + gen_jumpi(dc, dc->next_pc, slot); +} + static void gen_brcond(DisasContext *dc, TCGCond cond, TCGv_i32 t0, TCGv_i32 t1, uint32_t offset) { int label = gen_new_label(); tcg_gen_brcond_i32(cond, t0, t1, label); - gen_jumpi(dc, dc->next_pc, 0); + gen_jumpi_check_loop_end(dc, 0); gen_set_label(label); gen_jumpi(dc, dc->pc + offset, 1); } @@ -273,6 +299,11 @@ static void gen_rsr(DisasContext *dc, TCGv_i32 d, uint32_t sr) } } +static void gen_wsr_lend(DisasContext *dc, uint32_t sr, TCGv_i32 v) +{ + gen_helper_wsr_lend(v); +} + static void gen_wsr_sar(DisasContext *dc, uint32_t sr, TCGv_i32 s) { tcg_gen_andi_i32(cpu_SR[sr], s, 0x3f); @@ -292,6 +323,7 @@ static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) { static void (* const wsr_handler[256])(DisasContext *dc, uint32_t sr, TCGv_i32 v) = { + [LEND] = gen_wsr_lend, [SAR] = gen_wsr_sar, [WINDOW_BASE] = gen_wsr_windowbase, }; @@ -1502,15 +1534,29 @@ static void disas_xtensa_insn(DisasContext *dc) break; case 8: /*LOOP*/ - TBD(); - break; - case 9: /*LOOPNEZ*/ - TBD(); - break; - case 10: /*LOOPGTZ*/ - TBD(); + HAS_OPTION(XTENSA_OPTION_LOOP); + { + uint32_t lend = dc->pc + RRI8_IMM8 + 4; + TCGv_i32 tmp = tcg_const_i32(lend); + + tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_R[RRI8_S], 1); + tcg_gen_movi_i32(cpu_SR[LBEG], dc->next_pc); + gen_wsr_lend(dc, LEND, tmp); + tcg_temp_free(tmp); + + if (BRI8_R > 8) { + int label = gen_new_label(); + tcg_gen_brcondi_i32( + BRI8_R == 9 ? TCG_COND_NE : TCG_COND_GT, + cpu_R[RRI8_S], 0, label); + gen_jumpi(dc, lend, 1); + gen_set_label(label); + } + + gen_jumpi(dc, dc->next_pc, 0); + } break; default: /*reserved*/ @@ -1687,7 +1733,9 @@ static void disas_xtensa_insn(DisasContext *dc) break; } + gen_check_loop_end(dc, 0); dc->pc = dc->next_pc; + return; invalid_opcode: @@ -1731,6 +1779,7 @@ static void gen_intermediate_code_internal( dc.tb = tb; dc.pc = env->pc; dc.mem_idx = cpu_mmu_index(env); + dc.lend = env->sregs[LEND]; dc.is_jmp = DISAS_NEXT; reset_sar_tracker(&dc);