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