qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Filip Navara <filip.navara@gmail.com>
To: Laurent Desnogues <laurent.desnogues@gmail.com>
Cc: qemu-devel@nongnu.org, Paul Brook <paul@codesourcery.com>
Subject: Re: [Qemu-devel] [PATCH] RFC: TCG constant propagation.
Date: Thu, 23 Jul 2009 11:49:18 +0200	[thread overview]
Message-ID: <5b31733c0907230249xb1a4384k6c4f2b48defde1ae@mail.gmail.com> (raw)
In-Reply-To: <761ea48b0907230225g77d7d0e6q6e1fd8af302ed795@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 963 bytes --]

On Thu, Jul 23, 2009 at 11:25 AM, Laurent
Desnogues<laurent.desnogues@gmail.com> wrote:
> On Thu, Jul 23, 2009 at 11:08 AM, Filip Navara<filip.navara@gmail.com> wrote:
>> Also it looks that the actual code size is worse for TCG ARM target
>> with this optimization. To mitigate it I propose the other attached
>> patch which uses the barrel shifter for more optimal generation of the
>> "movi" operation. I can't test it, so any help is welcome.
>
> This is wrong for two reasons:
>   - this is a rotation, you only check for shifts

I deliberately didn't do it, but it's surely an opportunity for
further optimization.

>   - the rotation amount is multiplied by 2 before being applied to the
>     8-bit immediate field.

As Paul already pointed out, that's compensated by the shift (<< 7
instead of << 8) and the "& ~1" after ctz32 call.

Attached is fixed version of the patch, I forgot one "return" there.

Best regards,
Filip Navara

[-- Attachment #2: 0002-Use-ARM-barrel-shifter-for-more-optimal-generation-o.patch --]
[-- Type: application/octet-stream, Size: 1566 bytes --]

From d326aabe85412a91c17e0be2ebbfd078bec16713 Mon Sep 17 00:00:00 2001
From: Filip Navara <filip.navara@gmail.com>
Date: Thu, 23 Jul 2009 11:01:32 +0200
Subject: [PATCH 2/2] Use ARM barrel shifter for more optimal generation of MVN, MOV instructions for the MOVI TCG operation.

---
 tcg/arm/tcg-target.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/tcg/arm/tcg-target.c b/tcg/arm/tcg-target.c
index 7ef2b89..9748ce2 100644
--- a/tcg/arm/tcg-target.c
+++ b/tcg/arm/tcg-target.c
@@ -334,6 +334,7 @@ static inline void tcg_out_movi32(TCGContext *s,
                 int cond, int rd, int32_t arg)
 {
     int offset = (uint32_t) arg - ((uint32_t) s->code_ptr + 8);
+    int shift;
 
     /* TODO: This is very suboptimal, we can easily have a constant
      * pool somewhere after all the instructions.  */
@@ -346,6 +347,17 @@ static inline void tcg_out_movi32(TCGContext *s,
                 tcg_out_dat_imm(s, cond, ARITH_ADD, rd, 15, offset) :
                 tcg_out_dat_imm(s, cond, ARITH_SUB, rd, 15, -offset);
 
+    if (arg < 0x100)
+        return tcg_out_dat_imm(s, cond, ARITH_MOV, rd, 0, arg & 0xff);
+
+    shift = ctz32(arg) & ~1;
+    if (!((arg >> shift) & ~0xff))
+        return tcg_out_dat_imm(s, cond, ARITH_MOV, rd, 0, (arg >> shift) + (shift << 7));
+
+    shift = ctz32(~arg) & ~1;
+    if (!((~arg >> shift) & ~0xff))
+        return tcg_out_dat_imm(s, cond, ARITH_MVN, rd, 0, (~arg >> shift) + (shift << 7));
+
 #ifdef __ARM_ARCH_7A__
     /* use movw/movt */
     /* movw */
-- 
1.6.3.2.1299.gee46c


  parent reply	other threads:[~2009-07-23  9:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-21 14:37 [Qemu-devel] [PATCH] RFC: TCG constant propagation Filip Navara
2009-07-23  9:08 ` Filip Navara
2009-07-23  9:25   ` Laurent Desnogues
2009-07-23  9:30     ` Paul Brook
2009-07-23  9:49     ` Filip Navara [this message]
2009-07-23 20:10   ` Stuart Brady
2009-07-23 20:28     ` Filip Navara
2009-07-23 22:02   ` Daniel Jacobowitz
2009-08-05  8:13 ` Pablo Virolainen
2009-08-05  8:48   ` Filip Navara

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=5b31733c0907230249xb1a4384k6c4f2b48defde1ae@mail.gmail.com \
    --to=filip.navara@gmail.com \
    --cc=laurent.desnogues@gmail.com \
    --cc=paul@codesourcery.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).