target-s390x: fix CONVERT TO BINARY (CVD, CVDY)
PATCH 1/1 target-s390x: fix CONVERT TO BINARY (CVD, CVDY)
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.
--- target-s390x/int_helper.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
target-s390x/int_helper.c +4 -5
@@ -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 ; }
Signature · 1 line
2.1.4
target-s390x/int_helper.c uint64_t HELPER(cvd)(int32_t bin) · line 139
Quoted 7 lines · Aurelien Jarno
for (shift = 4; (shift < 64) && bin; shift += 4) {target-s390x/int_helper.c +1
-3-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~
Quoted 9 lines · Richard Henderson
target-s390x/int_helper.c uint64_t HELPER(cvd)(int32_t bin) · line 139
Quoted 7 lines · Aurelien Jarno
for (shift = 4; (shift < 64) && bin; shift += 4) {target-s390x/int_helper.c +1
-3-int current_number = bin %10 ; - - dec |= (current_number) << shift; + dec |= (bin %10 ) << shift; bin /=10 ; }
Quoted 3 lines
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_numberthere.
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.
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net
Richard Henderson
Reviewed-byQuoted 10 lines · Aurelien Jarno
Quoted 9 lines · Richard Henderson
Quoted 7 lines · Aurelien Jarno
for (shift = 4; (shift < 64) && bin; shift += 4) {target-s390x/int_helper.c +1
-3-int current_number = bin %10 ; - - dec |= (current_number) << shift; + dec |= (bin %10 ) << shift; bin /=10 ; }
Quoted 8 lines
Quoted 3 lines
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_numberthere.Changing the type of
current_numberinstead 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.
r~
Alexander Graf
AppliedQuoted 21 lines · Richard Henderson
Quoted 10 lines · Aurelien Jarno
Quoted 9 lines · Richard Henderson
Quoted 7 lines · Aurelien Jarno
for (shift = 4; (shift < 64) && bin; shift += 4) {target-s390x/int_helper.c +1
-3-int current_number = bin %10 ; - - dec |= (current_number) << shift; + dec |= (bin %10 ) << shift; bin /=10 ; }Quoted 9 lines
Quoted 4 lines
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_numberinstead 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.
Quoted 4 lines
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 <[email protected]>
Thanks, applied to s390-next.
Alex