2 * RISC-V translation routines for the RV64M Standard Extension.
4 * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
5 * Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de
6 * Bastian Koppelmann, kbastian@mail.uni-paderborn.de
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2 or later, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
22 static bool trans_mul(DisasContext
*ctx
, arg_mul
*a
)
24 REQUIRE_EXT(ctx
, RVM
);
25 return gen_arith(ctx
, a
, &tcg_gen_mul_tl
);
28 static bool trans_mulh(DisasContext
*ctx
, arg_mulh
*a
)
30 REQUIRE_EXT(ctx
, RVM
);
31 TCGv source1
= tcg_temp_new();
32 TCGv source2
= tcg_temp_new();
33 gen_get_gpr(source1
, a
->rs1
);
34 gen_get_gpr(source2
, a
->rs2
);
36 tcg_gen_muls2_tl(source2
, source1
, source1
, source2
);
38 gen_set_gpr(a
->rd
, source1
);
39 tcg_temp_free(source1
);
40 tcg_temp_free(source2
);
44 static bool trans_mulhsu(DisasContext
*ctx
, arg_mulhsu
*a
)
46 REQUIRE_EXT(ctx
, RVM
);
47 return gen_arith(ctx
, a
, &gen_mulhsu
);
50 static bool trans_mulhu(DisasContext
*ctx
, arg_mulhu
*a
)
52 REQUIRE_EXT(ctx
, RVM
);
53 TCGv source1
= tcg_temp_new();
54 TCGv source2
= tcg_temp_new();
55 gen_get_gpr(source1
, a
->rs1
);
56 gen_get_gpr(source2
, a
->rs2
);
58 tcg_gen_mulu2_tl(source2
, source1
, source1
, source2
);
60 gen_set_gpr(a
->rd
, source1
);
61 tcg_temp_free(source1
);
62 tcg_temp_free(source2
);
66 static bool trans_div(DisasContext
*ctx
, arg_div
*a
)
68 REQUIRE_EXT(ctx
, RVM
);
69 return gen_arith(ctx
, a
, &gen_div
);
72 static bool trans_divu(DisasContext
*ctx
, arg_divu
*a
)
74 REQUIRE_EXT(ctx
, RVM
);
75 return gen_arith(ctx
, a
, &gen_divu
);
78 static bool trans_rem(DisasContext
*ctx
, arg_rem
*a
)
80 REQUIRE_EXT(ctx
, RVM
);
81 return gen_arith(ctx
, a
, &gen_rem
);
84 static bool trans_remu(DisasContext
*ctx
, arg_remu
*a
)
86 REQUIRE_EXT(ctx
, RVM
);
87 return gen_arith(ctx
, a
, &gen_remu
);
91 static bool trans_mulw(DisasContext
*ctx
, arg_mulw
*a
)
93 REQUIRE_EXT(ctx
, RVM
);
94 return gen_arith(ctx
, a
, &gen_mulw
);
97 static bool trans_divw(DisasContext
*ctx
, arg_divw
*a
)
99 REQUIRE_EXT(ctx
, RVM
);
100 return gen_arith_div_w(ctx
, a
, &gen_div
);
103 static bool trans_divuw(DisasContext
*ctx
, arg_divuw
*a
)
105 REQUIRE_EXT(ctx
, RVM
);
106 return gen_arith_div_uw(ctx
, a
, &gen_divu
);
109 static bool trans_remw(DisasContext
*ctx
, arg_remw
*a
)
111 REQUIRE_EXT(ctx
, RVM
);
112 return gen_arith_div_w(ctx
, a
, &gen_rem
);
115 static bool trans_remuw(DisasContext
*ctx
, arg_remuw
*a
)
117 REQUIRE_EXT(ctx
, RVM
);
118 return gen_arith_div_uw(ctx
, a
, &gen_remu
);