1 /* Helper file for declaring TCG helper functions.
2 Used by other helper files.
4 Targets should use DEF_HELPER_N and DEF_HELPER_FLAGS_N to declare helper
5 functions. Names should be specified without the helper_ prefix, and
6 the return and argument types specified. 3 basic types are understood
7 (i32, i64 and ptr). Additional aliases are provided for convenience and
8 to match the types used by the C helper implementation.
10 The target helper.h should be included in all files that use/define
11 helper functions. THis will ensure that function prototypes are
12 consistent. In addition it should be included an extra two times for
14 GEN_HELPER 1 to produce op generation functions (gen_helper_*)
15 GEN_HELPER 2 to do runtime registration helper functions.
18 #ifndef EXEC_HELPER_HEAD_H
19 #define EXEC_HELPER_HEAD_H
21 #define HELPER(name) glue(helper_, name)
23 /* Some types that make sense in C, but not for TCG. */
24 #define dh_alias_i32 i32
25 #define dh_alias_s32 i32
26 #define dh_alias_int i32
27 #define dh_alias_i64 i64
28 #define dh_alias_s64 i64
29 #define dh_alias_f32 i32
30 #define dh_alias_f64 i64
31 #define dh_alias_ptr ptr
32 #define dh_alias_void void
33 #define dh_alias_noreturn noreturn
34 #define dh_alias(t) glue(dh_alias_, t)
36 #define dh_ctype_i32 uint32_t
37 #define dh_ctype_s32 int32_t
38 #define dh_ctype_int int
39 #define dh_ctype_i64 uint64_t
40 #define dh_ctype_s64 int64_t
41 #define dh_ctype_f32 float32
42 #define dh_ctype_f64 float64
43 #define dh_ctype_ptr void *
44 #define dh_ctype_void void
45 #define dh_ctype_noreturn void QEMU_NORETURN
46 #define dh_ctype(t) dh_ctype_##t
49 # ifdef TARGET_LONG_BITS
50 # if TARGET_LONG_BITS == 32
51 # define dh_alias_tl i32
53 # define dh_alias_tl i64
56 # define dh_alias_env ptr
57 # define dh_ctype_tl target_ulong
58 # define dh_ctype_env CPUArchState *
61 /* We can't use glue() here because it falls foul of C preprocessor
62 recursive expansion rules. */
63 #define dh_retvar_decl0_void void
64 #define dh_retvar_decl0_noreturn void
65 #define dh_retvar_decl0_i32 TCGv_i32 retval
66 #define dh_retvar_decl0_i64 TCGv_i64 retval
67 #define dh_retvar_decl0_ptr TCGv_ptr retval
68 #define dh_retvar_decl0(t) glue(dh_retvar_decl0_, dh_alias(t))
70 #define dh_retvar_decl_void
71 #define dh_retvar_decl_noreturn
72 #define dh_retvar_decl_i32 TCGv_i32 retval,
73 #define dh_retvar_decl_i64 TCGv_i64 retval,
74 #define dh_retvar_decl_ptr TCGv_ptr retval,
75 #define dh_retvar_decl(t) glue(dh_retvar_decl_, dh_alias(t))
77 #define dh_retvar_void NULL
78 #define dh_retvar_noreturn NULL
79 #define dh_retvar_i32 tcgv_i32_temp(retval)
80 #define dh_retvar_i64 tcgv_i64_temp(retval)
81 #define dh_retvar_ptr tcgv_ptr_temp(retval)
82 #define dh_retvar(t) glue(dh_retvar_, dh_alias(t))
84 #define dh_is_64bit_void 0
85 #define dh_is_64bit_noreturn 0
86 #define dh_is_64bit_i32 0
87 #define dh_is_64bit_i64 1
88 #define dh_is_64bit_ptr (sizeof(void *) == 8)
89 #define dh_is_64bit(t) glue(dh_is_64bit_, dh_alias(t))
91 #define dh_is_signed_void 0
92 #define dh_is_signed_noreturn 0
93 #define dh_is_signed_i32 0
94 #define dh_is_signed_s32 1
95 #define dh_is_signed_i64 0
96 #define dh_is_signed_s64 1
97 #define dh_is_signed_f32 0
98 #define dh_is_signed_f64 0
99 #define dh_is_signed_tl 0
100 #define dh_is_signed_int 1
101 /* ??? This is highly specific to the host cpu. There are even special
102 extension instructions that may be required, e.g. ia64's addp4. But
103 for now we don't support any 64-bit targets with 32-bit pointers. */
104 #define dh_is_signed_ptr 0
105 #define dh_is_signed_env dh_is_signed_ptr
106 #define dh_is_signed(t) dh_is_signed_##t
108 #define dh_sizemask(t, n) \
109 ((dh_is_64bit(t) << (n*2)) | (dh_is_signed(t) << (n*2+1)))
111 #define dh_arg(t, n) \
112 glue(glue(tcgv_, dh_alias(t)), _temp)(glue(arg, n))
114 #define dh_arg_decl(t, n) glue(TCGv_, dh_alias(t)) glue(arg, n)
116 #define DEF_HELPER_0(name, ret) \
117 DEF_HELPER_FLAGS_0(name, 0, ret)
118 #define DEF_HELPER_1(name, ret, t1) \
119 DEF_HELPER_FLAGS_1(name, 0, ret, t1)
120 #define DEF_HELPER_2(name, ret, t1, t2) \
121 DEF_HELPER_FLAGS_2(name, 0, ret, t1, t2)
122 #define DEF_HELPER_3(name, ret, t1, t2, t3) \
123 DEF_HELPER_FLAGS_3(name, 0, ret, t1, t2, t3)
124 #define DEF_HELPER_4(name, ret, t1, t2, t3, t4) \
125 DEF_HELPER_FLAGS_4(name, 0, ret, t1, t2, t3, t4)
126 #define DEF_HELPER_5(name, ret, t1, t2, t3, t4, t5) \
127 DEF_HELPER_FLAGS_5(name, 0, ret, t1, t2, t3, t4, t5)
128 #define DEF_HELPER_6(name, ret, t1, t2, t3, t4, t5, t6) \
129 DEF_HELPER_FLAGS_6(name, 0, ret, t1, t2, t3, t4, t5, t6)
131 /* MAX_OPC_PARAM_IARGS must be set to n if last entry is DEF_HELPER_FLAGS_n. */
133 #endif /* EXEC_HELPER_HEAD_H */