Skip to contentSkip to conversation

target-arm: inline abs, 64-bit negate

PATCH Superseded Peter Maydell 2 participants 5 messages Oct 18, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover target-arm: inline abs, 64-bit negate

Two minor patches which inline some operations rather than using helper functions. The 64 bit negate is a no-brainer since there's a simple TCG op for it. For abs we implement in terms of movcond:
movi_i32 tmp6,$0x0
neg_i32 tmp7,tmp5
movcond_i32 tmp5,tmp5,tmp6,tmp5,tmp7,gt
which the x86-64 backend turns into:

 0x603b53a7:  mov    %ebp,%ebx
 0x603b53a9:  neg    %ebx
 0x603b53ab:  mov    %ebp,%r12d
 0x603b53ae:  test   %ebp,%ebp
 0x603b53b0:  cmovle %ebx,%r12d

Not sure why it felt the need to use an extra move there, but for ARM this isn't in a particularly performance critical bit of the instruction set (it's a Neon operation) so I'm not too worried.

(A fully native TCG abs op would be able to use the fact that neg sets flags to avoid the test as well.)

Peter Maydell (2):
target-arm: Use TCG operation for Neon 64 bit negation
target-arm: Implement abs_i32 inline rather than as a helper

 target-arm/helper.c      |    5 -----
 target-arm/helper.h      |    2 --
 target-arm/neon_helper.c |    6 ------
 target-arm/translate.c   |   14 +++++++++++---
 4 files changed, 11 insertions(+), 16 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/2 target-arm: Use TCG operation for Neon 64 bit negation

Use the TCG operation to do Neon 64 bit negations rather than calling a helper routine for it.

---
 target-arm/helper.h      |    1 -
 target-arm/neon_helper.c |    6 ------
 target-arm/translate.c   |    4 +++-
 3 files changed, 3 insertions(+), 8 deletions(-)
target-arm/helper.h +0 -1
index 8b9adf1..fa3472f 100644
@@ -339,7 +339,6 @@ DEF_HELPER_2(neon_mull_s16, i64, i32, i32)
 
 DEF_HELPER_1(neon_negl_u16, i64, i64)
 DEF_HELPER_1(neon_negl_u32, i64, i64)
-DEF_HELPER_1(neon_negl_u64, i64, i64)
 
 DEF_HELPER_2(neon_qabs_s8, i32, env, i32)
 DEF_HELPER_2(neon_qabs_s16, i32, env, i32)
target-arm/neon_helper.c +0 -6
index 8bb5129..616cf95 100644
@@ -1665,12 +1665,6 @@ uint64_t HELPER(neon_negl_u32)(uint64_t x)
     return low | ((uint64_t)high << 32);
 }
 
-/* FIXME:  There should be a native op for this.  */
-uint64_t HELPER(neon_negl_u64)(uint64_t x)
-{
-    return -x;
-}
-
 /* Saturating sign manipulation.  */
 /* ??? Make these use NEON_VOP1 */
 #define DO_QABS8(x) do { \
target-arm/translate.c +3 -1
index daccb15..d33f94c 100644
@@ -4184,7 +4184,9 @@ static inline void gen_neon_negl(TCGv_i64 var, int size)
     switch (size) {
     case 0: gen_helper_neon_negl_u16(var, var); break;
     case 1: gen_helper_neon_negl_u32(var, var); break;
-    case 2: gen_helper_neon_negl_u64(var, var); break;
+    case 2:
+        tcg_gen_neg_i64(var, var);
+        break;
     default: abort();
     }
 }
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/2 target-arm: Implement abs_i32 inline rather than as a helper

In reply to Peter Maydell

Implement abs_i32 inline (with movcond) rather than using a helper function.

---
 target-arm/helper.c    |    5 -----
 target-arm/helper.h    |    1 -
 target-arm/translate.c |   10 ++++++++--
 3 files changed, 8 insertions(+), 8 deletions(-)
target-arm/helper.c +0 -5
index 58340bd..0601760 100644
@@ -1562,11 +1562,6 @@ uint32_t HELPER(rbit)(uint32_t x)
     return x;
 }
 
