Skip to content

Commit

Permalink
target-s390x: fix CONVERT TO BINARY (CVD, CVDY)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Signed-off-by: Alexander Graf <[email protected]>
  • Loading branch information
aurel32 authored and agraf committed Jul 7, 2015
1 parent c9c19b4 commit 92f2b4e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions target-s390x/int_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,20 @@ 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;
dec = 0x0d;
}

for (shift = 4; (shift < 64) && bin; shift += 4) {
int current_number = bin % 10;

dec |= (current_number) << shift;
dec |= (bin % 10) << shift;
bin /= 10;
}

Expand Down

0 comments on commit 92f2b4e

Please sign in to comment.