aboutsummaryrefslogtreecommitdiff
path: root/target/riscv/insn_trans/trans_rvzabha.c.inc
blob: ce8edcba62a2be4e0d927714099b5df86e6ff6ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * RISC-V translation routines for the Zabha Standard Extension.
 *
 * Copyright (c) 2024 Alibaba Group
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2 or later, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#define REQUIRE_ZABHA(ctx) do {           \
    if (!ctx->cfg_ptr->ext_zabha) {       \
        return false;                     \
    }                                     \
} while (0)

static bool trans_amoswap_b(DisasContext *ctx, arg_amoswap_b *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, MO_SB);
}

static bool trans_amoadd_b(DisasContext *ctx, arg_amoadd_b *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_add_tl, MO_SB);
}

static bool trans_amoxor_b(DisasContext *ctx, arg_amoxor_b *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_xor_tl, MO_SB);
}

static bool trans_amoand_b(DisasContext *ctx, arg_amoand_b *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_and_tl, MO_SB);
}

static bool trans_amoor_b(DisasContext *ctx, arg_amoor_b *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_or_tl, MO_SB);
}

static bool trans_amomin_b(DisasContext *ctx, arg_amomin_b *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smin_tl, MO_SB);
}

static bool trans_amomax_b(DisasContext *ctx, arg_amomax_b *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smax_tl, MO_SB);
}

static bool trans_amominu_b(DisasContext *ctx, arg_amominu_b *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umin_tl, MO_SB);
}

static bool trans_amomaxu_b(DisasContext *ctx, arg_amomaxu_b *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, MO_SB);
}

static bool trans_amoswap_h(DisasContext *ctx, arg_amoswap_h *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_xchg_tl, MO_TESW);
}

static bool trans_amoadd_h(DisasContext *ctx, arg_amoadd_h *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_add_tl, MO_TESW);
}

static bool trans_amoxor_h(DisasContext *ctx, arg_amoxor_h *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_xor_tl, MO_TESW);
}

static bool trans_amoand_h(DisasContext *ctx, arg_amoand_h *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_and_tl, MO_TESW);
}

static bool trans_amoor_h(DisasContext *ctx, arg_amoor_h *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_or_tl, MO_TESW);
}

static bool trans_amomin_h(DisasContext *ctx, arg_amomin_h *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smin_tl, MO_TESW);
}

static bool trans_amomax_h(DisasContext *ctx, arg_amomax_h *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_smax_tl, MO_TESW);
}

static bool trans_amominu_h(DisasContext *ctx, arg_amominu_h *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umin_tl, MO_TESW);
}

static bool trans_amomaxu_h(DisasContext *ctx, arg_amomaxu_h *a)
{
    REQUIRE_ZABHA(ctx);
    return gen_amo(ctx, a, &tcg_gen_atomic_fetch_umax_tl, MO_TESW);
}

static bool trans_amocas_b(DisasContext *ctx, arg_amocas_b *a)
{
    REQUIRE_ZACAS(ctx);
    REQUIRE_ZABHA(ctx);
    return gen_cmpxchg(ctx, a, MO_SB);
}

static bool trans_amocas_h(DisasContext *ctx, arg_amocas_h *a)
{
    REQUIRE_ZACAS(ctx);
    REQUIRE_ZABHA(ctx);
    return gen_cmpxchg(ctx, a, MO_ALIGN | MO_TESW);
}