[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 09/22] target/loongarch: Add fixed point bit instruction t
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH v2 09/22] target/loongarch: Add fixed point bit instruction translation |
Date: |
Wed, 21 Jul 2021 19:46:48 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 |
On 7/21/21 11:53 AM, Song Gao wrote:
> This patch implement fixed point bit instruction translation.
>
> This includes:
> - EXT.W.{B/H}
> - CL{O/Z}.{W/D}, CT{O/Z}.{W/D}
> - BYTEPICK.{W/D}
> - REVB.{2H/4H/2W/D}
> - REVH.{2W/D}
> - BITREV.{4B/8B}, BITREV.{W/D}
> - BSTRINS.{W/D}, BSTRPICK.{W/D}
> - MASKEQZ, MASKNEZ
>
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> ---
> target/loongarch/helper.h | 10 +
> target/loongarch/insns.decode | 45 +++
> target/loongarch/op_helper.c | 119 ++++++++
> target/loongarch/trans.inc.c | 665
> ++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 839 insertions(+)
> diff --git a/target/loongarch/op_helper.c b/target/loongarch/op_helper.c
> index b2cbdd7..07c3d52 100644
> --- a/target/loongarch/op_helper.c
> +++ b/target/loongarch/op_helper.c
> @@ -25,3 +25,122 @@ void helper_raise_exception(CPULoongArchState *env,
> uint32_t exception)
> {
> do_raise_exception(env, exception, GETPC());
> }
> +
> +target_ulong helper_cto_w(CPULoongArchState *env, target_ulong rj)
> +{
> + uint32_t v = (uint32_t)rj;
> + int temp = 0;
> +
> + while ((v & 0x1) == 1) {
> + temp++;
> + v = v >> 1;
> + }
Why not use cto32() from "qemu/host-utils.h"
> +
> + return (target_ulong)temp;
> +}
> +
> +target_ulong helper_ctz_w(CPULoongArchState *env, target_ulong rj)
> +{
> + uint32_t v = (uint32_t)rj;
> +
> + if (v == 0) {
> + return 32;
> + }
> +
> + int temp = 0;
> + while ((v & 0x1) == 0) {
> + temp++;
> + v = v >> 1;
> + }
ctz32
> +
> + return (target_ulong)temp;
> +}
> +
> +target_ulong helper_cto_d(CPULoongArchState *env, target_ulong rj)
> +{
> + uint64_t v = rj;
> + int temp = 0;
> +
> + while ((v & 0x1) == 1) {
> + temp++;
> + v = v >> 1;
> + }
cto64
> +
> + return (target_ulong)temp;
> +}
> +
> +target_ulong helper_ctz_d(CPULoongArchState *env, target_ulong rj)
> +{
> + uint64_t v = rj;
> +
> + if (v == 0) {
> + return 64;
> + }
> +
> + int temp = 0;
> + while ((v & 0x1) == 0) {
> + temp++;
> + v = v >> 1;
> + }
and ctz64?
> +
> + return (target_ulong)temp;
> +}
> +
> +target_ulong helper_bitrev_w(CPULoongArchState *env, target_ulong rj)
> +{
> + int32_t v = (int32_t)rj;
> + const int SIZE = 32;
> + uint8_t bytes[SIZE];
> +
> + int i;
> + for (i = 0; i < SIZE; i++) {
> + bytes[i] = v & 0x1;
> + v = v >> 1;
> + }
> + /* v == 0 */
> + for (i = 0; i < SIZE; i++) {
> + v = v | ((uint32_t)bytes[i] << (SIZE - 1 - i));
> + }
> +
> + return (target_ulong)(int32_t)v;
> +}
> +
> +target_ulong helper_bitrev_d(CPULoongArchState *env, target_ulong rj)
> +{
> + uint64_t v = rj;
> + const int SIZE = 64;
> + uint8_t bytes[SIZE];
> +
> + int i;
> + for (i = 0; i < SIZE; i++) {
> + bytes[i] = v & 0x1;
> + v = v >> 1;
> + }
> + /* v == 0 */
> + for (i = 0; i < SIZE; i++) {
> + v = v | ((uint64_t)bytes[i] << (SIZE - 1 - i));
> + }
> +
> + return (target_ulong)v;
> +}
> +
> +static inline target_ulong bitswap(target_ulong v)
> +{
> + v = ((v >> 1) & (target_ulong)0x5555555555555555ULL) |
> + ((v & (target_ulong)0x5555555555555555ULL) << 1);
> + v = ((v >> 2) & (target_ulong)0x3333333333333333ULL) |
> + ((v & (target_ulong)0x3333333333333333ULL) << 2);
> + v = ((v >> 4) & (target_ulong)0x0F0F0F0F0F0F0F0FULL) |
> + ((v & (target_ulong)0x0F0F0F0F0F0F0F0FULL) << 4);
> + return v;
Is this revbit64?
> +}
> +
> +target_ulong helper_loongarch_dbitswap(target_ulong rj)
> +{
> + return bitswap(rj);
> +}
> +
> +target_ulong helper_loongarch_bitswap(target_ulong rt)
> +{
> + return (int32_t)bitswap(rt);
> +}
[PATCH v2 08/22] target/loongarch: Add fixed point shift instruction translation, Song Gao, 2021/07/21
[PATCH v2 09/22] target/loongarch: Add fixed point bit instruction translation, Song Gao, 2021/07/21
[PATCH v2 10/22] target/loongarch: Add fixed point load/store instruction translation, Song Gao, 2021/07/21
[PATCH v2 11/22] target/loongarch: Add fixed point atomic instruction translation, Song Gao, 2021/07/21