161a3f8f6SPhilippe Mathieu-Daudé /*
261a3f8f6SPhilippe Mathieu-Daudé * Tiny Code Generator for QEMU
361a3f8f6SPhilippe Mathieu-Daudé *
461a3f8f6SPhilippe Mathieu-Daudé * Copyright (c) 2008 Fabrice Bellard
561a3f8f6SPhilippe Mathieu-Daudé *
661a3f8f6SPhilippe Mathieu-Daudé * Permission is hereby granted, free of charge, to any person obtaining a copy
761a3f8f6SPhilippe Mathieu-Daudé * of this software and associated documentation files (the "Software"), to deal
861a3f8f6SPhilippe Mathieu-Daudé * in the Software without restriction, including without limitation the rights
961a3f8f6SPhilippe Mathieu-Daudé * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1061a3f8f6SPhilippe Mathieu-Daudé * copies of the Software, and to permit persons to whom the Software is
1161a3f8f6SPhilippe Mathieu-Daudé * furnished to do so, subject to the following conditions:
1261a3f8f6SPhilippe Mathieu-Daudé *
1361a3f8f6SPhilippe Mathieu-Daudé * The above copyright notice and this permission notice shall be included in
1461a3f8f6SPhilippe Mathieu-Daudé * all copies or substantial portions of the Software.
1561a3f8f6SPhilippe Mathieu-Daudé *
1661a3f8f6SPhilippe Mathieu-Daudé * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1761a3f8f6SPhilippe Mathieu-Daudé * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1861a3f8f6SPhilippe Mathieu-Daudé * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1961a3f8f6SPhilippe Mathieu-Daudé * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2061a3f8f6SPhilippe Mathieu-Daudé * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2161a3f8f6SPhilippe Mathieu-Daudé * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2261a3f8f6SPhilippe Mathieu-Daudé * THE SOFTWARE.
2361a3f8f6SPhilippe Mathieu-Daudé */
2461a3f8f6SPhilippe Mathieu-Daudé #include "qemu/osdep.h"
2561a3f8f6SPhilippe Mathieu-Daudé #include "qemu/host-utils.h"
2661a3f8f6SPhilippe Mathieu-Daudé #include "cpu.h"
27*c213ee2dSRichard Henderson #include "exec/helper-proto-common.h"
2861a3f8f6SPhilippe Mathieu-Daudé #include "exec/cpu_ldst.h"
2961a3f8f6SPhilippe Mathieu-Daudé #include "exec/exec-all.h"
3061a3f8f6SPhilippe Mathieu-Daudé #include "disas/disas.h"
3161a3f8f6SPhilippe Mathieu-Daudé #include "exec/log.h"
32dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg.h"
3361a3f8f6SPhilippe Mathieu-Daudé
34d53106c9SRichard Henderson #define HELPER_H "accel/tcg/tcg-runtime.h"
35d53106c9SRichard Henderson #include "exec/helper-info.c.inc"
36d53106c9SRichard Henderson #undef HELPER_H
37d53106c9SRichard Henderson
3861a3f8f6SPhilippe Mathieu-Daudé /* 32-bit helpers */
3961a3f8f6SPhilippe Mathieu-Daudé
HELPER(div_i32)4061a3f8f6SPhilippe Mathieu-Daudé int32_t HELPER(div_i32)(int32_t arg1, int32_t arg2)
4161a3f8f6SPhilippe Mathieu-Daudé {
4261a3f8f6SPhilippe Mathieu-Daudé return arg1 / arg2;
4361a3f8f6SPhilippe Mathieu-Daudé }
4461a3f8f6SPhilippe Mathieu-Daudé
HELPER(rem_i32)4561a3f8f6SPhilippe Mathieu-Daudé int32_t HELPER(rem_i32)(int32_t arg1, int32_t arg2)
4661a3f8f6SPhilippe Mathieu-Daudé {
4761a3f8f6SPhilippe Mathieu-Daudé return arg1 % arg2;
4861a3f8f6SPhilippe Mathieu-Daudé }
4961a3f8f6SPhilippe Mathieu-Daudé
HELPER(divu_i32)5061a3f8f6SPhilippe Mathieu-Daudé uint32_t HELPER(divu_i32)(uint32_t arg1, uint32_t arg2)
5161a3f8f6SPhilippe Mathieu-Daudé {
5261a3f8f6SPhilippe Mathieu-Daudé return arg1 / arg2;
5361a3f8f6SPhilippe Mathieu-Daudé }
5461a3f8f6SPhilippe Mathieu-Daudé
HELPER(remu_i32)5561a3f8f6SPhilippe Mathieu-Daudé uint32_t HELPER(remu_i32)(uint32_t arg1, uint32_t arg2)
5661a3f8f6SPhilippe Mathieu-Daudé {
5761a3f8f6SPhilippe Mathieu-Daudé return arg1 % arg2;
5861a3f8f6SPhilippe Mathieu-Daudé }
5961a3f8f6SPhilippe Mathieu-Daudé
6061a3f8f6SPhilippe Mathieu-Daudé /* 64-bit helpers */
6161a3f8f6SPhilippe Mathieu-Daudé
HELPER(shl_i64)6261a3f8f6SPhilippe Mathieu-Daudé uint64_t HELPER(shl_i64)(uint64_t arg1, uint64_t arg2)
6361a3f8f6SPhilippe Mathieu-Daudé {
6461a3f8f6SPhilippe Mathieu-Daudé return arg1 << arg2;
6561a3f8f6SPhilippe Mathieu-Daudé }
6661a3f8f6SPhilippe Mathieu-Daudé
HELPER(shr_i64)6761a3f8f6SPhilippe Mathieu-Daudé uint64_t HELPER(shr_i64)(uint64_t arg1, uint64_t arg2)
6861a3f8f6SPhilippe Mathieu-Daudé {
6961a3f8f6SPhilippe Mathieu-Daudé return arg1 >> arg2;
7061a3f8f6SPhilippe Mathieu-Daudé }
7161a3f8f6SPhilippe Mathieu-Daudé
HELPER(sar_i64)7261a3f8f6SPhilippe Mathieu-Daudé int64_t HELPER(sar_i64)(int64_t arg1, int64_t arg2)
7361a3f8f6SPhilippe Mathieu-Daudé {
7461a3f8f6SPhilippe Mathieu-Daudé return arg1 >> arg2;
7561a3f8f6SPhilippe Mathieu-Daudé }
7661a3f8f6SPhilippe Mathieu-Daudé
HELPER(div_i64)7761a3f8f6SPhilippe Mathieu-Daudé int64_t HELPER(div_i64)(int64_t arg1, int64_t arg2)
7861a3f8f6SPhilippe Mathieu-Daudé {
7961a3f8f6SPhilippe Mathieu-Daudé return arg1 / arg2;
8061a3f8f6SPhilippe Mathieu-Daudé }
8161a3f8f6SPhilippe Mathieu-Daudé
HELPER(rem_i64)8261a3f8f6SPhilippe Mathieu-Daudé int64_t HELPER(rem_i64)(int64_t arg1, int64_t arg2)
8361a3f8f6SPhilippe Mathieu-Daudé {
8461a3f8f6SPhilippe Mathieu-Daudé return arg1 % arg2;
8561a3f8f6SPhilippe Mathieu-Daudé }
8661a3f8f6SPhilippe Mathieu-Daudé
HELPER(divu_i64)8761a3f8f6SPhilippe Mathieu-Daudé uint64_t HELPER(divu_i64)(uint64_t arg1, uint64_t arg2)
8861a3f8f6SPhilippe Mathieu-Daudé {
8961a3f8f6SPhilippe Mathieu-Daudé return arg1 / arg2;
9061a3f8f6SPhilippe Mathieu-Daudé }
9161a3f8f6SPhilippe Mathieu-Daudé
HELPER(remu_i64)9261a3f8f6SPhilippe Mathieu-Daudé uint64_t HELPER(remu_i64)(uint64_t arg1, uint64_t arg2)
9361a3f8f6SPhilippe Mathieu-Daudé {
9461a3f8f6SPhilippe Mathieu-Daudé return arg1 % arg2;
9561a3f8f6SPhilippe Mathieu-Daudé }
9661a3f8f6SPhilippe Mathieu-Daudé
HELPER(muluh_i64)9761a3f8f6SPhilippe Mathieu-Daudé uint64_t HELPER(muluh_i64)(uint64_t arg1, uint64_t arg2)
9861a3f8f6SPhilippe Mathieu-Daudé {
9961a3f8f6SPhilippe Mathieu-Daudé uint64_t l, h;
10061a3f8f6SPhilippe Mathieu-Daudé mulu64(&l, &h, arg1, arg2);
10161a3f8f6SPhilippe Mathieu-Daudé return h;
10261a3f8f6SPhilippe Mathieu-Daudé }
10361a3f8f6SPhilippe Mathieu-Daudé
HELPER(mulsh_i64)10461a3f8f6SPhilippe Mathieu-Daudé int64_t HELPER(mulsh_i64)(int64_t arg1, int64_t arg2)
10561a3f8f6SPhilippe Mathieu-Daudé {
10661a3f8f6SPhilippe Mathieu-Daudé uint64_t l, h;
10761a3f8f6SPhilippe Mathieu-Daudé muls64(&l, &h, arg1, arg2);
10861a3f8f6SPhilippe Mathieu-Daudé return h;
10961a3f8f6SPhilippe Mathieu-Daudé }
11061a3f8f6SPhilippe Mathieu-Daudé
HELPER(clz_i32)11161a3f8f6SPhilippe Mathieu-Daudé uint32_t HELPER(clz_i32)(uint32_t arg, uint32_t zero_val)
11261a3f8f6SPhilippe Mathieu-Daudé {
11361a3f8f6SPhilippe Mathieu-Daudé return arg ? clz32(arg) : zero_val;
11461a3f8f6SPhilippe Mathieu-Daudé }
11561a3f8f6SPhilippe Mathieu-Daudé
HELPER(ctz_i32)11661a3f8f6SPhilippe Mathieu-Daudé uint32_t HELPER(ctz_i32)(uint32_t arg, uint32_t zero_val)
11761a3f8f6SPhilippe Mathieu-Daudé {
11861a3f8f6SPhilippe Mathieu-Daudé return arg ? ctz32(arg) : zero_val;
11961a3f8f6SPhilippe Mathieu-Daudé }
12061a3f8f6SPhilippe Mathieu-Daudé
HELPER(clz_i64)12161a3f8f6SPhilippe Mathieu-Daudé uint64_t HELPER(clz_i64)(uint64_t arg, uint64_t zero_val)
12261a3f8f6SPhilippe Mathieu-Daudé {
12361a3f8f6SPhilippe Mathieu-Daudé return arg ? clz64(arg) : zero_val;
12461a3f8f6SPhilippe Mathieu-Daudé }
12561a3f8f6SPhilippe Mathieu-Daudé
HELPER(ctz_i64)12661a3f8f6SPhilippe Mathieu-Daudé uint64_t HELPER(ctz_i64)(uint64_t arg, uint64_t zero_val)
12761a3f8f6SPhilippe Mathieu-Daudé {
12861a3f8f6SPhilippe Mathieu-Daudé return arg ? ctz64(arg) : zero_val;
12961a3f8f6SPhilippe Mathieu-Daudé }
13061a3f8f6SPhilippe Mathieu-Daudé
HELPER(clrsb_i32)13161a3f8f6SPhilippe Mathieu-Daudé uint32_t HELPER(clrsb_i32)(uint32_t arg)
13261a3f8f6SPhilippe Mathieu-Daudé {
13361a3f8f6SPhilippe Mathieu-Daudé return clrsb32(arg);
13461a3f8f6SPhilippe Mathieu-Daudé }
13561a3f8f6SPhilippe Mathieu-Daudé
HELPER(clrsb_i64)13661a3f8f6SPhilippe Mathieu-Daudé uint64_t HELPER(clrsb_i64)(uint64_t arg)
13761a3f8f6SPhilippe Mathieu-Daudé {
13861a3f8f6SPhilippe Mathieu-Daudé return clrsb64(arg);
13961a3f8f6SPhilippe Mathieu-Daudé }
14061a3f8f6SPhilippe Mathieu-Daudé
HELPER(ctpop_i32)14161a3f8f6SPhilippe Mathieu-Daudé uint32_t HELPER(ctpop_i32)(uint32_t arg)
14261a3f8f6SPhilippe Mathieu-Daudé {
14361a3f8f6SPhilippe Mathieu-Daudé return ctpop32(arg);
14461a3f8f6SPhilippe Mathieu-Daudé }
14561a3f8f6SPhilippe Mathieu-Daudé
HELPER(ctpop_i64)14661a3f8f6SPhilippe Mathieu-Daudé uint64_t HELPER(ctpop_i64)(uint64_t arg)
14761a3f8f6SPhilippe Mathieu-Daudé {
14861a3f8f6SPhilippe Mathieu-Daudé return ctpop64(arg);
14961a3f8f6SPhilippe Mathieu-Daudé }
15061a3f8f6SPhilippe Mathieu-Daudé
HELPER(exit_atomic)15161a3f8f6SPhilippe Mathieu-Daudé void HELPER(exit_atomic)(CPUArchState *env)
15261a3f8f6SPhilippe Mathieu-Daudé {
15329a0af61SRichard Henderson cpu_loop_exit_atomic(env_cpu(env), GETPC());
15461a3f8f6SPhilippe Mathieu-Daudé }
155