From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:43459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhEAL-0005kF-OO for qemu-devel@nongnu.org; Tue, 28 May 2013 03:18:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UhEA8-0004rk-2y for qemu-devel@nongnu.org; Tue, 28 May 2013 03:17:53 -0400 Received: from lhrrgout.huawei.com ([194.213.3.17]:4028) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UhEA7-0004qp-Cm for qemu-devel@nongnu.org; Tue, 28 May 2013 03:17:39 -0400 Message-ID: <51A459F8.5030706@huawei.com> Date: Tue, 28 May 2013 09:17:12 +0200 From: Claudio Fontana MIME-Version: 1.0 References: <5141F36E.10004@huawei.com> <519DCEC8.8060000@huawei.com> <519DD0BF.4090702@huawei.com> <519E43EE.6090702@twiddle.net> <519F2A8F.6090903@huawei.com> <519F9D11.9020603@twiddle.net> <51A346EC.2080005@huawei.com> <51A3AA3A.4050406@twiddle.net> In-Reply-To: <51A3AA3A.4050406@twiddle.net> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/4] tcg/aarch64: implement new TCG target for aarch64 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: Peter Maydell , Jani Kokkonen , qemu-devel@nongnu.org On 27.05.2013 20:47, Richard Henderson wrote: > On 2013-05-27 04:43, Claudio Fontana wrote: >>> Hmm, true. Although I'd been thinking more along the lines of >>> arranging the code such that we'd use movz to set the zero. >> >> I think we need to keep treating zero specially if we want to keep the optimization where we don't emit needless MOVK instructions for half-words of value 0000h. >> >> I can however make one single function out of movi32 and movi64, it could look like this: >> >> if (!value) { >> tcg_out_movr(s, 0, rd, TCG_REG_ZXR); >> return; >> } >> >> base = (value > 0xffffffff) ? 0xd2800000 : 0x52800000; >> >> while (value) { >> /* etc etc */ >> } > > > if (type == TCG_TYPE_I32) { > value = (uint32_t)value; > ext = 0; > } else if (value <= 0xffffffff) { > ext = 0; > } else { > ext = 0x80000000; > } The check for type is probably unnecessary, since we don't gain anything (we still have to check something once), so I'd rather use a uint64_t parameter and then just check for value < 0xffffffff. > > base = 0x52800000; /* MOVZ */ > do { > int shift = ctz64(value) & (63 & -16); > int half = (value >> shift) & 0xffff; > tcg_out32(s, base | ext | half << 5 | rd); > value &= ~(0xffffUL << shift); > base = 0x72800000; /* MOVK */ > } while (value != 0); > > > Since we go through the loop at least once, we emit the movz for zero input. No need for any extra tests. And using ctz we can iterate fewer times. Of course, doh. I'll make use of do..while. Thanks, Claudio