diff mbox

[v2,10/10] tcg/optimize: add constant folding for deposit

Message ID 1348256598-8146-11-git-send-email-aurelien@aurel32.net
State New
Headers show

Commit Message

Aurelien Jarno Sept. 21, 2012, 7:43 p.m. UTC
Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
---
 tcg/optimize.c |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Richard Henderson Sept. 21, 2012, 11:22 p.m. UTC | #1
On 09/21/2012 12:43 PM, Aurelien Jarno wrote:
> +                tmp = ((1ull << args[4]) - 1);
> +                tmp = (temps[args[1]].val & ~(tmp << args[3]))
> +                      | ((temps[args[2]].val & tmp) << args[3]);
> +                tcg_opt_gen_movi(gen_args, args[0], tmp);

We do have a deposit64 function in bitops.h, fwiw.

Though, really, bitops.h has some crappy functions in it that are
redundant with the better functions in host-utils.h...


r~
Aurelien Jarno Sept. 22, 2012, 9:41 a.m. UTC | #2
On Fri, Sep 21, 2012 at 04:22:53PM -0700, Richard Henderson wrote:
> On 09/21/2012 12:43 PM, Aurelien Jarno wrote:
> > +                tmp = ((1ull << args[4]) - 1);
> > +                tmp = (temps[args[1]].val & ~(tmp << args[3]))
> > +                      | ((temps[args[2]].val & tmp) << args[3]);
> > +                tcg_opt_gen_movi(gen_args, args[0], tmp);
> 
> We do have a deposit64 function in bitops.h, fwiw.
> 
> Though, really, bitops.h has some crappy functions in it that are
> redundant with the better functions in host-utils.h...
> 

Is there a reason that bitops.h is not used from tcg/*, while
host-utils.h is? Licensing issue maybe (bitops.h is LGPL, host-utils.h
is BSD like).
Richard Henderson Sept. 22, 2012, 12:45 p.m. UTC | #3
On 2012-09-22 02:41, Aurelien Jarno wrote:
> On Fri, Sep 21, 2012 at 04:22:53PM -0700, Richard Henderson wrote:
>> On 09/21/2012 12:43 PM, Aurelien Jarno wrote:
>>> +                tmp = ((1ull << args[4]) - 1);
>>> +                tmp = (temps[args[1]].val & ~(tmp << args[3]))
>>> +                      | ((temps[args[2]].val & tmp) << args[3]);
>>> +                tcg_opt_gen_movi(gen_args, args[0], tmp);
>>
>> We do have a deposit64 function in bitops.h, fwiw.
>>
>> Though, really, bitops.h has some crappy functions in it that are
>> redundant with the better functions in host-utils.h...
>>
> 
> Is there a reason that bitops.h is not used from tcg/*, while
> host-utils.h is? Licensing issue maybe (bitops.h is LGPL, host-utils.h
> is BSD like).

I assumed without looking that bitops.h is newer.


r~
Blue Swirl Sept. 22, 2012, 2:41 p.m. UTC | #4
On Sat, Sep 22, 2012 at 9:41 AM, Aurelien Jarno <aurelien@aurel32.net> wrote:
> On Fri, Sep 21, 2012 at 04:22:53PM -0700, Richard Henderson wrote:
>> On 09/21/2012 12:43 PM, Aurelien Jarno wrote:
>> > +                tmp = ((1ull << args[4]) - 1);
>> > +                tmp = (temps[args[1]].val & ~(tmp << args[3]))
>> > +                      | ((temps[args[2]].val & tmp) << args[3]);
>> > +                tcg_opt_gen_movi(gen_args, args[0], tmp);
>>
>> We do have a deposit64 function in bitops.h, fwiw.
>>
>> Though, really, bitops.h has some crappy functions in it that are
>> redundant with the better functions in host-utils.h...

Better code should always replace bad code.

>>
>
> Is there a reason that bitops.h is not used from tcg/*, while
> host-utils.h is? Licensing issue maybe (bitops.h is LGPL, host-utils.h
> is BSD like).

No, it's just that bitops were added without converting all possible users.

>
>
> --
> Aurelien Jarno                          GPG: 1024D/F1BCDB73
> aurelien@aurel32.net                 http://www.aurel32.net
>
diff mbox

Patch

diff --git a/tcg/optimize.c b/tcg/optimize.c
index c8ae50b..35532a1 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -668,6 +668,26 @@  static TCGArg *tcg_constant_folding(TCGContext *s, uint16_t *tcg_opc_ptr,
             }
             args += 3;
             break;
+        CASE_OP_32_64(deposit):
+            if (temps[args[1]].state == TCG_TEMP_CONST
+                && temps[args[2]].state == TCG_TEMP_CONST) {
+                gen_opc_buf[op_index] = op_to_movi(op);
+                tmp = ((1ull << args[4]) - 1);
+                tmp = (temps[args[1]].val & ~(tmp << args[3]))
+                      | ((temps[args[2]].val & tmp) << args[3]);
+                tcg_opt_gen_movi(gen_args, args[0], tmp);
+                gen_args += 2;
+            } else {
+                reset_temp(args[0]);
+                gen_args[0] = args[0];
+                gen_args[1] = args[1];
+                gen_args[2] = args[2];
+                gen_args[3] = args[3];
+                gen_args[4] = args[4];
+                gen_args += 5;
+            }
+            args += 5;
+            break;
         CASE_OP_32_64(setcond):
             tmp = do_constant_folding_cond(op, args[1], args[2], args[3]);
             if (tmp != 2) {