ppc/pnv: reduce stack->stack_no usage
[qemu.git] / target / riscv / m128_helper.c
blob7bf115b85ef267f28ed60ed91f7db8b6b6b5208e
1 /*
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
14 * more details.
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"
21 #include "cpu.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)
30 target_ulong ql, qh;
31 Int128 q;
33 if (vl == 0 && vh == 0) { /* Handle special behavior on div by zero */
34 ql = ~0x0;
35 qh = ~0x0;
36 } else {
37 q = int128_divu(int128_make128(ul, uh), int128_make128(vl, vh));
38 ql = int128_getlo(q);
39 qh = int128_gethi(q);
42 env->retxh = qh;
43 return ql;
46 target_ulong HELPER(remu_i128)(CPURISCVState *env,
47 target_ulong ul, target_ulong uh,
48 target_ulong vl, target_ulong vh)
50 target_ulong rl, rh;
51 Int128 r;
53 if (vl == 0 && vh == 0) {
54 rl = ul;
55 rh = uh;
56 } else {
57 r = int128_remu(int128_make128(ul, uh), int128_make128(vl, vh));
58 rl = int128_getlo(r);
59 rh = int128_gethi(r);
62 env->retxh = rh;
63 return rl;
66 target_ulong HELPER(divs_i128)(CPURISCVState *env,
67 target_ulong ul, target_ulong uh,
68 target_ulong vl, target_ulong vh)
70 target_ulong qh, ql;
71 Int128 q;
73 if (vl == 0 && vh == 0) { /* Div by zero check */
74 ql = ~0x0;
75 qh = ~0x0;
76 } else if (uh == (1ULL << (TARGET_LONG_BITS - 1)) && ul == 0 &&
77 vh == ~0x0 && vl == ~0x0) {
78 /* Signed div overflow check (-2**127 / -1) */
79 ql = ul;
80 qh = uh;
81 } else {
82 q = int128_divs(int128_make128(ul, uh), int128_make128(vl, vh));
83 ql = int128_getlo(q);
84 qh = int128_gethi(q);
87 env->retxh = qh;
88 return ql;
91 target_ulong HELPER(rems_i128)(CPURISCVState *env,
92 target_ulong ul, target_ulong uh,
93 target_ulong vl, target_ulong vh)
95 target_ulong rh, rl;
96 Int128 r;
98 if (vl == 0 && vh == 0) {
99 rl = ul;
100 rh = uh;
101 } else {
102 r = int128_rems(int128_make128(ul, uh), int128_make128(vl, vh));
103 rl = int128_getlo(r);
104 rh = int128_gethi(r);
107 env->retxh = rh;
108 return rl;