1 | |
---|
2 | |
---|
3 | |
---|
4 | #include <orc/orc.h> |
---|
5 | #include <orc-test/orctest.h> |
---|
6 | #include <stdio.h> |
---|
7 | #include <string.h> |
---|
8 | #include <stdlib.h> |
---|
9 | #include <math.h> |
---|
10 | #include <stdint.h> |
---|
11 | |
---|
12 | #ifndef _ORC_INTEGER_TYPEDEFS_ |
---|
13 | #define _ORC_INTEGER_TYPEDEFS_ |
---|
14 | #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L |
---|
15 | #include <stdint.h> |
---|
16 | typedef int8_t orc_int8; |
---|
17 | typedef int16_t orc_int16; |
---|
18 | typedef int32_t orc_int32; |
---|
19 | typedef int64_t orc_int64; |
---|
20 | typedef uint8_t orc_uint8; |
---|
21 | typedef uint16_t orc_uint16; |
---|
22 | typedef uint32_t orc_uint32; |
---|
23 | typedef uint64_t orc_uint64; |
---|
24 | #define ORC_UINT64_C(x) UINT64_C(x) |
---|
25 | #elif defined(_MSC_VER) |
---|
26 | typedef signed __int8 orc_int8; |
---|
27 | typedef signed __int16 orc_int16; |
---|
28 | typedef signed __int32 orc_int32; |
---|
29 | typedef signed __int64 orc_int64; |
---|
30 | typedef unsigned __int8 orc_uint8; |
---|
31 | typedef unsigned __int16 orc_uint16; |
---|
32 | typedef unsigned __int32 orc_uint32; |
---|
33 | typedef unsigned __int64 orc_uint64; |
---|
34 | #define ORC_UINT64_C(x) (x##Ui64) |
---|
35 | #else |
---|
36 | #include <limits.h> |
---|
37 | typedef signed char orc_int8; |
---|
38 | typedef short orc_int16; |
---|
39 | typedef int orc_int32; |
---|
40 | typedef unsigned char orc_uint8; |
---|
41 | typedef unsigned short orc_uint16; |
---|
42 | typedef unsigned int orc_uint32; |
---|
43 | #if INT_MAX == LONG_MAX |
---|
44 | typedef long long orc_int64; |
---|
45 | typedef unsigned long long orc_uint64; |
---|
46 | #define ORC_UINT64_C(x) (x##ULL) |
---|
47 | #else |
---|
48 | typedef long orc_int64; |
---|
49 | typedef unsigned long orc_uint64; |
---|
50 | #define ORC_UINT64_C(x) (x##UL) |
---|
51 | #endif |
---|
52 | #endif |
---|
53 | typedef union { orc_int16 i; orc_int8 x2[2]; } orc_union16; |
---|
54 | typedef union { orc_int32 i; float f; orc_int16 x2[2]; orc_int8 x4[4]; } orc_union32; |
---|
55 | typedef union { orc_int64 i; double f; orc_int32 x2[2]; float x2f[2]; orc_int16 x4[4]; } orc_union64; |
---|
56 | #endif |
---|
57 | |
---|
58 | |
---|
59 | #define ORC_CLAMP(x,a,b) ((x)<(a) ? (a) : ((x)>(b) ? (b) : (x))) |
---|
60 | #define ORC_ABS(a) ((a)<0 ? -(a) : (a)) |
---|
61 | #define ORC_MIN(a,b) ((a)<(b) ? (a) : (b)) |
---|
62 | #define ORC_MAX(a,b) ((a)>(b) ? (a) : (b)) |
---|
63 | #define ORC_SB_MAX 127 |
---|
64 | #define ORC_SB_MIN (-1-ORC_SB_MAX) |
---|
65 | #define ORC_UB_MAX 255 |
---|
66 | #define ORC_UB_MIN 0 |
---|
67 | #define ORC_SW_MAX 32767 |
---|
68 | #define ORC_SW_MIN (-1-ORC_SW_MAX) |
---|
69 | #define ORC_UW_MAX 65535 |
---|
70 | #define ORC_UW_MIN 0 |
---|
71 | #define ORC_SL_MAX 2147483647 |
---|
72 | #define ORC_SL_MIN (-1-ORC_SL_MAX) |
---|
73 | #define ORC_UL_MAX 4294967295U |
---|
74 | #define ORC_UL_MIN 0 |
---|
75 | #define ORC_CLAMP_SB(x) ORC_CLAMP(x,ORC_SB_MIN,ORC_SB_MAX) |
---|
76 | #define ORC_CLAMP_UB(x) ORC_CLAMP(x,ORC_UB_MIN,ORC_UB_MAX) |
---|
77 | #define ORC_CLAMP_SW(x) ORC_CLAMP(x,ORC_SW_MIN,ORC_SW_MAX) |
---|
78 | #define ORC_CLAMP_UW(x) ORC_CLAMP(x,ORC_UW_MIN,ORC_UW_MAX) |
---|
79 | #define ORC_CLAMP_SL(x) ORC_CLAMP(x,ORC_SL_MIN,ORC_SL_MAX) |
---|
80 | #define ORC_CLAMP_UL(x) ORC_CLAMP(x,ORC_UL_MIN,ORC_UL_MAX) |
---|
81 | #define ORC_SWAP_W(x) ((((x)&0xff)<<8) | (((x)&0xff00)>>8)) |
---|
82 | #define ORC_SWAP_L(x) ((((x)&0xff)<<24) | (((x)&0xff00)<<8) | (((x)&0xff0000)>>8) | (((x)&0xff000000)>>24)) |
---|
83 | #define ORC_SWAP_Q(x) ((((x)&ORC_UINT64_C(0xff))<<56) | (((x)&ORC_UINT64_C(0xff00))<<40) | (((x)&ORC_UINT64_C(0xff0000))<<24) | (((x)&ORC_UINT64_C(0xff000000))<<8) | (((x)&ORC_UINT64_C(0xff00000000))>>8) | (((x)&ORC_UINT64_C(0xff0000000000))>>24) | (((x)&ORC_UINT64_C(0xff000000000000))>>40) | (((x)&ORC_UINT64_C(0xff00000000000000))>>56)) |
---|
84 | #define ORC_PTR_OFFSET(ptr,offset) ((void *)(((unsigned char *)(ptr)) + (offset))) |
---|
85 | #define ORC_DENORMAL(x) ((x) & ((((x)&0x7f800000) == 0) ? 0xff800000 : 0xffffffff)) |
---|
86 | #define ORC_ISNAN(x) ((((x)&0x7f800000) == 0x7f800000) && (((x)&0x007fffff) != 0)) |
---|
87 | #define ORC_DENORMAL_DOUBLE(x) ((x) & ((((x)&ORC_UINT64_C(0x7ff0000000000000)) == 0) ? ORC_UINT64_C(0xfff0000000000000) : ORC_UINT64_C(0xffffffffffffffff))) |
---|
88 | #define ORC_ISNAN_DOUBLE(x) ((((x)&ORC_UINT64_C(0x7ff0000000000000)) == ORC_UINT64_C(0x7ff0000000000000)) && (((x)&ORC_UINT64_C(0x000fffffffffffff)) != 0)) |
---|
89 | #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L |
---|
90 | #define ORC_RESTRICT restrict |
---|
91 | #elif defined(__GNUC__) && __GNUC__ >= 4 |
---|
92 | #define ORC_RESTRICT __restrict__ |
---|
93 | #else |
---|
94 | #define ORC_RESTRICT |
---|
95 | #endif |
---|
96 | |
---|
97 | |
---|
98 | |
---|
99 | static void |
---|
100 | _backup_convert_fc32_to_int32 (OrcExecutor * ORC_RESTRICT ex) |
---|
101 | { |
---|
102 | int i; |
---|
103 | int n = ex->n; |
---|
104 | orc_union32 * ORC_RESTRICT ptr0; |
---|
105 | const orc_union64 * ORC_RESTRICT ptr4; |
---|
106 | orc_union64 var34; |
---|
107 | orc_union64 var35; |
---|
108 | orc_union32 var36; |
---|
109 | orc_union64 var37; |
---|
110 | orc_union64 var38; |
---|
111 | |
---|
112 | ptr0 = (orc_union32 *)ex->arrays[0]; |
---|
113 | ptr4 = (orc_union64 *)ex->arrays[4]; |
---|
114 | |
---|
115 | |
---|
116 | var35.x2[0] = 0x46fffe00; |
---|
117 | var35.x2[1] = 0x46fffe00; |
---|
118 | |
---|
119 | for (i = 0; i < n; i++) { |
---|
120 | |
---|
121 | var34 = ptr4[i]; |
---|
122 | |
---|
123 | /** |
---|
124 | * This block of code causes the compiler to error out when |
---|
125 | * run with -O2 flag. |
---|
126 | */ |
---|
127 | { |
---|
128 | orc_union32 _src1; |
---|
129 | orc_union32 _src2; |
---|
130 | orc_union32 _dest1; |
---|
131 | _src1.i = ORC_DENORMAL(var34.x2[0]); |
---|
132 | _src2.i = ORC_DENORMAL(var35.x2[0]); |
---|
133 | _dest1.f = _src1.f * _src2.f; |
---|
134 | var37.x2[0] = ORC_DENORMAL(_dest1.i); |
---|
135 | } |
---|
136 | { |
---|
137 | orc_union32 _src1; |
---|
138 | orc_union32 _src2; |
---|
139 | orc_union32 _dest1; |
---|
140 | _src1.i = ORC_DENORMAL(var34.x2[1]); |
---|
141 | _src2.i = ORC_DENORMAL(var35.x2[1]); |
---|
142 | _dest1.f = _src1.f * _src2.f; |
---|
143 | var37.x2[1] = ORC_DENORMAL(_dest1.i); |
---|
144 | } |
---|
145 | { |
---|
146 | int tmp; |
---|
147 | tmp = (int)var37.x2f[0]; |
---|
148 | if (tmp == 0x80000000 && !(var37.x2[0]&0x80000000)) tmp = 0x7fffffff; |
---|
149 | var38.x2[0] = tmp; |
---|
150 | } |
---|
151 | { |
---|
152 | int tmp; |
---|
153 | tmp = (int)var37.x2f[1]; |
---|
154 | if (tmp == 0x80000000 && !(var37.x2[1]&0x80000000)) tmp = 0x7fffffff; |
---|
155 | var38.x2[1] = tmp; |
---|
156 | } |
---|
157 | /** |
---|
158 | * End block |
---|
159 | */ |
---|
160 | |
---|
161 | var36.x2[0] = var38.x2[0]; |
---|
162 | var36.x2[1] = var38.x2[1]; |
---|
163 | |
---|
164 | ptr0[i] = var36; |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | |
---|
169 | int |
---|
170 | main (int argc, char *argv[]) |
---|
171 | { |
---|
172 | void* p; |
---|
173 | |
---|
174 | orc_program_set_backup_function (p, _backup_convert_fc32_to_int32); |
---|
175 | return 0; |
---|
176 | } |
---|
177 | |
---|