Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tcg/tcg-op: Document bswap16_i32() byte pattern
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <20230823145542.79633-2-philmd@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
philmd authored and rth7680 committed Aug 24, 2023
1 parent 95bf306 commit 4de5a76
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions tcg/tcg-op.c
Expand Up @@ -1035,6 +1035,14 @@ void tcg_gen_ext16u_i32(TCGv_i32 ret, TCGv_i32 arg)
}
}

/*
* bswap16_i32: 16-bit byte swap on the low bits of a 32-bit value.
*
* Byte pattern: xxab -> yyba
*
* With TCG_BSWAP_IZ, x == zero, else undefined.
* With TCG_BSWAP_OZ, y == zero, with TCG_BSWAP_OS y == sign, else undefined.
*/
void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags)
{
/* Only one extension flag may be present. */
Expand All @@ -1046,22 +1054,25 @@ void tcg_gen_bswap16_i32(TCGv_i32 ret, TCGv_i32 arg, int flags)
TCGv_i32 t0 = tcg_temp_ebb_new_i32();
TCGv_i32 t1 = tcg_temp_ebb_new_i32();

tcg_gen_shri_i32(t0, arg, 8);
/* arg = ..ab (IZ) xxab (!IZ) */
tcg_gen_shri_i32(t0, arg, 8); /* t0 = ...a (IZ) .xxa (!IZ) */
if (!(flags & TCG_BSWAP_IZ)) {
tcg_gen_ext8u_i32(t0, t0);
tcg_gen_ext8u_i32(t0, t0); /* t0 = ...a */
}

if (flags & TCG_BSWAP_OS) {
tcg_gen_shli_i32(t1, arg, 24);
tcg_gen_sari_i32(t1, t1, 16);
tcg_gen_shli_i32(t1, arg, 24); /* t1 = b... */
tcg_gen_sari_i32(t1, t1, 16); /* t1 = ssb. */
} else if (flags & TCG_BSWAP_OZ) {
tcg_gen_ext8u_i32(t1, arg);
tcg_gen_shli_i32(t1, t1, 8);
tcg_gen_ext8u_i32(t1, arg); /* t1 = ...b */
tcg_gen_shli_i32(t1, t1, 8); /* t1 = ..b. */
} else {
tcg_gen_shli_i32(t1, arg, 8);
tcg_gen_shli_i32(t1, arg, 8); /* t1 = xab. */
}

tcg_gen_or_i32(ret, t0, t1);
tcg_gen_or_i32(ret, t0, t1); /* ret = ..ba (OZ) */
/* = ssba (OS) */
/* = xaba (no flag) */
tcg_temp_free_i32(t0);
tcg_temp_free_i32(t1);
}
Expand Down

0 comments on commit 4de5a76

Please sign in to comment.