2003-07-21 Andreas Nahr <ClassDevelopment@A-SoftTech.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 #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 #ifndef isunordered
48 #   define isunordered(u, v) (isnan(u) || isnan(v))
49 #endif
50
51 #ifndef islessgreater
52 #   define islessgreater(x, u) (!isunordered (x, y) && (x < y) || (y < x))
53 #endif
54
55 #ifndef islessequal
56 #   define islessequal(x, y) (!isunordered(x, y) && x <= y)
57 #endif
58
59 #ifndef isless
60 #   define isless(x, y) (!isunordered(x, y) && x < y) 
61 #endif
62
63 #ifndef isgreater
64 #   define isgreater(x, y) (!isunordered(x, y) && x > y)
65 #endif
66
67 #endif
68
69 /*
70  * Attempt at using the goto label construct of GNU GCC:
71  * it turns out this does give some benefit: 5-15% speedup.
72  * Don't look at these macros, it hurts...
73  */
74 #define GOTO_LABEL
75 #undef GOTO_LABEL
76 #ifdef GOTO_LABEL
77
78 #define SWITCH(a) goto *goto_map [(a)];
79 #define BREAK SWITCH(*ip)
80 #define CASE(l) l ## _LABEL:
81 #define DEFAULT \
82         CEE_ILLEGAL_LABEL:      \
83         CEE_ENDMAC_LABEL:
84 #define SUB_SWITCH \
85         CEE_PREFIX1_LABEL: \
86         CEE_ARGLIST_LABEL: \
87         CEE_CEQ_LABEL: \
88         CEE_CGT_LABEL: \
89         CEE_CGT_UN_LABEL: \
90         CEE_CLT_LABEL: \
91         CEE_CLT_UN_LABEL: \
92         CEE_LDFTN_LABEL: \
93         CEE_LDVIRTFTN_LABEL: \
94         CEE_UNUSED56_LABEL: \
95         CEE_LDARG_LABEL: \
96         CEE_LDARGA_LABEL: \
97         CEE_STARG_LABEL: \
98         CEE_LDLOC_LABEL: \
99         CEE_LDLOCA_LABEL: \
100         CEE_STLOC_LABEL: \
101         CEE_LOCALLOC_LABEL: \
102         CEE_UNUSED57_LABEL: \
103         CEE_ENDFILTER_LABEL: \
104         CEE_UNALIGNED__LABEL: \
105         CEE_VOLATILE__LABEL: \
106         CEE_TAIL__LABEL: \
107         CEE_INITOBJ_LABEL: \
108         CEE_UNUSED68_LABEL: \
109         CEE_CPBLK_LABEL: \
110         CEE_INITBLK_LABEL: \
111         CEE_UNUSED69_LABEL: \
112         CEE_RETHROW_LABEL: \
113         CEE_UNUSED_LABEL: \
114         CEE_SIZEOF_LABEL: \
115         CEE_REFANYTYPE_LABEL: \
116         CEE_UNUSED52_LABEL: \
117         CEE_UNUSED53_LABEL: \
118         CEE_UNUSED54_LABEL: \
119         CEE_UNUSED55_LABEL: \
120         CEE_UNUSED70_LABEL:
121 #define GOTO_LABEL_VARS \
122         const static void * const goto_map [] = {\
123 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \    \
124         && a ## _LABEL, \
125 #include "mono/cil/opcode.def"  \
126 #undef OPDEF    \
127         &&DUMMY_LABEL   \
128         };      \
129         DUMMY_LABEL:
130
131 #else
132         
133 #define SWITCH(a) switch(a)
134 #define BREAK   break
135 #define CASE(l) case l:
136 #define DEFAULT \
137                 default:        \
138                         g_error ("Unimplemented opcode: %x at 0x%x\n", *ip, ip-header->code);
139 #define SUB_SWITCH case 0xFE:
140 #define GOTO_LABEL_VARS
141
142 #endif