qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] target-s390x: fix CONVERT TO BINARY (CVD, CVDY)
@ 2015-06-25 19:16 Aurelien Jarno
  2015-06-29  9:28 ` Richard Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Aurelien Jarno @ 2015-06-25 19:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: Alexander Graf, Aurelien Jarno, Richard Henderson

current_number being shift left by more than 32 bits, we can't use a
simple int. Similarly use an int64_t type for the input binary value,
to not get the -2^31 case wrong. Finally don't initialize shift to 4,
it's already done in the for loop.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
Cc: Alexander Graf <agraf@suse.de>
Cc: Richard Henderson <rth@twiddle.net>
---
 target-s390x/int_helper.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/target-s390x/int_helper.c b/target-s390x/int_helper.c
index 2c2b3f6..a46c736 100644
--- a/target-s390x/int_helper.c
+++ b/target-s390x/int_helper.c
@@ -121,11 +121,12 @@ uint64_t HELPER(clz)(uint64_t v)
     return clz64(v);
 }
 
-uint64_t HELPER(cvd)(int32_t bin)
+uint64_t HELPER(cvd)(int32_t reg)
 {
     /* positive 0 */
     uint64_t dec = 0x0c;
-    int shift = 4;
+    int64_t bin = reg;
+    int shift;
 
     if (bin < 0) {
         bin = -bin;
@@ -133,9 +134,7 @@ uint64_t HELPER(cvd)(int32_t bin)
     }
 
     for (shift = 4; (shift < 64) && bin; shift += 4) {
-        int current_number = bin % 10;
-
-        dec |= (current_number) << shift;
+        dec |= (bin % 10) << shift;
         bin /= 10;
     }
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] target-s390x: fix CONVERT TO BINARY (CVD, CVDY)
  2015-06-25 19:16 [Qemu-devel] [PATCH] target-s390x: fix CONVERT TO BINARY (CVD, CVDY) Aurelien Jarno
@ 2015-06-29  9:28 ` Richard Henderson
  2015-06-29 20:24   ` Aurelien Jarno
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2015-06-29  9:28 UTC (permalink / raw)
  To: Aurelien Jarno, qemu-devel; +Cc: Alexander Graf

On 06/25/2015 08:16 PM, Aurelien Jarno wrote:
>       for (shift = 4; (shift < 64) && bin; shift += 4) {
> -        int current_number = bin % 10;
> -
> -        dec |= (current_number) << shift;
> +        dec |= (bin % 10) << shift;
>           bin /= 10;
>       }

You've changed from 32-bit division to 64-bit division just to solve a problem 
with the shift.  Better to just change the type of current_number there.


r~

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] target-s390x: fix CONVERT TO BINARY (CVD, CVDY)
  2015-06-29  9:28 ` Richard Henderson
@ 2015-06-29 20:24   ` Aurelien Jarno
  2015-06-30  5:53     ` Richard Henderson
  0 siblings, 1 reply; 5+ messages in thread
From: Aurelien Jarno @ 2015-06-29 20:24 UTC (permalink / raw)
  To: Richard Henderson; +Cc: qemu-devel, Alexander Graf

On 2015-06-29 10:28, Richard Henderson wrote:
> On 06/25/2015 08:16 PM, Aurelien Jarno wrote:
> >      for (shift = 4; (shift < 64) && bin; shift += 4) {
> >-        int current_number = bin % 10;
> >-
> >-        dec |= (current_number) << shift;
> >+        dec |= (bin % 10) << shift;
> >          bin /= 10;
> >      }
> 
> You've changed from 32-bit division to 64-bit division just to solve a
> problem with the shift.  Better to just change the type of current_number
> there.

Changing the type of current_number instead of bin would indeed solve
the shift issue, but not the -2^31 case. As we take the absolute value,
we need a 64-bit variable to hold the corresponding 2^31 value.

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                 http://www.aurel32.net

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] target-s390x: fix CONVERT TO BINARY (CVD, CVDY)
  2015-06-29 20:24   ` Aurelien Jarno
@ 2015-06-30  5:53     ` Richard Henderson
  2015-06-30  7:27       ` Alexander Graf
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Henderson @ 2015-06-30  5:53 UTC (permalink / raw)
  To: Aurelien Jarno; +Cc: qemu-devel, Alexander Graf

On 06/29/2015 09:24 PM, Aurelien Jarno wrote:
> On 2015-06-29 10:28, Richard Henderson wrote:
>> On 06/25/2015 08:16 PM, Aurelien Jarno wrote:
>>>       for (shift = 4; (shift < 64) && bin; shift += 4) {
>>> -        int current_number = bin % 10;
>>> -
>>> -        dec |= (current_number) << shift;
>>> +        dec |= (bin % 10) << shift;
>>>           bin /= 10;
>>>       }
>>
>> You've changed from 32-bit division to 64-bit division just to solve a
>> problem with the shift.  Better to just change the type of current_number
>> there.
>
> Changing the type of current_number instead of bin would indeed solve
> the shift issue, but not the -2^31 case. As we take the absolute value,
> we need a 64-bit variable to hold the corresponding 2^31 value.
>

Ah, true enough.  I suppose adding a 32-bit unsigned variable with which to do 
the division is more trouble than it's worth.

Reviewed-by: Richard Henderson <rth@twiddle.net>


r~

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] target-s390x: fix CONVERT TO BINARY (CVD, CVDY)
  2015-06-30  5:53     ` Richard Henderson
@ 2015-06-30  7:27       ` Alexander Graf
  0 siblings, 0 replies; 5+ messages in thread
From: Alexander Graf @ 2015-06-30  7:27 UTC (permalink / raw)
  To: Richard Henderson, Aurelien Jarno; +Cc: qemu-devel



On 30.06.15 07:53, Richard Henderson wrote:
> On 06/29/2015 09:24 PM, Aurelien Jarno wrote:
>> On 2015-06-29 10:28, Richard Henderson wrote:
>>> On 06/25/2015 08:16 PM, Aurelien Jarno wrote:
>>>>       for (shift = 4; (shift < 64) && bin; shift += 4) {
>>>> -        int current_number = bin % 10;
>>>> -
>>>> -        dec |= (current_number) << shift;
>>>> +        dec |= (bin % 10) << shift;
>>>>           bin /= 10;
>>>>       }
>>>
>>> You've changed from 32-bit division to 64-bit division just to solve a
>>> problem with the shift.  Better to just change the type of
>>> current_number
>>> there.
>>
>> Changing the type of current_number instead of bin would indeed solve
>> the shift issue, but not the -2^31 case. As we take the absolute value,
>> we need a 64-bit variable to hold the corresponding 2^31 value.
>>
> 
> Ah, true enough.  I suppose adding a 32-bit unsigned variable with which
> to do the division is more trouble than it's worth.
> 
> Reviewed-by: Richard Henderson <rth@twiddle.net>

Thanks, applied to s390-next.


Alex

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-30  7:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-25 19:16 [Qemu-devel] [PATCH] target-s390x: fix CONVERT TO BINARY (CVD, CVDY) Aurelien Jarno
2015-06-29  9:28 ` Richard Henderson
2015-06-29 20:24   ` Aurelien Jarno
2015-06-30  5:53     ` Richard Henderson
2015-06-30  7:27       ` Alexander Graf

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).