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