lightning
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 1/2] ppc: Use fallback for popcntr() instruction


From: Paul Cercueil
Subject: [PATCH 1/2] ppc: Use fallback for popcntr() instruction
Date: Sun, 7 Jan 2024 16:27:41 +0100

I could not find any "POPCNTB" instruction in the official
documentation, and qemu doesn't know about it either (it results in an
SIGILL).

Drop the custom implementation and use the fallback instead, which is
the safer option.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 lib/jit_ppc-cpu.c | 19 -------------------
 lib/jit_ppc.c     |  1 +
 2 files changed, 1 insertion(+), 19 deletions(-)

diff --git a/lib/jit_ppc-cpu.c b/lib/jit_ppc-cpu.c
index 8ea8e62..fc79944 100644
--- a/lib/jit_ppc-cpu.c
+++ b/lib/jit_ppc-cpu.c
@@ -392,7 +392,6 @@ static void _MCRXR(jit_state_t*, jit_int32_t);
 #  define ORI(d,a,u)                   FDu(24,a,d,u)
 #  define NOP()                                ORI(0,0,0)
 #  define ORIS(d,a,u)                  FDu(25,a,d,u)
-#  define POPCNTB(a,s)                 FX(31,s,a,0,122)
 #  define RFI()                                FXL(19,0,0,50)
 #  define RLWIMI(d,s,h,b,e)            FM(20,s,d,h,b,e,0)
 #  define RLWIMI_(d,s,h,b,e)           FM(20,s,d,h,b,e,1)
@@ -552,8 +551,6 @@ static void _clor(jit_state_t*, jit_int32_t, jit_int32_t);
 static void _ctor(jit_state_t*, jit_int32_t, jit_int32_t);
 #  define ctzr(r0, r1)                 _ctzr(_jit, r0, r1)
 static void _ctzr(jit_state_t*, jit_int32_t, jit_int32_t);
-#  define popcntr(r0, r1)              _popcntr(_jit, r0, r1)
-static void _popcntr(jit_state_t*, jit_int32_t, jit_int32_t);
 #  define extr(r0,r1,i0,i1)            _extr(_jit,r0,r1,i0,i1)
 static void _extr(jit_state_t*,jit_int32_t,jit_int32_t,jit_word_t,jit_word_t);
 #  define extr_u(r0,r1,i0,i1)          _extr_u(_jit,r0,r1,i0,i1)
@@ -1298,22 +1295,6 @@ _ctzr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
     jit_unget_reg(t1);
 }
 
-static void
-_popcntr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
-{
-    jit_int32_t                reg;
-    reg = jit_get_reg(jit_class_gpr);
-    POPCNTB(r0, r1);
-#if __WORDSIZE == 32
-    movi(rn(reg), 0x01010101);
-#else
-    movi(rn(reg), 0x0101010101010101);
-#endif
-    mullr(r0, r0, rn(reg));
-    rshi_u(r0, r0, __WORDSIZE - 8);
-    jit_unget_reg(reg);
-}
-
 static void
 _extr(jit_state_t *_jit,
       jit_int32_t r0, jit_int32_t r1, jit_word_t i0 ,jit_word_t i1)
diff --git a/lib/jit_ppc.c b/lib/jit_ppc.c
index 975d282..3b53aa6 100644
--- a/lib/jit_ppc.c
+++ b/lib/jit_ppc.c
@@ -1473,6 +1473,7 @@ _emit_code(jit_state_t *_jit)
                case_rr(ctz,);
 #define rbitr(r0, r1)  fallback_rbit(r0, r1)
                case_rr(rbit,);
+#define popcntr(r0, r1)        fallback_popcnt(r0, r1)
                case_rr(popcnt,);
            case jit_code_casr:
                casr(rn(node->u.w), rn(node->v.w),
-- 
2.43.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]