diff mbox series

[4/9] tcg: Use extract2 in tcg_gen_deposit_{i32, i64}

Message ID 20190307144126.31847-5-richard.henderson@linaro.org
State Superseded
Headers show
Series tcg: Add tcg_gen_extract2_{i32,i64} | expand

Commit Message

Richard Henderson March 7, 2019, 2:41 p.m. UTC
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

---
 tcg/tcg-op.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

-- 
2.17.2

Comments

Philippe Mathieu-Daudé March 9, 2019, 12:36 a.m. UTC | #1
On 3/7/19 3:41 PM, Richard Henderson wrote:
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>

> ---

>  tcg/tcg-op.c | 28 ++++++++++++++++++++++++++--

>  1 file changed, 26 insertions(+), 2 deletions(-)

> 

> diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c

> index 34e0dbc6e0..caee80235e 100644

> --- a/tcg/tcg-op.c

> +++ b/tcg/tcg-op.c

> @@ -614,6 +614,18 @@ void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,

>      mask = (1u << len) - 1;


FWIW you can move 'mask' ...

>      t1 = tcg_temp_new_i32();

>  

> +    if (TCG_TARGET_HAS_extract2_i32) {

> +        if (ofs + len == 32) {

> +            tcg_gen_shli_i32(t1, arg1, len);

> +            tcg_gen_extract2_i32(ret, t1, arg2, len);

> +            goto done;

> +        }

> +        if (ofs == 0) {

> +            tcg_gen_extract2_i32(ret, arg1, arg2, len);

> +            tcg_gen_rotli_i32(ret, ret, len);

> +            goto done;

> +        }

> +    }


... here, saving few instr if TCG_TARGET_HAS_extract2_i32 ;)

>      if (ofs + len < 32) {

>          tcg_gen_andi_i32(t1, arg2, mask);

>          tcg_gen_shli_i32(t1, t1, ofs);

> @@ -622,7 +634,7 @@ void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,

>      }

>      tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));

>      tcg_gen_or_i32(ret, ret, t1);

> -

> + done:

>      tcg_temp_free_i32(t1);

>  }

>  

> @@ -2027,6 +2039,18 @@ void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,

>      mask = (1ull << len) - 1;

>      t1 = tcg_temp_new_i64();

>  

> +    if (TCG_TARGET_HAS_extract2_i64) {

> +        if (ofs + len == 64) {

> +            tcg_gen_shli_i64(t1, arg1, len);

> +            tcg_gen_extract2_i64(ret, t1, arg2, len);

> +            goto done;

> +        }

> +        if (ofs == 0) {

> +            tcg_gen_extract2_i64(ret, arg1, arg2, len);

> +            tcg_gen_rotli_i64(ret, ret, len);

> +            goto done;

> +        }

> +    }


Ditto.

>      if (ofs + len < 64) {

>          tcg_gen_andi_i64(t1, arg2, mask);

>          tcg_gen_shli_i64(t1, t1, ofs);

> @@ -2035,7 +2059,7 @@ void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,

>      }

>      tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));

>      tcg_gen_or_i64(ret, ret, t1);

> -

> + done:

>      tcg_temp_free_i64(t1);

>  }

>  

>
diff mbox series

Patch

diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 34e0dbc6e0..caee80235e 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -614,6 +614,18 @@  void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,
     mask = (1u << len) - 1;
     t1 = tcg_temp_new_i32();
 
+    if (TCG_TARGET_HAS_extract2_i32) {
+        if (ofs + len == 32) {
+            tcg_gen_shli_i32(t1, arg1, len);
+            tcg_gen_extract2_i32(ret, t1, arg2, len);
+            goto done;
+        }
+        if (ofs == 0) {
+            tcg_gen_extract2_i32(ret, arg1, arg2, len);
+            tcg_gen_rotli_i32(ret, ret, len);
+            goto done;
+        }
+    }
     if (ofs + len < 32) {
         tcg_gen_andi_i32(t1, arg2, mask);
         tcg_gen_shli_i32(t1, t1, ofs);
@@ -622,7 +634,7 @@  void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,
     }
     tcg_gen_andi_i32(ret, arg1, ~(mask << ofs));
     tcg_gen_or_i32(ret, ret, t1);
-
+ done:
     tcg_temp_free_i32(t1);
 }
 
@@ -2027,6 +2039,18 @@  void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,
     mask = (1ull << len) - 1;
     t1 = tcg_temp_new_i64();
 
+    if (TCG_TARGET_HAS_extract2_i64) {
+        if (ofs + len == 64) {
+            tcg_gen_shli_i64(t1, arg1, len);
+            tcg_gen_extract2_i64(ret, t1, arg2, len);
+            goto done;
+        }
+        if (ofs == 0) {
+            tcg_gen_extract2_i64(ret, arg1, arg2, len);
+            tcg_gen_rotli_i64(ret, ret, len);
+            goto done;
+        }
+    }
     if (ofs + len < 64) {
         tcg_gen_andi_i64(t1, arg2, mask);
         tcg_gen_shli_i64(t1, t1, ofs);
@@ -2035,7 +2059,7 @@  void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,
     }
     tcg_gen_andi_i64(ret, arg1, ~(mask << ofs));
     tcg_gen_or_i64(ret, ret, t1);
-
+ done:
     tcg_temp_free_i64(t1);
 }