]> Git Repo - qemu.git/blob - target/loongarch/op_helper.c
bd2db783c91bf701fec084adc681137f4e513160
[qemu.git] / target / loongarch / op_helper.c
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * LoongArch emulation helpers for QEMU.
4  *
5  * Copyright (c) 2021 Loongson Technology Corporation Limited
6  */
7
8 #include "qemu/osdep.h"
9 #include "qemu/main-loop.h"
10 #include "cpu.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"
16
17 /* Exceptions helpers */
18 void helper_raise_exception(CPULoongArchState *env, uint32_t exception)
19 {
20     do_raise_exception(env, exception, GETPC());
21 }
22
23 target_ulong helper_bitrev_w(target_ulong rj)
24 {
25     return (int32_t)revbit32(rj);
26 }
27
28 target_ulong helper_bitrev_d(target_ulong rj)
29 {
30     return revbit64(rj);
31 }
32
33 target_ulong helper_bitswap(target_ulong v)
34 {
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);
41     return v;
42 }
43
44 /* loongarch assert op */
45 void helper_asrtle_d(CPULoongArchState *env, target_ulong rj, target_ulong rk)
46 {
47     if (rj > rk) {
48         do_raise_exception(env, EXCCODE_ADEM, GETPC());
49     }
50 }
51
52 void helper_asrtgt_d(CPULoongArchState *env, target_ulong rj, target_ulong rk)
53 {
54     if (rj <= rk) {
55         do_raise_exception(env, EXCCODE_ADEM, GETPC());
56     }
57 }
This page took 0.017677 seconds and 2 git commands to generate.