VirtualBox

source: vbox/trunk/src/recompiler/def-helper.h@ 37649

最後變更 在這個檔案從37649是 36170,由 vboxsync 提交於 14 年 前

rem: synced up to svn://svn.savannah.nongnu.org/qemu/trunk@6686 (repo UUID c046a42c-6fe2-441c-8c8c-71466251a162).

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 7.0 KB
 
1/* Helper file for declaring TCG helper functions.
2 Should be included at the start and end of target-foo/helper.h.
3
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.
9
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
13 helper.c, defining:
14 GEN_HELPER 1 to produce op generation functions (gen_helper_*)
15 GEN_HELPER 2 to do runtime registration helper functions.
16 */
17
18#ifndef DEF_HELPER_H
19#define DEF_HELPER_H 1
20
21#define HELPER(name) glue(helper_, name)
22
23#define GET_TCGV_i32 GET_TCGV_I32
24#define GET_TCGV_i64 GET_TCGV_I64
25#define GET_TCGV_ptr GET_TCGV_PTR
26
27/* Some types that make sense in C, but not for TCG. */
28#define dh_alias_i32 i32
29#define dh_alias_s32 i32
30#define dh_alias_int i32
31#define dh_alias_i64 i64
32#define dh_alias_s64 i64
33#define dh_alias_f32 i32
34#define dh_alias_f64 i64
35#if TARGET_LONG_BITS == 32
36#define dh_alias_tl i32
37#else
38#define dh_alias_tl i64
39#endif
40#define dh_alias_ptr ptr
41#define dh_alias_void void
42#define dh_alias_env ptr
43#ifdef VBOX
44# if ARCH_BITS == 32
45# define dh_alias_RTCCUINTREG i32
46# define dh_alias_RTCCINTREG i32
47# else
48# define dh_alias_RTCCUINTREG i64
49# define dh_alias_RTCCINTREG i64
50# endif
51#endif
52#define dh_alias(t) glue(dh_alias_, t)
53
54#define dh_ctype_i32 uint32_t
55#define dh_ctype_s32 int32_t
56#define dh_ctype_int int
57#define dh_ctype_i64 uint64_t
58#define dh_ctype_s64 int64_t
59#define dh_ctype_f32 float32
60#define dh_ctype_f64 float64
61#define dh_ctype_tl target_ulong
62#define dh_ctype_ptr void *
63#define dh_ctype_void void
64#define dh_ctype_env CPUState *
65#ifdef VBOX
66# if ARCH_BITS == 32
67# define dh_ctype_RTCCUINTREG uint32_t
68# define dh_ctype_RTCCINTREG int32_t
69# else
70# define dh_ctype_RTCCUINTREG uint64_t
71# define dh_ctype_RTCCINTREG int64_t
72# endif
73#endif
74#define dh_ctype(t) dh_ctype_##t
75
76/* We can't use glue() here because it falls foul of C preprocessor
77 recursive expansion rules. */
78#define dh_retvar_decl0_void void
79#define dh_retvar_decl0_i32 TCGv_i32 retval
80#define dh_retvar_decl0_i64 TCGv_i64 retval
81#define dh_retvar_decl0_ptr TCGv_iptr retval
82#define dh_retvar_decl0(t) glue(dh_retvar_decl0_, dh_alias(t))
83
84#define dh_retvar_decl_void
85#define dh_retvar_decl_i32 TCGv_i32 retval,
86#define dh_retvar_decl_i64 TCGv_i64 retval,
87#define dh_retvar_decl_ptr TCGv_iptr retval,
88#define dh_retvar_decl(t) glue(dh_retvar_decl_, dh_alias(t))
89
90#define dh_retvar_void TCG_CALL_DUMMY_ARG
91#define dh_retvar_i32 GET_TCGV_i32(retval)
92#define dh_retvar_i64 GET_TCGV_i64(retval)
93#define dh_retvar_ptr GET_TCGV_ptr(retval)
94#define dh_retvar(t) glue(dh_retvar_, dh_alias(t))
95
96#define dh_is_64bit_void 0
97#define dh_is_64bit_i32 0
98#define dh_is_64bit_i64 1
99#define dh_is_64bit_ptr (TCG_TARGET_REG_BITS == 64)
100#define dh_is_64bit(t) glue(dh_is_64bit_, dh_alias(t))
101
102#define dh_arg(t, n) \
103 args[n - 1] = glue(GET_TCGV_, dh_alias(t))(glue(arg, n)); \
104 sizemask |= dh_is_64bit(t) << n
105
106#define dh_arg_decl(t, n) glue(TCGv_, dh_alias(t)) glue(arg, n)
107
108
109#define DEF_HELPER_0(name, ret) \
110 DEF_HELPER_FLAGS_0(name, 0, ret)
111#define DEF_HELPER_1(name, ret, t1) \
112 DEF_HELPER_FLAGS_1(name, 0, ret, t1)
113#define DEF_HELPER_2(name, ret, t1, t2) \
114 DEF_HELPER_FLAGS_2(name, 0, ret, t1, t2)
115#define DEF_HELPER_3(name, ret, t1, t2, t3) \
116 DEF_HELPER_FLAGS_3(name, 0, ret, t1, t2, t3)
117#define DEF_HELPER_4(name, ret, t1, t2, t3, t4) \
118 DEF_HELPER_FLAGS_4(name, 0, ret, t1, t2, t3, t4)
119
120#endif /* DEF_HELPER_H */
121
122#ifndef GEN_HELPER
123/* Function prototypes. */
124
125#define DEF_HELPER_FLAGS_0(name, flags, ret) \
126dh_ctype(ret) HELPER(name) (void);
127
128#define DEF_HELPER_FLAGS_1(name, flags, ret, t1) \
129dh_ctype(ret) HELPER(name) (dh_ctype(t1));
130
131#define DEF_HELPER_FLAGS_2(name, flags, ret, t1, t2) \
132dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2));
133
134#define DEF_HELPER_FLAGS_3(name, flags, ret, t1, t2, t3) \
135dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3));
136
137#define DEF_HELPER_FLAGS_4(name, flags, ret, t1, t2, t3, t4) \
138dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \
139 dh_ctype(t4));
140
141#undef GEN_HELPER
142#define GEN_HELPER -1
143
144#elif GEN_HELPER == 1
145/* Gen functions. */
146
147#define DEF_HELPER_FLAGS_0(name, flags, ret) \
148static inline void glue(gen_helper_, name)(dh_retvar_decl0(ret)) \
149{ \
150 int sizemask; \
151 sizemask = dh_is_64bit(ret); \
152 tcg_gen_helperN(HELPER(name), flags, sizemask, dh_retvar(ret), 0, NULL); \
153}
154
155#define DEF_HELPER_FLAGS_1(name, flags, ret, t1) \
156static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) dh_arg_decl(t1, 1)) \
157{ \
158 TCGArg args[1]; \
159 int sizemask; \
160 sizemask = dh_is_64bit(ret); \
161 dh_arg(t1, 1); \
162 tcg_gen_helperN(HELPER(name), flags, sizemask, dh_retvar(ret), 1, args); \
163}
164
165#define DEF_HELPER_FLAGS_2(name, flags, ret, t1, t2) \
166static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) dh_arg_decl(t1, 1), \
167 dh_arg_decl(t2, 2)) \
168{ \
169 TCGArg args[2]; \
170 int sizemask; \
171 sizemask = dh_is_64bit(ret); \
172 dh_arg(t1, 1); \
173 dh_arg(t2, 2); \
174 tcg_gen_helperN(HELPER(name), flags, sizemask, dh_retvar(ret), 2, args); \
175}
176
177#define DEF_HELPER_FLAGS_3(name, flags, ret, t1, t2, t3) \
178static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) dh_arg_decl(t1, 1), \
179 dh_arg_decl(t2, 2), dh_arg_decl(t3, 3)) \
180{ \
181 TCGArg args[3]; \
182 int sizemask; \
183 sizemask = dh_is_64bit(ret); \
184 dh_arg(t1, 1); \
185 dh_arg(t2, 2); \
186 dh_arg(t3, 3); \
187 tcg_gen_helperN(HELPER(name), flags, sizemask, dh_retvar(ret), 3, args); \
188}
189
190#define DEF_HELPER_FLAGS_4(name, flags, ret, t1, t2, t3, t4) \
191static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) dh_arg_decl(t1, 1), \
192 dh_arg_decl(t2, 2), dh_arg_decl(t3, 3), dh_arg_decl(t4, 4)) \
193{ \
194 TCGArg args[4]; \
195 int sizemask; \
196 sizemask = dh_is_64bit(ret); \
197 dh_arg(t1, 1); \
198 dh_arg(t2, 2); \
199 dh_arg(t3, 3); \
200 dh_arg(t4, 4); \
201 tcg_gen_helperN(HELPER(name), flags, sizemask, dh_retvar(ret), 4, args); \
202}
203
204#undef GEN_HELPER
205#define GEN_HELPER -1
206
207#elif GEN_HELPER == 2
208/* Register helpers. */
209
210#define DEF_HELPER_FLAGS_0(name, flags, ret) \
211tcg_register_helper(HELPER(name), #name);
212
213#define DEF_HELPER_FLAGS_1(name, flags, ret, t1) \
214DEF_HELPER_FLAGS_0(name, flags, ret)
215
216#define DEF_HELPER_FLAGS_2(name, flags, ret, t1, t2) \
217DEF_HELPER_FLAGS_0(name, flags, ret)
218
219#define DEF_HELPER_FLAGS_3(name, flags, ret, t1, t2, t3) \
220DEF_HELPER_FLAGS_0(name, flags, ret)
221
222#define DEF_HELPER_FLAGS_4(name, flags, ret, t1, t2, t3, t4) \
223DEF_HELPER_FLAGS_0(name, flags, ret)
224
225#undef GEN_HELPER
226#define GEN_HELPER -1
227
228#elif GEN_HELPER == -1
229/* Undefine macros. */
230
231#undef DEF_HELPER_FLAGS_0
232#undef DEF_HELPER_FLAGS_1
233#undef DEF_HELPER_FLAGS_2
234#undef DEF_HELPER_FLAGS_3
235#undef DEF_HELPER_FLAGS_4
236#undef GEN_HELPER
237
238#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette