From patchwork Sun Sep 9 21:04:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 182675 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3FD392C0089 for ; Mon, 10 Sep 2012 08:01:07 +1000 (EST) Received: from localhost ([::1]:52258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAojV-0000Jq-Sj for incoming@patchwork.ozlabs.org; Sun, 09 Sep 2012 17:07:57 -0400 Received: from eggs.gnu.org ([208.118.235.92]:56322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAoiX-00077T-M2 for qemu-devel@nongnu.org; Sun, 09 Sep 2012 17:06:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TAoiW-0005x3-5l for qemu-devel@nongnu.org; Sun, 09 Sep 2012 17:06:57 -0400 Received: from mail-pz0-f45.google.com ([209.85.210.45]:63059) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAoiW-0005pO-0j for qemu-devel@nongnu.org; Sun, 09 Sep 2012 17:06:56 -0400 Received: by mail-pz0-f45.google.com with SMTP id n15so968311dad.4 for ; Sun, 09 Sep 2012 14:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=xRwi+64C06X+nbPrO1NWpdEaxCNmU4o7RmuDCR3+xxA=; b=KdhpCzZUphLdcaHmUasj3J83dJg17I6wSg6v0w9YTflxV/7mRYezj/Jp1nuAZFzU9m 0trYU1OGOZx5cXJ8OTMA9tOXw1L9IBiJb0SgUxu6Qj8QwmJA2dm+RMYEm2XNL5RwuFQy fi0/6GStR7Ow/kG6gHvcXhH3/pZWC5d9uDv7j3vOAFoRESifaMyii2RVfTsYLbiI9jGd jWbNlPNbHIxlcbRCxTTowlI03ySM8pkM6AvffmG8Fb1HkyFycwYwPzXORaCoIKQ8E/d/ dz6SReXa8sMOajJqborW3jKmKJHW6v8AzsFZ7ANsZLkijcc+Evq4X9n2Max/ro7m1ZE9 KJyg== Received: by 10.68.225.104 with SMTP id rj8mr2028604pbc.97.1347224815764; Sun, 09 Sep 2012 14:06:55 -0700 (PDT) Received: from anchor.twiddle.home ([173.160.232.49]) by mx.google.com with ESMTPS id tw5sm662053pbc.48.2012.09.09.14.06.54 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 09 Sep 2012 14:06:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Sun, 9 Sep 2012 14:04:44 -0700 Message-Id: <1347224784-19472-27-git-send-email-rth@twiddle.net> X-Mailer: git-send-email 1.7.11.4 In-Reply-To: <1347224784-19472-1-git-send-email-rth@twiddle.net> References: <1347224784-19472-1-git-send-email-rth@twiddle.net> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.45 Cc: Alexander Graf Subject: [Qemu-devel] [PATCH 026/126] target-s390: Convert BRANCH AND SAVE 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 Signed-off-by: Richard Henderson --- target-s390x/insn-data.def | 7 ++++ target-s390x/translate.c | 102 +++++++++++++++++++++++++-------------------- 2 files changed, 63 insertions(+), 46 deletions(-) diff --git a/target-s390x/insn-data.def b/target-s390x/insn-data.def index 3389e28..00b06a3 100644 --- a/target-s390x/insn-data.def +++ b/target-s390x/insn-data.def @@ -62,6 +62,13 @@ D(0xa506, NILH, RI_a, Z, r1_o, i2_16u, r1, 0, andi, 0, 0x1010) D(0xa507, NILL, RI_a, Z, r1_o, i2_16u, r1, 0, andi, 0, 0x1000) +/* BRANCH AND SAVE */ + C(0x0d00, BASR, RR_a, Z, 0, r2_nz, r1, 0, bas, 0) + C(0x4d00, BAS, RX_a, Z, 0, a2, r1, 0, bas, 0) +/* BRANCH RELATIVE AND SAVE */ + C(0xa705, BRAS, RI_b, Z, 0, 0, r1, 0, basi, 0) + C(0xc005, BRASL, RIL_b, Z, 0, 0, r1, 0, basi, 0) + /* COMPARE */ C(0x1900, CR, RR_a, Z, r1_o, r2_o, 0, 0, 0, cmps32) C(0x5900, C, RX_a, Z, r1_o, m2_32s, 0, 0, 0, cmps32) diff --git a/target-s390x/translate.c b/target-s390x/translate.c index 6b8bf42..407edd2 100644 --- a/target-s390x/translate.c +++ b/target-s390x/translate.c @@ -711,20 +711,23 @@ static inline TCGv_i64 decode_si(DisasContext *s, uint64_t insn, int *i2, return get_address(s, 0, *b1, *d1); } -static inline void gen_goto_tb(DisasContext *s, int tb_num, target_ulong pc) +static int use_goto_tb(DisasContext *s, uint64_t dest) { - TranslationBlock *tb; + /* NOTE: we handle the case where the TB spans two pages here */ + return (((dest & TARGET_PAGE_MASK) == (s->tb->pc & TARGET_PAGE_MASK) + || (dest & TARGET_PAGE_MASK) == ((s->pc - 1) & TARGET_PAGE_MASK)) + && !s->singlestep_enabled + && !(s->tb->cflags & CF_LAST_IO)); +} +static inline void gen_goto_tb(DisasContext *s, int tb_num, target_ulong pc) +{ gen_update_cc_op(s); - tb = s->tb; - /* NOTE: we handle the case where the TB spans two pages here */ - if ((pc & TARGET_PAGE_MASK) == (tb->pc & TARGET_PAGE_MASK) || - (pc & TARGET_PAGE_MASK) == ((s->pc - 1) & TARGET_PAGE_MASK)) { - /* jump to same page: we can use a direct jump */ + if (use_goto_tb(s, pc)) { tcg_gen_goto_tb(tb_num); tcg_gen_movi_i64(psw_addr, pc); - tcg_gen_exit_tb((tcg_target_long)tb + tb_num); + tcg_gen_exit_tb((tcg_target_long)s->tb + tb_num); } else { /* jump to another page: currently not optimized */ tcg_gen_movi_i64(psw_addr, pc); @@ -1810,13 +1813,6 @@ static void disas_a7(DisasContext *s, int op, int r1, int i2) case 0x4: /* brc m1, i2 */ gen_brc(r1, s, i2 * 2LL); return; - case 0x5: /* BRAS R1,I2 [RI] */ - tmp = tcg_const_i64(pc_to_link_info(s, s->pc + 4)); - store_reg(r1, tmp); - tcg_temp_free_i64(tmp); - gen_goto_tb(s, 0, s->pc + i2 * 2LL); - s->is_jmp = DISAS_TB_JUMP; - break; case 0x6: /* BRCT R1,I2 [RI] */ tmp32_1 = load_reg32(r1); tcg_gen_subi_i32(tmp32_1, tmp32_1, 1); @@ -2591,7 +2587,6 @@ static void disas_b9(DisasContext *s, int op, int r1, int r2) static void disas_c0(DisasContext *s, int op, int r1, int i2) { - TCGv_i64 tmp; TCGv_i32 tmp32_1, tmp32_2; uint64_t target = s->pc + i2 * 2LL; int l1; @@ -2618,13 +2613,6 @@ static void disas_c0(DisasContext *s, int op, int r1, int i2) tcg_temp_free_i32(tmp32_1); tcg_temp_free_i32(tmp32_2); break; - case 0x5: /* brasl r1, i2 */ - tmp = tcg_const_i64(pc_to_link_info(s, s->pc + 6)); - store_reg(r1, tmp); - tcg_temp_free_i64(tmp); - gen_goto_tb(s, 0, target); - s->is_jmp = DISAS_TB_JUMP; - break; default: LOG_DISAS("illegal c0 operation 0x%x\n", op); gen_illegal_opcode(s); @@ -2705,19 +2693,6 @@ static void disas_s390_insn(DisasContext *s) tcg_temp_free_i32(tmp32_1); tcg_temp_free_i32(tmp32_2); break; - case 0xd: /* BASR R1,R2 [RR] */ - insn = ld_code2(s->pc); - decode_rr(s, insn, &r1, &r2); - tmp = tcg_const_i64(pc_to_link_info(s, s->pc + 2)); - store_reg(r1, tmp); - if (r2) { - tmp2 = load_reg(r2); - tcg_gen_mov_i64(psw_addr, tmp2); - tcg_temp_free_i64(tmp2); - s->is_jmp = DISAS_JUMP; - } - tcg_temp_free_i64(tmp); - break; case 0xe: /* MVCL R1,R2 [RR] */ insn = ld_code2(s->pc); decode_rr(s, insn, &r1, &r2); @@ -2831,16 +2806,6 @@ static void disas_s390_insn(DisasContext *s) tcg_temp_free_i64(tmp); s->is_jmp = DISAS_TB_JUMP; break; - case 0x4d: /* BAS R1,D2(X2,B2) [RX] */ - insn = ld_code4(s->pc); - tmp = decode_rx(s, insn, &r1, &x2, &b2, &d2); - tmp2 = tcg_const_i64(pc_to_link_info(s, s->pc + 4)); - store_reg(r1, tmp2); - tcg_gen_mov_i64(psw_addr, tmp); - tcg_temp_free_i64(tmp); - tcg_temp_free_i64(tmp2); - s->is_jmp = DISAS_JUMP; - break; case 0x4e: /* CVD R1,D2(X2,B2) [RX] */ insn = ld_code4(s->pc); tmp = decode_rx(s, insn, &r1, &x2, &b2, &d2); @@ -3733,6 +3698,26 @@ struct DisasInsn { }; /* ====================================================================== */ +/* Miscelaneous helpers, used by several operations. */ + +static ExitStatus help_goto_direct(DisasContext *s, uint64_t dest) +{ + if (dest == s->next_pc) { + return NO_EXIT; + } + if (use_goto_tb(s, dest)) { + gen_update_cc_op(s); + tcg_gen_goto_tb(0); + tcg_gen_movi_i64(psw_addr, dest); + tcg_gen_exit_tb((tcg_target_long)s->tb); + return EXIT_GOTO_TB; + } else { + tcg_gen_movi_i64(psw_addr, dest); + return EXIT_PC_UPDATED; + } +} + +/* ====================================================================== */ /* The operations. These perform the bulk of the work for any insn, usually after the operands have been loaded and output initialized. */ @@ -3788,6 +3773,23 @@ static ExitStatus op_andi(DisasContext *s, DisasOps *o) return NO_EXIT; } +static ExitStatus op_bas(DisasContext *s, DisasOps *o) +{ + tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->next_pc)); + if (!TCGV_IS_UNUSED_I64(o->in2)) { + tcg_gen_mov_i64(psw_addr, o->in2); + return EXIT_PC_UPDATED; + } else { + return NO_EXIT; + } +} + +static ExitStatus op_basi(DisasContext *s, DisasOps *o) +{ + tcg_gen_movi_i64(o->out, pc_to_link_info(s, s->next_pc)); + return help_goto_direct(s, s->pc + 2 * get_field(s->fields, i2)); +} + static ExitStatus op_insi(DisasContext *s, DisasOps *o) { int shift = s->insn->data & 0xff; @@ -4276,6 +4278,14 @@ static void in2_r2_o(DisasContext *s, DisasFields *f, DisasOps *o) o->g_in2 = true; } +static void in2_r2_nz(DisasContext *s, DisasFields *f, DisasOps *o) +{ + int r2 = get_field(f, r2); + if (r2 != 0) { + o->in2 = load_reg(r2); + } +} + static void in2_r2_8s(DisasContext *s, DisasFields *f, DisasOps *o) { o->in2 = tcg_temp_new_i64();