Received: from eggs.gnu.org ([208.118.235.92]:37185) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UbsjG-0005rm-CU for qemu-devel@nongnu.org; Mon, 13 May 2013 09:23:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UbsjA-0001Bs-I7 for qemu-devel@nongnu.org; Mon, 13 May 2013 09:23:50 -0400 Received: from mail.rt-rk.ftn.uns.ac.rs ([147.91.177.140]:34021 helo=mail.rt-rk.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UbsjA-000191-Bh for qemu-devel@nongnu.org; Mon, 13 May 2013 09:23:44 -0400 Received: from mail.rt-rk.com (mail.localdomain [127.0.0.1]) by mail.rt-rk.com (Postfix) with SMTP id C790625B32C for ; Mon, 13 May 2013 15:23:41 +0200 (CEST) From: Petar Jovanovic Date: Mon, 13 May 2013 15:20:26 +0200 Message-Id: <1368451227-6973-1-git-send-email-petar.jovanovic@rt-rk.com> Subject: [Qemu-devel] [PATCH 1/2] target-mips: fix incorrect behaviour for EXTP List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: petar.jovanovic@imgtec.com, aurelien@aurel32.net From: Petar Jovanovic The mask for EXTP instruction when size=31 has not been correctly calculated. The test (mips32-dsp/extp.c) has been extended to include the case that triggers the issue. Signed-off-by: Petar Jovanovic --- target-mips/dsp_helper.c | 3 +-- tests/tcg/mips/mips32-dsp/extp.c | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/target-mips/dsp_helper.c b/target-mips/dsp_helper.c index 9212789..a55f866 100644 --- a/target-mips/dsp_helper.c +++ b/target-mips/dsp_helper.c @@ -3415,8 +3415,7 @@ target_ulong helper_extp(target_ulong ac, target_ulong size, CPUMIPSState *env) if (sub >= -1) { acc = ((uint64_t)env->active_tc.HI[ac] << 32) | ((uint64_t)env->active_tc.LO[ac] & MIPSDSP_LLO); - temp = (acc >> (start_pos - size)) & - (((uint32_t)0x01 << (size + 1)) - 1); + temp = (acc >> (start_pos - size)) & (~0U >> (31 - size)); set_DSPControl_efi(0, env); } else { set_DSPControl_efi(1, env); diff --git a/tests/tcg/mips/mips32-dsp/extp.c b/tests/tcg/mips/mips32-dsp/extp.c index 21a67af..b18bdb3 100644 --- a/tests/tcg/mips/mips32-dsp/extp.c +++ b/tests/tcg/mips/mips32-dsp/extp.c @@ -40,5 +40,23 @@ int main() dsp = (dsp >> 14) & 0x01; assert(dsp == 1); + ach = 0; + acl = 0x80000001; + dsp = 0x1F; + result = 0x80000001; + + __asm + ("wrdsp %1\n\t" + "mthi %2, $ac2\n\t" + "mtlo %3, $ac2\n\t" + "extp %0, $ac2, 0x1F\n\t" + "rddsp %1\n\t" + : "=r"(rt), "+r"(dsp) + : "r"(ach), "r"(acl) + ); + dsp = (dsp >> 14) & 0x01; + assert(dsp == 0); + assert(result == rt); + return 0; } -- 1.7.9.5