From patchwork Thu Jun 25 19:16:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jarno X-Patchwork-Id: 488525 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 00B9B14012C for ; Fri, 26 Jun 2015 05:17:36 +1000 (AEST) Received: from localhost ([::1]:57169 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8CeT-0007wd-Ih for incoming@patchwork.ozlabs.org; Thu, 25 Jun 2015 15:17:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8CeD-0007g3-0b for qemu-devel@nongnu.org; Thu, 25 Jun 2015 15:17:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z8CeC-0002Ub-5h for qemu-devel@nongnu.org; Thu, 25 Jun 2015 15:17:16 -0400 Received: from [2001:bc8:30d7:101::1] (port=55305 helo=hall.aurel32.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z8CeB-0002Mj-Vg for qemu-devel@nongnu.org; Thu, 25 Jun 2015 15:17:16 -0400 Received: from weber.rr44.fr ([2001:470:d4ed:0:7e05:7ff:fe0d:f152]) by hall.aurel32.net with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84) (envelope-from ) id 1Z8Ce1-0000NH-6c; Thu, 25 Jun 2015 21:17:05 +0200 Received: from aurel32 by weber.rr44.fr with local (Exim 4.85) (envelope-from ) id 1Z8Ce0-0001nS-BY; Thu, 25 Jun 2015 21:17:04 +0200 From: Aurelien Jarno To: qemu-devel@nongnu.org Date: Thu, 25 Jun 2015 21:16:58 +0200 Message-Id: <1435259818-6864-1-git-send-email-aurelien@aurel32.net> X-Mailer: git-send-email 2.1.4 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:bc8:30d7:101::1 Cc: Alexander Graf , Aurelien Jarno , Richard Henderson Subject: [Qemu-devel] [PATCH] target-s390x: fix CONVERT TO BINARY (CVD, CVDY) X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Cc: Alexander Graf Cc: Richard Henderson Reviewed-by: Richard Henderson --- 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; }