Commit c38ac98da54d2da7a71efde0cbf5ad9021dac4e4

Authored by edgar_igl
1 parent 85220fba

CRIS: Use a helper for lz.

Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6205 c046a42c-6fe2-441c-8c8c-71466251a162
target-cris/helper.h
@@ -10,6 +10,7 @@ DEF_HELPER_0(rfn, void); @@ -10,6 +10,7 @@ DEF_HELPER_0(rfn, void);
10 DEF_HELPER_2(movl_sreg_reg, void, i32, i32) 10 DEF_HELPER_2(movl_sreg_reg, void, i32, i32)
11 DEF_HELPER_2(movl_reg_sreg, void, i32, i32) 11 DEF_HELPER_2(movl_reg_sreg, void, i32, i32)
12 12
  13 +DEF_HELPER_FLAGS_1(lz, TCG_CALL_PURE, i32, i32);
13 DEF_HELPER_FLAGS_3(btst, TCG_CALL_PURE, i32, i32, i32, i32); 14 DEF_HELPER_FLAGS_3(btst, TCG_CALL_PURE, i32, i32, i32, i32);
14 15
15 DEF_HELPER_0(evaluate_flags_muls, void) 16 DEF_HELPER_0(evaluate_flags_muls, void)
target-cris/op_helper.c
@@ -23,6 +23,7 @@ @@ -23,6 +23,7 @@
23 #include "exec.h" 23 #include "exec.h"
24 #include "mmu.h" 24 #include "mmu.h"
25 #include "helper.h" 25 #include "helper.h"
  26 +#include "host-utils.h"
26 27
27 #define D(x) 28 #define D(x)
28 29
@@ -243,6 +244,11 @@ void helper_rfn(void) @@ -243,6 +244,11 @@ void helper_rfn(void)
243 env->pregs[PR_CCS] |= M_FLAG; 244 env->pregs[PR_CCS] |= M_FLAG;
244 } 245 }
245 246
  247 +uint32_t helper_lz(uint32_t t0)
  248 +{
  249 + return clz32(t0);
  250 +}
  251 +
246 uint32_t helper_btst(uint32_t t0, uint32_t t1, uint32_t ccs) 252 uint32_t helper_btst(uint32_t t0, uint32_t t1, uint32_t ccs)
247 { 253 {
248 /* FIXME: clean this up. */ 254 /* FIXME: clean this up. */
target-cris/translate.c
@@ -320,74 +320,6 @@ static void t_gen_mulu(TCGv d, TCGv d2, TCGv a, TCGv b) @@ -320,74 +320,6 @@ static void t_gen_mulu(TCGv d, TCGv d2, TCGv a, TCGv b)
320 tcg_temp_free_i64(t1); 320 tcg_temp_free_i64(t1);
321 } 321 }
322 322
323 -/* 32bit branch-free binary search for counting leading zeros. */  
324 -static void t_gen_lz_i32(TCGv d, TCGv x)  
325 -{  
326 - TCGv_i32 y, m, n;  
327 -  
328 - y = tcg_temp_new_i32();  
329 - m = tcg_temp_new_i32();  
330 - n = tcg_temp_new_i32();  
331 -  
332 - /* y = -(x >> 16) */  
333 - tcg_gen_shri_i32(y, x, 16);  
334 - tcg_gen_neg_i32(y, y);  
335 -  
336 - /* m = (y >> 16) & 16 */  
337 - tcg_gen_sari_i32(m, y, 16);  
338 - tcg_gen_andi_i32(m, m, 16);  
339 -  
340 - /* n = 16 - m */  
341 - tcg_gen_sub_i32(n, tcg_const_i32(16), m);  
342 - /* x = x >> m */  
343 - tcg_gen_shr_i32(x, x, m);  
344 -  
345 - /* y = x - 0x100 */  
346 - tcg_gen_subi_i32(y, x, 0x100);  
347 - /* m = (y >> 16) & 8 */  
348 - tcg_gen_sari_i32(m, y, 16);  
349 - tcg_gen_andi_i32(m, m, 8);  
350 - /* n = n + m */  
351 - tcg_gen_add_i32(n, n, m);  
352 - /* x = x << m */  
353 - tcg_gen_shl_i32(x, x, m);  
354 -  
355 - /* y = x - 0x1000 */  
356 - tcg_gen_subi_i32(y, x, 0x1000);  
357 - /* m = (y >> 16) & 4 */  
358 - tcg_gen_sari_i32(m, y, 16);  
359 - tcg_gen_andi_i32(m, m, 4);  
360 - /* n = n + m */  
361 - tcg_gen_add_i32(n, n, m);  
362 - /* x = x << m */  
363 - tcg_gen_shl_i32(x, x, m);  
364 -  
365 - /* y = x - 0x4000 */  
366 - tcg_gen_subi_i32(y, x, 0x4000);  
367 - /* m = (y >> 16) & 2 */  
368 - tcg_gen_sari_i32(m, y, 16);  
369 - tcg_gen_andi_i32(m, m, 2);  
370 - /* n = n + m */  
371 - tcg_gen_add_i32(n, n, m);  
372 - /* x = x << m */  
373 - tcg_gen_shl_i32(x, x, m);  
374 -  
375 - /* y = x >> 14 */  
376 - tcg_gen_shri_i32(y, x, 14);  
377 - /* m = y & ~(y >> 1) */  
378 - tcg_gen_sari_i32(m, y, 1);  
379 - tcg_gen_not_i32(m, m);  
380 - tcg_gen_and_i32(m, m, y);  
381 -  
382 - /* d = n + 2 - m */  
383 - tcg_gen_addi_i32(d, n, 2);  
384 - tcg_gen_sub_i32(d, d, m);  
385 -  
386 - tcg_temp_free(y);  
387 - tcg_temp_free(m);  
388 - tcg_temp_free(n);  
389 -}  
390 -  
391 static void t_gen_cris_dstep(TCGv d, TCGv a, TCGv b) 323 static void t_gen_cris_dstep(TCGv d, TCGv a, TCGv b)
392 { 324 {
393 int l1; 325 int l1;
@@ -825,7 +757,7 @@ static void cris_alu_op_exec(DisasContext *dc, int op, @@ -825,7 +757,7 @@ static void cris_alu_op_exec(DisasContext *dc, int op,
825 t_gen_subx_carry(dc, dst); 757 t_gen_subx_carry(dc, dst);
826 break; 758 break;
827 case CC_OP_LZ: 759 case CC_OP_LZ:
828 - t_gen_lz_i32(dst, b); 760 + gen_helper_lz(dst, b);
829 break; 761 break;
830 case CC_OP_MULS: 762 case CC_OP_MULS:
831 t_gen_muls(dst, cpu_PR[PR_MOF], a, b); 763 t_gen_muls(dst, cpu_PR[PR_MOF], a, b);