[generics.cs] enable more testcases for interpreter
[mono.git] / mono / mini / 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 #ifdef __GNUC__
9
10 #ifndef isunordered
11 #   define isunordered(u, v)                              \
12     (__extension__                                        \
13      ({ __typeof__(u) __u = (u); __typeof__(v) __v = (v); \
14         isnan(__u) || isnan(__v); }))
15 #endif
16
17 #ifndef islessgreater
18 #   define islessgreater(x, u)                                    \
19     (__extension__                                                \
20      ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y);         \
21         !isunordered (__x, __y) && (__x < __y) || (__y < __x); }))
22 #endif
23
24 #ifndef islessequal
25 #   define islessequal(x, y)                              \
26     (__extension__                                        \
27      ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
28         !isunordered(__x, __y) && __x <= __y; })) 
29 #endif
30
31 #ifndef isless
32 #   define isless(x, y)                                   \
33     (__extension__                                        \
34      ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
35         !isunordered(__x, __y) && __x < __y; })) 
36 #endif
37
38 #ifndef isgreater
39 #   define isgreater(x, y)                                \
40     (__extension__                                        \
41      ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); \
42         !isunordered(__x, __y) && __x > __y; }))
43 #endif
44
45 #else
46
47 /*  isunordered seems to crash on HPUX when built 64 bits
48     so use generic implementation.
49 */
50 #if defined(__hpux) && SIZEOF_VOID_P == 8
51 #undef isunordered
52 #undef islessgreater
53 #undef islessequal
54 #undef isless
55 #undef isgreater
56 #endif
57
58 #ifndef isunordered
59 #   define isunordered(u, v) (isnan(u) || isnan(v))
60 #endif
61
62 #ifndef islessgreater
63 #   define islessgreater(x, u) (!isunordered (x, y) && (x < y) || (y < x))
64 #endif
65
66 #ifndef islessequal
67 #   define islessequal(x, y) (!isunordered(x, y) && x <= y)
68 #endif
69
70 #ifndef isless
71 #   define isless(x, y) (!isunordered(x, y) && x < y) 
72 #endif
73
74 #ifndef isgreater
75 #   define isgreater(x, y) (!isunordered(x, y) && x > y)
76 #endif
77
78 #endif
79
80 /*
81  * Attempt at using the goto label construct of GNU GCC:
82  * it turns out this does give some benefit: 5-15% speedup.
83  * Don't look at these macros, it hurts...
84  */
85 #define GOTO_LABEL
86 #undef GOTO_LABEL
87 #ifdef GOTO_LABEL
88
89 #define SWITCH(a) goto *goto_map [(a)];
90 #define BREAK SWITCH(*ip)
91 #define CASE(l) l ## _LABEL:
92 #define DEFAULT \
93         CEE_ILLEGAL_LABEL:      \
94         CEE_ENDMAC_LABEL:
95 #define SUB_SWITCH \
96         CEE_PREFIX1_LABEL: \
97         CEE_ARGLIST_LABEL: \
98         CEE_CEQ_LABEL: \
99         CEE_CGT_LABEL: \
100         CEE_CGT_UN_LABEL: \
101         CEE_CLT_LABEL: \
102         CEE_CLT_UN_LABEL: \
103         CEE_LDFTN_LABEL: \
104         CEE_LDVIRTFTN_LABEL: \
105         CEE_UNUSED56_LABEL: \
106         CEE_LDARG_LABEL: \
107         CEE_LDARGA_LABEL: \
108         CEE_STARG_LABEL: \
109         CEE_LDLOC_LABEL: \
110         CEE_LDLOCA_LABEL: \
111         CEE_STLOC_LABEL: \
112         CEE_LOCALLOC_LABEL: \
113         CEE_UNUSED57_LABEL: \
114         CEE_ENDFILTER_LABEL: \
115         CEE_UNALIGNED__LABEL: \
116         CEE_VOLATILE__LABEL: \
117         CEE_TAIL__LABEL: \
118         CEE_INITOBJ_LABEL: \
119         CEE_UNUSED68_LABEL: \
120         CEE_CPBLK_LABEL: \
121         CEE_INITBLK_LABEL: \
122         CEE_UNUSED69_LABEL: \
123         CEE_RETHROW_LABEL: \
124         CEE_UNUSED_LABEL: \
125         CEE_SIZEOF_LABEL: \
126         CEE_REFANYTYPE_LABEL: \
127         CEE_UNUSED52_LABEL: \
128         CEE_UNUSED53_LABEL: \
129         CEE_UNUSED54_LABEL: \
130         CEE_UNUSED55_LABEL: \
131         CEE_UNUSED70_LABEL:
132 #define GOTO_LABEL_VARS \
133         const static void * const goto_map [] = {\
134 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \    \
135         && a ## _LABEL, \
136 #include "mono/cil/opcode.def"  \
137 #undef OPDEF    \
138         &&DUMMY_LABEL   \
139         };      \
140         DUMMY_LABEL:
141
142 #else
143         
144 #define SWITCH(a) switch(a)
145 #define BREAK   break
146 #define CASE(l) case l:
147 #define DEFAULT \
148                 default:        \
149                         g_error ("Unimplemented opcode: %x at 0x%x\n", *ip, ip-header->code);
150 #define SUB_SWITCH case 0xFE:
151 #define GOTO_LABEL_VARS
152
153 #endif