Patchwork target-mips: fix for incorrect multiplication with MULQ_S.PH

login
register
mail settings
Submitter Petar Jovanovic
Date Feb. 6, 2013, 5:05 p.m.
Message ID <1360170325-3218-1-git-send-email-petar.jovanovic@rt-rk.com>
Download mbox | patch
Permalink /patch/218695/
State New
Headers show

Comments

Petar Jovanovic - Feb. 6, 2013, 5:05 p.m.
From: Petar Jovanovic <petarj@mips.com>

The change corrects sign-related issue with MULQ_S.PH. It also includes
extension to the already existing test which will trigger the issue.

Signed-off-by: Petar Jovanovic <petarj@mips.com>
---
 target-mips/dsp_helper.c                |    2 +-
 tests/tcg/mips/mips32-dspr2/mulq_s_ph.c |   15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
Aurelien Jarno - Feb. 23, 2013, 10:54 p.m.
On Wed, Feb 06, 2013 at 06:05:25PM +0100, Petar Jovanovic wrote:
> From: Petar Jovanovic <petarj@mips.com>
> 
> The change corrects sign-related issue with MULQ_S.PH. It also includes
> extension to the already existing test which will trigger the issue.
> 
> Signed-off-by: Petar Jovanovic <petarj@mips.com>
> ---
>  target-mips/dsp_helper.c                |    2 +-
>  tests/tcg/mips/mips32-dspr2/mulq_s_ph.c |   15 +++++++++++++++
>  2 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/target-mips/dsp_helper.c b/target-mips/dsp_helper.c
> index 96cb044..6781da8 100644
> --- a/target-mips/dsp_helper.c
> +++ b/target-mips/dsp_helper.c
> @@ -652,7 +652,7 @@ static inline int32_t mipsdsp_sat16_mul_q15_q15(uint16_t a, uint16_t b,
>          temp = 0x7FFF0000;
>          set_DSPControl_overflow_flag(1, 21, env);
>      } else {
> -        temp = ((uint32_t)a * (uint32_t)b);
> +        temp = (int16_t)a * (int16_t)b;
>          temp = temp << 1;
>      }
>  
> diff --git a/tests/tcg/mips/mips32-dspr2/mulq_s_ph.c b/tests/tcg/mips/mips32-dspr2/mulq_s_ph.c
> index d0f7674..00e0155 100644
> --- a/tests/tcg/mips/mips32-dspr2/mulq_s_ph.c
> +++ b/tests/tcg/mips/mips32-dspr2/mulq_s_ph.c
> @@ -6,6 +6,21 @@ int main()
>      int rd, rs, rt, dsp;
>      int result, resultdsp;
>  
> +    rs = 0x80000000;
> +    rt = 0x0ffc0000;
> +    result = 0xF0040000;
> +    resultdsp = 0;
> +
> +    __asm
> +        ("mulq_s.ph %0, %2, %3\n\t"
> +         "rddsp %1\n\t"
> +         : "=r"(rd), "=r"(dsp)
> +         : "r"(rs), "r"(rt)
> +        );
> +    dsp = (dsp >> 21) & 0x01;
> +    assert(rd  == result);
> +    assert(dsp == resultdsp);
> +
>      rs = 0x80001234;
>      rt = 0x80004321;
>      result = 0x7FFF098B;

Thanks, applied.

Patch

diff --git a/target-mips/dsp_helper.c b/target-mips/dsp_helper.c
index 96cb044..6781da8 100644
--- a/target-mips/dsp_helper.c
+++ b/target-mips/dsp_helper.c
@@ -652,7 +652,7 @@  static inline int32_t mipsdsp_sat16_mul_q15_q15(uint16_t a, uint16_t b,
         temp = 0x7FFF0000;
         set_DSPControl_overflow_flag(1, 21, env);
     } else {
-        temp = ((uint32_t)a * (uint32_t)b);
+        temp = (int16_t)a * (int16_t)b;
         temp = temp << 1;
     }
 
diff --git a/tests/tcg/mips/mips32-dspr2/mulq_s_ph.c b/tests/tcg/mips/mips32-dspr2/mulq_s_ph.c
index d0f7674..00e0155 100644
--- a/tests/tcg/mips/mips32-dspr2/mulq_s_ph.c
+++ b/tests/tcg/mips/mips32-dspr2/mulq_s_ph.c
@@ -6,6 +6,21 @@  int main()
     int rd, rs, rt, dsp;
     int result, resultdsp;
 
+    rs = 0x80000000;
+    rt = 0x0ffc0000;
+    result = 0xF0040000;
+    resultdsp = 0;
+
+    __asm
+        ("mulq_s.ph %0, %2, %3\n\t"
+         "rddsp %1\n\t"
+         : "=r"(rd), "=r"(dsp)
+         : "r"(rs), "r"(rt)
+        );
+    dsp = (dsp >> 21) & 0x01;
+    assert(rd  == result);
+    assert(dsp == resultdsp);
+
     rs = 0x80001234;
     rt = 0x80004321;
     result = 0x7FFF098B;