* [Qemu-devel] [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
@ 2013-06-30 23:54 Petar Jovanovic
2013-07-01 14:52 ` Richard Henderson
2013-07-28 22:28 ` Aurelien Jarno
0 siblings, 2 replies; 7+ messages in thread
From: Petar Jovanovic @ 2013-06-30 23:54 UTC (permalink / raw)
To: qemu-devel; +Cc: petar.jovanovic, aurelien, rth
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>
---
v2:
- added comments to the code
target-mips/dsp_helper.c | 16 +++++++++++-----
tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c | 24 ++++++++++++++++++++----
2 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/target-mips/dsp_helper.c b/target-mips/dsp_helper.c
index 4116de9..85950b3 100644
--- a/target-mips/dsp_helper.c
+++ b/target-mips/dsp_helper.c
@@ -648,16 +648,22 @@ 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;
+ uint16_t temp;
- temp = (int32_t)a + 0x00008000;
- if (a > (int)0x7fff8000) {
- temp = 0x7FFFFFFF;
+ /*
+ * The value 0x00008000 will be added to the input Q31 value, and the code
+ * needs to check if the addition causes an overflow. Since a positive value
+ * is added, overflow can happen in one direction only.
+ */
+ 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] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
2013-06-30 23:54 [Qemu-devel] [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round Petar Jovanovic
@ 2013-07-01 14:52 ` Richard Henderson
2013-07-08 9:14 ` Petar Jovanovic
2013-07-28 22:28 ` Aurelien Jarno
1 sibling, 1 reply; 7+ messages in thread
From: Richard Henderson @ 2013-07-01 14:52 UTC (permalink / raw)
To: Petar Jovanovic; +Cc: qemu-devel, aurelien, petar.jovanovic
On 06/30/2013 04:54 PM, Petar Jovanovic wrote:
> 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>
> ---
>
> v2:
>
> - added comments to the code
>
> target-mips/dsp_helper.c | 16 +++++++++++-----
> tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c | 24 ++++++++++++++++++++----
> 2 files changed, 31 insertions(+), 9 deletions(-)
Reviewed-by: Richard Henderson <rth@twiddle.net>
r~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
2013-07-01 14:52 ` Richard Henderson
@ 2013-07-08 9:14 ` Petar Jovanovic
2013-07-15 11:46 ` Petar Jovanovic
0 siblings, 1 reply; 7+ messages in thread
From: Petar Jovanovic @ 2013-07-08 9:14 UTC (permalink / raw)
To: Richard Henderson, Petar Jovanovic; +Cc: qemu-devel, aurelien
ping
http://patchwork.ozlabs.org/patch/255967/
________________________________________
From: Richard Henderson [rth7680@gmail.com] on behalf of Richard Henderson [rth@twiddle.net]
Sent: Monday, July 01, 2013 4:52 PM
To: Petar Jovanovic
Cc: qemu-devel@nongnu.org; Petar Jovanovic; aurelien@aurel32.net
Subject: Re: [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
On 06/30/2013 04:54 PM, Petar Jovanovic wrote:
> 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>
> ---
>
> v2:
>
> - added comments to the code
>
> target-mips/dsp_helper.c | 16 +++++++++++-----
> tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c | 24 ++++++++++++++++++++----
> 2 files changed, 31 insertions(+), 9 deletions(-)
Reviewed-by: Richard Henderson <rth@twiddle.net>
r~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
2013-07-08 9:14 ` Petar Jovanovic
@ 2013-07-15 11:46 ` Petar Jovanovic
2013-07-22 8:51 ` Petar Jovanovic
0 siblings, 1 reply; 7+ messages in thread
From: Petar Jovanovic @ 2013-07-15 11:46 UTC (permalink / raw)
To: Richard Henderson, Petar Jovanovic; +Cc: qemu-devel, aurelien
ping
________________________________________
From: Petar Jovanovic
Sent: Monday, July 08, 2013 11:14 AM
To: Richard Henderson; Petar Jovanovic
Cc: qemu-devel@nongnu.org; aurelien@aurel32.net
Subject: RE: [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
ping
http://patchwork.ozlabs.org/patch/255967/
________________________________________
From: Richard Henderson [rth7680@gmail.com] on behalf of Richard Henderson [rth@twiddle.net]
Sent: Monday, July 01, 2013 4:52 PM
To: Petar Jovanovic
Cc: qemu-devel@nongnu.org; Petar Jovanovic; aurelien@aurel32.net
Subject: Re: [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
On 06/30/2013 04:54 PM, Petar Jovanovic wrote:
> 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>
> ---
>
> v2:
>
> - added comments to the code
>
> target-mips/dsp_helper.c | 16 +++++++++++-----
> tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c | 24 ++++++++++++++++++++----
> 2 files changed, 31 insertions(+), 9 deletions(-)
Reviewed-by: Richard Henderson <rth@twiddle.net>
r~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
2013-07-15 11:46 ` Petar Jovanovic
@ 2013-07-22 8:51 ` Petar Jovanovic
2013-07-27 23:33 ` Petar Jovanovic
0 siblings, 1 reply; 7+ messages in thread
From: Petar Jovanovic @ 2013-07-22 8:51 UTC (permalink / raw)
To: Richard Henderson, Petar Jovanovic; +Cc: qemu-devel, aurelien
ping
________________________________________
From: Petar Jovanovic
Sent: Monday, July 15, 2013 1:46 PM
To: Richard Henderson; Petar Jovanovic
Cc: qemu-devel@nongnu.org; aurelien@aurel32.net
Subject: RE: [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
ping
________________________________________
From: Petar Jovanovic
Sent: Monday, July 08, 2013 11:14 AM
To: Richard Henderson; Petar Jovanovic
Cc: qemu-devel@nongnu.org; aurelien@aurel32.net
Subject: RE: [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
ping
http://patchwork.ozlabs.org/patch/255967/
________________________________________
From: Richard Henderson [rth7680@gmail.com] on behalf of Richard Henderson [rth@twiddle.net]
Sent: Monday, July 01, 2013 4:52 PM
To: Petar Jovanovic
Cc: qemu-devel@nongnu.org; Petar Jovanovic; aurelien@aurel32.net
Subject: Re: [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
On 06/30/2013 04:54 PM, Petar Jovanovic wrote:
> 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>
> ---
>
> v2:
>
> - added comments to the code
>
> target-mips/dsp_helper.c | 16 +++++++++++-----
> tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c | 24 ++++++++++++++++++++----
> 2 files changed, 31 insertions(+), 9 deletions(-)
Reviewed-by: Richard Henderson <rth@twiddle.net>
r~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
2013-07-22 8:51 ` Petar Jovanovic
@ 2013-07-27 23:33 ` Petar Jovanovic
0 siblings, 0 replies; 7+ messages in thread
From: Petar Jovanovic @ 2013-07-27 23:33 UTC (permalink / raw)
To: Richard Henderson, Petar Jovanovic; +Cc: qemu-devel, aurelien
ping
Can somebody submit these for 1.6?
Thank you.
Regards,
Petar
__________________________________
From: Petar Jovanovic
Sent: Monday, July 22, 2013 10:51 AM
To: Richard Henderson; Petar Jovanovic
Cc: qemu-devel@nongnu.org; aurelien@aurel32.net
Subject: RE: [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
ping
________________________________________
From: Petar Jovanovic
Sent: Monday, July 15, 2013 1:46 PM
To: Richard Henderson; Petar Jovanovic
Cc: qemu-devel@nongnu.org; aurelien@aurel32.net
Subject: RE: [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
ping
________________________________________
From: Petar Jovanovic
Sent: Monday, July 08, 2013 11:14 AM
To: Richard Henderson; Petar Jovanovic
Cc: qemu-devel@nongnu.org; aurelien@aurel32.net
Subject: RE: [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
ping
http://patchwork.ozlabs.org/patch/255967/
________________________________________
From: Richard Henderson [rth7680@gmail.com] on behalf of Richard Henderson [rth@twiddle.net]
Sent: Monday, July 01, 2013 4:52 PM
To: Petar Jovanovic
Cc: qemu-devel@nongnu.org; Petar Jovanovic; aurelien@aurel32.net
Subject: Re: [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
On 06/30/2013 04:54 PM, Petar Jovanovic wrote:
> 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>
> ---
>
> v2:
>
> - added comments to the code
>
> target-mips/dsp_helper.c | 16 +++++++++++-----
> tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c | 24 ++++++++++++++++++++----
> 2 files changed, 31 insertions(+), 9 deletions(-)
Reviewed-by: Richard Henderson <rth@twiddle.net>
r~
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round
2013-06-30 23:54 [Qemu-devel] [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round Petar Jovanovic
2013-07-01 14:52 ` Richard Henderson
@ 2013-07-28 22:28 ` Aurelien Jarno
1 sibling, 0 replies; 7+ messages in thread
From: Aurelien Jarno @ 2013-07-28 22:28 UTC (permalink / raw)
To: Petar Jovanovic; +Cc: rth, qemu-devel, petar.jovanovic
On Mon, Jul 01, 2013 at 01:54:47AM +0200, Petar Jovanovic wrote:
> 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>
> ---
>
> v2:
>
> - added comments to the code
>
> target-mips/dsp_helper.c | 16 +++++++++++-----
> tests/tcg/mips/mips32-dsp/precrq_rs_ph_w.c | 24 ++++++++++++++++++++----
> 2 files changed, 31 insertions(+), 9 deletions(-)
>
> diff --git a/target-mips/dsp_helper.c b/target-mips/dsp_helper.c
> index 4116de9..85950b3 100644
> --- a/target-mips/dsp_helper.c
> +++ b/target-mips/dsp_helper.c
> @@ -648,16 +648,22 @@ 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;
> + uint16_t temp;
>
> - temp = (int32_t)a + 0x00008000;
>
> - if (a > (int)0x7fff8000) {
> - temp = 0x7FFFFFFF;
> + /*
> + * The value 0x00008000 will be added to the input Q31 value, and the code
> + * needs to check if the addition causes an overflow. Since a positive value
> + * is added, overflow can happen in one direction only.
> + */
> + 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)
Thanks, applied.
--
Aurelien Jarno GPG: 1024D/F1BCDB73
aurelien@aurel32.net http://www.aurel32.net
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-07-28 22:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-30 23:54 [Qemu-devel] [PATCH v2] target-mips: fix mipsdsp_trunc16_sat16_round Petar Jovanovic
2013-07-01 14:52 ` Richard Henderson
2013-07-08 9:14 ` Petar Jovanovic
2013-07-15 11:46 ` Petar Jovanovic
2013-07-22 8:51 ` Petar Jovanovic
2013-07-27 23:33 ` Petar Jovanovic
2013-07-28 22:28 ` Aurelien Jarno
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.