Received: from eggs.gnu.org ([2001:4830:134:3::10]:36757) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c2Kgs-0006oB-64 for qemu-devel@nongnu.org; Thu, 03 Nov 2016 12:16:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c2Kgn-0002Qv-4L for qemu-devel@nongnu.org; Thu, 03 Nov 2016 12:16:34 -0400 Received: from mail-qt0-x244.google.com ([2607:f8b0:400d:c0d::244]:34062) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c2Kgm-0002Qg-WE for qemu-devel@nongnu.org; Thu, 03 Nov 2016 12:16:29 -0400 Received: by mail-qt0-x244.google.com with SMTP id l20so1872060qta.1 for ; Thu, 03 Nov 2016 09:16:28 -0700 (PDT) Sender: Richard Henderson References: <1478121319-31986-1-git-send-email-laurent@vivier.eu> <1478121319-31986-2-git-send-email-laurent@vivier.eu> From: Richard Henderson Message-ID: Date: Thu, 3 Nov 2016 10:16:24 -0600 MIME-Version: 1.0 In-Reply-To: <1478121319-31986-2-git-send-email-laurent@vivier.eu> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 1/3] target-m68k: add abcd/sbcd/nbcd List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Laurent Vivier , qemu-devel@nongnu.org Cc: schwab@linux-m68k.org, agraf@suse.de, gerg@uclinux.org On 11/02/2016 03:15 PM, Laurent Vivier wrote: > +static void bcd_sub(TCGv dest, TCGv src) > +{ > + TCGv t0, t1, t2; > + > + /* dest10 = dest10 - src10 - X > + * = bcd_add(dest + 1 - X, 0xf99 - src) > + */ > + > + /* t0 = 0xfff - src */ > + > + t0 = tcg_temp_new(); > + tcg_gen_neg_i32(t0, src); > + tcg_gen_addi_i32(t0, t0, 0xfff); tcg_gen_subfi_i32(t0, 0xfff, src); And how did we get 0xfff from 0xf99? Also, see below... > + > + /* t1 = t0 + dest + 1 - X*/ > + > + t1 = tcg_temp_new(); > + tcg_gen_add_i32(t1, t0, dest); > + tcg_gen_addi_i32(t1, t1, 1); > + tcg_gen_sub_i32(t1, t1, QREG_CC_X); > + > + /* t2 = t0 ^ dest ^ 1 ^ X */ > + > + t2 = tcg_temp_new(); > + tcg_gen_xor_i32(t2, t0, dest); > + tcg_gen_xori_i32(t2, t2, 1); > + tcg_gen_xor_i32(t2, t2, QREG_CC_X); Since you only care about bits 0x110, you can drop the ^ 1 ^ X; they won't affect the result. (Similarly wrt bcd_add, dropping ^ X). > + /* t2 = ~t0 & 0x110 */ > + > + tcg_gen_not_i32(t2, t0); > + tcg_gen_andi_i32(t2, t2, 0x110); > + > + /* t0 = (t2 >> 2) | (t2 >> 3) */ > + > + tcg_gen_shri_i32(t0, t2, 2); > + tcg_gen_shri_i32(t2, t2, 3); > + tcg_gen_or_i32(t0, t0, t2); For the benefit of hosts that have 8-bit immediate AND insns (e.g. arm32), it would be better to rearrange this a little: t2 = t0 >> 3; t3 = ~t2 & 0x22; t4 = t3 + t3; t5 = t3 + t4; (Similarly in bcd_add). > + > + /* return t1 - t0 */ > + > + tcg_gen_sub_i32(dest, t1, t0); > +} > + > +static void bcd_flags(TCGv val) > +{ > + tcg_gen_andi_i32(QREG_CC_C, val, 0x0ff); > + tcg_gen_or_i32(QREG_CC_Z, QREG_CC_Z, QREG_CC_C); > + > + tcg_gen_movi_i32(QREG_CC_X, 0); > + tcg_gen_andi_i32(val, val, 0xf00); > + tcg_gen_setcond_i32(TCG_COND_NE, QREG_CC_C, val, QREG_CC_X); Surely 0x100 is the carry. I don't see how you could produce 0x2xx from addition. For subtraction, I think we got things other than 0/1 in the third nibble simply because we started with 0xf99 instead of 0x199. r~