Tue Feb 12 14:08:47 CET 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / interpreter / hacks.h
1 /* we need some special math function */
2 #ifndef _ISOC99_SOURCE
3 #define _ISOC99_SOURCE
4 #endif
5 #include <math.h>
6
7 /* which are not defined on FreeBSD */
8 #ifndef isunordered
9 #   define isunordered(u, v)                              \
10     (__extension__                                        \
11      ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \
12         isnan(__u) || isnan(__v); }))
13 #endif
14
15 #ifndef islessgreater
16 #   define islessgreater(x, u)                                    \
17     (__extension__                                                \
18      ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);         \
19         !isunordered (__x, __y) && (__x < __y) || (__y < __x); }))
20 #endif
21
22 #ifndef islessequal
23 #   define islessequal(x, y)                              \
24     (__extension__                                        \
25      ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
26         !isunordered(__x, __y) && __x <= __y; })) 
27 #endif
28
29 #ifndef isless
30 #   define isless(x, y)                                   \
31     (__extension__                                        \
32      ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
33         !isunordered(__x, __y) && __x < __y; })) 
34 #endif
35
36 #ifndef isgreater
37 #   define isgreater(x, y)                                \
38     (__extension__                                        \
39      ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
40         !isunordered(__x, __y) && __x > __y; }))
41 #endif
42
43 /*
44  * Attempt at using the goto label construct of GNU GCC:
45  * it turns out this does give some benefit: 5-15% speedup.
46  * Don't look at these macros, it hurts...
47  */
48 #define GOTO_LABEL
49 #undef GOTO_LABEL
50 #ifdef GOTO_LABEL
51
52 #define SWITCH(a) goto *goto_map [(a)];
53 #define BREAK SWITCH(*ip)
54 #define CASE(l) l ## _LABEL:
55 #define DEFAULT \
56         CEE_ILLEGAL_LABEL:      \
57         CEE_ENDMAC_LABEL:
58 #define SUB_SWITCH \
59         CEE_PREFIX1_LABEL: \
60         CEE_ARGLIST_LABEL: \
61         CEE_CEQ_LABEL: \
62         CEE_CGT_LABEL: \
63         CEE_CGT_UN_LABEL: \
64         CEE_CLT_LABEL: \
65         CEE_CLT_UN_LABEL: \
66         CEE_LDFTN_LABEL: \
67         CEE_LDVIRTFTN_LABEL: \
68         CEE_UNUSED56_LABEL: \
69         CEE_LDARG_LABEL: \
70         CEE_LDARGA_LABEL: \
71         CEE_STARG_LABEL: \
72         CEE_LDLOC_LABEL: \
73         CEE_LDLOCA_LABEL: \
74         CEE_STLOC_LABEL: \
75         CEE_LOCALLOC_LABEL: \
76         CEE_UNUSED57_LABEL: \
77         CEE_ENDFILTER_LABEL: \
78         CEE_UNALIGNED__LABEL: \
79         CEE_VOLATILE__LABEL: \
80         CEE_TAIL__LABEL: \
81         CEE_INITOBJ_LABEL: \
82         CEE_UNUSED68_LABEL: \
83         CEE_CPBLK_LABEL: \
84         CEE_INITBLK_LABEL: \
85         CEE_UNUSED69_LABEL: \
86         CEE_RETHROW_LABEL: \
87         CEE_UNUSED_LABEL: \
88         CEE_SIZEOF_LABEL: \
89         CEE_REFANYTYPE_LABEL: \
90         CEE_UNUSED52_LABEL: \
91         CEE_UNUSED53_LABEL: \
92         CEE_UNUSED54_LABEL: \
93         CEE_UNUSED55_LABEL: \
94         CEE_UNUSED70_LABEL:
95 #define GOTO_LABEL_VARS \
96         const static void * const goto_map [] = {\
97 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \    \
98         && a ## _LABEL, \
99 #include "mono/cil/opcode.def"  \
100 #undef OPDEF    \
101         &&DUMMY_LABEL   \
102         };      \
103         DUMMY_LABEL:
104
105 #else
106         
107 #define SWITCH(a) switch(a)
108 #define BREAK   break
109 #define CASE(l) case l:
110 #define DEFAULT \
111                 default:        \
112                         g_error ("Unimplemented opcode: %x at 0x%x\n", *ip, ip-header->code);
113 #define SUB_SWITCH case 0xFE:
114 #define GOTO_LABEL_VARS
115
116 #endif