From patchwork Wed May 23 00:14:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10419781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 559706032C for ; Wed, 23 May 2018 00:18:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 459AD28D8B for ; Wed, 23 May 2018 00:18:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39D7628E2B; Wed, 23 May 2018 00:18:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9EF1228D8B for ; Wed, 23 May 2018 00:18:26 +0000 (UTC) Received: from localhost ([::1]:58494 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLHU1-0000Xt-QL for patchwork-qemu-devel@patchwork.kernel.org; Tue, 22 May 2018 20:18:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLHSg-0007qp-4U for qemu-devel@nongnu.org; Tue, 22 May 2018 20:17:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLHSf-0000Zu-2L for qemu-devel@nongnu.org; Tue, 22 May 2018 20:17:02 -0400 Received: from mail-pg0-x234.google.com ([2607:f8b0:400e:c05::234]:37752) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fLHSe-0000ZL-T4 for qemu-devel@nongnu.org; Tue, 22 May 2018 20:17:01 -0400 Received: by mail-pg0-x234.google.com with SMTP id a13-v6so8571054pgu.4 for ; Tue, 22 May 2018 17:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GLJm5hNEigx1oy1r/uy/2EeTSOyWf03jPlIDuqIQCAw=; b=S6SwlaDDbIDG0TGf6ieXU/rzT/vJAyJYIjBCKbEDRLFgNTMYh+92QMQsC3q2O7LHPq 4BEnrYSZRyw5BTECCNOScOz8YkxZvLjWY9SMnY1ORjyWRA3fsxh3JroEuiaC4Q9ppqBu FAMBMZqRXgV077yNlT2OZ3qSVKd6cr8jeFxbzObkBK2mXDQPCsz91pBJNhDdp80iRGBP bjB8P+jpEghYzJfVr7KSxUHRgtoEMzdk9oHJ6dcNZJcfj7UpwwFW0fRKrBo2Z9cXUNdG x3AOwD0Y3PqUA/L7jOsNf550FYnk7npJ3jLpTEf4XoSB/5ylJcgGin82W1mc1ndncxpV PXYQ== 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=GLJm5hNEigx1oy1r/uy/2EeTSOyWf03jPlIDuqIQCAw=; b=NuV8GdFikGa1saxv2B7w2yhPijqcemJRxHgGpydOK+65GALFGOkl5CX6sEWv4zahw+ fim7UxufuGdZQRREDqPuZaNE8xSyLQzk9ktj48Nf0Rkk4ki7AXfZ7th6NwnXGUC4X59H Ilyr8/++TBV9KZniqpIQzPPy2PKdVLf7oy0uQ2+5X4zdoYHTr0bGYxaQNvpPepRL+9MK 4MR9rc0AmMzvs26vXNgQ4PFNf6PTddElXTVJl5p7d/76NAIYN8XFr8LpqKWRps+vRFit 4TfhSpqENKaQydLTkuBVOrm6XWhjdUEkbH/yq/0Z9z5lb6MldG8aMaHFADmI8JPXErmC hlBw== X-Gm-Message-State: ALKqPwff1uyZykIaZIaV9o38EmVfTUP9h0OGuzG+BD8lAqem/P91gCRW GjSdOXDPBE6fJpv+x5VgX3xkRwJ7hZM= X-Google-Smtp-Source: AB8JxZqXgxnNO0+wux4eYD6AhMaLHURlnO+4rPzfIAKjoTEs3wUY1UBZ/IZGqvR23Ncv59xuoJLSHw== X-Received: by 2002:a65:4d8e:: with SMTP id p14-v6mr473146pgq.296.1527034619995; Tue, 22 May 2018 17:16:59 -0700 (PDT) Received: from localhost.localdomain (122-58-167-22-fibre.bb.spark.co.nz. [122.58.167.22]) by smtp.gmail.com with ESMTPSA id j1-v6sm28935626pfh.95.2018.05.22.17.16.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 May 2018 17:16:59 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Wed, 23 May 2018 12:14:51 +1200 Message-Id: <1527034517-7851-5-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1527034517-7851-1-git-send-email-mjc@sifive.com> References: <1527034517-7851-1-git-send-email-mjc@sifive.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::234 Subject: [Qemu-devel] [PATCH v1 04/30] RISC-V: Simplify riscv_cpu_local_irqs_pending 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: Sagar Karandikar , Bastian Koppelmann , Palmer Dabbelt , Michael Clark , Alistair Francis , patches@groups.riscv.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This commit is intended to improve readability. There is no change to the logic. Cc: Sagar Karandikar Cc: Bastian Koppelmann Cc: Palmer Dabbelt Cc: Alistair Francis Signed-off-by: Michael Clark Reviewed-by: Alistair Francis Reviewed-by: Richard Henderson --- target/riscv/helper.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/target/riscv/helper.c b/target/riscv/helper.c index 3b57e1360549..47d116e9c13f 100644 --- a/target/riscv/helper.c +++ b/target/riscv/helper.c @@ -35,28 +35,18 @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) } #ifndef CONFIG_USER_ONLY -/* - * Return RISC-V IRQ number if an interrupt should be taken, else -1. - * Used in cpu-exec.c - * - * Adapted from Spike's processor_t::take_interrupt() - */ -static int riscv_cpu_hw_interrupts_pending(CPURISCVState *env) +static int riscv_cpu_local_irq_pending(CPURISCVState *env) { - target_ulong pending_interrupts = atomic_read(&env->mip) & env->mie; - - target_ulong mie = get_field(env->mstatus, MSTATUS_MIE); - target_ulong m_enabled = env->priv < PRV_M || (env->priv == PRV_M && mie); - target_ulong enabled_interrupts = pending_interrupts & - ~env->mideleg & -m_enabled; - - target_ulong sie = get_field(env->mstatus, MSTATUS_SIE); - target_ulong s_enabled = env->priv < PRV_S || (env->priv == PRV_S && sie); - enabled_interrupts |= pending_interrupts & env->mideleg & - -s_enabled; - - if (enabled_interrupts) { - return ctz64(enabled_interrupts); /* since non-zero */ + target_ulong mstatus_mie = get_field(env->mstatus, MSTATUS_MIE); + target_ulong mstatus_sie = get_field(env->mstatus, MSTATUS_SIE); + target_ulong pending = atomic_read(&env->mip) & env->mie; + target_ulong mie = env->priv < PRV_M || (env->priv == PRV_M && mstatus_mie); + target_ulong sie = env->priv < PRV_S || (env->priv == PRV_S && mstatus_sie); + target_ulong irqs = (pending & ~env->mideleg & -mie) | + (pending & env->mideleg & -sie); + + if (irqs) { + return ctz64(irqs); /* since non-zero */ } else { return EXCP_NONE; /* indicates no pending interrupt */ } @@ -69,7 +59,7 @@ bool riscv_cpu_exec_interrupt(CPUState *cs, int interrupt_request) if (interrupt_request & CPU_INTERRUPT_HARD) { RISCVCPU *cpu = RISCV_CPU(cs); CPURISCVState *env = &cpu->env; - int interruptno = riscv_cpu_hw_interrupts_pending(env); + int interruptno = riscv_cpu_local_irq_pending(env); if (interruptno >= 0) { cs->exception_index = RISCV_EXCP_INT_FLAG | interruptno; riscv_cpu_do_interrupt(cs);