From 944eea962be94b98f8f6f570f9c4eb3b58dc296d Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Mon, 7 Apr 2014 23:08:47 -0700 Subject: [PATCH] tcg: Push tcg-runtime routines into exec/helper-* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rather than special casing them, use the standard mechanisms for tcg helper generation. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- include/exec/helper-gen.h | 1 + include/exec/helper-head.h | 12 ++++++---- include/exec/helper-proto.h | 1 + include/exec/helper-tcg.h | 1 + tcg-runtime.c | 46 ++++++++++++++++++++++--------------- tcg/tcg-op.h | 35 ++++++++++++++-------------- tcg/tcg-runtime.h | 30 +++++++++++------------- tcg/tcg.c | 16 ------------- tcg/tcg.h | 2 -- 9 files changed, 70 insertions(+), 74 deletions(-) diff --git a/include/exec/helper-gen.h b/include/exec/helper-gen.h index f6d9ec3167..abde615e92 100644 --- a/include/exec/helper-gen.h +++ b/include/exec/helper-gen.h @@ -80,6 +80,7 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ } #include "helper.h" +#include "tcg-runtime.h" #undef DEF_HELPER_FLAGS_0 #undef DEF_HELPER_FLAGS_1 diff --git a/include/exec/helper-head.h b/include/exec/helper-head.h index 2cbae22b5f..0b5bd8398e 100644 --- a/include/exec/helper-head.h +++ b/include/exec/helper-head.h @@ -18,6 +18,8 @@ #ifndef DEF_HELPER_H #define DEF_HELPER_H 1 +#include "qemu/osdep.h" + #define HELPER(name) glue(helper_, name) #define GET_TCGV_i32 GET_TCGV_I32 @@ -32,10 +34,12 @@ #define dh_alias_s64 i64 #define dh_alias_f32 i32 #define dh_alias_f64 i64 -#if TARGET_LONG_BITS == 32 -#define dh_alias_tl i32 -#else -#define dh_alias_tl i64 +#ifdef TARGET_LONG_BITS +# if TARGET_LONG_BITS == 32 +# define dh_alias_tl i32 +# else +# define dh_alias_tl i64 +# endif #endif #define dh_alias_ptr ptr #define dh_alias_void void diff --git a/include/exec/helper-proto.h b/include/exec/helper-proto.h index 88d3543119..828951c609 100644 --- a/include/exec/helper-proto.h +++ b/include/exec/helper-proto.h @@ -27,6 +27,7 @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \ dh_ctype(t4), dh_ctype(t5)); #include "helper.h" +#include "tcg-runtime.h" #undef DEF_HELPER_FLAGS_0 #undef DEF_HELPER_FLAGS_1 diff --git a/include/exec/helper-tcg.h b/include/exec/helper-tcg.h index 9be5429fa1..0da6b9788a 100644 --- a/include/exec/helper-tcg.h +++ b/include/exec/helper-tcg.h @@ -24,6 +24,7 @@ DEF_HELPER_FLAGS_0(name, flags, ret) DEF_HELPER_FLAGS_0(name, flags, ret) #include "helper.h" +#include "tcg-runtime.h" #undef DEF_HELPER_FLAGS_0 #undef DEF_HELPER_FLAGS_1 diff --git a/tcg-runtime.c b/tcg-runtime.c index 4b66e51ce7..9daba6945e 100644 --- a/tcg-runtime.c +++ b/tcg-runtime.c @@ -23,75 +23,85 @@ */ #include #include "qemu/host-utils.h" -#include "tcg/tcg-runtime.h" + +/* This file is compiled once, and thus we can't include the standard + "exec/helper-proto.h", which has includes that are target specific. */ + +#include "exec/helper-head.h" + +#define DEF_HELPER_FLAGS_2(name, flags, ret, t1, t2) \ + dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2)); + +#include "tcg-runtime.h" + /* 32-bit helpers */ -int32_t tcg_helper_div_i32(int32_t arg1, int32_t arg2) +int32_t HELPER(div_i32)(int32_t arg1, int32_t arg2) { return arg1 / arg2; } -int32_t tcg_helper_rem_i32(int32_t arg1, int32_t arg2) +int32_t HELPER(rem_i32)(int32_t arg1, int32_t arg2) { return arg1 % arg2; } -uint32_t tcg_helper_divu_i32(uint32_t arg1, uint32_t arg2) +uint32_t HELPER(divu_i32)(uint32_t arg1, uint32_t arg2) { return arg1 / arg2; } -uint32_t tcg_helper_remu_i32(uint32_t arg1, uint32_t arg2) +uint32_t HELPER(remu_i32)(uint32_t arg1, uint32_t arg2) { return arg1 % arg2; } /* 64-bit helpers */ -int64_t tcg_helper_shl_i64(int64_t arg1, int64_t arg2) +uint64_t HELPER(shl_i64)(uint64_t arg1, uint64_t arg2) { return arg1 << arg2; } -int64_t tcg_helper_shr_i64(int64_t arg1, int64_t arg2) -{ - return (uint64_t)arg1 >> arg2; -} - -int64_t tcg_helper_sar_i64(int64_t arg1, int64_t arg2) +uint64_t HELPER(shr_i64)(uint64_t arg1, uint64_t arg2) { return arg1 >> arg2; } -int64_t tcg_helper_div_i64(int64_t arg1, int64_t arg2) +int64_t HELPER(sar_i64)(int64_t arg1, int64_t arg2) +{ + return arg1 >> arg2; +} + +int64_t HELPER(div_i64)(int64_t arg1, int64_t arg2) { return arg1 / arg2; } -int64_t tcg_helper_rem_i64(int64_t arg1, int64_t arg2) +int64_t HELPER(rem_i64)(int64_t arg1, int64_t arg2) { return arg1 % arg2; } -uint64_t tcg_helper_divu_i64(uint64_t arg1, uint64_t arg2) +uint64_t HELPER(divu_i64)(uint64_t arg1, uint64_t arg2) { return arg1 / arg2; } -uint64_t tcg_helper_remu_i64(uint64_t arg1, uint64_t arg2) +uint64_t HELPER(remu_i64)(uint64_t arg1, uint64_t arg2) { return arg1 % arg2; } -uint64_t tcg_helper_muluh_i64(uint64_t arg1, uint64_t arg2) +uint64_t HELPER(muluh_i64)(uint64_t arg1, uint64_t arg2) { uint64_t l, h; mulu64(&l, &h, arg1, arg2); return h; } -int64_t tcg_helper_mulsh_i64(int64_t arg1, int64_t arg2) +int64_t HELPER(mulsh_i64)(int64_t arg1, int64_t arg2) { uint64_t l, h; muls64(&l, &h, arg1, arg2); diff --git a/tcg/tcg-op.h b/tcg/tcg-op.h index bdd0139482..8560695930 100644 --- a/tcg/tcg-op.h +++ b/tcg/tcg-op.h @@ -22,6 +22,7 @@ * THE SOFTWARE. */ #include "tcg.h" +#include "exec/helper-proto.h" int gen_new_label(void); @@ -712,7 +713,7 @@ static inline void tcg_gen_div_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) sizemask |= tcg_gen_sizemask(0, 0, 1); sizemask |= tcg_gen_sizemask(1, 0, 1); sizemask |= tcg_gen_sizemask(2, 0, 1); - tcg_gen_helper32(tcg_helper_div_i32, sizemask, ret, arg1, arg2); + tcg_gen_helper32(helper_div_i32, sizemask, ret, arg1, arg2); } } @@ -737,7 +738,7 @@ static inline void tcg_gen_rem_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) sizemask |= tcg_gen_sizemask(0, 0, 1); sizemask |= tcg_gen_sizemask(1, 0, 1); sizemask |= tcg_gen_sizemask(2, 0, 1); - tcg_gen_helper32(tcg_helper_rem_i32, sizemask, ret, arg1, arg2); + tcg_gen_helper32(helper_rem_i32, sizemask, ret, arg1, arg2); } } @@ -756,7 +757,7 @@ static inline void tcg_gen_divu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) sizemask |= tcg_gen_sizemask(0, 0, 0); sizemask |= tcg_gen_sizemask(1, 0, 0); sizemask |= tcg_gen_sizemask(2, 0, 0); - tcg_gen_helper32(tcg_helper_divu_i32, sizemask, ret, arg1, arg2); + tcg_gen_helper32(helper_divu_i32, sizemask, ret, arg1, arg2); } } @@ -781,7 +782,7 @@ static inline void tcg_gen_remu_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) sizemask |= tcg_gen_sizemask(0, 0, 0); sizemask |= tcg_gen_sizemask(1, 0, 0); sizemask |= tcg_gen_sizemask(2, 0, 0); - tcg_gen_helper32(tcg_helper_remu_i32, sizemask, ret, arg1, arg2); + tcg_gen_helper32(helper_remu_i32, sizemask, ret, arg1, arg2); } } @@ -951,7 +952,7 @@ static inline void tcg_gen_shl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) sizemask |= tcg_gen_sizemask(1, 1, 1); sizemask |= tcg_gen_sizemask(2, 1, 1); - tcg_gen_helper64(tcg_helper_shl_i64, sizemask, ret, arg1, arg2); + tcg_gen_helper64(helper_shl_i64, sizemask, ret, arg1, arg2); } static inline void tcg_gen_shli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2) @@ -967,7 +968,7 @@ static inline void tcg_gen_shr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) sizemask |= tcg_gen_sizemask(1, 1, 1); sizemask |= tcg_gen_sizemask(2, 1, 1); - tcg_gen_helper64(tcg_helper_shr_i64, sizemask, ret, arg1, arg2); + tcg_gen_helper64(helper_shr_i64, sizemask, ret, arg1, arg2); } static inline void tcg_gen_shri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2) @@ -983,7 +984,7 @@ static inline void tcg_gen_sar_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) sizemask |= tcg_gen_sizemask(1, 1, 1); sizemask |= tcg_gen_sizemask(2, 1, 1); - tcg_gen_helper64(tcg_helper_sar_i64, sizemask, ret, arg1, arg2); + tcg_gen_helper64(helper_sar_i64, sizemask, ret, arg1, arg2); } static inline void tcg_gen_sari_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2) @@ -1057,7 +1058,7 @@ static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) sizemask |= tcg_gen_sizemask(1, 1, 1); sizemask |= tcg_gen_sizemask(2, 1, 1); - tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2); + tcg_gen_helper64(helper_div_i64, sizemask, ret, arg1, arg2); } static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) @@ -1068,7 +1069,7 @@ static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) sizemask |= tcg_gen_sizemask(1, 1, 1); sizemask |= tcg_gen_sizemask(2, 1, 1); - tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2); + tcg_gen_helper64(helper_rem_i64, sizemask, ret, arg1, arg2); } static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) @@ -1079,7 +1080,7 @@ static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) sizemask |= tcg_gen_sizemask(1, 1, 0); sizemask |= tcg_gen_sizemask(2, 1, 0); - tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2); + tcg_gen_helper64(helper_divu_i64, sizemask, ret, arg1, arg2); } static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) @@ -1090,7 +1091,7 @@ static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) sizemask |= tcg_gen_sizemask(1, 1, 0); sizemask |= tcg_gen_sizemask(2, 1, 0); - tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2); + tcg_gen_helper64(helper_remu_i64, sizemask, ret, arg1, arg2); } #else @@ -1362,7 +1363,7 @@ static inline void tcg_gen_div_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) sizemask |= tcg_gen_sizemask(0, 1, 1); sizemask |= tcg_gen_sizemask(1, 1, 1); sizemask |= tcg_gen_sizemask(2, 1, 1); - tcg_gen_helper64(tcg_helper_div_i64, sizemask, ret, arg1, arg2); + tcg_gen_helper64(helper_div_i64, sizemask, ret, arg1, arg2); } } @@ -1387,7 +1388,7 @@ static inline void tcg_gen_rem_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) sizemask |= tcg_gen_sizemask(0, 1, 1); sizemask |= tcg_gen_sizemask(1, 1, 1); sizemask |= tcg_gen_sizemask(2, 1, 1); - tcg_gen_helper64(tcg_helper_rem_i64, sizemask, ret, arg1, arg2); + tcg_gen_helper64(helper_rem_i64, sizemask, ret, arg1, arg2); } } @@ -1406,7 +1407,7 @@ static inline void tcg_gen_divu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) sizemask |= tcg_gen_sizemask(0, 1, 0); sizemask |= tcg_gen_sizemask(1, 1, 0); sizemask |= tcg_gen_sizemask(2, 1, 0); - tcg_gen_helper64(tcg_helper_divu_i64, sizemask, ret, arg1, arg2); + tcg_gen_helper64(helper_divu_i64, sizemask, ret, arg1, arg2); } } @@ -1431,7 +1432,7 @@ static inline void tcg_gen_remu_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2) sizemask |= tcg_gen_sizemask(0, 1, 0); sizemask |= tcg_gen_sizemask(1, 1, 0); sizemask |= tcg_gen_sizemask(2, 1, 0); - tcg_gen_helper64(tcg_helper_remu_i64, sizemask, ret, arg1, arg2); + tcg_gen_helper64(helper_remu_i64, sizemask, ret, arg1, arg2); } } #endif /* TCG_TARGET_REG_BITS == 32 */ @@ -2536,7 +2537,7 @@ static inline void tcg_gen_mulu2_i64(TCGv_i64 rl, TCGv_i64 rh, sizemask |= tcg_gen_sizemask(1, 1, 0); sizemask |= tcg_gen_sizemask(2, 1, 0); tcg_gen_mul_i64(t0, arg1, arg2); - tcg_gen_helper64(tcg_helper_muluh_i64, sizemask, rh, arg1, arg2); + tcg_gen_helper64(helper_muluh_i64, sizemask, rh, arg1, arg2); tcg_gen_mov_i64(rl, t0); tcg_temp_free_i64(t0); } @@ -2581,7 +2582,7 @@ static inline void tcg_gen_muls2_i64(TCGv_i64 rl, TCGv_i64 rh, sizemask |= tcg_gen_sizemask(1, 1, 1); sizemask |= tcg_gen_sizemask(2, 1, 1); tcg_gen_mul_i64(t0, arg1, arg2); - tcg_gen_helper64(tcg_helper_mulsh_i64, sizemask, rh, arg1, arg2); + tcg_gen_helper64(helper_mulsh_i64, sizemask, rh, arg1, arg2); tcg_gen_mov_i64(rl, t0); tcg_temp_free_i64(t0); } diff --git a/tcg/tcg-runtime.h b/tcg/tcg-runtime.h index a1ebef9f9c..23a0c37711 100644 --- a/tcg/tcg-runtime.h +++ b/tcg/tcg-runtime.h @@ -1,20 +1,16 @@ -#ifndef TCG_RUNTIME_H -#define TCG_RUNTIME_H +DEF_HELPER_FLAGS_2(div_i32, TCG_CALL_NO_RWG_SE, s32, s32, s32) +DEF_HELPER_FLAGS_2(rem_i32, TCG_CALL_NO_RWG_SE, s32, s32, s32) +DEF_HELPER_FLAGS_2(divu_i32, TCG_CALL_NO_RWG_SE, i32, i32, i32) +DEF_HELPER_FLAGS_2(remu_i32, TCG_CALL_NO_RWG_SE, i32, i32, i32) -/* tcg-runtime.c */ -int32_t tcg_helper_div_i32(int32_t arg1, int32_t arg2); -int32_t tcg_helper_rem_i32(int32_t arg1, int32_t arg2); -uint32_t tcg_helper_divu_i32(uint32_t arg1, uint32_t arg2); -uint32_t tcg_helper_remu_i32(uint32_t arg1, uint32_t arg2); +DEF_HELPER_FLAGS_2(div_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64) +DEF_HELPER_FLAGS_2(rem_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64) +DEF_HELPER_FLAGS_2(divu_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64) +DEF_HELPER_FLAGS_2(remu_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64) -int64_t tcg_helper_shl_i64(int64_t arg1, int64_t arg2); -int64_t tcg_helper_shr_i64(int64_t arg1, int64_t arg2); -int64_t tcg_helper_sar_i64(int64_t arg1, int64_t arg2); -int64_t tcg_helper_div_i64(int64_t arg1, int64_t arg2); -int64_t tcg_helper_rem_i64(int64_t arg1, int64_t arg2); -int64_t tcg_helper_mulsh_i64(int64_t arg1, int64_t arg2); -uint64_t tcg_helper_divu_i64(uint64_t arg1, uint64_t arg2); -uint64_t tcg_helper_remu_i64(uint64_t arg1, uint64_t arg2); -uint64_t tcg_helper_muluh_i64(uint64_t arg1, uint64_t arg2); +DEF_HELPER_FLAGS_2(shl_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64) +DEF_HELPER_FLAGS_2(shr_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64) +DEF_HELPER_FLAGS_2(sar_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64) -#endif +DEF_HELPER_FLAGS_2(mulsh_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64) +DEF_HELPER_FLAGS_2(muluh_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64) diff --git a/tcg/tcg.c b/tcg/tcg.c index 3100d57896..4679c19846 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -316,22 +316,6 @@ typedef struct TCGHelperInfo { static const TCGHelperInfo all_helpers[] = { #include "exec/helper-tcg.h" - - /* Include tcg-runtime.c functions. */ - { tcg_helper_div_i32, "div_i32" }, - { tcg_helper_rem_i32, "rem_i32" }, - { tcg_helper_divu_i32, "divu_i32" }, - { tcg_helper_remu_i32, "remu_i32" }, - - { tcg_helper_shl_i64, "shl_i64" }, - { tcg_helper_shr_i64, "shr_i64" }, - { tcg_helper_sar_i64, "sar_i64" }, - { tcg_helper_div_i64, "div_i64" }, - { tcg_helper_rem_i64, "rem_i64" }, - { tcg_helper_divu_i64, "divu_i64" }, - { tcg_helper_remu_i64, "remu_i64" }, - { tcg_helper_mulsh_i64, "mulsh_i64" }, - { tcg_helper_muluh_i64, "muluh_i64" }, }; void tcg_context_init(TCGContext *s) diff --git a/tcg/tcg.h b/tcg/tcg.h index fbc93101cf..7e7d5910e8 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -54,8 +54,6 @@ typedef uint64_t tcg_target_ulong; #error unsupported #endif -#include "tcg-runtime.h" - #if TCG_TARGET_NB_REGS <= 32 typedef uint32_t TCGRegSet; #elif TCG_TARGET_NB_REGS <= 64