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