Received: from eggs.gnu.org ([2001:4830:134:3::10]:46379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c5CUx-0001lN-BV for qemu-devel@nongnu.org; Fri, 11 Nov 2016 09:08:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c5CUt-0003fs-Bs for qemu-devel@nongnu.org; Fri, 11 Nov 2016 09:08:07 -0500 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:38592) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c5CUt-0003ez-3D for qemu-devel@nongnu.org; Fri, 11 Nov 2016 09:08:03 -0500 Received: by mail-wm0-x236.google.com with SMTP id f82so94017749wmf.1 for ; Fri, 11 Nov 2016 06:08:03 -0800 (PST) Sender: Richard Henderson References: <1478818284-9482-1-git-send-email-laurent@vivier.eu> From: Richard Henderson Message-ID: <70c4f9ee-461a-da57-2ece-d7e656d46942@twiddle.net> Date: Fri, 11 Nov 2016 15:07:56 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [Qemu-devel] [PATCH v2] target-m68k: add rol/ror/roxl/roxr instructions List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laurent Vivier , qemu-devel@nongnu.org On 11/11/2016 12:21 PM, Laurent Vivier wrote: > Le 11/11/2016 à 08:31, Richard Henderson a écrit : >> On 11/10/2016 11:51 PM, Laurent Vivier wrote: >>> +/* Result of rotate_x() is valid if 0 < shift < (size + 1) < 32 */ >>> +static TCGv rotate_x(TCGv dest, TCGv src, TCGv shift, int left, int >>> size) >>> +{ >>> + TCGv X, shl, shr, shx; >>> + >>> + shr = tcg_temp_new(); >>> + shl = tcg_temp_new(); >>> + shx = tcg_temp_new(); >>> + if (left) { >>> + tcg_gen_mov_i32(shl, shift); /* shl = shift */ >>> + tcg_gen_movi_i32(shr, size + 1); >>> + tcg_gen_sub_i32(shr, shr, shift); /* shr = size + 1 - shift */ >>> + tcg_gen_subi_i32(shx, shift, 1); /* shx = shift - 1 */ >> >> You're failing to bound shx properly. If shift == 0, you produce -1 >> here which is illegal. You could mask this to 31, but it's even better > > Yes, but in this case the result is ignored by the following movcond. > > tcg/README says: > > * shl_i32/i64 t0, t1, t2 > > t0=t1 << t2. Unspecified behavior if t2 < 0 or t2 >= 32 (resp 64) > > * shr_i32/i64 t0, t1, t2 > > t0=t1 >> t2 (unsigned). Unspecified behavior if t2 < 0 or t2 >= 32 (resp 64) > > An operation with "unspecified behavior" shall not crash. However, > the result may be one of several possibilities so may be considered > an "undefined result". > >> to produce size, as I said before, because then you don't have to have > > Perhaps I've missed something (again), but I've tested with > "int shr = shl ^ (size - 1);" and it produces the wrong result. Huh? I'm talking about shx = shl - 1; shx = shx < 0 ? size : shx; > To do "int shx = shl ? shl - 1 : 16;", we need a "movcond" in every > case, which should not be needed in the case of "rotate_im" where shift > is between 1 and 8. For constant input, the movcond will be folded to a constant. Along with all of the other shr/shl/shx computation. r~