From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37104) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsGoH-0006iu-TC for qemu-devel@nongnu.org; Thu, 27 Jun 2013 14:20:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UsGoB-0005w0-M6 for qemu-devel@nongnu.org; Thu, 27 Jun 2013 14:20:45 -0400 Received: from mail-ye0-x22b.google.com ([2607:f8b0:4002:c04::22b]:33045) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsGoB-0005vv-8N for qemu-devel@nongnu.org; Thu, 27 Jun 2013 14:20:39 -0400 Received: by mail-ye0-f171.google.com with SMTP id q14so201836yen.30 for ; Thu, 27 Jun 2013 11:20:38 -0700 (PDT) Sender: Richard Henderson Message-ID: <51CC8271.6040204@twiddle.net> Date: Thu, 27 Jun 2013 11:20:33 -0700 From: Richard Henderson MIME-Version: 1.0 References: <1369229701-87540-1-git-send-email-petar.jovanovic@rt-rk.com>, <56EA75BA695AE044ACFB41322F6D2BF402230260@BADAG02.ba.imgtec.org> <56EA75BA695AE044ACFB41322F6D2BF4022320A1@BADAG02.ba.imgtec.org> In-Reply-To: <56EA75BA695AE044ACFB41322F6D2BF4022320A1@BADAG02.ba.imgtec.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] target-mips: fix mipsdsp_trunc16_sat16_round List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Petar Jovanovic Cc: Petar Jovanovic , "aurelien@aurel32.net" , "qemu-devel@nongnu.org" On 06/17/2013 03:39 PM, Petar Jovanovic wrote: > - int64_t temp; > - > - temp = (int32_t)a + 0x00008000; > + uint16_t temp; > > - if (a > (int)0x7fff8000) { > - temp = 0x7FFFFFFF; > + if (a > 0x7FFF7FFF) { > + temp = 0x7FFF; > set_DSPControl_overflow_flag(1, 22, env); > + } else { > + temp = ((a + 0x8000) >> 16) & 0xFFFF; This doesn't look right either, as it doesn't properly check for overflow of negative values. I'd feel better if we implement this function exactly as documented, modulo actually using 64-bit arithmetic. How about int32_t temp; /* Shift right by one, to avoid needing 64-bit arithmetic. As this A is signed, this creates the copy of the sign bit as documented. */ a >>= 1; temp = a + 0x4000; /* Compare temp{31} with temp{30} by xoring into the sign bit. */ if ((temp ^ (temp << 1)) < 0) { set_DSPControl_overflow_flag(1, 22, env); return 0x7fff; } return temp >> 15; r~