[PATCH v2 3/3] target/nios2: Use deposit32() to update ipending register

Peter Maydell posted 3 patches 5 years, 2 months ago
Maintainers: Marek Vasut <marex@denx.de>, Chris Wulff <crwulff@gmail.com>
[PATCH v2 3/3] target/nios2: Use deposit32() to update ipending register
Posted by Peter Maydell 5 years, 2 months ago
In nios2_cpu_set_irq(), use deposit32() rather than raw shift-and-mask
operations to set the appropriate bit in the ipending register.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
In patch 1 I left the code for this identical to the old
code from nios2_iic.c for clarity of that refactoring,
but deposit32() is a clearer way to write it.
---
 target/nios2/cpu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/target/nios2/cpu.c b/target/nios2/cpu.c
index 52ebda89ca7..58688e1623a 100644
--- a/target/nios2/cpu.c
+++ b/target/nios2/cpu.c
@@ -71,8 +71,7 @@ static void nios2_cpu_set_irq(void *opaque, int irq, int level)
     CPUNios2State *env = &cpu->env;
     CPUState *cs = CPU(cpu);
 
-    env->regs[CR_IPENDING] &= ~(1 << irq);
-    env->regs[CR_IPENDING] |= !!level << irq;
+    env->regs[CR_IPENDING] = deposit32(env->regs[CR_IPENDING], irq, 1, !!level);
 
     env->irq_pending = env->regs[CR_IPENDING] & env->regs[CR_IENABLE];
 
-- 
2.20.1


Re: [PATCH v2 3/3] target/nios2: Use deposit32() to update ipending register
Posted by Philippe Mathieu-Daudé 5 years, 2 months ago
On 11/29/20 6:40 PM, Peter Maydell wrote:
> In nios2_cpu_set_irq(), use deposit32() rather than raw shift-and-mask
> operations to set the appropriate bit in the ipending register.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> In patch 1 I left the code for this identical to the old
> code from nios2_iic.c for clarity of that refactoring,
> but deposit32() is a clearer way to write it.
> ---
>  target/nios2/cpu.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>