* [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
@ 2013-05-22 13:35 Petar Jovanovic
2013-06-09 2:34 ` Petar Jovanovic
0 siblings, 1 reply; 8+ messages in thread
From: Petar Jovanovic @ 2013-05-22 13:35 UTC (permalink / raw)
To: qemu-devel; +Cc: petar.jovanovic, aurelien
From: Petar Jovanovic <petar.jovanovic@imgtec.com>
This change corrects rounding and saturation of Q31 fractional value in
mipsdsp_trunc16_sat16_round(). Overflow detection was incorrect for the
corner case for PRECRQ_RS.PH, and this test case is also part of the change.
Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com>
---
target-mips/dsp_helper.c | 12 ++++++------
tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c | 24 ++++++++++++++++++++----
2 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/target-mips/dsp_helper.c b/target-mips/dsp_helper.c
index 4116de9..306b332 100644
--- a/target-mips/dsp_helper.c
+++ b/target-mips/dsp_helper.c
@@ -648,16 +648,16 @@ static inline int32_t mipsdsp_sat16_mul_q15_q15(uint16_t a, uint16_t b,
static inline uint16_t mipsdsp_trunc16_sat16_round(int32_t a,
CPUMIPSState *env)
{
- int64_t temp;
-
- temp = (int32_t)a + 0x00008000;
+ uint16_t temp;
- if (a > (int)0x7fff8000) {
- temp = 0x7FFFFFFF;
+ if (a > 0x7FFF7FFF) {
+ temp = 0x7FFF;
set_DSPControl_overflow_flag(1, 22, env);
+ } else {
+ temp = ((a + 0x8000) >> 16) & 0xFFFF;
}
- return (temp >> 16) & 0xFFFF;
+ return temp;
}
static inline uint8_t mipsdsp_sat8_reduce_precision(uint16_t a,
diff --git a/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c b/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
index 3535b37..da6845b 100644
--- a/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
+++ b/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
@@ -12,18 +12,34 @@ int main()
result = 0x12348765;
__asm
- ("precrq_rs.ph.w %0, %1, %2\n\t"
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %1, %2\n\t"
: "=r"(rd)
: "r"(rs), "r"(rt)
);
assert(result == rd);
- rs = 0x7fffC678;
+ rs = 0x7FFFC678;
rt = 0x865432A0;
- result = 0x7fff8654;
+ result = 0x7FFF8654;
__asm
- ("precrq_rs.ph.w %0, %2, %3\n\t"
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %2, %3\n\t"
+ "rddsp %1\n\t"
+ : "=r"(rd), "=r"(dsp)
+ : "r"(rs), "r"(rt)
+ );
+ assert(((dsp >> 22) & 0x01) == 1);
+ assert(result == rd);
+
+ rs = 0xBEEFFEED;
+ rt = 0x7FFF8000;
+ result = 0xBEF07FFF;
+
+ __asm
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %2, %3\n\t"
"rddsp %1\n\t"
: "=r"(rd), "=r"(dsp)
: "r"(rs), "r"(rt)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
2013-05-22 13:35 [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round Petar Jovanovic
@ 2013-06-09 2:34 ` Petar Jovanovic
2013-06-17 22:39 ` Petar Jovanovic
0 siblings, 1 reply; 8+ messages in thread
From: Petar Jovanovic @ 2013-06-09 2:34 UTC (permalink / raw)
To: Petar Jovanovic, qemu-devel@nongnu.org; +Cc: aurelien@aurel32.net
ping
http://patchwork.ozlabs.org/patch/245624/
________________________________________
From: Petar Jovanovic [petar.jovanovic@rt-rk.com]
Sent: Wednesday, May 22, 2013 3:35 PM
To: qemu-devel@nongnu.org
Cc: Petar Jovanovic; aurelien@aurel32.net
Subject: [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
From: Petar Jovanovic <petar.jovanovic@imgtec.com>
This change corrects rounding and saturation of Q31 fractional value in
mipsdsp_trunc16_sat16_round(). Overflow detection was incorrect for the
corner case for PRECRQ_RS.PH, and this test case is also part of the change.
Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com>
---
target-mips/dsp_helper.c | 12 ++++++------
tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c | 24 ++++++++++++++++++++----
2 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/target-mips/dsp_helper.c b/target-mips/dsp_helper.c
index 4116de9..306b332 100644
--- a/target-mips/dsp_helper.c
+++ b/target-mips/dsp_helper.c
@@ -648,16 +648,16 @@ static inline int32_t mipsdsp_sat16_mul_q15_q15(uint16_t a, uint16_t b,
static inline uint16_t mipsdsp_trunc16_sat16_round(int32_t a,
CPUMIPSState *env)
{
- int64_t temp;
-
- temp = (int32_t)a + 0x00008000;
+ uint16_t temp;
- if (a > (int)0x7fff8000) {
- temp = 0x7FFFFFFF;
+ if (a > 0x7FFF7FFF) {
+ temp = 0x7FFF;
set_DSPControl_overflow_flag(1, 22, env);
+ } else {
+ temp = ((a + 0x8000) >> 16) & 0xFFFF;
}
- return (temp >> 16) & 0xFFFF;
+ return temp;
}
static inline uint8_t mipsdsp_sat8_reduce_precision(uint16_t a,
diff --git a/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c b/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
index 3535b37..da6845b 100644
--- a/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
+++ b/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
@@ -12,18 +12,34 @@ int main()
result = 0x12348765;
__asm
- ("precrq_rs.ph.w %0, %1, %2\n\t"
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %1, %2\n\t"
: "=r"(rd)
: "r"(rs), "r"(rt)
);
assert(result == rd);
- rs = 0x7fffC678;
+ rs = 0x7FFFC678;
rt = 0x865432A0;
- result = 0x7fff8654;
+ result = 0x7FFF8654;
__asm
- ("precrq_rs.ph.w %0, %2, %3\n\t"
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %2, %3\n\t"
+ "rddsp %1\n\t"
+ : "=r"(rd), "=r"(dsp)
+ : "r"(rs), "r"(rt)
+ );
+ assert(((dsp >> 22) & 0x01) == 1);
+ assert(result == rd);
+
+ rs = 0xBEEFFEED;
+ rt = 0x7FFF8000;
+ result = 0xBEF07FFF;
+
+ __asm
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %2, %3\n\t"
"rddsp %1\n\t"
: "=r"(rd), "=r"(dsp)
: "r"(rs), "r"(rt)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
2013-06-09 2:34 ` Petar Jovanovic
@ 2013-06-17 22:39 ` Petar Jovanovic
2013-06-25 10:18 ` Petar Jovanovic
2013-06-27 18:20 ` Richard Henderson
0 siblings, 2 replies; 8+ messages in thread
From: Petar Jovanovic @ 2013-06-17 22:39 UTC (permalink / raw)
To: Petar Jovanovic, qemu-devel@nongnu.org; +Cc: aurelien@aurel32.net
ping
________________________________________
From: Petar Jovanovic
Sent: Sunday, June 09, 2013 4:34 AM
To: Petar Jovanovic; qemu-devel@nongnu.org
Cc: aurelien@aurel32.net
Subject: RE: [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
ping
http://patchwork.ozlabs.org/patch/245624/
________________________________________
From: Petar Jovanovic [petar.jovanovic@rt-rk.com]
Sent: Wednesday, May 22, 2013 3:35 PM
To: qemu-devel@nongnu.org
Cc: Petar Jovanovic; aurelien@aurel32.net
Subject: [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
From: Petar Jovanovic <petar.jovanovic@imgtec.com>
This change corrects rounding and saturation of Q31 fractional value in
mipsdsp_trunc16_sat16_round(). Overflow detection was incorrect for the
corner case for PRECRQ_RS.PH, and this test case is also part of the change.
Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com>
---
target-mips/dsp_helper.c | 12 ++++++------
tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c | 24 ++++++++++++++++++++----
2 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/target-mips/dsp_helper.c b/target-mips/dsp_helper.c
index 4116de9..306b332 100644
--- a/target-mips/dsp_helper.c
+++ b/target-mips/dsp_helper.c
@@ -648,16 +648,16 @@ static inline int32_t mipsdsp_sat16_mul_q15_q15(uint16_t a, uint16_t b,
static inline uint16_t mipsdsp_trunc16_sat16_round(int32_t a,
CPUMIPSState *env)
{
- int64_t temp;
-
- temp = (int32_t)a + 0x00008000;
+ uint16_t temp;
- if (a > (int)0x7fff8000) {
- temp = 0x7FFFFFFF;
+ if (a > 0x7FFF7FFF) {
+ temp = 0x7FFF;
set_DSPControl_overflow_flag(1, 22, env);
+ } else {
+ temp = ((a + 0x8000) >> 16) & 0xFFFF;
}
- return (temp >> 16) & 0xFFFF;
+ return temp;
}
static inline uint8_t mipsdsp_sat8_reduce_precision(uint16_t a,
diff --git a/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c b/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
index 3535b37..da6845b 100644
--- a/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
+++ b/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
@@ -12,18 +12,34 @@ int main()
result = 0x12348765;
__asm
- ("precrq_rs.ph.w %0, %1, %2\n\t"
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %1, %2\n\t"
: "=r"(rd)
: "r"(rs), "r"(rt)
);
assert(result == rd);
- rs = 0x7fffC678;
+ rs = 0x7FFFC678;
rt = 0x865432A0;
- result = 0x7fff8654;
+ result = 0x7FFF8654;
__asm
- ("precrq_rs.ph.w %0, %2, %3\n\t"
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %2, %3\n\t"
+ "rddsp %1\n\t"
+ : "=r"(rd), "=r"(dsp)
+ : "r"(rs), "r"(rt)
+ );
+ assert(((dsp >> 22) & 0x01) == 1);
+ assert(result == rd);
+
+ rs = 0xBEEFFEED;
+ rt = 0x7FFF8000;
+ result = 0xBEF07FFF;
+
+ __asm
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %2, %3\n\t"
"rddsp %1\n\t"
: "=r"(rd), "=r"(dsp)
: "r"(rs), "r"(rt)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
2013-06-17 22:39 ` Petar Jovanovic
@ 2013-06-25 10:18 ` Petar Jovanovic
2013-06-27 18:20 ` Richard Henderson
1 sibling, 0 replies; 8+ messages in thread
From: Petar Jovanovic @ 2013-06-25 10:18 UTC (permalink / raw)
To: Petar Jovanovic, qemu-devel@nongnu.org; +Cc: aurelien@aurel32.net
ping
________________________________________
From: Petar Jovanovic
Sent: Tuesday, June 18, 2013 12:39 AM
To: Petar Jovanovic; qemu-devel@nongnu.org
Cc: aurelien@aurel32.net
Subject: RE: [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
ping
________________________________________
From: Petar Jovanovic
Sent: Sunday, June 09, 2013 4:34 AM
To: Petar Jovanovic; qemu-devel@nongnu.org
Cc: aurelien@aurel32.net
Subject: RE: [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
ping
http://patchwork.ozlabs.org/patch/245624/
________________________________________
From: Petar Jovanovic [petar.jovanovic@rt-rk.com]
Sent: Wednesday, May 22, 2013 3:35 PM
To: qemu-devel@nongnu.org
Cc: Petar Jovanovic; aurelien@aurel32.net
Subject: [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
From: Petar Jovanovic <petar.jovanovic@imgtec.com>
This change corrects rounding and saturation of Q31 fractional value in
mipsdsp_trunc16_sat16_round(). Overflow detection was incorrect for the
corner case for PRECRQ_RS.PH, and this test case is also part of the change.
Signed-off-by: Petar Jovanovic <petar.jovanovic@imgtec.com>
---
target-mips/dsp_helper.c | 12 ++++++------
tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c | 24 ++++++++++++++++++++----
2 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/target-mips/dsp_helper.c b/target-mips/dsp_helper.c
index 4116de9..306b332 100644
--- a/target-mips/dsp_helper.c
+++ b/target-mips/dsp_helper.c
@@ -648,16 +648,16 @@ static inline int32_t mipsdsp_sat16_mul_q15_q15(uint16_t a, uint16_t b,
static inline uint16_t mipsdsp_trunc16_sat16_round(int32_t a,
CPUMIPSState *env)
{
- int64_t temp;
-
- temp = (int32_t)a + 0x00008000;
+ uint16_t temp;
- if (a > (int)0x7fff8000) {
- temp = 0x7FFFFFFF;
+ if (a > 0x7FFF7FFF) {
+ temp = 0x7FFF;
set_DSPControl_overflow_flag(1, 22, env);
+ } else {
+ temp = ((a + 0x8000) >> 16) & 0xFFFF;
}
- return (temp >> 16) & 0xFFFF;
+ return temp;
}
static inline uint8_t mipsdsp_sat8_reduce_precision(uint16_t a,
diff --git a/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c b/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
index 3535b37..da6845b 100644
--- a/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
+++ b/tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c
@@ -12,18 +12,34 @@ int main()
result = 0x12348765;
__asm
- ("precrq_rs.ph.w %0, %1, %2\n\t"
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %1, %2\n\t"
: "=r"(rd)
: "r"(rs), "r"(rt)
);
assert(result == rd);
- rs = 0x7fffC678;
+ rs = 0x7FFFC678;
rt = 0x865432A0;
- result = 0x7fff8654;
+ result = 0x7FFF8654;
__asm
- ("precrq_rs.ph.w %0, %2, %3\n\t"
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %2, %3\n\t"
+ "rddsp %1\n\t"
+ : "=r"(rd), "=r"(dsp)
+ : "r"(rs), "r"(rt)
+ );
+ assert(((dsp >> 22) & 0x01) == 1);
+ assert(result == rd);
+
+ rs = 0xBEEFFEED;
+ rt = 0x7FFF8000;
+ result = 0xBEF07FFF;
+
+ __asm
+ ("wrdsp $0\n\t"
+ "precrq_rs.ph.w %0, %2, %3\n\t"
"rddsp %1\n\t"
: "=r"(rd), "=r"(dsp)
: "r"(rs), "r"(rt)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
2013-06-17 22:39 ` Petar Jovanovic
2013-06-25 10:18 ` Petar Jovanovic
@ 2013-06-27 18:20 ` Richard Henderson
2013-06-27 21:48 ` Petar Jovanovic
1 sibling, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2013-06-27 18:20 UTC (permalink / raw)
To: Petar Jovanovic
Cc: Petar Jovanovic, aurelien@aurel32.net, qemu-devel@nongnu.org
On 06/17/2013 03:39 PM, Petar Jovanovic wrote:
> - int64_t temp;
> -
> - temp = (int32_t)a + 0x00008000;
> + uint16_t temp;
>
> - if (a > (int)0x7fff8000) {
> - temp = 0x7FFFFFFF;
> + if (a > 0x7FFF7FFF) {
> + temp = 0x7FFF;
> set_DSPControl_overflow_flag(1, 22, env);
> + } else {
> + temp = ((a + 0x8000) >> 16) & 0xFFFF;
This doesn't look right either, as it doesn't properly check for overflow of
negative values. I'd feel better if we implement this function exactly as
documented, modulo actually using 64-bit arithmetic. How about
int32_t temp;
/* Shift right by one, to avoid needing 64-bit arithmetic. As this A is
signed, this creates the copy of the sign bit as documented. */
a >>= 1;
temp = a + 0x4000;
/* Compare temp{31} with temp{30} by xoring into the sign bit. */
if ((temp ^ (temp << 1)) < 0) {
set_DSPControl_overflow_flag(1, 22, env);
return 0x7fff;
}
return temp >> 15;
r~
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
2013-06-27 18:20 ` Richard Henderson
@ 2013-06-27 21:48 ` Petar Jovanovic
2013-06-28 17:40 ` Richard Henderson
0 siblings, 1 reply; 8+ messages in thread
From: Petar Jovanovic @ 2013-06-27 21:48 UTC (permalink / raw)
To: Richard Henderson
Cc: Petar Jovanovic, aurelien@aurel32.net, qemu-devel@nongnu.org
________________________________________
From: Richard Henderson [rth7680@gmail.com] on behalf of Richard Henderson [rth@twiddle.net]
Sent: Thursday, June 27, 2013 8:20 PM
To: Petar Jovanovic
Cc: Petar Jovanovic; qemu-devel@nongnu.org; aurelien@aurel32.net
Subject: Re: [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
On 06/17/2013 03:39 PM, Petar Jovanovic wrote:
> - int64_t temp;
> -
> - temp = (int32_t)a + 0x00008000;
> + uint16_t temp;
>
> - if (a > (int)0x7fff8000) {
> - temp = 0x7FFFFFFF;
> + if (a > 0x7FFF7FFF) {
> + temp = 0x7FFF;
> set_DSPControl_overflow_flag(1, 22, env);
> + } else {
> + temp = ((a + 0x8000) >> 16) & 0xFFFF;
> This doesn't look right either, as it doesn't properly check for overflow of
> negative values.
What overflow of negative values?
Can you please list the values for which the result would not be correct?
Thanks.
Petar
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
2013-06-27 21:48 ` Petar Jovanovic
@ 2013-06-28 17:40 ` Richard Henderson
2013-06-30 23:53 ` Petar Jovanovic
0 siblings, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2013-06-28 17:40 UTC (permalink / raw)
To: Petar Jovanovic
Cc: Petar Jovanovic, aurelien@aurel32.net, qemu-devel@nongnu.org
On 06/27/2013 02:48 PM, Petar Jovanovic wrote:
>> This doesn't look right either, as it doesn't properly check for overflow of
>> negative values.
>
> What overflow of negative values?
> Can you please list the values for which the result would not be correct?
Hmm, I suppose since we're always rounding to +INF, we can't
overflow in the negative direction. The patch could use some
commentary along those lines...
r~
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
2013-06-28 17:40 ` Richard Henderson
@ 2013-06-30 23:53 ` Petar Jovanovic
0 siblings, 0 replies; 8+ messages in thread
From: Petar Jovanovic @ 2013-06-30 23:53 UTC (permalink / raw)
To: Richard Henderson
Cc: Petar Jovanovic, aurelien@aurel32.net, qemu-devel@nongnu.org
________________________________________
From: Richard Henderson [rth7680@gmail.com] on behalf of Richard Henderson [rth@twiddle.net]
Sent: Friday, June 28, 2013 7:40 PM
To: Petar Jovanovic
Cc: Petar Jovanovic; qemu-devel@nongnu.org; aurelien@aurel32.net
Subject: Re: [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round
On 06/27/2013 02:48 PM, Petar Jovanovic wrote:
>> This doesn't look right either, as it doesn't properly check for overflow of
>> negative values.
>
> What overflow of negative values?
> Can you please list the values for which the result would not be correct?
> Hmm, I suppose since we're always rounding to +INF, we can't
> overflow in the negative direction. The patch could use some
> commentary along those lines...
> r~
Ok, I will add comments in the code and resubmit the patch.
Petar
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-06-30 23:53 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-22 13:35 [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round Petar Jovanovic
2013-06-09 2:34 ` Petar Jovanovic
2013-06-17 22:39 ` Petar Jovanovic
2013-06-25 10:18 ` Petar Jovanovic
2013-06-27 18:20 ` Richard Henderson
2013-06-27 21:48 ` Petar Jovanovic
2013-06-28 17:40 ` Richard Henderson
2013-06-30 23:53 ` Petar Jovanovic
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).