ssa: move optimizations from P_BinaryOp to P_BinaryConstOp
[ajla.git] / options.h
blobc6954af006e3d0afccf1a2d3dadbec4b69029ac7
1 /*
2 * Copyright (C) 2024 Mikulas Patocka
4 * This file is part of Ajla.
6 * Ajla is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
9 * version.
11 * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * Ajla. If not, see <https://www.gnu.org/licenses/>.
19 #define MINIMUM_STACK_SIZE 0x100000
22 #ifndef UNUSUAL_DISABLE_INT128_T
23 #if defined(SIZEOF_UNSIGNED___INT128) && SIZEOF_UNSIGNED___INT128 == 16
24 #define TYPE_FIXED_N 5
25 typedef signed __int128 int128_t;
26 typedef unsigned __int128 uint128_t;
27 #endif
28 #endif
30 #ifndef TYPE_FIXED_N
31 #define TYPE_FIXED_N 4
32 #endif
35 #define TYPE_INT_N TYPE_FIXED_N
36 #define INT_MASK ((1 << TYPE_INT_N) - 1)
37 #if INT_MASK & 0x10
38 #define TYPE_INT_MAX int128_t
39 #elif INT_MASK & 0x8
40 #define TYPE_INT_MAX int64_t
41 #elif INT_MASK & 0x4
42 #define TYPE_INT_MAX int32_t
43 #elif INT_MASK & 0x2
44 #define TYPE_INT_MAX int16_t
45 #elif INT_MASK & 0x1
46 #define TYPE_INT_MAX int8_t
47 #endif
50 #define ajla_time_t int64_t
51 #define ajla_utime_t uint64_t
54 #if (defined(HAVE_GMP_H) || defined(HAVE_GMP_GMP_H)) && defined(HAVE_LIBGMP)
55 #define MPINT_GMP
56 #endif
59 #ifdef __MINGW32__
60 #undef HAVE_ISNANF
61 #undef HAVE_ISNANL
62 #endif
64 #if !defined(HAVE_FABSF)
65 #define fabsf fabs
66 #endif
67 #if !defined(HAVE_SQRTF)
68 #define sqrtf sqrt
69 #endif
71 #if !defined(HAVE_SINF)
72 #define sinf sin
73 #endif
74 #if !defined(HAVE_COSF)
75 #define cosf cos
76 #endif
77 #if !defined(HAVE_TANF)
78 #define tanf tan
79 #endif
80 #if !defined(HAVE_ASINF)
81 #define asinf asin
82 #endif
83 #if !defined(HAVE_ACOSF)
84 #define acosf acos
85 #endif
86 #if !defined(HAVE_ATANF)
87 #define atanf atan
88 #endif
90 #if !defined(HAVE_SINHF)
91 #define sinhf sinh
92 #endif
93 #if !defined(HAVE_COSHF)
94 #define coshf cosh
95 #endif
96 #if !defined(HAVE_TANHF)
97 #define tanhf tanh
98 #endif
99 #if !defined(HAVE_ASINHF)
100 #define asinhf asinh
101 #endif
102 #if !defined(HAVE_ACOSHF)
103 #define acoshf acosh
104 #endif
105 #if !defined(HAVE_ATANHF)
106 #define atanhf atanh
107 #endif
109 #if !defined(HAVE_EXPF)
110 #define expf exp
111 #endif
112 #if !defined(HAVE_LOGF)
113 #define logf log
114 #endif
115 #if !defined(HAVE_LOG10F)
116 #define log10f log10
117 #endif
119 #if !defined(HAVE_CEILF)
120 #define ceilf ceil
121 #endif
122 #if !defined(HAVE_FLOORF)
123 #define floorf floor
124 #endif
125 #if !defined(HAVE_FMODF)
126 #define fmodf fmod
127 #endif
128 #if !defined(HAVE_FREXPF)
129 #define frexpf frexp
130 #endif
132 #if !defined(HAVE_ATAN2F)
133 #define atan2f atan2
134 #endif
135 #if !defined(HAVE_POWF)
136 #define powf pow
137 #endif
138 #if !defined(HAVE_LDEXPF)
139 #define ldexpf ldexp
140 #endif
142 float half_to_float(uint16_t x);
143 uint16_t float_to_half(float x);
145 #if FLT_RADIX == 2 && (defined(HAVE___FP16) || defined(HAVE__FLOAT16)) && \
146 !(defined(__ARM_FP) && !defined(__ARM_FP16_FORMAT_IEEE)) && \
147 !(defined(ARCH_ARM32) && CLANG_ATLEAST(5,0,0)) /* clang 5, 6, 7 fail fp16 bist */
148 #define TEST_HALF_FLOAT_CONVERSION
149 #if (defined(__ARM_FP) && __ARM_FP & 2) || defined(__F16C__)
150 #define HAVE_NATIVE_FP16
151 #ifdef HAVE___FP16
152 typedef __fp16 real16_t;
153 #else
154 typedef _Float16 real16_t;
155 #endif
156 #define mathfunc_real16_t(fn) cat(fn,f)
157 #define bits_real16_t 11
158 #define isfinite_real16_t(x) isfinite_real32_t(x)
159 #define isnan_real16_t(x) isnan_real32_t(x)
160 #define REAL_MASK_0 (1 << 0)
161 #endif
162 #endif
164 #if FLT_RADIX == 2
165 typedef float real32_t;
166 #define mathfunc_real32_t(fn) cat(fn,f)
167 #define bits_real32_t FLT_MANT_DIG
168 #if defined(HAVE_ISFINITEF)
169 #define isfinite_real32_t(x) isfinitef(x)
170 #endif
171 #if defined(HAVE_ISNANF)
172 #define isnan_real32_t(x) isnanf(x)
173 #elif defined(isnan)
174 #define isnan_real32_t(x) isnan(x)
175 #endif
176 #define REAL_MASK_1 (1 << 1)
177 #endif
179 #if FLT_RADIX == 2
180 typedef double real64_t;
181 #define mathfunc_real64_t(fn) fn
182 #define bits_real64_t DBL_MANT_DIG
183 #if defined(HAVE_ISFINITE)
184 #define isfinite_real64_t(x) isfinite(x)
185 #endif
186 #if defined(HAVE_ISNAN) || defined(isnan)
187 #define isnan_real64_t(x) isnan(x)
188 #endif
189 #define REAL_MASK_2 (1 << 2)
190 #endif
192 #if !defined(HAVE_FABSL) || !defined(HAVE_FREXPL) || !defined(HAVE_LDEXPL) || !defined(HAVE_POWL) || !defined(HAVE_SQRTL) || !defined(HAVE_RINTL) || !defined(HAVE_MODFL)
193 #ifdef HAVE_LONG_DOUBLE
194 #undef HAVE_LONG_DOUBLE
195 #endif
196 #endif
198 #if FLT_RADIX == 2 && defined(HAVE_LONG_DOUBLE) && \
199 (defined(LDBL_MIN_EXP) && LDBL_MIN_EXP <= -16381 && defined(LDBL_MAX_EXP) && LDBL_MAX_EXP >= 16384 && defined(LDBL_MANT_DIG) && LDBL_MANT_DIG >= 64) && \
200 !(defined(LDBL_MIN_EXP) && LDBL_MIN_EXP <= -16381 && defined(LDBL_MAX_EXP) && LDBL_MAX_EXP >= 16384 && defined(LDBL_MANT_DIG) && LDBL_MANT_DIG >= 113)
201 typedef long double real80_t;
202 #define mathfunc_real80_t(fn) cat(fn,l)
203 #define bits_real80_t LDBL_MANT_DIG
204 #if defined(HAVE_ISFINITEL)
205 #define isfinite_real80_t(x) isfinitel(x)
206 #endif
207 #if defined(HAVE_ISNANL) && !defined(__HAIKU__)
208 #define isnan_real80_t(x) isnanl(x)
209 #endif
210 #define REAL_MASK_3 (1 << 3)
211 #endif
213 #if defined(HAVE___FLOAT128) && \
214 defined(FLT128_MIN_EXP) && FLT128_MIN_EXP <= -16381 && defined(FLT128_MAX_EXP) && FLT128_MAX_EXP >= 16384 && defined(FLT128_MANT_DIG) && FLT128_MANT_DIG >= 113 && \
215 defined(HAVE_FABSQ) && defined(HAVE_FREXPQ) && defined(HAVE_LDEXPQ) && defined(HAVE_POWQ) && defined(HAVE_SQRTQ)
216 #define USEABLE___FLOAT128
217 #endif
219 #if FLT_RADIX == 2 && defined(HAVE_LONG_DOUBLE) && \
220 defined(LDBL_MIN_EXP) && LDBL_MIN_EXP <= -16381 && defined(LDBL_MAX_EXP) && LDBL_MAX_EXP >= 16384 && defined(LDBL_MANT_DIG) && LDBL_MANT_DIG >= 113 && \
221 !(!defined(HAVE_ISNANL) && defined(HAVE_ISNANQ) && defined(USEABLE___FLOAT128))
222 typedef long double real128_t;
223 #define mathfunc_real128_t(fn) cat(fn,l)
224 #define bits_real128_t LDBL_MANT_DIG
225 #if defined(HAVE_ISFINITEL)
226 #define isfinite_real128_t(x) isfinitel(x)
227 #endif
228 #if defined(HAVE_ISNANL)
229 #define isnan_real128_t(x) isnanl(x)
230 #endif
231 #define REAL_MASK_4 (1 << 4)
232 #elif FLT_RADIX == 2 && defined(USEABLE___FLOAT128)
233 #define HAVE_NATIVE_FLOAT128
234 typedef __float128 real128_t;
235 #define mathfunc_real128_t(fn) cat(fn,q)
236 #define bits_real128_t 113
237 #if defined(HAVE_ISFINITEQ)
238 #define isfinite_real128_t(x) isfiniteq(x)
239 #endif
240 #if defined(HAVE_ISNANQ)
241 #define isnan_real128_t(x) isnanq(x)
242 #endif
243 #define REAL_MASK_4 (1 << 4)
244 #endif
246 #if !defined(REAL_MASK_0) && defined(REAL_MASK_1)
247 #define HALF_FLOAT_CONVERSION
248 #ifdef DEBUG
249 typedef struct {
250 uint16_t val;
251 } real16_t;
252 #define native_real16_t real32_t
253 static inline native_real16_t unpack_real16_t(real16_t x)
255 return half_to_float(x.val);
257 static inline real16_t pack_real16_t(native_real16_t x)
259 real16_t v;
260 v.val = float_to_half(x);
261 return v;
263 #define mathfunc_real16_t(fn) cat(fn,f)
264 #define bits_real16_t 11
265 #define isfinite_real16_t(x) (((x).val & 0x7fff) < 0x7c00)
266 #define isnan_real16_t(x) (((x).val & 0x7fff) > 0x7c00)
267 #else
268 #define REAL16_T_IS_UINT16_T 1
269 typedef uint16_t real16_t;
270 #define native_real16_t real32_t
271 #define unpack_real16_t(x) (half_to_float(x))
272 #define pack_real16_t(x) (float_to_half(x))
273 #define mathfunc_real16_t(fn) cat(fn,f)
274 #define bits_real16_t 11
275 #define isfinite_real16_t(x) (((x) & 0x7fff) < 0x7c00)
276 #define isnan_real16_t(x) (((x) & 0x7fff) > 0x7c00)
277 #endif
278 #define REAL_MASK_0 (1 << 0)
279 #endif
281 #ifndef REAL16_T_IS_UINT16_T
282 #define REAL16_T_IS_UINT16_T 0
283 #endif
285 #ifndef native_real16_t
286 #define native_real16_t real16_t
287 #define unpack_real16_t(x) (x)
288 #define pack_real16_t(x) (x)
289 #endif
290 #ifndef native_real32_t
291 #define native_real32_t real32_t
292 #define unpack_real32_t(x) (x)
293 #define pack_real32_t(x) (x)
294 #endif
295 #ifndef native_real64_t
296 #define native_real64_t real64_t
297 #define unpack_real64_t(x) (x)
298 #define pack_real64_t(x) (x)
299 #endif
300 #ifndef native_real80_t
301 #define native_real80_t real80_t
302 #define unpack_real80_t(x) (x)
303 #define pack_real80_t(x) (x)
304 #endif
305 #ifndef native_real128_t
306 #define native_real128_t real128_t
307 #define unpack_real128_t(x) (x)
308 #define pack_real128_t(x) (x)
309 #endif
311 #define FP_HAVE_INFINITY (HUGE_VAL == HUGE_VAL / 2)
313 #ifndef isfinite_real16_t
314 #define isfinite_real16_t(x) (FP_HAVE_INFINITY && cat(mathfunc_,real16_t)(fabs)(x) < HUGE_VAL)
315 #endif
316 #ifndef isfinite_real32_t
317 #define isfinite_real32_t(x) (FP_HAVE_INFINITY && cat(mathfunc_,real32_t)(fabs)(x) < HUGE_VAL)
318 #endif
319 #ifndef isfinite_real64_t
320 #define isfinite_real64_t(x) (FP_HAVE_INFINITY && cat(mathfunc_,real64_t)(fabs)(x) < HUGE_VAL)
321 #endif
322 #ifndef isfinite_real80_t
323 #define isfinite_real80_t(x) (FP_HAVE_INFINITY && cat(mathfunc_,real80_t)(fabs)(x) < HUGE_VAL)
324 #endif
325 #ifndef isfinite_real128_t
326 #define isfinite_real128_t(x) (FP_HAVE_INFINITY && cat(mathfunc_,real128_t)(fabs)(x) < HUGE_VAL)
327 #endif
329 #if defined(__BORLANDC__) || defined(_MSC_VER)
330 #define isnan_real32_t(x) _isnan(x)
331 #define isnan_real64_t(x) _isnan(x)
332 #define isnan_real80_t(x) _isnanl(x)
333 #endif
335 #ifndef isnan_real16_t
336 #define isnan_real16_t(x) ((x) != (x))
337 #endif
338 #ifndef isnan_real32_t
339 #define isnan_real32_t(x) ((x) != (x))
340 #endif
341 #ifndef isnan_real64_t
342 #define isnan_real64_t(x) ((x) != (x))
343 #endif
344 #ifndef isnan_real80_t
345 #define isnan_real80_t(x) ((x) != (x))
346 #endif
347 #ifndef isnan_real128_t
348 #define isnan_real128_t(x) ((x) != (x))
349 #endif
351 #ifndef REAL_MASK_0
352 #define REAL_MASK_0 0
353 #endif
354 #ifndef REAL_MASK_1
355 #define REAL_MASK_1 0
356 #endif
357 #ifndef REAL_MASK_2
358 #define REAL_MASK_2 0
359 #endif
360 #ifndef REAL_MASK_3
361 #define REAL_MASK_3 0
362 #endif
363 #ifndef REAL_MASK_4
364 #define REAL_MASK_4 0
365 #endif
367 #define REAL_MASK (REAL_MASK_0 | REAL_MASK_1 | REAL_MASK_2 | REAL_MASK_3 | REAL_MASK_4)
368 #if REAL_MASK & 0x10
369 #define TYPE_REAL_N 5
370 #define real_max_t real128_t
371 #elif REAL_MASK & 0x8
372 #define TYPE_REAL_N 4
373 #define real_max_t real80_t
374 #elif REAL_MASK & 0x4
375 #define TYPE_REAL_N 3
376 #define real_max_t real64_t
377 #elif REAL_MASK & 0x2
378 #define TYPE_REAL_N 2
379 #define real_max_t real32_t
380 #elif REAL_MASK & 0x1
381 #define TYPE_REAL_N 1
382 #define real_max_t real16_t
383 #else
384 #define TYPE_REAL_N 0
385 #endif
387 #define NEED_OP_EMULATION (INT_MASK != 0x1f || REAL_MASK != 0x1f)
389 #if !defined(signbit) || (defined(HAVE___FLOAT128) && !defined(HAVE_SIGNBIT___FLOAT128))
390 #ifdef signbit
391 #undef signbit
392 #endif
393 int signbit_d(double d);
394 #define signbit(x) signbit_d((double)(x))
395 #define need_signbit_d
396 #endif
399 /* these macros cause a crash on 64-bit HPUX */
400 #if defined(isunordered) && defined(islessgreater) && defined(isgreater) && defined(isgreaterequal) && defined(isless) && defined(islessequal)
401 #if GNUC_ATLEAST(3,0,0) && defined(__linux__)
402 #define use_is_macros
403 #endif
404 #endif
406 typedef uchar_efficient_t ajla_flat_option_t;
409 typedef int32_t pcode_t;
410 typedef uint32_t upcode_t;
412 #define SIZEOF_IP_T 4
413 typedef uint32_t ip_t;
414 typedef uint32_t frame_t;
415 typedef uint32_t stack_size_t;
416 #define ARG_MODE_N 3
417 typedef uint32_t arg_t;
418 #define NO_FRAME_T ((frame_t)-1)
420 #define frame_t_is_const(f) ((f) != NO_FRAME_T && (f) & sign_bit(frame_t))
421 static inline int32_t frame_t_get_const(frame_t f)
423 return (int32_t)(f - 0xc0000000UL);
425 static inline frame_t frame_t_from_const(int32_t c)
427 /* this logic is copied in simplify_instr */
428 /*ajla_assert_lo(c >= -0x40000000L && c < 0x3fffffffL, (file_line, "frame_t_from_const: invalid constant %ld", (long)c));*/
429 return (frame_t)c + 0xc0000000UL;
432 typedef frame_t ajla_option_t; /* some code casts ajla_option_t to frame_t */
434 #if (defined(HAVE_SYS_MMAN_H) && defined(HAVE_MMAP)) || defined(OS_OS2) || defined(OS_WIN32)
435 #define USE_AMALLOC
436 #endif
438 #if defined(SIZEOF_VOID_P) && SIZEOF_VOID_P >= 8 && !defined(UNUSUAL_NO_POINTER_COMPRESSION) && defined(USE_AMALLOC) && !defined(__hpux) && !defined(__OpenBSD__)
439 #define POINTER_COMPRESSION_POSSIBLE 3
440 #endif
442 #if defined(POINTER_COMPRESSION_POSSIBLE) && defined(HAVE_SYS_MMAN_H) && (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__APPLE__))
443 #include <sys/mman.h>
444 #ifndef MAP_EXCL
445 #undef POINTER_COMPRESSION_POSSIBLE
446 #endif
447 #endif
450 #if defined(C_BIG_ENDIAN) ^ defined(UNUSUAL)
451 #define CODE_ENDIAN 1
452 #else
453 #define CODE_ENDIAN 0
454 #endif
456 #if !defined(UNUSUAL)
457 #define STACK_INITIAL_SIZE 1024
458 #else
459 #define STACK_INITIAL_SIZE 1
460 #endif
462 /* valid values: 16 - 128 */
463 #if !defined(UNUSUAL)
464 #define BTREE_MAX_SIZE 16
465 #else
466 #define BTREE_MAX_SIZE 128
467 #endif
469 #define ARRAY_PREALLOC_SIZE 4
471 #define DEFAULT_TICK_US 10000