PR144 (aligned patchers on x86_64)
[cacao.git] / src / vm / jit / builtin.hpp
1 /* src/vm/jit/builtin.hpp - prototypes of builtin functions
2
3    Copyright (C) 1996-2005, 2006, 2007, 2008
4    CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5
6    This file is part of CACAO.
7
8    This program is free software; you can redistribute it and/or
9    modify it under the terms of the GNU General Public License as
10    published by the Free Software Foundation; either version 2, or (at
11    your option) any later version.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23 */
24
25
26 #ifndef _BUILTIN_HPP
27 #define _BUILTIN_HPP
28
29 /* forward typedefs ***********************************************************/
30
31 typedef struct builtintable_entry builtintable_entry;
32
33 #include "config.h"
34 #include "vm/types.h"
35
36 #include "arch.h"
37 #include "md-abi.h"
38
39 #include "toolbox/logging.hpp"
40
41 #include "vm/descriptor.hpp"
42 #include "vm/utf8.h"
43
44
45 /* define infinity for floating point numbers */
46
47 #define FLT_NAN     0x7fc00000
48 #define FLT_POSINF  0x7f800000
49 #define FLT_NEGINF  0xff800000
50
51 /* define infinity for double floating point numbers */
52
53 #define DBL_NAN     0x7ff8000000000000LL
54 #define DBL_POSINF  0x7ff0000000000000LL
55 #define DBL_NEGINF  0xfff0000000000000LL
56
57
58 /* float versions are not defined in GNU classpath's fdlibm */
59
60 #define copysignf    copysign
61 #define finitef      finite
62 #define fmodf        fmod
63 #define isnanf       isnan
64
65
66 /* builtin functions table ****************************************************/
67
68 struct builtintable_entry {
69         s4           opcode;                /* opcode which is replaced           */
70         u4           flags;                 /* e.g. check for exception           */
71         functionptr  fp;                    /* function pointer of builtin        */
72         u1          *stub;                  /* pointer to builtin stub code       */
73         const char*  cclassname;            /* char name of the class             */
74         const char*  cname;                 /* char name of the function          */
75         const char*  cdescriptor;           /* char name of the descriptor        */
76         utf         *classname;             /* class of the function              */
77         utf         *name;                  /* name of the function               */
78         utf         *descriptor;            /* descriptor of the function         */
79         methoddesc  *md;
80         functionptr  emit_fastpath;         /* emitter for fast-path code         */
81 };
82
83
84 /* builtin table flag defines *************************************************/
85
86 #define BUILTINTABLE_FLAG_STUB         0x0001 /* builtin needs a stub         */
87 #define BUILTINTABLE_FLAG_EXCEPTION    0x0002 /* check for excepion on return */
88
89
90 /* function prototypes ********************************************************/
91
92 #ifdef __cplusplus
93 extern "C" {
94 #endif
95
96 bool builtin_init(void);
97
98 builtintable_entry *builtintable_get_internal(functionptr fp);
99 builtintable_entry *builtintable_get_automatic(s4 opcode);
100
101 bool builtintable_replace_function(void *iptr);
102
103
104 /**********************************************************************/
105 /* BUILTIN FUNCTIONS                                                  */
106 /**********************************************************************/
107
108 /* NOTE: Builtin functions which are used in the BUILTIN* opcodes must
109  * have a BUILTIN_... macro defined as seen below. In code dealing
110  * with the BUILTIN* opcodes the functions may only be addressed by
111  * these macros, never by their actual name! (This helps to make this
112  * code more portable.)
113  *
114  * C and assembler code which does not deal with the BUILTIN* opcodes,
115  * can use the builtin functions normally (like all other functions).
116  *
117  * IMPORTANT:
118  * For each builtin function which is used in a BUILTIN* opcode there
119  * must be an entry in the builtin_desc table in jit/jit.c.
120  *
121  * Below each prototype is either the BUILTIN_ macro definition or a
122  * comment specifiying that this function is not used in BUILTIN*
123  * opcodes.
124  *
125  * (The BUILTIN* opcodes are ICMD_BUILTIN1, ICMD_BUILTIN2 and
126  * ICMD_BUILTIN3.)
127  */
128
129 #if USES_NEW_SUBTYPE
130 bool fast_subtype_check(struct _vftbl *, struct _vftbl *);
131 #endif
132
133 /* From lock.hpp: bool lock_monitor_enter(java_handle_t *); */
134 #define LOCK_monitor_enter          (functionptr) lock_monitor_enter
135 #if defined(__X86_64__)
136 # define EMIT_FASTPATH_monitor_enter (functionptr) emit_fastpath_monitor_enter
137 #else
138 # define EMIT_FASTPATH_monitor_enter (functionptr) NULL
139 #endif
140
141 /* From lock.hpp: bool lock_monitor_exit(java_handle_t *); */
142 #define LOCK_monitor_exit          (functionptr) lock_monitor_exit
143 #if defined(__X86_64__)
144 # define EMIT_FASTPATH_monitor_exit (functionptr) emit_fastpath_monitor_exit
145 #else
146 # define EMIT_FASTPATH_monitor_exit (functionptr) NULL
147 #endif
148
149 bool builtin_instanceof(java_handle_t *obj, classinfo *c);
150 /* NOT AN OP */
151 bool builtin_checkcast(java_handle_t *obj, classinfo *c);
152 /* NOT AN OP */
153 bool builtin_arrayinstanceof(java_handle_t *h, classinfo *targetclass);
154 /* NOT AN OP */
155 bool builtin_fast_arrayinstanceof(java_object_t *o, classinfo *targetclass);
156 #define BUILTIN_arrayinstanceof (functionptr) builtin_fast_arrayinstanceof
157 bool builtin_fast_arraycheckcast(java_object_t *o, classinfo *targetclass);
158 #define BUILTIN_arraycheckcast (functionptr) builtin_fast_arraycheckcast
159
160 bool builtin_canstore(java_handle_objectarray_t *oa, java_handle_t *o);
161 /* NOT AN OP */
162 bool builtin_fast_canstore(java_objectarray_t *oa, java_object_t *o);
163 #define BUILTIN_FAST_canstore (functionptr) builtin_fast_canstore
164
165 void *builtin_throw_exception(java_object_t *exception);
166 /* NOT AN OP */
167 java_object_t *builtin_retrieve_exception(void);
168 /* NOT AN OP */
169
170 java_handle_t *builtin_new(classinfo *c);
171 /* NOT AN OP */
172 java_handle_t *builtin_java_new(java_handle_t *c);
173 #define BUILTIN_new (functionptr) builtin_java_new
174
175 #if defined(ENABLE_TLH)
176 #define BUILTIN_tlh_new (functionptr) builtin_tlh_new
177 java_handle_t *builtin_tlh_new(classinfo *c);
178 #endif
179
180 #if defined(ENABLE_ESCAPE_REASON)
181 #define BUILTIN_escape_reason_new (functionptr)builtin_escape_reason_new
182 java_handle_t *builtin_escape_reason_new(classinfo *c);
183 #endif
184
185 java_object_t *builtin_fast_new(classinfo *c);
186 #define BUILTIN_FAST_new (functionptr) builtin_fast_new
187
188 java_handle_array_t *builtin_java_newarray(int32_t size, java_handle_t *arrayclass);
189 #define BUILTIN_newarray (functionptr) builtin_java_newarray
190
191 java_handle_booleanarray_t *builtin_newarray_boolean(int32_t size);
192 #define BUILTIN_newarray_boolean (functionptr) builtin_newarray_boolean
193 java_handle_chararray_t *builtin_newarray_char(int32_t size);
194 #define BUILTIN_newarray_char (functionptr) builtin_newarray_char
195 java_handle_floatarray_t *builtin_newarray_float(int32_t size);
196 #define BUILTIN_newarray_float (functionptr) builtin_newarray_float
197 java_handle_doublearray_t *builtin_newarray_double(int32_t size);
198 #define BUILTIN_newarray_double (functionptr) builtin_newarray_double
199 java_handle_bytearray_t *builtin_newarray_byte(int32_t size);
200 #define BUILTIN_newarray_byte (functionptr) builtin_newarray_byte
201 java_handle_shortarray_t *builtin_newarray_short(int32_t size);
202 #define BUILTIN_newarray_short (functionptr) builtin_newarray_short
203 java_handle_intarray_t *builtin_newarray_int(int32_t size);
204 #define BUILTIN_newarray_int (functionptr) builtin_newarray_int
205 java_handle_longarray_t *builtin_newarray_long(int32_t size);
206 #define BUILTIN_newarray_long (functionptr) builtin_newarray_long
207
208 java_handle_objectarray_t *builtin_multianewarray(int n,
209                                                                                                   java_handle_t *arrayclass,
210                                                                                                   long *dims);
211 #define BUILTIN_multianewarray (functionptr) builtin_multianewarray
212
213 #if defined(TRACE_ARGS_NUM)
214 void builtin_verbosecall_enter(s8 a0, s8 a1,
215 # if TRACE_ARGS_NUM >= 4
216                                                            s8 a2, s8 a3,
217 # endif
218 # if TRACE_ARGS_NUM >= 6
219                                                            s8 a4, s8 a5,
220 # endif
221 # if TRACE_ARGS_NUM == 8
222                                                            s8 a6, s8 a7,
223 # endif
224                                                            methodinfo *m);
225 /* NOT AN OP */
226 #endif /* defined(TRACE_ARGS_NUM) */
227
228 void builtin_verbosecall_exit(s8 l, double d, float f, methodinfo *m);
229 /* NOT AN OP */
230
231 s4 builtin_idiv(s4 a, s4 b);
232 #define BUILTIN_idiv (functionptr) builtin_idiv
233 s4 builtin_irem(s4 a, s4 b);
234 #define BUILTIN_irem (functionptr) builtin_irem
235
236 s8 builtin_ladd(s8 a, s8 b);
237 #define BUILTIN_ladd (functionptr) builtin_ladd
238 s8 builtin_lsub(s8 a, s8 b);
239 #define BUILTIN_lsub (functionptr) builtin_lsub
240 s8 builtin_lmul(s8 a, s8 b);
241 #define BUILTIN_lmul (functionptr) builtin_lmul
242
243 s8 builtin_ldiv(s8 a, s8 b);
244 #define BUILTIN_ldiv (functionptr) builtin_ldiv
245 s8 builtin_lrem(s8 a, s8 b);
246 #define BUILTIN_lrem (functionptr) builtin_lrem
247
248 s8 builtin_lshl(s8 a, s4 b);
249 #define BUILTIN_lshl (functionptr) builtin_lshl
250 s8 builtin_lshr(s8 a, s4 b);
251 #define BUILTIN_lshr (functionptr) builtin_lshr
252 s8 builtin_lushr(s8 a, s4 b);
253 #define BUILTIN_lushr (functionptr) builtin_lushr
254 s8 builtin_land(s8 a, s8 b);
255 #define BUILTIN_land (functionptr) builtin_land
256 s8 builtin_lor(s8 a, s8 b);
257 #define BUILTIN_lor (functionptr) builtin_lor
258 s8 builtin_lxor(s8 a, s8 b);
259 #define BUILTIN_lxor (functionptr) builtin_lxor
260 s8 builtin_lneg(s8 a);
261 #define BUILTIN_lneg (functionptr) builtin_lneg
262 s4 builtin_lcmp(s8 a, s8 b);
263 #define BUILTIN_lcmp (functionptr) builtin_lcmp
264
265 float builtin_fadd(float a, float b);
266 #define BUILTIN_fadd (functionptr) builtin_fadd
267 float builtin_fsub(float a, float b);
268 #define BUILTIN_fsub (functionptr) builtin_fsub
269 float builtin_fmul(float a, float b);
270 #define BUILTIN_fmul (functionptr) builtin_fmul
271 float builtin_fdiv(float a, float b);
272 #define BUILTIN_fdiv (functionptr) builtin_fdiv
273 float builtin_fneg(float a);         
274 #define BUILTIN_fneg (functionptr) builtin_fneg
275 s4 builtin_fcmpl(float a, float b);  
276 #define BUILTIN_fcmpl (functionptr) builtin_fcmpl
277 s4 builtin_fcmpg(float a, float b);  
278 #define BUILTIN_fcmpg (functionptr) builtin_fcmpg
279 float builtin_frem(float a, float b);
280 #define BUILTIN_frem (functionptr) builtin_frem
281
282 double builtin_dadd(double a, double b);
283 #define BUILTIN_dadd (functionptr) builtin_dadd
284 double builtin_dsub(double a, double b);
285 #define BUILTIN_dsub (functionptr) builtin_dsub
286 double builtin_dmul(double a, double b);
287 #define BUILTIN_dmul (functionptr) builtin_dmul
288 double builtin_ddiv(double a, double b);
289 #define BUILTIN_ddiv (functionptr) builtin_ddiv
290 double builtin_dneg(double a);          
291 #define BUILTIN_dneg (functionptr) builtin_dneg
292 s4 builtin_dcmpl(double a, double b);   
293 #define BUILTIN_dcmpl (functionptr) builtin_dcmpl
294 s4 builtin_dcmpg(double a, double b);   
295 #define BUILTIN_dcmpg (functionptr) builtin_dcmpg
296 double builtin_drem(double a, double b);
297 #define BUILTIN_drem (functionptr) builtin_drem
298
299 float    builtin_i2f(s4 i);
300 #define BUILTIN_i2f (functionptr) builtin_i2f
301 double   builtin_i2d(s4 i);
302 #define BUILTIN_i2d (functionptr) builtin_i2d
303 float    builtin_l2f(s8 l);
304 #define BUILTIN_l2f (functionptr) builtin_l2f
305 double   builtin_l2d(s8 l);
306 #define BUILTIN_l2d (functionptr) builtin_l2d
307
308 s4       builtin_f2i(float a);
309 #define BUILTIN_f2i (functionptr) builtin_f2i
310 s4       asm_builtin_f2i(float a);
311 /* NOT AN OP */
312 s8       builtin_f2l(float a);
313 #define BUILTIN_f2l (functionptr) builtin_f2l
314 s8       asm_builtin_f2l(float a);
315 /* NOT AN OP */
316
317 double   builtin_f2d(float a);
318 #define BUILTIN_f2d (functionptr) builtin_f2d
319
320 s4       builtin_d2i(double a);
321 #define BUILTIN_d2i (functionptr) builtin_d2i
322 s4       asm_builtin_d2i(double a);
323 /* NOT AN OP */
324 s8       builtin_d2l(double a);
325 #define BUILTIN_d2l (functionptr) builtin_d2l
326 s8       asm_builtin_d2l(double a);
327 /* NOT AN OP */
328
329 float    builtin_d2f(double a);
330 #define BUILTIN_d2f (functionptr) builtin_d2f
331
332 java_handle_t *builtin_clone(void *env, java_handle_t *o);
333 #define BUILTIN_clone (functionptr) builtin_clone
334
335 void builtin_arraycopy(java_handle_t *src, s4 srcStart,
336                                            java_handle_t *dest, s4 destStart, s4 len);
337 #define BUILTIN_arraycopy (functionptr) builtin_arraycopy
338
339 s8 builtin_nanotime(void);
340 s8 builtin_currenttimemillis(void);
341 #define BUILTIN_currenttimemillis (functionptr) builtin_currenttimemillis
342
343 #if defined(ENABLE_CYCLES_STATS)
344 void builtin_print_cycles_stats(FILE *file);
345 #endif
346
347 #ifdef __cplusplus
348 }
349 #endif
350
351 #endif // _BUILTIN_HPP
352
353
354 /*
355  * These are local overrides for various environment variables in Emacs.
356  * Please do not remove this and leave it at the end of the file, where
357  * Emacs will automagically detect them.
358  * ---------------------------------------------------------------------
359  * Local variables:
360  * mode: c++
361  * indent-tabs-mode: t
362  * c-basic-offset: 4
363  * tab-width: 4
364  * End:
365  * vim:noexpandtab:sw=4:ts=4:
366  */