Debian Codegraph @

src/h/ecl-inl.h

raw symbols SCIP
1 /* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*- */
2 /* vim: set filetype=c tabstop=8 shiftwidth=4 expandtab: */
3
4
5 #ifndef ECL_ECL_INL_H
6 #define ECL_ECL_INL_H
7
8 #ifdef ECL_COMPLEX_FLOAT
9 /* We need this include for the constant I. */
10 #include <complex.h>
11 #endif
12
13 /*
14 * If minimum unnormalized floating point values defined in ISO C11
15 * are not declared, we use the normalized ones as the next best
16 * portable approximation.
17 */
18 #include <float.h>
19
20 #ifndef FLT_TRUE_MIN
21 # define FLT_TRUE_MIN FLT_MIN
22 #endif
23 #ifndef DBL_TRUE_MIN
24 # define DBL_TRUE_MIN DBL_MIN
25 #endif
26 #ifndef LDBL_TRUE_MIN
27 # define LDBL_TRUE_MIN LDBL_MIN
28 #endif
29
30 /*
31 * Loops over a proper list. Complains on circularity
32 */
33 #define loop_for_in_no_circle(list) { \
34 cl_object __slow; \
35 bool __flag = TRUE; \
36 for (__slow = list; !ecl_endp(list); list = ECL_CONS_CDR(list)) { \
37 if ((__flag = !__flag)) { \
38 if (__slow == list) FEcircular_list(list); \
39 __slow = ECL_CONS_CDR(__slow); \
40 }
41
42 /*
43 * Loops over a proper list
44 */
45 #define loop_for_in(list) { \
46 const cl_object __ecl_l0 = list; \
47 for (; list != ECL_NIL; list = ECL_CONS_CDR(list)) { \
48 if (ecl_unlikely(!ECL_LISTP(list))) FEtype_error_proper_list(__ecl_l0);
49
50 #define end_loop_for_in }}
51
52 /*
53 * Loops over a dotted list. Complains on circularity.
54 */
55 #define loop_for_on_no_circle(list) \
56 if (!CONSP(list)) { \
57 if (list != ECL_NIL) FEtype_error_list(list); \
58 }else { \
59 cl_object __slow; \
60 bool __flag = TRUE; \
61 for (__slow = list; CONSP(list); list = ECL_CONS_CDR(list)) { \
62 if ((__flag = !__flag)) { \
63 if (__slow == list) FEcircular_list(list); \
64 __slow = CDR(__slow); \
65 }
66
67 /*
68 * Loops over a list. Ignores errors.
69 */
70 #define loop_for_on_unsafe(list) \
71 for (; ECL_CONSP(list); list = ECL_CONS_CDR(list)) {
72 #define end_loop_for_on_unsafe(list) }
73
74 /*
75 * Loops over a dotted list
76 */
77 #define loop_for_on(list) \
78 if (Null(list)) { \
79 (void)0; \
80 } else if (ecl_unlikely(!ECL_LISTP(list))) { \
81 FEtype_error_list(list); \
82 } else do {
83 #define end_loop_for_on(list) } while (list = ECL_CONS_CDR(list), ECL_CONSP(list))
84
85 /*
86 * Loops over a vector.
87 */
88 #define loop_across_stack_fifo(var, obj) { \
89 cl_index __ecl_idx; \
90 cl_index __ecl_ndx = obj->vector.fillp; \
91 cl_object *__ecl_v = obj->vector.self.t; \
92 for(__ecl_idx = 0; __ecl_idx < __ecl_ndx; __ecl_idx++) { \
93 cl_object var = __ecl_v[__ecl_idx];
94
95
96 #define loop_across_stack_filo(var, obj) { \
97 cl_index __ecl_idx; \
98 cl_index __ecl_ndx = obj->vector.fillp; \
99 cl_object *__ecl_v = obj->vector.self.t; \
100 for(__ecl_idx = __ecl_ndx; __ecl_idx > 0; __ecl_idx--) { \
101 cl_object var = __ecl_v[__ecl_idx-1];
102
103 #define end_loop_across_stack() }}
104
105 /*
106 * Loops over a stack frame.
107 */
108
109 #define loop_across_frame_fifo(var, obj) { \
110 cl_object *__ecl_ptr = ECL_STACK_FRAME_PTR(obj); \
111 cl_object *__ecl_top = ECL_STACK_FRAME_TOP(obj); \
112 while(__ecl_ptr++ < __ecl_top) { \
113 cl_object var = *(__ecl_ptr-1); \
114
115 #define loop_across_frame_filo(var, obj) { \
116 cl_object *__ecl_ptr = ECL_STACK_FRAME_PTR(obj); \
117 cl_object *__ecl_top = ECL_STACK_FRAME_TOP(obj); \
118 while(__ecl_ptr < __ecl_top--) { \
119 cl_object var = *__ecl_top;
120
121 #define end_loop_across_frame() }}
122
123 /*
124 * Static constant definition.
125 */
126 #ifdef __cplusplus
127 #define ecl_cast_ptr(type,n) reinterpret_cast<type>((void*)n)
128 #else
129 #define ecl_cast_ptr(type,n) ((type)(n))
130 #endif
131
132 #define ecl_def_string_array(name,static,const) \
133 static const union { \
134 struct ecl_base_string elt; \
135 cl_fixnum padding[(sizeof(struct ecl_base_string)+3)/4*4]; \
136 } name[]
137
138 #define ecl_def_string_array_elt(chars) { { \
139 (int8_t)t_base_string, 0, ecl_aet_bc, 0, \
140 ECL_NIL, (cl_index)(sizeof(chars))-1, \
141 (cl_index)(sizeof(chars))-1, \
142 (ecl_base_char*)(chars) } }
143
144 #define ecl_def_ct_base_string(name,chars,len,static,const) \
145 static const struct ecl_base_string name ## _data = { \
146 (int8_t)t_base_string, 0, ecl_aet_bc, 0, \
147 ECL_NIL, (cl_index)(len), (cl_index)(len), \
148 (ecl_base_char*)(chars) }; \
149 static const cl_object name = (cl_object)(& name ## _data)
150
151 #define ecl_def_ct_single_float(name,f,static,const) \
152 static const struct ecl_singlefloat name ## _data = { \
153 (int8_t)t_singlefloat, 0, 0, 0, \
154 (float)(f) }; \
155 static const cl_object name = (cl_object)(& name ## _data)
156
157 #define ecl_def_ct_double_float(name,f,static,const) \
158 static const struct ecl_doublefloat name ## _data = { \
159 (int8_t)t_doublefloat, 0, 0, 0, \
160 (double)(f) }; \
161 static const cl_object name = (cl_object)(& name ## _data)
162
163 #define ecl_def_ct_long_float(name,f,static,const) \
164 static const struct ecl_long_float name ## _data = { \
165 (int8_t)t_longfloat, 0, 0, 0, \
166 (long double)(f) }; \
167 static const cl_object name = (cl_object)(& name ## _data)
168
169 #define ecl_def_ct_ratio(name,num,den,static,const) \
170 static const struct ecl_ratio name ## _data = { \
171 (int8_t)t_ratio, 0, 0, 0, \
172 den, num }; \
173 static const cl_object name = (cl_object)(& name ## _data)
174
175 #define ecl_def_ct_complex(name,real,imag,static,const) \
176 static const struct ecl_complex name ## _data = { \
177 (int8_t)t_complex, 0, 0, 0, \
178 (cl_object)real, (cl_object)imag }; \
179 static const cl_object name = (cl_object)(& name ## _data)
180
181 #ifdef ECL_COMPLEX_FLOAT
182 #define ecl_def_ct_csfloat(name,f,static,const) \
183 static const struct ecl_csfloat name ## _data = { \
184 (int8_t)t_csfloat, 0, 0, 0, \
185 (float _Complex)(f) }; \
186 static const cl_object name = (cl_object)(& name ## _data)
187
188 #define ecl_def_ct_cdfloat(name,f,static,const) \
189 static const struct ecl_cdfloat name ## _data = { \
190 (int8_t)t_cdfloat, 0, 0, 0, \
191 (double _Complex)(f) }; \
192 static const cl_object name = (cl_object)(& name ## _data)
193
194 #define ecl_def_ct_clfloat(name,f,static,const) \
195 static const struct ecl_clfloat name ## _data = { \
196 (int8_t)t_clfloat, 0, 0, 0, \
197 (long double _Complex)(f) }; \
198 static const cl_object name = (cl_object)(& name ## _data)
199 #endif
200
201 #define ecl_def_ct_vector(name,type,raw,len,static,const) \
202 static const struct ecl_vector name ## _data = { \
203 (int8_t)t_vector, 0, (type), 0, \
204 ECL_NIL, (cl_index)(len), (cl_index)(len), \
205 ecl_cast_ptr(cl_object*,raw), 0 }; \
206 static const cl_object name = (cl_object)(& name ## _data)
207
208 #ifdef ECL_SSE2
209
210 /*
211 * Static SSE constant.
212 */
213
214 #define ecl_def_ct_sse_pack(name,type,v0,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15) \
215 static const struct ecl_sse_pack name ## _data = { \
216 (int8_t)t_sse_pack, 0, (type), 0, \
217 {{v0,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15}} \
218 }; \
219 static const cl_object name = (cl_object)(& name ## _data)
220
221 /*
222 * Missing SSE intrinsics
223 */
224
225 #if (defined(__INTEL_COMPILER) ? __INTEL_COMPILER < 810 : defined(_MSC_VER) && (_MSC_VER < 1500))
226
227 __forceinline __m128i _mm_castps_si128(__m128 a) { union { __m128 f; __m128i i;} c; c.f = a; return c.i; }
228 __forceinline __m128 _mm_castsi128_ps(__m128i a) { union { __m128 f; __m128i i;} c; c.i = a; return c.f; }
229 __forceinline __m128i _mm_castpd_si128(__m128d a) { union { __m128d d; __m128i i;} c; c.d = a; return c.i; }
230 __forceinline __m128d _mm_castsi128_pd(__m128i a) { union { __m128d d; __m128i i;} c; c.i = a; return c.d; }
231 __forceinline __m128d _mm_castps_pd(__m128 a) { union { __m128d d; __m128 f;} c; c.f = a; return c.d; }
232 __forceinline __m128 _mm_castpd_ps(__m128d a) { union { __m128d d; __m128 f;} c; c.d = a; return c.f; }
233
234 #elif defined(__GNUC__) && (__GNUC__ < 4) && !defined(__INTEL_COMPILER)
235
236 // Copied from GCC 4 headers:
237 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
238 _mm_castpd_ps(__m128d __A) { return (__m128) __A; }
239
240 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
241 _mm_castpd_si128(__m128d __A) { return (__m128i) __A; }
242
243 extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
244 _mm_castps_pd(__m128 __A) { return (__m128d) __A; }
245
246 extern __inline __m128i __attribute__((__gnu_inline__, __always_inline__, __artificial__))
247 _mm_castps_si128(__m128 __A) { return (__m128i) __A; }
248
249 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__, __artificial__))
250 _mm_castsi128_ps(__m128i __A) { return (__m128) __A; }
251
252 extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__, __artificial__))
253 _mm_castsi128_pd(__m128i __A) { return (__m128d) __A; }
254
255 #endif
256
257 #endif /* ECL_SSE2 */
258
259 #endif /* !ECL_ECL_INL_H */