| ... | ... | @@ -530,6 +530,10 @@ typedef ptrdiff_t intptr_t; |
| 530 | 530 | return (val & UINT##w##_C(1) << (bits - UINT8_C(1))) != 0 \ |
| 531 | 531 | ? val | zig_minInt_i(w, bits) : val & zig_maxInt_i(w, bits); \ |
| 532 | 532 | } \ |
| 533 | \ |
| 534 | static inline uint##w##_t zig_abs_i##w(int##w##_t val) { \ |
| 535 | return (val < 0) ? -(uint##w##_t)val : (uint##w##_t)val; \ |
| 536 | } \ |
| 533 | 537 | \ |
| 534 | 538 | zig_basic_operator(uint##w##_t, div_floor_u##w, /) \ |
| 535 | 539 | \ |
| ... | ... | @@ -990,24 +994,6 @@ typedef unsigned long zig_Builtin64; |
| 990 | 994 | typedef unsigned long long zig_Builtin64; |
| 991 | 995 | #endif |
| 992 | 996 | |
| 993 | | #define zig_builtin8_rev(name, val) __builtin_##name(val) |
| 994 | | |
| 995 | | #define zig_builtin16_rev(name, val) __builtin_##name(val) |
| 996 | | |
| 997 | | #if INT_MIN <= INT32_MIN |
| 998 | | #define zig_builtin32_rev(name, val) __builtin_##name(val) |
| 999 | | #elif LONG_MIN <= INT32_MIN |
| 1000 | | #define zig_builtin32_rev(name, val) __builtin_l##name(val) |
| 1001 | | #endif |
| 1002 | | |
| 1003 | | #if INT_MIN <= INT64_MIN |
| 1004 | | #define zig_builtin64_rev(name, val) __builtin_##name(val) |
| 1005 | | #elif LONG_MIN <= INT64_MIN |
| 1006 | | #define zig_builtin64_rev(name, val) __builtin_l##name(val) |
| 1007 | | #elif LLONG_MIN <= INT64_MIN |
| 1008 | | #define zig_builtin64_rev(name, val) __builtin_ll##name(val) |
| 1009 | | #endif |
| 1010 | | |
| 1011 | 997 | static inline uint8_t zig_byte_swap_u8(uint8_t val, uint8_t bits) { |
| 1012 | 998 | return zig_wrap_u8(val >> (8 - bits), bits); |
| 1013 | 999 | } |
| ... | ... | @@ -1203,24 +1189,6 @@ zig_builtin_clz(16) |
| 1203 | 1189 | zig_builtin_clz(32) |
| 1204 | 1190 | zig_builtin_clz(64) |
| 1205 | 1191 | |
| 1206 | | #if zig_has_builtin(abs) || defined(zig_gnuc) |
| 1207 | | #define zig_builtin_abs(w) \ |
| 1208 | | static inline int##w##_t zig_abs_i##w(int##w##_t val) { \ |
| 1209 | | return zig_builtin##w##_rev(abs, val); \ |
| 1210 | | } |
| 1211 | | #else |
| 1212 | | #define zig_builtin_abs(w) \ |
| 1213 | | static inline int##w##_t zig_abs_i##w(int##w##_t val) { \ |
| 1214 | | if (val == INT##w##_MIN) return val; \ |
| 1215 | | int##w##_t tmp = val >> (w - 1); \ |
| 1216 | | return (val ^ tmp) - tmp; \ |
| 1217 | | } |
| 1218 | | #endif |
| 1219 | | zig_builtin_abs(8) |
| 1220 | | zig_builtin_abs(16) |
| 1221 | | zig_builtin_abs(32) |
| 1222 | | zig_builtin_abs(64) |
| 1223 | | |
| 1224 | 1192 | /* ======================== 128-bit Integer Support ========================= */ |
| 1225 | 1193 | |
| 1226 | 1194 | #if !defined(zig_has_int128) |
| ... | ... | @@ -3375,31 +3343,31 @@ zig_float_negate_builtin(128, zig_make_u128, (UINT64_C(1) << 63, UINT64_C(0))) |
| 3375 | 3343 | zig_expand_concat(zig_float_binary_builtin_, zig_has_f##w)(f##w, sub, -) \ |
| 3376 | 3344 | zig_expand_concat(zig_float_binary_builtin_, zig_has_f##w)(f##w, mul, *) \ |
| 3377 | 3345 | zig_expand_concat(zig_float_binary_builtin_, zig_has_f##w)(f##w, div, /) \ |
| 3378 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(sqrt)))(zig_f##w, zig_float_fn_f##w##_sqrt, zig_libc_name_f##w(sqrt), (zig_f##w x), (x)) \ |
| 3379 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(sin)))(zig_f##w, zig_float_fn_f##w##_sin, zig_libc_name_f##w(sin), (zig_f##w x), (x)) \ |
| 3380 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(cos)))(zig_f##w, zig_float_fn_f##w##_cos, zig_libc_name_f##w(cos), (zig_f##w x), (x)) \ |
| 3381 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(tan)))(zig_f##w, zig_float_fn_f##w##_tan, zig_libc_name_f##w(tan), (zig_f##w x), (x)) \ |
| 3382 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(exp)))(zig_f##w, zig_float_fn_f##w##_exp, zig_libc_name_f##w(exp), (zig_f##w x), (x)) \ |
| 3383 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(exp2)))(zig_f##w, zig_float_fn_f##w##_exp2, zig_libc_name_f##w(exp2), (zig_f##w x), (x)) \ |
| 3384 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(log)))(zig_f##w, zig_float_fn_f##w##_log, zig_libc_name_f##w(log), (zig_f##w x), (x)) \ |
| 3385 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(log2)))(zig_f##w, zig_float_fn_f##w##_log2, zig_libc_name_f##w(log2), (zig_f##w x), (x)) \ |
| 3386 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(log10)))(zig_f##w, zig_float_fn_f##w##_log10, zig_libc_name_f##w(log10), (zig_f##w x), (x)) \ |
| 3387 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(fabs)))(zig_f##w, zig_float_fn_f##w##_fabs, zig_libc_name_f##w(fabs), (zig_f##w x), (x)) \ |
| 3388 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(floor)))(zig_f##w, zig_float_fn_f##w##_floor, zig_libc_name_f##w(floor), (zig_f##w x), (x)) \ |
| 3389 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(ceil)))(zig_f##w, zig_float_fn_f##w##_ceil, zig_libc_name_f##w(ceil), (zig_f##w x), (x)) \ |
| 3390 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(round)))(zig_f##w, zig_float_fn_f##w##_round, zig_libc_name_f##w(round), (zig_f##w x), (x)) \ |
| 3391 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(trunc)))(zig_f##w, zig_float_fn_f##w##_trunc, zig_libc_name_f##w(trunc), (zig_f##w x), (x)) \ |
| 3392 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(fmod)))(zig_f##w, zig_float_fn_f##w##_fmod, zig_libc_name_f##w(fmod), (zig_f##w x, zig_f##w y), (x, y)) \ |
| 3393 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(fmin)))(zig_f##w, zig_float_fn_f##w##_fmin, zig_libc_name_f##w(fmin), (zig_f##w x, zig_f##w y), (x, y)) \ |
| 3394 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(fmax)))(zig_f##w, zig_float_fn_f##w##_fmax, zig_libc_name_f##w(fmax), (zig_f##w x, zig_f##w y), (x, y)) \ |
| 3395 | | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(fma)))(zig_f##w, zig_float_fn_f##w##_fma, zig_libc_name_f##w(fma), (zig_f##w x, zig_f##w y, zig_f##w z), (x, y, z)) \ |
| 3346 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(sqrt)))(zig_f##w, zig_sqrt_f##w, zig_libc_name_f##w(sqrt), (zig_f##w x), (x)) \ |
| 3347 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(sin)))(zig_f##w, zig_sin_f##w, zig_libc_name_f##w(sin), (zig_f##w x), (x)) \ |
| 3348 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(cos)))(zig_f##w, zig_cos_f##w, zig_libc_name_f##w(cos), (zig_f##w x), (x)) \ |
| 3349 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(tan)))(zig_f##w, zig_tan_f##w, zig_libc_name_f##w(tan), (zig_f##w x), (x)) \ |
| 3350 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(exp)))(zig_f##w, zig_exp_f##w, zig_libc_name_f##w(exp), (zig_f##w x), (x)) \ |
| 3351 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(exp2)))(zig_f##w, zig_exp2_f##w, zig_libc_name_f##w(exp2), (zig_f##w x), (x)) \ |
| 3352 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(log)))(zig_f##w, zig_log_f##w, zig_libc_name_f##w(log), (zig_f##w x), (x)) \ |
| 3353 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(log2)))(zig_f##w, zig_log2_f##w, zig_libc_name_f##w(log2), (zig_f##w x), (x)) \ |
| 3354 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(log10)))(zig_f##w, zig_log10_f##w, zig_libc_name_f##w(log10), (zig_f##w x), (x)) \ |
| 3355 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(fabs)))(zig_f##w, zig_abs_f##w, zig_libc_name_f##w(fabs), (zig_f##w x), (x)) \ |
| 3356 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(floor)))(zig_f##w, zig_floor_f##w, zig_libc_name_f##w(floor), (zig_f##w x), (x)) \ |
| 3357 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(ceil)))(zig_f##w, zig_ceil_f##w, zig_libc_name_f##w(ceil), (zig_f##w x), (x)) \ |
| 3358 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(round)))(zig_f##w, zig_round_f##w, zig_libc_name_f##w(round), (zig_f##w x), (x)) \ |
| 3359 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(trunc)))(zig_f##w, zig_trunc_f##w, zig_libc_name_f##w(trunc), (zig_f##w x), (x)) \ |
| 3360 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(fmod)))(zig_f##w, zig_fmod_f##w, zig_libc_name_f##w(fmod), (zig_f##w x, zig_f##w y), (x, y)) \ |
| 3361 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(fmin)))(zig_f##w, zig_min_f##w, zig_libc_name_f##w(fmin), (zig_f##w x, zig_f##w y), (x, y)) \ |
| 3362 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(fmax)))(zig_f##w, zig_max_f##w, zig_libc_name_f##w(fmax), (zig_f##w x, zig_f##w y), (x, y)) \ |
| 3363 | zig_expand_concat(zig_expand_import_, zig_expand_has_builtin(zig_libc_name_f##w(fma)))(zig_f##w, zig_fma_f##w, zig_libc_name_f##w(fma), (zig_f##w x, zig_f##w y, zig_f##w z), (x, y, z)) \ |
| 3396 | 3364 | \ |
| 3397 | 3365 | static inline zig_f##w zig_div_trunc_f##w(zig_f##w lhs, zig_f##w rhs) { \ |
| 3398 | | return zig_float_fn_f##w##_trunc(zig_div_f##w(lhs, rhs)); \ |
| 3366 | return zig_trunc_f##w(zig_div_f##w(lhs, rhs)); \ |
| 3399 | 3367 | } \ |
| 3400 | 3368 | \ |
| 3401 | 3369 | static inline zig_f##w zig_div_floor_f##w(zig_f##w lhs, zig_f##w rhs) { \ |
| 3402 | | return zig_float_fn_f##w##_floor(zig_div_f##w(lhs, rhs)); \ |
| 3370 | return zig_floor_f##w(zig_div_f##w(lhs, rhs)); \ |
| 3403 | 3371 | } \ |
| 3404 | 3372 | \ |
| 3405 | 3373 | static inline zig_f##w zig_mod_f##w(zig_f##w lhs, zig_f##w rhs) { \ |
| ... | ... | @@ -3503,7 +3471,7 @@ zig_float_builtins(64) |
| 3503 | 3471 | zig_##Type zig_atomicrmw_desired; \ |
| 3504 | 3472 | zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \ |
| 3505 | 3473 | do { \ |
| 3506 | | zig_atomicrmw_desired = zig_float_fn_##Type##_fmin(zig_atomicrmw_expected, arg); \ |
| 3474 | zig_atomicrmw_desired = zig_min_##Type(zig_atomicrmw_expected, arg); \ |
| 3507 | 3475 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \ |
| 3508 | 3476 | res = zig_atomicrmw_expected; \ |
| 3509 | 3477 | } while (0) |
| ... | ... | @@ -3512,7 +3480,7 @@ zig_float_builtins(64) |
| 3512 | 3480 | zig_##Type zig_atomicrmw_desired; \ |
| 3513 | 3481 | zig_atomic_load(zig_atomicrmw_expected, obj, zig_memory_order_relaxed, Type, ReprType); \ |
| 3514 | 3482 | do { \ |
| 3515 | | zig_atomicrmw_desired = zig_float_fn_##Type##_fmax(zig_atomicrmw_expected, arg); \ |
| 3483 | zig_atomicrmw_desired = zig_max_##Type(zig_atomicrmw_expected, arg); \ |
| 3516 | 3484 | } while (!zig_cmpxchg_weak(obj, zig_atomicrmw_expected, zig_atomicrmw_desired, order, zig_memory_order_relaxed, Type, ReprType)); \ |
| 3517 | 3485 | res = zig_atomicrmw_expected; \ |
| 3518 | 3486 | } while (0) |