qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [4309] CRIS: Convert lz (leading zeros) to TCG.
Date: Sat, 03 May 2008 17:11:37 +0000	[thread overview]
Message-ID: <E1JsLGr-0004yw-Hk@cvs.savannah.gnu.org> (raw)

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
===================================================================
--- trunk/target-cris/translate.c	2008-05-03 15:55:42 UTC (rev 4308)
+++ trunk/target-cris/translate.c	2008-05-03 17:11:36 UTC (rev 4309)
@@ -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();

                 reply	other threads:[~2008-05-03 17:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1JsLGr-0004yw-Hk@cvs.savannah.gnu.org \
    --to=edgar.iglesias@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).