-uint32_t HELPER(abs)(uint32_t x)
-{
-    return ((int32_t)x < 0) ? -x : x;
-}
-
 #if defined(CONFIG_USER_ONLY)
 
 void do_interrupt (CPUARMState *env)
target-arm/helper.h +0 -1
index fa3472f..60812de 100644
@@ -13,7 +13,6 @@ DEF_HELPER_2(double_saturate, i32, env, s32)
 DEF_HELPER_FLAGS_2(sdiv, TCG_CALL_CONST | TCG_CALL_PURE, s32, s32, s32)
 DEF_HELPER_FLAGS_2(udiv, TCG_CALL_CONST | TCG_CALL_PURE, i32, i32, i32)
 DEF_HELPER_FLAGS_1(rbit, TCG_CALL_CONST | TCG_CALL_PURE, i32, i32)
-DEF_HELPER_FLAGS_1(abs, TCG_CALL_CONST | TCG_CALL_PURE, i32, i32)
 
 #define PAS_OP(pfx)  \
     DEF_HELPER_3(pfx ## add8, i32, i32, i32, ptr) \
target-arm/translate.c +8 -2
index d33f94c..5a7602a 100644
@@ -462,8 +462,14 @@ static void gen_sar(TCGv dest, TCGv t0, TCGv t1)
     tcg_temp_free_i32(tmp1);
 }
 
-/* FIXME:  Implement this natively.  */
-#define tcg_gen_abs_i32(t0, t1) gen_helper_abs(t0, t1)
+static void tcg_gen_abs_i32(TCGv dest, TCGv src)
+{
+    TCGv c0 = tcg_const_i32(0);
+    printf("tcg_gen_abs_i32\n");
+    tcg_gen_neg_i32(dest, src);
+    tcg_gen_movcond_i32(TCG_COND_GT, dest, src, c0, src, dest);
+    tcg_temp_free_i32(c0);
+}
 
 static void shifter_out_im(TCGv var, int shift)
 {
Signature · 1 line
1.7.9.5
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-arm: Implement abs_i32 inline rather than as a helper

On Thu, 18 Oct 2012, Peter Maydell wrote:

[..snip..]

target-arm/translate.c static void gen_sar(TCGv dest, TCGv t0, TCGv t1) · line 468

Quoted 7 lines
target-arm/translate.c +4 -2
-/* FIXME:  Implement this natively.  */
-#define tcg_gen_abs_i32(t0, t1) gen_helper_abs(t0, t1)
+static void tcg_gen_abs_i32(TCGv dest, TCGv src)
+{
+    TCGv c0 = tcg_const_i32(0);
+    printf("tcg_gen_abs_i32\n");

^^^^^^ doubt it was intentional

Quoted 8 lines
target-arm/translate.c +4 -0
+    tcg_gen_neg_i32(dest, src);
+    tcg_gen_movcond_i32(TCG_COND_GT, dest, src, c0, src, dest);
+    tcg_temp_free_i32(c0);
+}
 
 static void shifter_out_im(TCGv var, int shift)
 {
Signature · 1 line
mailto:[email protected]
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] target-arm: Implement abs_i32 inline rather than as a helper

Quoted 5 lines · malc

On Thu, 18 Oct 2012, Peter Maydell wrote:

[..snip..]

Quoted 1 line
Quoted 8 lines

target-arm/translate.c static void gen_sar(TCGv dest, TCGv t0, TCGv t1) · line 468

Quoted 6 lines
target-arm/translate.c +4 -2
-/* FIXME:  Implement this natively.  */
-#define tcg_gen_abs_i32(t0, t1) gen_helper_abs(t0, t1)
+static void tcg_gen_abs_i32(TCGv dest, TCGv src)
+{
+    TCGv c0 = tcg_const_i32(0);
+    printf("tcg_gen_abs_i32\n");

^^^^^^ doubt it was intentional

Indeed, thanks. I seem to be making a lot of silly errors today...

-- PMM