exceptionptr update for native threads
[cacao.git] / builtin.h
1 /* builtin.h - prototypes of builtin functions
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Reinhard Grafl
28
29    Changes: Edwin Steiner
30
31    $Id: builtin.h 862 2004-01-06 23:42:01Z stefan $
32
33 */
34
35
36 #ifndef _BUILTIN_H
37 #define _BUILTIN_H
38
39 #include "config.h"
40 #include "toolbox/loging.h"
41
42
43 /* define infinity for floating point numbers */
44
45 #define FLT_NAN     0x7fc00000
46 #define FLT_POSINF  0x7f800000
47 #define FLT_NEGINF  0xff800000
48
49 /* define infinity for double floating point numbers */
50
51 #define DBL_NAN     0x7ff8000000000000LL
52 #define DBL_POSINF  0x7ff0000000000000LL
53 #define DBL_NEGINF  0xfff0000000000000LL
54
55
56 /* some platforms do not have float versions of these functions */
57
58 #ifndef HAVE_COPYSIGNF
59 #define copysignf copysign
60 #endif
61
62 #ifndef HAVE_FINITEF
63 #define finitef finite
64 #endif
65
66 #ifndef HAVE_FMODF
67 #define fmodf fmod
68 #endif
69
70 #ifndef HAVE_ISNANF
71 #define isnanf isnan
72 #endif
73
74
75 /**********************************************************************/
76 /* BUILTIN FUNCTIONS TABLE                                            */
77 /**********************************************************************/
78
79 /* IMPORTANT:
80  * For each builtin function which is used in a BUILTIN* opcode there
81  * must be an entry in the builtin_desc table in jit/jit.c.
82  */
83  
84 /* XXX delete */
85 #if 0
86 typedef struct builtin_descriptor {
87         functionptr bptr;
88         char        *name;
89         } builtin_descriptor;
90 #endif
91
92 typedef struct builtin_descriptor builtin_descriptor;
93
94 /* There is a builtin_descriptor in builtin_desc for every builtin
95  * function used in BUILTIN* opcodes.
96  */
97 struct builtin_descriptor {
98         int         opcode;   /* opcode which is replaced by this builtin */
99                               /* (255 means no automatic replacement,     */
100                               /*    0 means end of list.)                 */
101         functionptr builtin;  /* the builtin function (specify BUILTIN_...*/
102                               /* macro)                                   */
103         int         icmd;     /* the BUILTIN* opcode to use (# of args)   */
104         u1          type_s1;  /* type of 1st argument                     */
105         u1          type_s2;  /* type of 2nd argument, or TYPE_VOID       */
106         u1          type_s3;  /* type of 3rd argument, or TYPE_VOID       */
107         u1          type_d;   /* type of result (may be TYPE_VOID)        */
108         bool        supported;/* is <opcode> supported without builtin?   */
109         bool        isfloat;  /* is this a floating point operation?      */
110         char        *name;    /* display name of the builtin function     */
111 };
112
113 extern builtin_descriptor builtin_desc[];
114
115 /**********************************************************************/
116 /* GLOBAL VARIABLES                                                   */
117 /**********************************************************************/
118
119 #define THREADSPECIFIC
120 #define exceptionptr (&_exceptionptr)
121
122 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
123 #ifdef HAVE___THREAD
124
125 #undef THREADSPECIFIC
126 #define THREADSPECIFIC __thread
127
128 #else
129
130 #undef exceptionptr
131 #define exceptionptr builtin_get_exceptionptrptr()
132
133 #endif
134 #endif
135
136 extern THREADSPECIFIC java_objectheader* _exceptionptr;
137
138
139 /**********************************************************************/
140 /* BUILTIN FUNCTIONS                                                  */
141 /**********************************************************************/
142
143 /* NOTE: Builtin functions which are used in the BUILTIN* opcodes must
144  * have a BUILTIN_... macro defined as seen below. In code dealing
145  * with the BUILTIN* opcodes the functions may only be addressed by
146  * these macros, never by their actual name! (This helps to make this
147  * code more portable.)
148  *
149  * C and assembler code which does not deal with the BUILTIN* opcodes,
150  * can use the builtin functions normally (like all other functions).
151  *
152  * IMPORTANT:
153  * For each builtin function which is used in a BUILTIN* opcode there
154  * must be an entry in the builtin_desc table in jit/jit.c.
155  *
156  * Below each prototype is either the BUILTIN_ macro definition or a
157  * comment specifiying that this function is not used in BUILTIN*
158  * opcodes.
159  *
160  * (The BUILTIN* opcodes are ICMD_BUILTIN1, ICMD_BUILTIN2 and
161  * ICMD_BUILTIN3.)
162  */
163
164 s4 builtin_instanceof(java_objectheader *obj, classinfo *class);
165 #define BUILTIN_instanceof (functionptr) builtin_instanceof
166 s4 builtin_isanysubclass (classinfo *sub, classinfo *super);
167 /* NOT AN OP */
168 s4 builtin_isanysubclass_vftbl (vftbl *sub, vftbl *super);
169 /* NOT AN OP */
170 s4 builtin_checkcast(java_objectheader *obj, classinfo *class);
171 /* NOT AN OP */
172 s4 builtin_arrayinstanceof(java_objectheader *obj, vftbl *target);
173 #define BUILTIN_arrayinstanceof (functionptr) builtin_arrayinstanceof
174
175 #if defined(__I386__)
176 s4 asm_builtin_arrayinstanceof(java_objectheader *obj, classinfo *class); /* XXX ? */
177 #undef  BUILTIN_arrayinstanceof
178 #define BUILTIN_arrayinstanceof (functionptr) asm_builtin_arrayinstanceof
179 #endif
180
181 s4 builtin_checkarraycast(java_objectheader *obj, vftbl *target);
182 /* NOT AN OP */
183 s4 asm_builtin_checkarraycast(java_objectheader *obj, vftbl *target);
184 #define BUILTIN_checkarraycast (functionptr) asm_builtin_checkarraycast
185
186 java_objectheader *builtin_throw_exception(java_objectheader *exception);
187 /* NOT AN OP */
188 java_objectheader *builtin_trace_exception(java_objectheader *_exceptionptr,
189                                                                                    methodinfo *method, 
190                                                                                    int *pos, int noindent);
191 /* NOT AN OP */
192
193 static inline java_objectheader **builtin_get_exceptionptrptr();
194 /* NOT AN OP */
195 void builtin_reset_exceptionptr();
196 /* NOT AN OP */
197
198 java_objectheader *builtin_new(classinfo *c);
199 #define BUILTIN_new (functionptr) builtin_new
200
201 java_arrayheader *builtin_newarray(s4 size, vftbl *arrayvftbl);
202 #define BUILTIN_newarray (functionptr) builtin_newarray
203 java_objectarray *builtin_anewarray(s4 size, classinfo *component);
204 /* NOT AN OP */
205
206 #if defined(__I386__)
207 void asm_builtin_newarray(s4 size, vftbl *arrayvftbl);
208 #undef  BUILTIN_newarray
209 #define BUILTIN_newarray (functionptr) asm_builtin_newarray
210 #endif
211
212 java_booleanarray *builtin_newarray_boolean(s4 size);
213 #define BUILTIN_newarray_boolean (functionptr) builtin_newarray_boolean
214 java_chararray *builtin_newarray_char(s4 size);
215 #define BUILTIN_newarray_char (functionptr) builtin_newarray_char
216 java_floatarray *builtin_newarray_float(s4 size);
217 #define BUILTIN_newarray_float (functionptr) builtin_newarray_float
218 java_doublearray *builtin_newarray_double(s4 size);
219 #define BUILTIN_newarray_double (functionptr) builtin_newarray_double
220 java_bytearray *builtin_newarray_byte(s4 size);
221 #define BUILTIN_newarray_byte (functionptr) builtin_newarray_byte
222 java_shortarray *builtin_newarray_short(s4 size);
223 #define BUILTIN_newarray_short (functionptr) builtin_newarray_short
224 java_intarray *builtin_newarray_int(s4 size);
225 #define BUILTIN_newarray_int (functionptr) builtin_newarray_int
226 java_longarray *builtin_newarray_long(s4 size);
227 #define BUILTIN_newarray_long (functionptr) builtin_newarray_long
228 java_arrayheader *builtin_nmultianewarray(int n,
229                                           vftbl *arrayvftbl, long *dims);
230 /* NOT AN OP */
231
232 s4 builtin_canstore(java_objectarray *a, java_objectheader *o);
233 /* NOT AN OP */
234 void asm_builtin_aastore(java_objectarray *a, s4 index, java_objectheader *o);
235 #define BUILTIN_aastore (functionptr) asm_builtin_aastore
236
237 #ifdef TRACE_ARGS_NUM
238 #if TRACE_ARGS_NUM == 6
239 void builtin_trace_args(s8 a0, s8 a1, s8 a2, s8 a3, s8 a4, s8 a5, methodinfo *method);
240 /* NOT AN OP */
241 #else
242 void builtin_trace_args(s8 a0, s8 a1, s8 a2, s8 a3, s8 a4, s8 a5, s8 a6, s8 a7, methodinfo *method);
243 /* NOT AN OP */
244 #endif
245 #endif
246 void builtin_displaymethodstart(methodinfo *method); /* XXX? */
247 /* NOT AN OP */
248 void builtin_displaymethodstop(methodinfo *method, s8 l, double d, float f);
249 /* NOT AN OP */
250 /* void builtin_displaymethodstop(methodinfo *method); */ /* XXX? */
251 void builtin_displaymethodexception(methodinfo *method); /* XXX? */
252 /* NOT AN OP */
253
254 void builtin_monitorenter(java_objectheader *o);
255 /* NOT AN OP */
256 void asm_builtin_monitorenter(java_objectheader *o);
257 #define BUILTIN_monitorenter (functionptr) asm_builtin_monitorenter
258 void builtin_monitorexit(java_objectheader *o);
259 /* NOT AN OP */
260 void asm_builtin_monitorexit(java_objectheader *o);
261 #define BUILTIN_monitorexit (functionptr) asm_builtin_monitorexit
262
263 s4 builtin_idiv(s4 a, s4 b);
264 /* NOT AN OP */
265 s4 asm_builtin_idiv(s4 a, s4 b);
266 #define BUILTIN_idiv (functionptr) asm_builtin_idiv
267 s4 builtin_irem(s4 a, s4 b);
268 /* NOT AN OP */
269 s4 asm_builtin_irem(s4 a, s4 b);
270 #define BUILTIN_irem (functionptr) asm_builtin_irem
271
272 s8 builtin_ladd(s8 a, s8 b);
273 #define BUILTIN_ladd (functionptr) builtin_ladd
274 s8 builtin_lsub(s8 a, s8 b);
275 #define BUILTIN_lsub (functionptr) builtin_lsub
276 s8 builtin_lmul(s8 a, s8 b);
277 #define BUILTIN_lmul (functionptr) builtin_lmul
278 s8 builtin_ldiv(s8 a, s8 b);
279 /* NOT AN OP */
280 s8 asm_builtin_ldiv(s8 a, s8 b);
281 #define BUILTIN_ldiv (functionptr) asm_builtin_ldiv
282 s8 builtin_lrem(s8 a, s8 b);
283 /* NOT AN OP */
284 s8 asm_builtin_lrem(s8 a, s8 b);
285 #define BUILTIN_lrem (functionptr) asm_builtin_lrem
286 s8 builtin_lshl(s8 a, s4 b);
287 #define BUILTIN_lshl (functionptr) builtin_lshl
288 s8 builtin_lshr(s8 a, s4 b);
289 #define BUILTIN_lshr (functionptr) builtin_lshr
290 s8 builtin_lushr(s8 a, s4 b);
291 #define BUILTIN_lushr (functionptr) builtin_lushr
292 s8 builtin_land(s8 a, s8 b);
293 #define BUILTIN_land (functionptr) builtin_land
294 s8 builtin_lor(s8 a, s8 b);
295 #define BUILTIN_lor (functionptr) builtin_lor
296 s8 builtin_lxor(s8 a, s8 b);
297 #define BUILTIN_lxor (functionptr) builtin_lxor
298 s8 builtin_lneg(s8 a);
299 #define BUILTIN_lneg (functionptr) builtin_lneg
300 s4 builtin_lcmp(s8 a, s8 b);
301 #define BUILTIN_lcmp (functionptr) builtin_lcmp
302
303 float builtin_fadd(float a, float b); /* XXX? */
304 /* NOT AN OP */
305 float builtin_fsub(float a, float b); /* XXX? */
306 /* NOT AN OP */
307 float builtin_fmul(float a, float b); /* XXX? */
308 /* NOT AN OP */
309 float builtin_fdiv(float a, float b); /* XXX? */
310 /* NOT AN OP */
311 float builtin_fneg(float a);          /* XXX? */
312 /* NOT AN OP */
313 s4 builtin_fcmpl(float a, float b);   /* XXX? */
314 /* NOT AN OP */
315 s4 builtin_fcmpg(float a, float b);   /* XXX? */
316 /* NOT AN OP */
317 float builtin_frem(float a, float b);
318 #define BUILTIN_frem (functionptr) builtin_frem
319
320 double builtin_dadd(double a, double b); /* XXX? */
321 /* NOT AN OP */
322 double builtin_dsub(double a, double b); /* XXX? */
323 /* NOT AN OP */
324 double builtin_dmul(double a, double b); /* XXX? */
325 /* NOT AN OP */
326 double builtin_ddiv(double a, double b); /* XXX? */
327 /* NOT AN OP */
328 double builtin_dneg(double a);           /* XXX? */ 
329 /* NOT AN OP */
330 s4 builtin_dcmpl(double a, double b);    /* XXX? */
331 /* NOT AN OP */
332 s4 builtin_dcmpg(double a, double b);    /* XXX? */
333 /* NOT AN OP */
334 double builtin_drem(double a, double b);
335 #define BUILTIN_drem (functionptr) builtin_drem
336
337 s8       builtin_i2l(s4 i);
338 /* NOT AN OP */
339 float    builtin_i2f(s4 i);
340 #define BUILTIN_i2f (functionptr) builtin_i2f
341 double   builtin_i2d(s4 i);
342 #define BUILTIN_i2d (functionptr) builtin_i2d
343 s4       builtin_l2i(s8 l);
344 /* NOT AN OP */
345 float    builtin_l2f(s8 l);
346 #define BUILTIN_l2f (functionptr) builtin_l2f
347 double   builtin_l2d(s8 l);
348 #define BUILTIN_l2d (functionptr) builtin_l2d
349
350 s4       builtin_f2i(float a);
351 #define BUILTIN_f2i (functionptr) builtin_f2i
352 s4       asm_builtin_f2i(float a);
353 /* NOT AN OP */
354 s8       builtin_f2l(float a);
355 #define BUILTIN_f2l (functionptr) builtin_f2l
356 s8       asm_builtin_f2l(float a);
357 /* NOT AN OP */
358
359 double   builtin_f2d(float a);     /* XXX? */
360 /* NOT AN OP */
361
362 s4       builtin_d2i(double a);
363 #define BUILTIN_d2i (functionptr) builtin_d2i
364 s4       asm_builtin_d2i(double a);
365 /* NOT AN OP */
366 s8       builtin_d2l(double a);
367 #define BUILTIN_d2l (functionptr) builtin_d2l
368 s8       asm_builtin_d2l(double a);
369 /* NOT AN OP */
370
371 float    builtin_d2f(double a);    /* XXX? */
372 /* NOT AN OP */
373
374 java_arrayheader *builtin_clone_array(void *env, java_arrayheader *o);
375 /* NOT AN OP */
376
377 /* conversion helper functions */
378
379 inline float intBitsToFloat(s4 i);
380 inline float longBitsToDouble(s8 l);
381
382
383 static inline java_objectheader **builtin_get_exceptionptrptr()
384 {
385 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
386 #ifdef HAVE___THREAD
387     return &_exceptionptr;
388 #else
389     return &((nativethread*) pthread_getspecific(tkey_exceptionptr))->_exceptionptr;
390 #endif
391 #else
392     panic("builtin_get_exceptionptrptr should not be used in this configuration");
393     return NULL;
394 #endif
395 }
396
397 #endif /* _BUILTIN_H */
398
399
400 /*
401  * These are local overrides for various environment variables in Emacs.
402  * Please do not remove this and leave it at the end of the file, where
403  * Emacs will automagically detect them.
404  * ---------------------------------------------------------------------
405  * Local variables:
406  * mode: c
407  * indent-tabs-mode: t
408  * c-basic-offset: 4
409  * tab-width: 4
410  * End:
411  */