From patchwork Wed Apr 25 23:45:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Clark X-Patchwork-Id: 10364387 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 17263602DC for ; Wed, 25 Apr 2018 23:57:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01D2A28E38 for ; Wed, 25 Apr 2018 23:57:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA8A028FC2; Wed, 25 Apr 2018 23:57:20 +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 6646228E38 for ; Wed, 25 Apr 2018 23:57:20 +0000 (UTC) Received: from localhost ([::1]:39599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBUHn-0004lG-Lk for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 Apr 2018 19:57:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBU9I-0005S5-OZ for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:48:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBU9H-0005NF-QX for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:48:32 -0400 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:35088) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fBU9H-0005Mv-Jy for qemu-devel@nongnu.org; Wed, 25 Apr 2018 19:48:31 -0400 Received: by mail-pf0-x241.google.com with SMTP id j5so16588719pfh.2 for ; Wed, 25 Apr 2018 16:48:31 -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=3Yv3tu741CryHb9N90JREQ7Fi95HiAAmz4JhG1xWAtM=; b=GeAb8SLLhO6PyY70abEoITOoI5uDEnYSYWllbMZmdJxHC1b9we7/rRxZgZRRFKLnVD /2UZ4DZfR3Eh/m6qe+0tD+GVcgycL5kTBwW63ORJ8NwFVs8fQ9TlpFKjZw7s948Do6EP 12L9hgVCJLLjHYrSq6GgyfVmod3k9+10oqDt3M8jDQqPybKc6pCCZbyeklC//G/CFFpR aQkzghuG1OXLRXU4kzbqXAHZuMWUiURD/ppj1r0e6Tqc47akqgkZuKioALiz+kZfIJ91 cxLJ195mySRb4S7Ch9Cj3JowSxBz6RB5lYKKZdfkQfs/u7uiS9h4WqH1HQiFzdwnWSLX iBUg== 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=3Yv3tu741CryHb9N90JREQ7Fi95HiAAmz4JhG1xWAtM=; b=Cck/SuBcWC7q1LL/NHadAV34/0CcFv5dWQNLv7Zn+fGSMQggJC+dcTMQq5earcLw29 0m/Oc9RFKKqIvdodptJylTr5QkfFDitCAN08zJRzV7CsNTPIeRJhgt/GDWdZrY0PavL3 vUxEJ8dWBDMDhz/z1vH4WDfXN4mCnk42GZ5v7hhYkfFYxclG07JA1seVwQJnm36WX7pp rt487p395rY3kodm2aHwkEz2L24wQkL+fXqch8WjBoh3eVNXjBk5l8xvuaFHHjONWL3l mN0YqrcI0+O+GgorLNEOoHwyvK2J1fOMzzcB/HAV0RaTnhlB2lZ8qIo6qx1YJOYtF9RN kpHQ== X-Gm-Message-State: ALQs6tBZwACONsZlqpztXzljGPducudnVxK4KlBF3swLOFvdXct/Dwlv 6cXgPH/1d8HGtjZDLbK1AD53pQ8hugU= X-Google-Smtp-Source: AIpwx4+BmrM/L6U+f9Sm/U/4DyzfSv/JEj7fKUTqNwVJJdyXiRizai7BALf+Z48YliAcYZ3//1op4w== X-Received: by 2002:a17:902:6113:: with SMTP id t19-v6mr30649368plj.372.1524700110624; Wed, 25 Apr 2018 16:48:30 -0700 (PDT) Received: from localhost.localdomain (122-58-167-38-fibre.bb.spark.co.nz. [122.58.167.38]) by smtp.gmail.com with ESMTPSA id e10sm29577549pfn.67.2018.04.25.16.48.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Apr 2018 16:48:30 -0700 (PDT) From: Michael Clark To: qemu-devel@nongnu.org Date: Thu, 26 Apr 2018 11:45:26 +1200 Message-Id: <1524699938-6764-24-git-send-email-mjc@sifive.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1524699938-6764-1-git-send-email-mjc@sifive.com> References: <1524699938-6764-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:c00::241 Subject: [Qemu-devel] [PATCH v8 23/35] 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 --- 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 3b57e13..47d116e 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);