Message ID | 20210614083800.1166166-9-richard.henderson@linaro.org |
---|---|
State | Superseded |
Headers | show |
Series | tcg: bswap improvements | expand |
On Mon, 14 Jun 2021 at 09:42, Richard Henderson <richard.henderson@linaro.org> wrote: > > Signed-off-by: Richard Henderson <richard.henderson@linaro.org> > --- > tcg/ppc/tcg-target.c.inc | 28 ++++++++++++---------------- > 1 file changed, 12 insertions(+), 16 deletions(-) > > diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc > index 64c24382a8..f0e42e4b88 100644 > --- a/tcg/ppc/tcg-target.c.inc > +++ b/tcg/ppc/tcg-target.c.inc > @@ -798,6 +798,17 @@ static void tcg_out_bswap16(TCGContext *s, TCGReg dst, TCGReg src) > tcg_out_mov(s, TCG_TYPE_REG, dst, tmp); > } > > +static void tcg_out_bswap32(TCGContext *s, TCGReg dst, TCGReg src) > +{ > + TCGReg tmp = dst == src ? TCG_REG_R0 : dst; > + > + /* Stolen from gcc's builtin_bswap32. src = abcd */ > + tcg_out_rlw(s, RLWINM, tmp, src, 8, 0, 31); /* tmp = bcda */ > + tcg_out_rlw(s, RLWIMI, tmp, src, 24, 0, 7); /* tmp = dcda */ > + tcg_out_rlw(s, RLWIMI, tmp, src, 24, 16, 23); /* tmp = dcba */ > + tcg_out_mov(s, TCG_TYPE_REG, dst, tmp); > +} > + > /* Emit a move into ret of arg, if it can be done in one insn. */ > static bool tcg_out_movi_one(TCGContext *s, TCGReg ret, tcg_target_long arg) > { > @@ -2791,24 +2802,9 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, > case INDEX_op_bswap16_i64: > tcg_out_bswap16(s, args[0], args[1]); > break; > - > case INDEX_op_bswap32_i32: > case INDEX_op_bswap32_i64: > - /* Stolen from gcc's builtin_bswap32 */ > - a1 = args[1]; > - a0 = args[0] == a1 ? TCG_REG_R0 : args[0]; > - > - /* a1 = args[1] # abcd */ > - /* a0 = rotate_left (a1, 8) # bcda */ > - tcg_out_rlw(s, RLWINM, a0, a1, 8, 0, 31); > - /* a0 = (a0 & ~0xff000000) | ((a1 r<< 24) & 0xff000000) # dcda */ > - tcg_out_rlw(s, RLWIMI, a0, a1, 24, 0, 7); > - /* a0 = (a0 & ~0x0000ff00) | ((a1 r<< 24) & 0x0000ff00) # dcba */ > - tcg_out_rlw(s, RLWIMI, a0, a1, 24, 16, 23); > - > - if (a0 == TCG_REG_R0) { > - tcg_out_mov(s, TCG_TYPE_REG, args[0], a0); > - } > + tcg_out_bswap32(s, args[0], args[1]); > break; > Same remark about keeping the comments; otherwise Reviewed-by: Peter Maydell <peter.maydell@linaro.org> thanks -- PMM
diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc index 64c24382a8..f0e42e4b88 100644 --- a/tcg/ppc/tcg-target.c.inc +++ b/tcg/ppc/tcg-target.c.inc @@ -798,6 +798,17 @@ static void tcg_out_bswap16(TCGContext *s, TCGReg dst, TCGReg src) tcg_out_mov(s, TCG_TYPE_REG, dst, tmp); } +static void tcg_out_bswap32(TCGContext *s, TCGReg dst, TCGReg src) +{ + TCGReg tmp = dst == src ? TCG_REG_R0 : dst; + + /* Stolen from gcc's builtin_bswap32. src = abcd */ + tcg_out_rlw(s, RLWINM, tmp, src, 8, 0, 31); /* tmp = bcda */ + tcg_out_rlw(s, RLWIMI, tmp, src, 24, 0, 7); /* tmp = dcda */ + tcg_out_rlw(s, RLWIMI, tmp, src, 24, 16, 23); /* tmp = dcba */ + tcg_out_mov(s, TCG_TYPE_REG, dst, tmp); +} + /* Emit a move into ret of arg, if it can be done in one insn. */ static bool tcg_out_movi_one(TCGContext *s, TCGReg ret, tcg_target_long arg) { @@ -2791,24 +2802,9 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, case INDEX_op_bswap16_i64: tcg_out_bswap16(s, args[0], args[1]); break; - case INDEX_op_bswap32_i32: case INDEX_op_bswap32_i64: - /* Stolen from gcc's builtin_bswap32 */ - a1 = args[1]; - a0 = args[0] == a1 ? TCG_REG_R0 : args[0]; - - /* a1 = args[1] # abcd */ - /* a0 = rotate_left (a1, 8) # bcda */ - tcg_out_rlw(s, RLWINM, a0, a1, 8, 0, 31); - /* a0 = (a0 & ~0xff000000) | ((a1 r<< 24) & 0xff000000) # dcda */ - tcg_out_rlw(s, RLWIMI, a0, a1, 24, 0, 7); - /* a0 = (a0 & ~0x0000ff00) | ((a1 r<< 24) & 0x0000ff00) # dcba */ - tcg_out_rlw(s, RLWIMI, a0, a1, 24, 16, 23); - - if (a0 == TCG_REG_R0) { - tcg_out_mov(s, TCG_TYPE_REG, args[0], a0); - } + tcg_out_bswap32(s, args[0], args[1]); break; case INDEX_op_bswap64_i64:
Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- tcg/ppc/tcg-target.c.inc | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) -- 2.25.1