1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * LoongArch emulation helpers for QEMU.
5 * Copyright (c) 2021 Loongson Technology Corporation Limited
8 #include "qemu/osdep.h"
9 #include "qemu/main-loop.h"
11 #include "qemu/host-utils.h"
12 #include "exec/helper-proto.h"
13 #include "exec/exec-all.h"
14 #include "exec/cpu_ldst.h"
15 #include "internals.h"
17 /* Exceptions helpers */
18 void helper_raise_exception(CPULoongArchState *env, uint32_t exception)
20 do_raise_exception(env, exception, GETPC());
23 target_ulong helper_bitrev_w(target_ulong rj)
25 return (int32_t)revbit32(rj);
28 target_ulong helper_bitrev_d(target_ulong rj)
33 target_ulong helper_bitswap(target_ulong v)
35 v = ((v >> 1) & (target_ulong)0x5555555555555555ULL) |
36 ((v & (target_ulong)0x5555555555555555ULL) << 1);
37 v = ((v >> 2) & (target_ulong)0x3333333333333333ULL) |
38 ((v & (target_ulong)0x3333333333333333ULL) << 2);
39 v = ((v >> 4) & (target_ulong)0x0F0F0F0F0F0F0F0FULL) |
40 ((v & (target_ulong)0x0F0F0F0F0F0F0F0FULL) << 4);