From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JxRP7-0006Qm-LJ for qemu-devel@nongnu.org; Sat, 17 May 2008 14:45:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JxRP7-0006QT-2m for qemu-devel@nongnu.org; Sat, 17 May 2008 14:45:13 -0400 Received: from [199.232.76.173] (port=43804 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JxRP6-0006QG-QX for qemu-devel@nongnu.org; Sat, 17 May 2008 14:45:12 -0400 Received: from savannah.gnu.org ([199.232.41.3]:34919 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JxRP6-0001Z7-Cm for qemu-devel@nongnu.org; Sat, 17 May 2008 14:45:12 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1JxRP2-0006J5-Fr for qemu-devel@nongnu.org; Sat, 17 May 2008 18:45:09 +0000 Received: from bellard by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1JxROw-0006Gv-0n for qemu-devel@nongnu.org; Sat, 17 May 2008 18:45:04 +0000 MIME-Version: 1.0 Errors-To: bellard Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Fabrice Bellard Message-Id: Date: Sat, 17 May 2008 18:45:02 +0000 Subject: [Qemu-devel] [4477] BSR/BSF TCG conversion 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 Revision: 4477 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4477 Author: bellard Date: 2008-05-17 18:44:58 +0000 (Sat, 17 May 2008) Log Message: ----------- BSR/BSF TCG conversion Modified Paths: -------------- trunk/target-i386/helper.c trunk/target-i386/helper.h trunk/target-i386/ops_template.h trunk/target-i386/translate.c Modified: trunk/target-i386/helper.c =================================================================== --- trunk/target-i386/helper.c 2008-05-17 18:18:04 UTC (rev 4476) +++ trunk/target-i386/helper.c 2008-05-17 18:44:58 UTC (rev 4477) @@ -5240,6 +5240,37 @@ #endif +/* bit operations */ +target_ulong helper_bsf(target_ulong t0) +{ + int count; + target_ulong res; + + res = t0; + count = 0; + while ((res & 1) == 0) { + count++; + res >>= 1; + } + return count; +} + +target_ulong helper_bsr(target_ulong t0) +{ + int count; + target_ulong res, mask; + + res = t0; + count = TARGET_LONG_BITS - 1; + mask = (target_ulong)1 << (TARGET_LONG_BITS - 1); + while ((res & mask) == 0) { + count--; + res <<= 1; + } + return count; +} + + static int compute_all_eflags(void) { return CC_SRC; Modified: trunk/target-i386/helper.h =================================================================== --- trunk/target-i386/helper.h 2008-05-17 18:18:04 UTC (rev 4476) +++ trunk/target-i386/helper.h 2008-05-17 18:44:58 UTC (rev 4477) @@ -187,6 +187,8 @@ void helper_frstor(target_ulong ptr, int data32); void helper_fxsave(target_ulong ptr, int data64); void helper_fxrstor(target_ulong ptr, int data64); +target_ulong helper_bsf(target_ulong t0); +target_ulong helper_bsr(target_ulong t0); /* MMX/SSE */ Modified: trunk/target-i386/ops_template.h =================================================================== --- trunk/target-i386/ops_template.h 2008-05-17 18:18:04 UTC (rev 4476) +++ trunk/target-i386/ops_template.h 2008-05-17 18:44:58 UTC (rev 4477) @@ -200,51 +200,6 @@ T0 = ((DATA_STYPE)src1 <= (DATA_STYPE)src2); } -/* bit operations */ -#if DATA_BITS >= 16 - -void OPPROTO glue(glue(op_bsf, SUFFIX), _T0_cc)(void) -{ - int count; - target_long res; - - res = T0 & DATA_MASK; - if (res != 0) { - count = 0; - while ((res & 1) == 0) { - count++; - res >>= 1; - } - T1 = count; - CC_DST = 1; /* ZF = 0 */ - } else { - CC_DST = 0; /* ZF = 1 */ - } - FORCE_RET(); -} - -void OPPROTO glue(glue(op_bsr, SUFFIX), _T0_cc)(void) -{ - int count; - target_long res; - - res = T0 & DATA_MASK; - if (res != 0) { - count = DATA_BITS - 1; - while ((res & SIGN_MASK) == 0) { - count--; - res <<= 1; - } - T1 = count; - CC_DST = 1; /* ZF = 0 */ - } else { - CC_DST = 0; /* ZF = 1 */ - } - FORCE_RET(); -} - -#endif - /* string operations */ void OPPROTO glue(op_movl_T0_Dshift, SUFFIX)(void) Modified: trunk/target-i386/translate.c =================================================================== --- trunk/target-i386/translate.c 2008-05-17 18:18:04 UTC (rev 4476) +++ trunk/target-i386/translate.c 2008-05-17 18:44:58 UTC (rev 4477) @@ -498,23 +498,6 @@ #endif }; -static GenOpFunc *gen_op_bsx_T0_cc[3][2] = { - [0] = { - gen_op_bsfw_T0_cc, - gen_op_bsrw_T0_cc, - }, - [1] = { - gen_op_bsfl_T0_cc, - gen_op_bsrl_T0_cc, - }, -#ifdef TARGET_X86_64 - [2] = { - gen_op_bsfq_T0_cc, - gen_op_bsrq_T0_cc, - }, -#endif -}; - static inline void gen_op_lds_T0_A0(int idx) { int mem_index = (idx >> 2) - 1; @@ -5837,16 +5820,27 @@ break; case 0x1bc: /* bsf */ case 0x1bd: /* bsr */ - ot = dflag + OT_WORD; - modrm = ldub_code(s->pc++); - reg = ((modrm >> 3) & 7) | rex_r; - gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0); - /* NOTE: in order to handle the 0 case, we must load the - result. It could be optimized with a generated jump */ - gen_op_mov_TN_reg(ot, 1, reg); - gen_op_bsx_T0_cc[ot - OT_WORD][b & 1](); - gen_op_mov_reg_T1(ot, reg); - s->cc_op = CC_OP_LOGICB + ot; + { + int label1; + ot = dflag + OT_WORD; + modrm = ldub_code(s->pc++); + reg = ((modrm >> 3) & 7) | rex_r; + gen_ldst_modrm(s, modrm, ot, OR_TMP0, 0); + gen_extu(ot, cpu_T[0]); + label1 = gen_new_label(); + tcg_gen_movi_tl(cpu_cc_dst, 0); + tcg_gen_brcond_tl(TCG_COND_EQ, cpu_T[0], tcg_const_tl(0), label1); + if (b & 1) { + tcg_gen_helper_1_1(helper_bsr, cpu_T[0], cpu_T[0]); + } else { + tcg_gen_helper_1_1(helper_bsf, cpu_T[0], cpu_T[0]); + } + gen_op_mov_reg_T0(ot, reg); + tcg_gen_movi_tl(cpu_cc_dst, 1); + gen_set_label(label1); + tcg_gen_discard_tl(cpu_cc_src); + s->cc_op = CC_OP_LOGICB + ot; + } break; /************************/ /* bcd */