[4309] CRIS: Convert lz (leading zeros) to TCG.
Revision: 4309
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=4309 Author: edgar_igl Date: 2008-05-03 17:11:36 +0000 (Sat, 03 May 2008)
Log Message:
-----------
CRIS: Convert lz (leading zeros) to TCG.
Modified Paths:
--------------
trunk/target-cris/translate.c
Modified: trunk/target-cris/translate.c
===================================================================
target-cris/translate.c +69 -1
@@ -307,6 +307,74 @@tcg_gen_discard_i64 (t1); } +/* 32bit branch-free binary search for counting leading zeros. */ +static void t_gen_lz_i32 (TCGv d,TCGv x) +{ +TCGv y, m, n; + + y =tcg_temp_new (TCG_TYPE_I32 ); + m =tcg_temp_new (TCG_TYPE_I32 ); + n =tcg_temp_new (TCG_TYPE_I32 ); + +/* y = -(x >> 16) */ +tcg_gen_shri_i32 (y, x,16 ); +tcg_gen_sub_i32 (y,tcg_const_i32 (0 ), y); + +/* m = (y >> 16) & 16 */ +tcg_gen_sari_i32 (m, y,16 ); +tcg_gen_andi_i32 (m, m,16 ); + +/* n = 16 - m */ +tcg_gen_sub_i32 (n,tcg_const_i32 (16 ), m); +/* x = x >> m */ +tcg_gen_shr_i32 (x, x, m); + +/* y = x - 0x100 */ +tcg_gen_subi_i32 (y, x,0x100 ); +/* m = (y >> 16) & 8 */ +tcg_gen_sari_i32 (m, y,16 ); +tcg_gen_andi_i32 (m, m,8 ); +/* n = n + m */ +tcg_gen_add_i32 (n, n, m); +/* x = x << m */ +tcg_gen_shl_i32 (x, x, m); + +/* y = x - 0x1000 */ +tcg_gen_subi_i32 (y, x,0x1000 ); +/* m = (y >> 16) & 4 */ +tcg_gen_sari_i32 (m, y,16 ); +tcg_gen_andi_i32 (m, m,4 ); +/* n = n + m */ +tcg_gen_add_i32 (n, n, m); +/* x = x << m */ +tcg_gen_shl_i32 (x, x, m); + +/* y = x - 0x4000 */ +tcg_gen_subi_i32 (y, x,0x4000 ); +/* m = (y >> 16) & 2 */ +tcg_gen_sari_i32 (m, y,16 ); +tcg_gen_andi_i32 (m, m,2 ); +/* n = n + m */ +tcg_gen_add_i32 (n, n, m); +/* x = x << m */ +tcg_gen_shl_i32 (x, x, m); + +/* y = x >> 14 */ +tcg_gen_shri_i32 (y, x,14 ); +/* m = y & ~(y >> 1) */ +tcg_gen_sari_i32 (m, y,1 ); +tcg_gen_xori_i32 (m, m,0xffffffff ); +tcg_gen_and_i32 (m, m, y); + +/* d = n + 2 - m */ +tcg_gen_addi_i32 (d, n,2 ); +tcg_gen_sub_i32 (d, d, m); + +tcg_gen_discard_i32 (y); +tcg_gen_discard_i32 (m); +tcg_gen_discard_i32 (n); +} +/* Extended arithmetics on CRIS. */ static inline void t_gen_add_flag (TCGv d,int flag) {
@@ -632,7 +700,7 @@t_gen_subx_carry (cpu_T[0 ]);break ;case CC_OP_LZ : -gen_op_lz_T0_T1 (); +t_gen_lz_i32 (cpu_T[0 ], cpu_T[1 ]);break ;case CC_OP_BTST :gen_op_btst_T0_T1 ();