1/*
2 * RISC-V translation routines for the Zicond Standard Extension.
3 *
4 * Copyright (c) 2020-2023 PLCT Lab
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2 or later, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#define REQUIRE_ZICOND(ctx) do {          \
20    if (!ctx->cfg_ptr->ext_zicond) {      \
21        return false;                     \
22    }                                     \
23} while (0)
24
25static bool trans_czero_eqz(DisasContext *ctx, arg_czero_eqz *a)
26{
27    REQUIRE_ZICOND(ctx);
28
29    TCGv dest = dest_gpr(ctx, a->rd);
30    TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE);
31    TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE);
32
33    tcg_gen_movcond_tl(TCG_COND_EQ, dest, src2, ctx->zero, ctx->zero, src1);
34    gen_set_gpr(ctx, a->rd, dest);
35    return true;
36}
37
38static bool trans_czero_nez(DisasContext *ctx, arg_czero_nez *a)
39{
40    REQUIRE_ZICOND(ctx);
41
42    TCGv dest = dest_gpr(ctx, a->rd);
43    TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE);
44    TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE);
45
46    tcg_gen_movcond_tl(TCG_COND_NE, dest, src2, ctx->zero, ctx->zero, src1);
47    gen_set_gpr(ctx, a->rd, dest);
48    return true;
49}
50