Received: from eggs.gnu.org ([2001:4830:134:3::10]:33830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQ1b7-0003UZ-4V for qemu-devel@nongnu.org; Tue, 18 Mar 2014 17:31:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WQ1b1-0007vy-6W for qemu-devel@nongnu.org; Tue, 18 Mar 2014 17:30:57 -0400 Received: from mail-pd0-x232.google.com ([2607:f8b0:400e:c02::232]:47991) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WQ1b1-0007vm-02 for qemu-devel@nongnu.org; Tue, 18 Mar 2014 17:30:51 -0400 Received: by mail-pd0-f178.google.com with SMTP id x10so7661331pdj.23 for ; Tue, 18 Mar 2014 14:30:50 -0700 (PDT) Sender: Richard Henderson From: Richard Henderson Date: Tue, 18 Mar 2014 14:30:35 -0700 Message-Id: <1395178235-29056-5-git-send-email-rth@twiddle.net> In-Reply-To: <1395178235-29056-1-git-send-email-rth@twiddle.net> References: <1395178235-29056-1-git-send-email-rth@twiddle.net> Subject: [Qemu-devel] [PATCH v2 4/4] tcg: Fix out of range shift in deposit optimizations List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org By inspection, for a deposit(x, y, 0, 64), we'd have a shift of (1<<64) and everything else falls apart. But we can reuse the existing deposit logic to get this right. Signed-off-by: Richard Henderson --- tcg/optimize.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tcg/optimize.c b/tcg/optimize.c index 2fb708e..c447062 100644 --- a/tcg/optimize.c +++ b/tcg/optimize.c @@ -843,9 +843,8 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, break; CASE_OP_32_64(deposit): - tmp = ((1ull << args[4]) - 1); - mask = ((temps[args[1]].mask & ~(tmp << args[3])) - | ((temps[args[2]].mask & tmp) << args[3])); + mask = deposit64(temps[args[1]].mask, args[3], args[4], + temps[args[2]].mask); break; CASE_OP_32_64(or): @@ -1060,9 +1059,8 @@ static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr, if (temps[args[1]].state == TCG_TEMP_CONST && temps[args[2]].state == TCG_TEMP_CONST) { s->gen_opc_buf[op_index] = op_to_movi(op); - tmp = ((1ull << args[4]) - 1); - tmp = (temps[args[1]].val & ~(tmp << args[3])) - | ((temps[args[2]].val & tmp) << args[3]); + tmp = deposit64(temps[args[1]].val, args[3], args[4], + temps[args[2]].val); tcg_opt_gen_movi(gen_args, args[0], tmp); gen_args += 2; args += 5; -- 1.8.5.3