lightning
[Top][All Lists]
Advanced

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

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


From: Paulo César Pereira de Andrade
Subject: Re: [PATCH 1/2] ppc: Use fallback for popcntr() instruction
Date: Mon, 22 Jan 2024 18:10:34 -0300

Em dom., 7 de jan. de 2024 às 12:27, Paul Cercueil
<paul@crapouillou.net> escreveu:
>
> I could not find any "POPCNTB" instruction in the official
> documentation, and qemu doesn't know about it either (it results in an
> SIGILL).

  Searching for PPC_Vers202_Book1_public.pdf in google should find
a few links to a document that describes it.

  From gcc documentation:

‘popcntb’‘no-popcntb’
    Generate code that uses (does not use) the popcount and
double-precision FP reciprocal estimate instruction implemented on the
POWER5 processor and other processors that support the PowerPC V2.02
architecture.

  I will work on a path to either detect, but disabled by default, attempt
to execute the instruction and catch SIGILL, or some other procedure.
  For Linux could read /proc/cpuinfo and check the cpu: and/or release:
flags.

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

  A few ports have a jit_get_cpu() call that does a brute force test for
instructions. In all cases it is disabled by default, only known to work.
For now it would only provide a "hidden" flag to enable or disable
the popcntb instruction.

> 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

Thanks,
Paulo



reply via email to

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