From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHg05-0005rO-2N for qemu-devel@nongnu.org; Thu, 05 Sep 2013 16:18:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VHfzw-00029F-M5 for qemu-devel@nongnu.org; Thu, 05 Sep 2013 16:17:57 -0400 Received: from [2a03:4000:1::4e2f:c7ac:d] (port=43213 helo=v220110690675601.yourvserver.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VHfzw-00027c-F7 for qemu-devel@nongnu.org; Thu, 05 Sep 2013 16:17:48 -0400 Message-ID: <5228E6DF.6090301@weilnetz.de> Date: Thu, 05 Sep 2013 22:17:35 +0200 From: Stefan Weil MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] tci: Add implementation of rotl_i64, rotr_i64 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jay Foad Cc: qemu-devel@nongnu.org, Richard Henderson Am 05.09.2013 14:00, schrieb Jay Foad: >> diff --git a/tci.c b/tci.c >> index 18c888e..94b7851 100644 >> --- a/tci.c >> +++ b/tci.c >> @@ -952,8 +952,16 @@ uintptr_t tcg_qemu_tb_exec(CPUArchState *env, uint8_t *tb_ptr) >> break; >> #if TCG_TARGET_HAS_rot_i64 >> case INDEX_op_rotl_i64: >> + t0 = *tb_ptr++; >> + t1 = tci_read_ri64(&tb_ptr); >> + t2 = tci_read_ri64(&tb_ptr); >> + tci_write_reg64(t0, (t1 << t2) | (t1 >> (64 - t2))); >> + break; >> case INDEX_op_rotr_i64: >> - TODO(); >> + t0 = *tb_ptr++; >> + t1 = tci_read_ri64(&tb_ptr); >> + t2 = tci_read_ri64(&tb_ptr); >> + tci_write_reg64(t0, (t1 >> t2) | (t1 << (64 - t2))); > << (64 - t2) is undefined behaviour in C when t2 is 0. How about << (-t2 & 63) ? > > Jay. A short test confirms that the behaviour for (t1 << 64) is indeed unexpected. I added assertions for (t2 > 0) and (t2 < 64). They never raised an abort. Are those cases possible? We already have similar code for 32 bit shifts, and tcg/optimize.c also includes an implementation which is identical to my rotl_i64, rotr_i64. Therefore I think my patch can be applied as it is. Stefan