tcg/ppc: Split out tcg_out_bswap32
Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
783d3ecdda
commit
8a611d8640
@ -807,6 +807,27 @@ static void tcg_out_bswap16(TCGContext *s, TCGReg dst, TCGReg src)
|
|||||||
tcg_out_mov(s, TCG_TYPE_REG, dst, tmp);
|
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. */
|
/* 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)
|
static bool tcg_out_movi_one(TCGContext *s, TCGReg ret, tcg_target_long arg)
|
||||||
{
|
{
|
||||||
@ -2799,24 +2820,9 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc,
|
|||||||
case INDEX_op_bswap16_i64:
|
case INDEX_op_bswap16_i64:
|
||||||
tcg_out_bswap16(s, args[0], args[1]);
|
tcg_out_bswap16(s, args[0], args[1]);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INDEX_op_bswap32_i32:
|
case INDEX_op_bswap32_i32:
|
||||||
case INDEX_op_bswap32_i64:
|
case INDEX_op_bswap32_i64:
|
||||||
/* Stolen from gcc's builtin_bswap32 */
|
tcg_out_bswap32(s, args[0], args[1]);
|
||||||
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);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INDEX_op_bswap64_i64:
|
case INDEX_op_bswap64_i64:
|
||||||
|
Loading…
Reference in New Issue
Block a user