Skip to content

Commit

Permalink
tcg/ppc: Split out tcg_out_bswap32
Browse files Browse the repository at this point in the history
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Jun 29, 2021
1 parent 783d3ec commit 8a611d8
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions tcg/ppc/tcg-target.c.inc
Expand Up @@ -807,6 +807,27 @@ 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.
* In the following,
* dep(a, b, m) -> (a & ~m) | (b & m)
*
* Begin with: src = xxxxabcd
*/
/* tmp = rol32(src, 8) & 0xffffffff = 0000bcda */
tcg_out_rlw(s, RLWINM, tmp, src, 8, 0, 31);
/* tmp = dep(tmp, rol32(src, 24), 0xff000000) = 0000dcda */
tcg_out_rlw(s, RLWIMI, tmp, src, 24, 0, 7);
/* tmp = dep(tmp, rol32(src, 24), 0x0000ff00) = 0000dcba */
tcg_out_rlw(s, RLWIMI, tmp, src, 24, 16, 23);

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)
{
Expand Down Expand Up @@ -2799,24 +2820,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:
Expand Down

0 comments on commit 8a611d8

Please sign in to comment.