From patchwork Mon May 14 22:27:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 135795 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp215546lji; Mon, 14 May 2018 15:51:51 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpJgfuE1H6I99rRJjaE01Z2K8oYr90el+uJY2NtUQ+wV98q4wbdpU6kOfI6ckmYOgEWM25j X-Received: by 2002:a37:1424:: with SMTP id e36-v6mr9619096qkh.315.1526338311632; Mon, 14 May 2018 15:51:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526338311; cv=none; d=google.com; s=arc-20160816; b=AzZ6UWeIMQvr0YWJDXdyY9eKKuckH1FGB2u0tr6EYtY8V5kUSiudwSnAWP/w4SYJYs GA+p5PhoQqyoeWQYboyoHP6rhhMtUdvZ8vI45dG5xbMbB5zriKG/Of86TlFykOsnugoJ dDxsGx+5pGNaEhltfo9ZW29SWNJs7uQWC8a1xUgS1FLIYHizP828/CHpTP+qaC1c7CBQ Dms0oSE8KG0NWb6IsbYeKCpLNkSBn1sEwMGkWerLrCCC3WIYY2rFKcxlrgj9AhdlEKL7 IMFElZvsz95z8nbb/thdpdtfTvmkuFH4YTBJn8rnikpHveLz1h9HAu9xLYkwYYip5One h5tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=gBVw2QmyZsM6DDeAJNqWC2Q0zEZ3R3c086bfMiVvVyg=; b=RmH+eC31i/LgWGRCZNPsqtKxX9iKAdMz1W1oEQcRMAzhK6fMqy/A0PoERNjyWk9sN8 qZQyCqQfEQf9YMVWUBXQhhyZvNU4Ykzqy5wYLK9o4H+/BpgZ1aAICNZN5atOUuRk6Qph dvfNIfq5cKKE4TDMQ8fgFeiFIGtJ1hKstz7NskGNbw6Vsefx78HPByNt+L8l7nV5ni5E vsvh4/desIp0u49MDZHT/jHzJxKm2vZUYOWBDhbMMvMZdDAcwOCDpb4nT7NE+WIwTYOH hkSt2oYcB7sJBzlGOL8VNG9l1I6ZjLL9l4u+15cXg5MNeKgxXmxyGLhLMMsz0pUfJNF+ /DPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GCzKxsnF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q8-v6si5710034qkl.53.2018.05.14.15.51.51 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 14 May 2018 15:51:51 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GCzKxsnF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51693 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fIMJr-000723-4u for patch@linaro.org; Mon, 14 May 2018 18:51:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fILwC-000472-LO for qemu-devel@nongnu.org; Mon, 14 May 2018 18:27:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fILwB-0008Kd-CC for qemu-devel@nongnu.org; Mon, 14 May 2018 18:27:24 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:34951) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fILwB-0008K8-43 for qemu-devel@nongnu.org; Mon, 14 May 2018 18:27:23 -0400 Received: by mail-pf0-x241.google.com with SMTP id x9-v6so6682068pfm.2 for ; Mon, 14 May 2018 15:27:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gBVw2QmyZsM6DDeAJNqWC2Q0zEZ3R3c086bfMiVvVyg=; b=GCzKxsnFZ+VslFam7NHedOuLeOpl3LtwotqnGU6XDGob2hTjZ/tJ5leb6CVycngiM1 WpHXtRzEoauGJqnUrf0dDd26PjrWnMcJUEPqqz53PFvYxUBKrABSJ7/hwBGH9SSMW65k stCgZO93lLdTvmynd2RbOwgavsGHq0U/INgdM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gBVw2QmyZsM6DDeAJNqWC2Q0zEZ3R3c086bfMiVvVyg=; b=UQGUB+aQc294diqn10/3t/96KWyUEpPQrVTwnCXjsRWCQGKGYrsfdw/abHLTQK6C/7 86mNe6QxE49HN2HFEidcmcNbPxwtE5heb4UJ/cFVL7CtoxHOhxif3uQgfw5e4IU9rd3W KnNYg0qL46zZuJbA/nsD4/GbPq0MO+9muugxUl53eYqBkFhPlvEpwjHqCbhKXiBrVvJg VRhs+JhFg33wZ7SzSkgbbJOMIf/EenoertJoEuZp29jYOLnvtEcBqau3gMljV/GqQcfD 5lBmmwCzrNnRqH/EK5BBDVwbdZOvd2ZiBUbaaNu3IrDmOMgRn/WGuzzGErnWdRSXrxmg XvcA== X-Gm-Message-State: ALKqPwdWfY6BorpEappUv06olP4F5Cq+61zgdBOv0Y5sL4RduSs5jg2I u7e1GDMmPE2RJgIiHLHA04j2HAKnR6c= X-Received: by 2002:a63:b70b:: with SMTP id t11-v6mr9591951pgf.390.1526336841788; Mon, 14 May 2018 15:27:21 -0700 (PDT) Received: from cloudburst.twiddle.net (97-113-2-170.tukw.qwest.net. [97.113.2.170]) by smtp.gmail.com with ESMTPSA id g13-v6sm19517976pfm.67.2018.05.14.15.27.20 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 May 2018 15:27:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 14 May 2018 15:27:04 -0700 Message-Id: <20180514222714.7982-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514222714.7982-1-richard.henderson@linaro.org> References: <20180514222714.7982-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PULL 03/13] target/openrisc: Convert branch insns 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: peter.maydell@linaro.org, Stafford Horne Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Acked-by: Stafford Horne Signed-off-by: Richard Henderson --- target/openrisc/translate.c | 150 +++++++++++++++++------------------ target/openrisc/insns.decode | 12 +++ 2 files changed, 84 insertions(+), 78 deletions(-) -- 2.17.0 diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c index a4b67f94c5..3a02a1d688 100644 --- a/target/openrisc/translate.c +++ b/target/openrisc/translate.c @@ -193,52 +193,6 @@ static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest) } } -static void gen_jump(DisasContext *dc, int32_t n26, uint32_t reg, uint32_t op0) -{ - target_ulong tmp_pc = dc->base.pc_next + n26 * 4; - - switch (op0) { - case 0x00: /* l.j */ - tcg_gen_movi_tl(jmp_pc, tmp_pc); - break; - case 0x01: /* l.jal */ - tcg_gen_movi_tl(cpu_R[9], dc->base.pc_next + 8); - /* Optimize jal being used to load the PC for PIC. */ - if (tmp_pc == dc->base.pc_next + 8) { - return; - } - tcg_gen_movi_tl(jmp_pc, tmp_pc); - break; - case 0x03: /* l.bnf */ - case 0x04: /* l.bf */ - { - TCGv t_next = tcg_const_tl(dc->base.pc_next + 8); - TCGv t_true = tcg_const_tl(tmp_pc); - TCGv t_zero = tcg_const_tl(0); - - tcg_gen_movcond_tl(op0 == 0x03 ? TCG_COND_EQ : TCG_COND_NE, - jmp_pc, cpu_sr_f, t_zero, t_true, t_next); - - tcg_temp_free(t_next); - tcg_temp_free(t_true); - tcg_temp_free(t_zero); - } - break; - case 0x11: /* l.jr */ - tcg_gen_mov_tl(jmp_pc, cpu_R[reg]); - break; - case 0x12: /* l.jalr */ - tcg_gen_movi_tl(cpu_R[9], (dc->base.pc_next + 8)); - tcg_gen_mov_tl(jmp_pc, cpu_R[reg]); - break; - default: - gen_illegal_exception(dc); - break; - } - - dc->delayed_branch = 2; -} - static void gen_ove_cy(DisasContext *dc) { if (dc->tb_flags & SR_OVE) { @@ -713,12 +667,83 @@ static void dec_calc(DisasContext *dc, uint32_t insn) gen_illegal_exception(dc); } +static bool trans_l_j(DisasContext *dc, arg_l_j *a, uint32_t insn) +{ + target_ulong tmp_pc = dc->base.pc_next + a->n * 4; + + LOG_DIS("l.j %d\n", a->n); + tcg_gen_movi_tl(jmp_pc, tmp_pc); + dc->delayed_branch = 2; + return true; +} + +static bool trans_l_jal(DisasContext *dc, arg_l_jal *a, uint32_t insn) +{ + target_ulong tmp_pc = dc->base.pc_next + a->n * 4; + target_ulong ret_pc = dc->base.pc_next + 8; + + LOG_DIS("l.jal %d\n", a->n); + tcg_gen_movi_tl(cpu_R[9], ret_pc); + /* Optimize jal being used to load the PC for PIC. */ + if (tmp_pc != ret_pc) { + tcg_gen_movi_tl(jmp_pc, tmp_pc); + dc->delayed_branch = 2; + } + return true; +} + +static void do_bf(DisasContext *dc, arg_l_bf *a, TCGCond cond) +{ + target_ulong tmp_pc = dc->base.pc_next + a->n * 4; + TCGv t_next = tcg_const_tl(dc->base.pc_next + 8); + TCGv t_true = tcg_const_tl(tmp_pc); + TCGv t_zero = tcg_const_tl(0); + + tcg_gen_movcond_tl(cond, jmp_pc, cpu_sr_f, t_zero, t_true, t_next); + + tcg_temp_free(t_next); + tcg_temp_free(t_true); + tcg_temp_free(t_zero); + dc->delayed_branch = 2; +} + +static bool trans_l_bf(DisasContext *dc, arg_l_bf *a, uint32_t insn) +{ + LOG_DIS("l.bf %d\n", a->n); + do_bf(dc, a, TCG_COND_NE); + return true; +} + +static bool trans_l_bnf(DisasContext *dc, arg_l_bf *a, uint32_t insn) +{ + LOG_DIS("l.bnf %d\n", a->n); + do_bf(dc, a, TCG_COND_EQ); + return true; +} + +static bool trans_l_jr(DisasContext *dc, arg_l_jr *a, uint32_t insn) +{ + LOG_DIS("l.jr r%d\n", a->b); + tcg_gen_mov_tl(jmp_pc, cpu_R[a->b]); + dc->delayed_branch = 2; + return true; +} + +static bool trans_l_jalr(DisasContext *dc, arg_l_jalr *a, uint32_t insn) +{ + LOG_DIS("l.jalr r%d\n", a->b); + tcg_gen_mov_tl(jmp_pc, cpu_R[a->b]); + tcg_gen_movi_tl(cpu_R[9], dc->base.pc_next + 8); + dc->delayed_branch = 2; + return true; +} + static void dec_misc(DisasContext *dc, uint32_t insn) { uint32_t op0, op1; uint32_t ra, rb, rd; uint32_t L6, K5, K16, K5_11; - int32_t I16, I5_11, N26; + int32_t I16, I5_11; TCGMemOp mop; TCGv t0; @@ -731,31 +756,10 @@ static void dec_misc(DisasContext *dc, uint32_t insn) K5 = extract32(insn, 0, 5); K16 = extract32(insn, 0, 16); I16 = (int16_t)K16; - N26 = sextract32(insn, 0, 26); K5_11 = (extract32(insn, 21, 5) << 11) | extract32(insn, 0, 11); I5_11 = (int16_t)K5_11; switch (op0) { - case 0x00: /* l.j */ - LOG_DIS("l.j %d\n", N26); - gen_jump(dc, N26, 0, op0); - break; - - case 0x01: /* l.jal */ - LOG_DIS("l.jal %d\n", N26); - gen_jump(dc, N26, 0, op0); - break; - - case 0x03: /* l.bnf */ - LOG_DIS("l.bnf %d\n", N26); - gen_jump(dc, N26, 0, op0); - break; - - case 0x04: /* l.bf */ - LOG_DIS("l.bf %d\n", N26); - gen_jump(dc, N26, 0, op0); - break; - case 0x05: switch (op1) { case 0x01: /* l.nop */ @@ -768,16 +772,6 @@ static void dec_misc(DisasContext *dc, uint32_t insn) } break; - case 0x11: /* l.jr */ - LOG_DIS("l.jr r%d\n", rb); - gen_jump(dc, 0, rb, op0); - break; - - case 0x12: /* l.jalr */ - LOG_DIS("l.jalr r%d\n", rb); - gen_jump(dc, 0, rb, op0); - break; - case 0x13: /* l.maci */ LOG_DIS("l.maci r%d, %d\n", ra, I16); t0 = tcg_const_tl(I16); diff --git a/target/openrisc/insns.decode b/target/openrisc/insns.decode index 47d31afc5b..8d35011eab 100644 --- a/target/openrisc/insns.decode +++ b/target/openrisc/insns.decode @@ -26,3 +26,15 @@ l_trap 001000 0100000000 k:16 l_msync 001000 1000000000 00000000 00000000 l_psync 001000 1010000000 00000000 00000000 l_csync 001000 1100000000 00000000 00000000 + +#### +# Branch Instructions +#### + +l_j 000000 n:s26 +l_jal 000001 n:s26 +l_bnf 000011 n:s26 +l_bf 000100 n:s26 + +l_jr 010001 ---------- b:5 ----------- +l_jalr 010010 ---------- b:5 -----------