2 * RISC-V Emulation Helpers for QEMU.
4 * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
5 * Copyright (c) 2017-2018 SiFive, Inc.
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.
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
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/>.
20 #include "qemu/osdep.h"
22 #include "qemu/main-loop.h"
23 #include "exec/exec-all.h"
24 #include "exec/helper-proto.h"
26 target_ulong
HELPER(divu_i128
)(CPURISCVState
*env
,
27 target_ulong ul
, target_ulong uh
,
28 target_ulong vl
, target_ulong vh
)
33 if (vl
== 0 && vh
== 0) { /* Handle special behavior on div by zero */
37 q
= int128_divu(int128_make128(ul
, uh
), int128_make128(vl
, vh
));
46 target_ulong
HELPER(remu_i128
)(CPURISCVState
*env
,
47 target_ulong ul
, target_ulong uh
,
48 target_ulong vl
, target_ulong vh
)
53 if (vl
== 0 && vh
== 0) {
57 r
= int128_remu(int128_make128(ul
, uh
), int128_make128(vl
, vh
));
66 target_ulong
HELPER(divs_i128
)(CPURISCVState
*env
,
67 target_ulong ul
, target_ulong uh
,
68 target_ulong vl
, target_ulong vh
)
73 if (vl
== 0 && vh
== 0) { /* Div by zero check */
76 } else if (uh
== (1ULL << (TARGET_LONG_BITS
- 1)) && ul
== 0 &&
77 vh
== ~0x0 && vl
== ~0x0) {
78 /* Signed div overflow check (-2**127 / -1) */
82 q
= int128_divs(int128_make128(ul
, uh
), int128_make128(vl
, vh
));
91 target_ulong
HELPER(rems_i128
)(CPURISCVState
*env
,
92 target_ulong ul
, target_ulong uh
,
93 target_ulong vl
, target_ulong vh
)
98 if (vl
== 0 && vh
== 0) {
102 r
= int128_rems(int128_make128(ul
, uh
), int128_make128(vl
, vh
));
103 rl
= int128_getlo(r
);
104 rh
= int128_gethi(r
);