Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1FT2rc-0008S5-Lo for qemu-devel@nongnu.org; Mon, 10 Apr 2006 16:19:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1FT2rb-0008Rp-09 for qemu-devel@nongnu.org; Mon, 10 Apr 2006 16:19:56 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FT2ra-0008Rl-Rr for qemu-devel@nongnu.org; Mon, 10 Apr 2006 16:19:54 -0400 Received: from [212.247.154.76] (helo=swip.net) by monty-python.gnu.org with esmtp (Exim 4.52) id 1FT2wI-0004MD-Jh for qemu-devel@nongnu.org; Mon, 10 Apr 2006 16:24:47 -0400 Received: from d80-170-66-134.cust.tele2.fr ([80.170.66.134] verified) by mailfe03.swip.net (CommuniGate Pro SMTP 5.0.8) with ESMTP id 182829875 for qemu-devel@nongnu.org; Mon, 10 Apr 2006 22:18:21 +0200 From: Even Rouault Subject: Re: [Qemu-devel] [PATCH] SPARC target : Fix carry flag =?iso-8859-1?q?update=09inaddxcc_and?= subxc Date: Mon, 10 Apr 2006 22:18:20 +0200 References: <443AA820.2000206@wanadoo.fr> In-Reply-To: <443AA820.2000206@wanadoo.fr> MIME-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_N2rOEZRCpVfZfNl" Message-Id: <200604102218.21494.even.rouault@mines-paris.org> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --Boundary-00=_N2rOEZRCpVfZfNl Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline To be clear, I just ran into the problem of the update of the carry flag bu= t=20 I'm not at all a specialist of SPARC assembly. =46rom what I've understood, Paul is certainly right when suggesting to add= a=20 fix for the SPARC64 case (for the addxcc and subxcc, not addx and subx) and= I=20 send a new version of the patch (qemu-sparc-carry-xcc-2.patch) I've also tried to take into account Blue Swirl's suggestion of storing the= =20 intermediate results of the addition T0 + FLAG_SET(PSR_CARRY), but the resu= lt=20 wasn't correct in all cases (specifically if T0=3D0xFFFFFFFF). I think we=20 really need a '<' and '<=3D' comparison.=20 However, I've tried to refactor a bit the code to save some comparisons in= =20 another version of the patch (qemu-sparc-carry-xcc-3.patch), really close t= o=20 the arm code, and hopefully equivalent to qemu-sparc-carry-xcc-2.patch (but= =20 less sexy). As far as the V flag is concerned, mmm, I'm not really sure whether we shou= ld=20 change something in the sparc code. If we compare to the arm code, we don't= =20 take into account the fact that the carry flag is set before. We'd probably need some extensive tests and their associated expected resul= ts. Even Le Lundi 10 Avril 2006 20:46, Laurent Desnogues a =E9crit=A0: > Blue Swirl a =E9crit : > >> Doesn't this condition in addx and the corresponding line in subx need > >> similar > >> treatment? > > > > They don't change the flags. > > ADDX (now named ADDC in v9) doesn't change the flags, while ADDXcc > (ADDCcc) does. The cc versions also compute overflow. > > cf. SPARC v9 on www.sparg.org > > > Laurent > > > > _______________________________________________ > Qemu-devel mailing list > Qemu-devel@nongnu.org > http://lists.nongnu.org/mailman/listinfo/qemu-devel --Boundary-00=_N2rOEZRCpVfZfNl Content-Type: text/x-diff; charset="iso-8859-1"; name="qemu-sparc-carry-xcc-ops-3.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="qemu-sparc-carry-xcc-ops-3.patch" ? qemu-sparc-carry-xcc-ops-2.patch ? qemu-sparc-carry-xcc-ops-3.patch ? qemu-sparc-carry-xcc-ops.patch Index: op.c =================================================================== RCS file: /sources/qemu/qemu/target-sparc/op.c,v retrieving revision 1.18 diff -u -p -r1.18 op.c --- op.c 30 Oct 2005 17:28:50 -0000 1.18 +++ op.c 10 Apr 2006 20:03:37 -0000 @@ -415,28 +415,50 @@ void OPPROTO op_addx_T1_T0(void) void OPPROTO op_addx_T1_T0_cc(void) { target_ulong src1; - src1 = T0; - T0 += T1 + FLAG_SET(PSR_CARRY); - env->psr = 0; + if (FLAG_SET(PSR_CARRY)) + { + T0 += T1 + 1; + env->psr = 0; +#ifdef TARGET_SPARC64 + if ((T0 & 0xffffffff) <= (src1 & 0xffffffff)) + env->psr |= PSR_CARRY; + env->xcc = 0; + if (T0 <= src1) + env->xcc |= PSR_CARRY; +#else + if (T0 <= src1) + env->psr |= PSR_CARRY; +#endif + } + else + { + T0 += T1; + env->psr = 0; +#ifdef TARGET_SPARC64 + if ((T0 & 0xffffffff) < (src1 & 0xffffffff)) + env->psr |= PSR_CARRY; + env->xcc = 0; + if (T0 < src1) + env->xcc |= PSR_CARRY; +#else + if (T0 < src1) + env->psr |= PSR_CARRY; +#endif + } #ifdef TARGET_SPARC64 if (!(T0 & 0xffffffff)) env->psr |= PSR_ZERO; if ((int32_t) T0 < 0) env->psr |= PSR_NEG; - if ((T0 & 0xffffffff) < (src1 & 0xffffffff)) - env->psr |= PSR_CARRY; if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff) ^ -1) & ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31)) env->psr |= PSR_OVF; - env->xcc = 0; if (!T0) env->xcc |= PSR_ZERO; if ((int64_t) T0 < 0) env->xcc |= PSR_NEG; - if (T0 < src1) - env->xcc |= PSR_CARRY; if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1ULL << 63)) env->xcc |= PSR_OVF; #else @@ -444,8 +466,6 @@ void OPPROTO op_addx_T1_T0_cc(void) env->psr |= PSR_ZERO; if ((int32_t) T0 < 0) env->psr |= PSR_NEG; - if (T0 < src1) - env->psr |= PSR_CARRY; if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31)) env->psr |= PSR_OVF; #endif @@ -505,28 +525,50 @@ void OPPROTO op_subx_T1_T0(void) void OPPROTO op_subx_T1_T0_cc(void) { target_ulong src1; - src1 = T0; - T0 -= T1 + FLAG_SET(PSR_CARRY); - env->psr = 0; + if (FLAG_SET(PSR_CARRY)) + { + T0 -= T1 + 1; + env->psr = 0; +#ifdef TARGET_SPARC64 + if ((src1 & 0xffffffff) <= (T1 & 0xffffffff)) + env->psr |= PSR_CARRY; + env->xcc = 0; + if (src1 <= T1) + env->xcc |= PSR_CARRY; +#else + if (src1 <= T1) + env->psr |= PSR_CARRY; +#endif + } + else + { + T0 -= T1; + env->psr = 0; +#ifdef TARGET_SPARC64 + if ((src1 & 0xffffffff) < (T1 & 0xffffffff)) + env->psr |= PSR_CARRY; + env->xcc = 0; + if (src1 < T1) + env->xcc |= PSR_CARRY; +#else + if (src1 < T1) + env->psr |= PSR_CARRY; +#endif + } #ifdef TARGET_SPARC64 if (!(T0 & 0xffffffff)) env->psr |= PSR_ZERO; if ((int32_t) T0 < 0) env->psr |= PSR_NEG; - if ((src1 & 0xffffffff) < (T1 & 0xffffffff)) - env->psr |= PSR_CARRY; if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff)) & ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31)) env->psr |= PSR_OVF; - env->xcc = 0; if (!T0) env->xcc |= PSR_ZERO; if ((int64_t) T0 < 0) env->xcc |= PSR_NEG; - if (src1 < T1) - env->xcc |= PSR_CARRY; if (((src1 ^ T1) & (src1 ^ T0)) & (1ULL << 63)) env->xcc |= PSR_OVF; #else @@ -534,8 +576,6 @@ void OPPROTO op_subx_T1_T0_cc(void) env->psr |= PSR_ZERO; if ((int32_t) T0 < 0) env->psr |= PSR_NEG; - if (src1 < T1) - env->psr |= PSR_CARRY; if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31)) env->psr |= PSR_OVF; #endif --Boundary-00=_N2rOEZRCpVfZfNl Content-Type: text/x-diff; charset="iso-8859-1"; name="qemu-sparc-carry-xcc-ops-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="qemu-sparc-carry-xcc-ops-2.patch" ? qemu-sparc-carry-xcc-ops-2.patch ? qemu-sparc-carry-xcc-ops.patch Index: op.c =================================================================== RCS file: /sources/qemu/qemu/target-sparc/op.c,v retrieving revision 1.18 diff -u -p -r1.18 op.c --- op.c 30 Oct 2005 17:28:50 -0000 1.18 +++ op.c 10 Apr 2006 18:57:46 -0000 @@ -415,16 +415,17 @@ void OPPROTO op_addx_T1_T0(void) void OPPROTO op_addx_T1_T0_cc(void) { target_ulong src1; - + target_ulong has_carry = FLAG_SET(PSR_CARRY); src1 = T0; - T0 += T1 + FLAG_SET(PSR_CARRY); + T0 += T1 + has_carry; env->psr = 0; #ifdef TARGET_SPARC64 if (!(T0 & 0xffffffff)) env->psr |= PSR_ZERO; if ((int32_t) T0 < 0) env->psr |= PSR_NEG; - if ((T0 & 0xffffffff) < (src1 & 0xffffffff)) + if (((T0 & 0xffffffff) < (src1 & 0xffffffff)) || + (has_carry && ((T0 & 0xffffffff) <= (src1 & 0xffffffff)))) env->psr |= PSR_CARRY; if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff) ^ -1) & ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31)) @@ -435,7 +436,7 @@ void OPPROTO op_addx_T1_T0_cc(void) env->xcc |= PSR_ZERO; if ((int64_t) T0 < 0) env->xcc |= PSR_NEG; - if (T0 < src1) + if (T0 < src1 || (has_carry && T0 <= src1)) env->xcc |= PSR_CARRY; if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1ULL << 63)) env->xcc |= PSR_OVF; @@ -444,7 +445,7 @@ void OPPROTO op_addx_T1_T0_cc(void) env->psr |= PSR_ZERO; if ((int32_t) T0 < 0) env->psr |= PSR_NEG; - if (T0 < src1) + if (T0 < src1 || (has_carry && T0 <= src1)) env->psr |= PSR_CARRY; if (((src1 ^ T1 ^ -1) & (src1 ^ T0)) & (1 << 31)) env->psr |= PSR_OVF; @@ -505,16 +506,17 @@ void OPPROTO op_subx_T1_T0(void) void OPPROTO op_subx_T1_T0_cc(void) { target_ulong src1; - + target_ulong has_carry = FLAG_SET(PSR_CARRY); src1 = T0; - T0 -= T1 + FLAG_SET(PSR_CARRY); + T0 -= T1 + has_carry; env->psr = 0; #ifdef TARGET_SPARC64 if (!(T0 & 0xffffffff)) env->psr |= PSR_ZERO; if ((int32_t) T0 < 0) env->psr |= PSR_NEG; - if ((src1 & 0xffffffff) < (T1 & 0xffffffff)) + if (((src1 & 0xffffffff) < (T1 & 0xffffffff)) || + (has_carry && ((src1 & 0xffffffff) <= (T1 & 0xffffffff)))) env->psr |= PSR_CARRY; if ((((src1 & 0xffffffff) ^ (T1 & 0xffffffff)) & ((src1 & 0xffffffff) ^ (T0 & 0xffffffff))) & (1 << 31)) @@ -525,7 +527,7 @@ void OPPROTO op_subx_T1_T0_cc(void) env->xcc |= PSR_ZERO; if ((int64_t) T0 < 0) env->xcc |= PSR_NEG; - if (src1 < T1) + if (src1 < T1 || (has_carry && src1 <= T1)) env->xcc |= PSR_CARRY; if (((src1 ^ T1) & (src1 ^ T0)) & (1ULL << 63)) env->xcc |= PSR_OVF; @@ -534,7 +536,7 @@ void OPPROTO op_subx_T1_T0_cc(void) env->psr |= PSR_ZERO; if ((int32_t) T0 < 0) env->psr |= PSR_NEG; - if (src1 < T1) + if (src1 < T1 || (has_carry && src1 <= T1)) env->psr |= PSR_CARRY; if (((src1 ^ T1) & (src1 ^ T0)) & (1 << 31)) env->psr |= PSR_OVF; --Boundary-00=_N2rOEZRCpVfZfNl--