From patchwork Fri May 11 04:23:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 135489 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp390655lji; Thu, 10 May 2018 21:24:05 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoGh+++mH8q4UH7UN+nNT6R2M7uF4ApP6ZgqgiN/hMHLCLuV2CabbavYmUFQLE/x4bWnsMT X-Received: by 2002:a37:1f0f:: with SMTP id f15-v6mr3580302qkf.421.1526012645084; Thu, 10 May 2018 21:24:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526012645; cv=none; d=google.com; s=arc-20160816; b=TpG1mC+1iYnkj2CMhvRJ3IxnIAfDyXillDTY3OkOThQkCqKVze8HRoHMBmFqFrrK8a TySFTQwTVjehVyZhBiI3HvnIPmA8EPUmi8DwcM3+yFbRvxGEDGsU65wGDz9n1dUx+YGL INV7qIZqZ8s26Gx+FLe/QYTnMYwsNzOhCC11NhFQYsaT8QvaQ77/Y3swnwlorluUvBGh dq8+or5QrrufRilXV3RLc2yBh0W5iDzXAZqNlWxMICOuXTPwygqAkC9fF/UtCSa52XT+ uTPOkrCXYg0x/AOV8DFMq9P726IZR883De1n4a7xmTs3eJLZ4NN44L5FTwtix/2YItvK HDwQ== 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=tT+S22tWudduYX9UJYbKgHZL6JwAHlr4YVC3LpEsAQk=; b=ZyFPo4olh0S0gzXtzEwNuqg3c20XrXZavAzCJBAIwriHos/guCJjZRnDG00/zp8sYY McOzGuAtTpC4PS6ebxE1SzvQ7TFthmcGtvWNq3lHHDY0U+BISKt3W57Fuyj9zR21iKHL PExsJ0u1XV5QHkS97rU3m5dMrLkTvSo3YmsZUe4l1EErlYRyrWFs7+AZB9ec841SFeN0 Cq62lS0s/TO7QrZCBfvN8qfpP4XrFyXG8u0QduNCK8UhJHTCsAU/z4Kb3XA2mfJ37lew mrPPBa6IsW9bCrQzpI3VbnqyxDi/ED3ud+WuRxnFYcuLkWDei258Nc7O9MeQD97NYqVt a4sQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=EjQU50P1; 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 24-v6si2370725qtw.104.2018.05.10.21.24.04 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 10 May 2018 21:24:05 -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=EjQU50P1; 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]:36669 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGzbA-0000Z0-FC for patch@linaro.org; Fri, 11 May 2018 00:24:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55586) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGzag-0000XD-2k for qemu-devel@nongnu.org; Fri, 11 May 2018 00:23:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGzaf-00086D-0l for qemu-devel@nongnu.org; Fri, 11 May 2018 00:23:34 -0400 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]:36572) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGzae-00085u-Ov for qemu-devel@nongnu.org; Fri, 11 May 2018 00:23:32 -0400 Received: by mail-pf0-x242.google.com with SMTP id w129-v6so2100207pfd.3 for ; Thu, 10 May 2018 21:23:32 -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=tT+S22tWudduYX9UJYbKgHZL6JwAHlr4YVC3LpEsAQk=; b=EjQU50P14OHlrJO1LCfpUDaz+A6AuX9hDZV3RKo02o/WvsGo/I/5Oxm2Q/q7TluxEK dJX1xvs+2foGL77QKHhEvspYROODfr8/migkhWdTsBeMdi6g/JNC3BciBWD7qVzNiv1v t3WcCmgluzopknQiz5ovGiwn3ucklScDK/Umg= 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=tT+S22tWudduYX9UJYbKgHZL6JwAHlr4YVC3LpEsAQk=; b=DzWpRxOQ8wfp9Jl2N/LyQvrxMJb3WvAXBbOJfpBo/E6NsQDua4bG48T8YCTS/bT1Cs PNWTfwHVE6t9NOyIep7zoE/Viwcz5GRINL7ckNyFMuPwsgy/2QsGSJn3fVVTIQZP6f2p 9b/fZVM3ftCq8HQahqqPayCcH01M81VgBrFF01GbRHkkrC/T9ctJI/wtaF2WdEc7XX/o GWa9mKevuRtpkazFgIa+BgKnO2mUK4ub5SKvETlP92bSUgwRWtMPR5BQKYYHlQvhwTOn ftYQP1kl4xtYWmt6noUUVsYi94IxAMPnNXnbGVbroNrJHhm00hgo9Cd2rpUjcE83QJYN NLag== X-Gm-Message-State: ALKqPwdu7cdnXrlOd0RSymZ3TtAFr1b0p7KXvOqDSRFwopcVsbG1590q 9x2H7I4DVv7qwLU75YNQ/JG6Cq9A4cU= X-Received: by 2002:a63:3286:: with SMTP id y128-v6mr3277995pgy.419.1526012611386; Thu, 10 May 2018 21:23:31 -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 r76-v6sm4509462pfl.1.2018.05.10.21.23.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 May 2018 21:23:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Thu, 10 May 2018 21:23:14 -0700 Message-Id: <20180511042324.5070-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180511042324.5070-1-richard.henderson@linaro.org> References: <20180511042324.5070-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::242 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 | 149 +++++++++++++++++------------------ target/openrisc/insns.decode | 12 +++ 2 files changed, 83 insertions(+), 78 deletions(-) -- 2.17.0 diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c index 40b21a5db1..95e4f17b8a 100644 --- a/target/openrisc/translate.c +++ b/target/openrisc/translate.c @@ -195,52 +195,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->pc + 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->pc + 8); - /* Optimize jal being used to load the PC for PIC. */ - if (tmp_pc == dc->pc + 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->pc + 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->pc + 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) { @@ -715,12 +669,82 @@ 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->pc + 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->pc + a->n * 4; + + LOG_DIS("l.jal %d\n", a->n); + tcg_gen_movi_tl(cpu_R[9], dc->pc + 8); + /* Optimize jal being used to load the PC for PIC. */ + if (tmp_pc != dc->pc + 8) { + 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->pc + a->n * 4; + TCGv t_next = tcg_const_tl(dc->pc + 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->pc + 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; @@ -733,31 +757,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 */ @@ -770,16 +773,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 -----------