| ... | @@ -502,6 +502,15 @@ typedef ptrdiff_t intptr_t; | ... | @@ -502,6 +502,15 @@ typedef ptrdiff_t intptr_t; |
| 502 | | 502 | |
| 503 | #endif | 503 | #endif |
| 504 | | 504 | |
| | 505 | #define zig_make_small_i8(val) INT8_C(val) |
| | 506 | #define zig_make_small_u8(val) UINT8_C(val) |
| | 507 | #define zig_make_small_i16(val) INT16_C(val) |
| | 508 | #define zig_make_small_u16(val) UINT16_C(val) |
| | 509 | #define zig_make_small_i32(val) INT32_C(val) |
| | 510 | #define zig_make_small_u32(val) UINT32_C(val) |
| | 511 | #define zig_make_small_i64(val) INT64_C(val) |
| | 512 | #define zig_make_small_u64(val) UINT64_C(val) |
| | 513 | |
| 505 | #define zig_minInt_i8 INT8_MIN | 514 | #define zig_minInt_i8 INT8_MIN |
| 506 | #define zig_maxInt_i8 INT8_MAX | 515 | #define zig_maxInt_i8 INT8_MAX |
| 507 | #define zig_minInt_u8 UINT8_C(0) | 516 | #define zig_minInt_u8 UINT8_C(0) |
| ... | @@ -585,7 +594,7 @@ typedef ptrdiff_t intptr_t; | ... | @@ -585,7 +594,7 @@ typedef ptrdiff_t intptr_t; |
| 585 | } \ | 594 | } \ |
| 586 | \ | 595 | \ |
| 587 | static inline int##w##_t zig_shlw_i##w(int##w##_t lhs, uint8_t rhs, uint8_t bits) { \ | 596 | static inline int##w##_t zig_shlw_i##w(int##w##_t lhs, uint8_t rhs, uint8_t bits) { \ |
| 588 | return zig_wrap_i##w((int##w##_t)zig_shl_u##w((uint##w##_t)lhs, (uint##w##_t)rhs), bits); \ | 597 | return zig_wrap_i##w((int##w##_t)zig_shl_u##w((uint##w##_t)lhs, rhs), bits); \ |
| 589 | } \ | 598 | } \ |
| 590 | \ | 599 | \ |
| 591 | static inline uint##w##_t zig_addw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ | 600 | static inline uint##w##_t zig_addw_u##w(uint##w##_t lhs, uint##w##_t rhs, uint8_t bits) { \ |
| ... | @@ -1294,6 +1303,9 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128; | ... | @@ -1294,6 +1303,9 @@ typedef struct { zig_align(16) int64_t hi; uint64_t lo; } zig_i128; |
| 1294 | | 1303 | |
| 1295 | #endif /* zig_has_int128 */ | 1304 | #endif /* zig_has_int128 */ |
| 1296 | | 1305 | |
| | 1306 | #define zig_make_small_u128(val) zig_make_u128(0, val) |
| | 1307 | #define zig_make_small_i128(val) zig_make_i128((val) < 0 ? -INT64_C(1) : INT64_C(0), val) |
| | 1308 | |
| 1297 | #define zig_minInt_u128 zig_make_u128(zig_minInt_u64, zig_minInt_u64) | 1309 | #define zig_minInt_u128 zig_make_u128(zig_minInt_u64, zig_minInt_u64) |
| 1298 | #define zig_maxInt_u128 zig_make_u128(zig_maxInt_u64, zig_maxInt_u64) | 1310 | #define zig_maxInt_u128 zig_make_u128(zig_maxInt_u64, zig_maxInt_u64) |
| 1299 | #define zig_minInt_i128 zig_make_i128(zig_minInt_i64, zig_minInt_u64) | 1311 | #define zig_minInt_i128 zig_make_i128(zig_minInt_i64, zig_minInt_u64) |
| ... | @@ -2796,6 +2808,10 @@ static inline uint16_t zig_popcount_big(const void *val, bool is_signed, uint16_ | ... | @@ -2796,6 +2808,10 @@ static inline uint16_t zig_popcount_big(const void *val, bool is_signed, uint16_ |
| 2796 | /* ========================= Floating Point Support ========================= */ | 2808 | /* ========================= Floating Point Support ========================= */ |
| 2797 | | 2809 | |
| 2798 | #if _MSC_VER | 2810 | #if _MSC_VER |
| | 2811 | float __cdecl nanf(char const* input); |
| | 2812 | double __cdecl nan(char const* input); |
| | 2813 | long double __cdecl nanl(char const* input); |
| | 2814 | |
| 2799 | #define zig_msvc_flt_inf ((double)(1e+300 * 1e+300)) | 2815 | #define zig_msvc_flt_inf ((double)(1e+300 * 1e+300)) |
| 2800 | #define zig_msvc_flt_inff ((float)(1e+300 * 1e+300)) | 2816 | #define zig_msvc_flt_inff ((float)(1e+300 * 1e+300)) |
| 2801 | #define zig_msvc_flt_infl ((long double)(1e+300 * 1e+300)) | 2817 | #define zig_msvc_flt_infl ((long double)(1e+300 * 1e+300)) |
| ... | @@ -2828,7 +2844,7 @@ static inline uint16_t zig_popcount_big(const void *val, bool is_signed, uint16_ | ... | @@ -2828,7 +2844,7 @@ static inline uint16_t zig_popcount_big(const void *val, bool is_signed, uint16_ |
| 2828 | | 2844 | |
| 2829 | #define zig_has_f16 1 | 2845 | #define zig_has_f16 1 |
| 2830 | #define zig_bitSizeOf_f16 16 | 2846 | #define zig_bitSizeOf_f16 16 |
| 2831 | typedef int16_t zig_repr_f16; | 2847 | typedef uint16_t zig_repr_f16; |
| 2832 | #define zig_libc_name_f16(name) __##name##h | 2848 | #define zig_libc_name_f16(name) __##name##h |
| 2833 | #define zig_init_special_f16(sign, name, arg, repr) zig_make_special_f16(sign, name, arg, repr) | 2849 | #define zig_init_special_f16(sign, name, arg, repr) zig_make_special_f16(sign, name, arg, repr) |
| 2834 | #if FLT_MANT_DIG == 11 | 2850 | #if FLT_MANT_DIG == 11 |
| ... | @@ -2854,17 +2870,23 @@ typedef __fp16 zig_f16; | ... | @@ -2854,17 +2870,23 @@ typedef __fp16 zig_f16; |
| 2854 | #undef zig_has_f16 | 2870 | #undef zig_has_f16 |
| 2855 | #define zig_has_f16 0 | 2871 | #define zig_has_f16 0 |
| 2856 | #define zig_bitSizeOf_repr_f16 16 | 2872 | #define zig_bitSizeOf_repr_f16 16 |
| 2857 | typedef int16_t zig_f16; | 2873 | typedef zig_repr_f16 zig_f16; |
| 2858 | #define zig_make_f16(fp, repr) repr | 2874 | #define zig_make_f16(fp, repr) repr |
| 2859 | #undef zig_make_special_f16 | 2875 | #undef zig_make_special_f16 |
| 2860 | #define zig_make_special_f16(sign, name, arg, repr) repr | 2876 | #define zig_make_special_f16(sign, name, arg, repr) repr |
| 2861 | #undef zig_init_special_f16 | 2877 | #undef zig_init_special_f16 |
| 2862 | #define zig_init_special_f16(sign, name, arg, repr) repr | 2878 | #define zig_init_special_f16(sign, name, arg, repr) repr |
| 2863 | #endif | 2879 | #endif |
| | 2880 | #if __APPLE__ |
| | 2881 | typedef zig_repr_f16 zig_compiler_rt_f16; |
| | 2882 | #else |
| | 2883 | typedef zig_f16 zig_compiler_rt_f16; |
| | 2884 | #endif |
| | 2885 | #define zig_compiler_rt_abbrev_zig_compiler_rt_f16 zig_compiler_rt_abbrev_zig_f16 |
| 2864 | | 2886 | |
| 2865 | #define zig_has_f32 1 | 2887 | #define zig_has_f32 1 |
| 2866 | #define zig_bitSizeOf_f32 32 | 2888 | #define zig_bitSizeOf_f32 32 |
| 2867 | typedef int32_t zig_repr_f32; | 2889 | typedef uint32_t zig_repr_f32; |
| 2868 | #define zig_libc_name_f32(name) name##f | 2890 | #define zig_libc_name_f32(name) name##f |
| 2869 | #if _MSC_VER | 2891 | #if _MSC_VER |
| 2870 | #define zig_init_special_f32(sign, name, arg, repr) sign zig_make_f32(zig_msvc_flt_##name, ) | 2892 | #define zig_init_special_f32(sign, name, arg, repr) sign zig_make_f32(zig_msvc_flt_##name, ) |
| ... | @@ -2891,7 +2913,7 @@ typedef _Float32 zig_f32; | ... | @@ -2891,7 +2913,7 @@ typedef _Float32 zig_f32; |
| 2891 | #undef zig_has_f32 | 2913 | #undef zig_has_f32 |
| 2892 | #define zig_has_f32 0 | 2914 | #define zig_has_f32 0 |
| 2893 | #define zig_bitSizeOf_repr_f32 32 | 2915 | #define zig_bitSizeOf_repr_f32 32 |
| 2894 | typedef int32_t zig_f32; | 2916 | typedef zig_repr_f32 zig_f32; |
| 2895 | #define zig_make_f32(fp, repr) repr | 2917 | #define zig_make_f32(fp, repr) repr |
| 2896 | #undef zig_make_special_f32 | 2918 | #undef zig_make_special_f32 |
| 2897 | #define zig_make_special_f32(sign, name, arg, repr) repr | 2919 | #define zig_make_special_f32(sign, name, arg, repr) repr |
| ... | @@ -2901,7 +2923,7 @@ typedef int32_t zig_f32; | ... | @@ -2901,7 +2923,7 @@ typedef int32_t zig_f32; |
| 2901 | | 2923 | |
| 2902 | #define zig_has_f64 1 | 2924 | #define zig_has_f64 1 |
| 2903 | #define zig_bitSizeOf_f64 64 | 2925 | #define zig_bitSizeOf_f64 64 |
| 2904 | typedef int64_t zig_repr_f64; | 2926 | typedef uint64_t zig_repr_f64; |
| 2905 | #define zig_libc_name_f64(name) name | 2927 | #define zig_libc_name_f64(name) name |
| 2906 | #if _MSC_VER | 2928 | #if _MSC_VER |
| 2907 | #ifdef ZIG_TARGET_ABI_MSVC | 2929 | #ifdef ZIG_TARGET_ABI_MSVC |
| ... | @@ -2937,7 +2959,7 @@ typedef _Float32x zig_f64; | ... | @@ -2937,7 +2959,7 @@ typedef _Float32x zig_f64; |
| 2937 | #undef zig_has_f64 | 2959 | #undef zig_has_f64 |
| 2938 | #define zig_has_f64 0 | 2960 | #define zig_has_f64 0 |
| 2939 | #define zig_bitSizeOf_repr_f64 64 | 2961 | #define zig_bitSizeOf_repr_f64 64 |
| 2940 | typedef int64_t zig_f64; | 2962 | typedef zig_repr_f64 zig_f64; |
| 2941 | #define zig_make_f64(fp, repr) repr | 2963 | #define zig_make_f64(fp, repr) repr |
| 2942 | #undef zig_make_special_f64 | 2964 | #undef zig_make_special_f64 |
| 2943 | #define zig_make_special_f64(sign, name, arg, repr) repr | 2965 | #define zig_make_special_f64(sign, name, arg, repr) repr |
| ... | @@ -2947,7 +2969,7 @@ typedef int64_t zig_f64; | ... | @@ -2947,7 +2969,7 @@ typedef int64_t zig_f64; |
| 2947 | | 2969 | |
| 2948 | #define zig_has_f80 1 | 2970 | #define zig_has_f80 1 |
| 2949 | #define zig_bitSizeOf_f80 80 | 2971 | #define zig_bitSizeOf_f80 80 |
| 2950 | typedef zig_i128 zig_repr_f80; | 2972 | typedef zig_u128 zig_repr_f80; |
| 2951 | #define zig_libc_name_f80(name) __##name##x | 2973 | #define zig_libc_name_f80(name) __##name##x |
| 2952 | #define zig_init_special_f80(sign, name, arg, repr) zig_make_special_f80(sign, name, arg, repr) | 2974 | #define zig_init_special_f80(sign, name, arg, repr) zig_make_special_f80(sign, name, arg, repr) |
| 2953 | #if FLT_MANT_DIG == 64 | 2975 | #if FLT_MANT_DIG == 64 |
| ... | @@ -2976,7 +2998,7 @@ typedef __float80 zig_f80; | ... | @@ -2976,7 +2998,7 @@ typedef __float80 zig_f80; |
| 2976 | #undef zig_has_f80 | 2998 | #undef zig_has_f80 |
| 2977 | #define zig_has_f80 0 | 2999 | #define zig_has_f80 0 |
| 2978 | #define zig_bitSizeOf_repr_f80 128 | 3000 | #define zig_bitSizeOf_repr_f80 128 |
| 2979 | typedef zig_i128 zig_f80; | 3001 | typedef zig_repr_f80 zig_f80; |
| 2980 | #define zig_make_f80(fp, repr) repr | 3002 | #define zig_make_f80(fp, repr) repr |
| 2981 | #undef zig_make_special_f80 | 3003 | #undef zig_make_special_f80 |
| 2982 | #define zig_make_special_f80(sign, name, arg, repr) repr | 3004 | #define zig_make_special_f80(sign, name, arg, repr) repr |
| ... | @@ -2986,7 +3008,7 @@ typedef zig_i128 zig_f80; | ... | @@ -2986,7 +3008,7 @@ typedef zig_i128 zig_f80; |
| 2986 | | 3008 | |
| 2987 | #define zig_has_f128 1 | 3009 | #define zig_has_f128 1 |
| 2988 | #define zig_bitSizeOf_f128 128 | 3010 | #define zig_bitSizeOf_f128 128 |
| 2989 | typedef zig_i128 zig_repr_f128; | 3011 | typedef zig_u128 zig_repr_f128; |
| 2990 | #define zig_libc_name_f128(name) name##q | 3012 | #define zig_libc_name_f128(name) name##q |
| 2991 | #define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr) | 3013 | #define zig_init_special_f128(sign, name, arg, repr) zig_make_special_f128(sign, name, arg, repr) |
| 2992 | #if FLT_MANT_DIG == 113 | 3014 | #if FLT_MANT_DIG == 113 |
| ... | @@ -3017,7 +3039,7 @@ typedef __float128 zig_f128; | ... | @@ -3017,7 +3039,7 @@ typedef __float128 zig_f128; |
| 3017 | #undef zig_has_f128 | 3039 | #undef zig_has_f128 |
| 3018 | #define zig_has_f128 0 | 3040 | #define zig_has_f128 0 |
| 3019 | #define zig_bitSizeOf_repr_f128 128 | 3041 | #define zig_bitSizeOf_repr_f128 128 |
| 3020 | typedef zig_i128 zig_f128; | 3042 | typedef zig_repr_f128 zig_f128; |
| 3021 | #define zig_make_f128(fp, repr) repr | 3043 | #define zig_make_f128(fp, repr) repr |
| 3022 | #undef zig_make_special_f128 | 3044 | #undef zig_make_special_f128 |
| 3023 | #define zig_make_special_f128(sign, name, arg, repr) repr | 3045 | #define zig_make_special_f128(sign, name, arg, repr) repr |
| ... | @@ -3076,15 +3098,15 @@ zig_float_from_repr(f128) | ... | @@ -3076,15 +3098,15 @@ zig_float_from_repr(f128) |
| 3076 | #define zig_convert_builtin(ResType, operation, ArgType, version) \ | 3098 | #define zig_convert_builtin(ResType, operation, ArgType, version) \ |
| 3077 | zig_extern ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \ | 3099 | zig_extern ResType zig_expand_concat(zig_expand_concat(zig_expand_concat(__##operation, \ |
| 3078 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ArgType); | 3100 | zig_compiler_rt_abbrev_##ArgType), zig_compiler_rt_abbrev_##ResType), version)(ArgType); |
| 3079 | zig_convert_builtin(zig_f16, trunc, zig_f32, 2) | 3101 | zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f32, 2) |
| 3080 | zig_convert_builtin(zig_f16, trunc, zig_f64, 2) | 3102 | zig_convert_builtin(zig_compiler_rt_f16, trunc, zig_f64, 2) |
| 3081 | zig_convert_builtin(zig_f16, trunc, zig_f80, 2) | 3103 | zig_convert_builtin(zig_f16, trunc, zig_f80, 2) |
| 3082 | zig_convert_builtin(zig_f16, trunc, zig_f128, 2) | 3104 | zig_convert_builtin(zig_f16, trunc, zig_f128, 2) |
| 3083 | zig_convert_builtin(zig_f32, extend, zig_f16, 2) | 3105 | zig_convert_builtin(zig_f32, extend, zig_compiler_rt_f16, 2) |
| 3084 | zig_convert_builtin(zig_f32, trunc, zig_f64, 2) | 3106 | zig_convert_builtin(zig_f32, trunc, zig_f64, 2) |
| 3085 | zig_convert_builtin(zig_f32, trunc, zig_f80, 2) | 3107 | zig_convert_builtin(zig_f32, trunc, zig_f80, 2) |
| 3086 | zig_convert_builtin(zig_f32, trunc, zig_f128, 2) | 3108 | zig_convert_builtin(zig_f32, trunc, zig_f128, 2) |
| 3087 | zig_convert_builtin(zig_f64, extend, zig_f16, 2) | 3109 | zig_convert_builtin(zig_f64, extend, zig_compiler_rt_f16, 2) |
| 3088 | zig_convert_builtin(zig_f64, extend, zig_f32, 2) | 3110 | zig_convert_builtin(zig_f64, extend, zig_f32, 2) |
| 3089 | zig_convert_builtin(zig_f64, trunc, zig_f80, 2) | 3111 | zig_convert_builtin(zig_f64, trunc, zig_f80, 2) |
| 3090 | zig_convert_builtin(zig_f64, trunc, zig_f128, 2) | 3112 | zig_convert_builtin(zig_f64, trunc, zig_f128, 2) |
| ... | @@ -3097,15 +3119,18 @@ zig_convert_builtin(zig_f128, extend, zig_f32, 2) | ... | @@ -3097,15 +3119,18 @@ zig_convert_builtin(zig_f128, extend, zig_f32, 2) |
| 3097 | zig_convert_builtin(zig_f128, extend, zig_f64, 2) | 3119 | zig_convert_builtin(zig_f128, extend, zig_f64, 2) |
| 3098 | zig_convert_builtin(zig_f128, extend, zig_f80, 2) | 3120 | zig_convert_builtin(zig_f128, extend, zig_f80, 2) |
| 3099 | | 3121 | |
| 3100 | #define zig_float_negate_builtin_0(Type) \ | 3122 | #define zig_float_negate_builtin_0(w) \ |
| 3101 | static inline zig_##Type zig_neg_##Type(zig_##Type arg) { \ | 3123 | static inline zig_f##w zig_neg_f##w(zig_f##w arg) { \ |
| 3102 | return zig_expand_concat(zig_xor_i, zig_bitSizeOf_repr_##Type)( \ | 3124 | return zig_expand_concat(zig_xor_u, zig_bitSizeOf_repr_f##w)( \ |
| 3103 | arg, \ | 3125 | arg, \ |
| 3104 | zig_minInt_i(zig_bitSizeOf_repr_##Type, zig_bitSizeOf_##Type) \ | 3126 | zig_expand_concat(zig_shl_u, zig_bitSizeOf_repr_f##w)( \ |
| | 3127 | zig_expand_concat(zig_make_small_u, zig_bitSizeOf_repr_f##w)(1), \ |
| | 3128 | UINT8_C(w - 1) \ |
| | 3129 | ) \ |
| 3105 | ); \ | 3130 | ); \ |
| 3106 | } | 3131 | } |
| 3107 | #define zig_float_negate_builtin_1(Type) \ | 3132 | #define zig_float_negate_builtin_1(w) \ |
| 3108 | static inline zig_##Type zig_neg_##Type(zig_##Type arg) { \ | 3133 | static inline zig_f##w zig_neg_f##w(zig_f##w arg) { \ |
| 3109 | return -arg; \ | 3134 | return -arg; \ |
| 3110 | } | 3135 | } |
| 3111 | | 3136 | |
| ... | @@ -3138,75 +3163,75 @@ zig_convert_builtin(zig_f128, extend, zig_f80, 2) | ... | @@ -3138,75 +3163,75 @@ zig_convert_builtin(zig_f128, extend, zig_f80, 2) |
| 3138 | return lhs operator rhs; \ | 3163 | return lhs operator rhs; \ |
| 3139 | } | 3164 | } |
| 3140 | | 3165 | |
| 3141 | #define zig_float_builtins(Type) \ | 3166 | #define zig_float_builtins(w) \ |
| 3142 | zig_convert_builtin( int32_t, fix, zig_##Type, ) \ | 3167 | zig_convert_builtin( int32_t, fix, zig_f##w, ) \ |
| 3143 | zig_convert_builtin(uint32_t, fixuns, zig_##Type, ) \ | 3168 | zig_convert_builtin(uint32_t, fixuns, zig_f##w, ) \ |
| 3144 | zig_convert_builtin( int64_t, fix, zig_##Type, ) \ | 3169 | zig_convert_builtin( int64_t, fix, zig_f##w, ) \ |
| 3145 | zig_convert_builtin(uint64_t, fixuns, zig_##Type, ) \ | 3170 | zig_convert_builtin(uint64_t, fixuns, zig_f##w, ) \ |
| 3146 | zig_convert_builtin(zig_i128, fix, zig_##Type, ) \ | 3171 | zig_convert_builtin(zig_i128, fix, zig_f##w, ) \ |
| 3147 | zig_convert_builtin(zig_u128, fixuns, zig_##Type, ) \ | 3172 | zig_convert_builtin(zig_u128, fixuns, zig_f##w, ) \ |
| 3148 | zig_convert_builtin(zig_##Type, float, int32_t, ) \ | 3173 | zig_convert_builtin(zig_f##w, float, int32_t, ) \ |
| 3149 | zig_convert_builtin(zig_##Type, floatun, uint32_t, ) \ | 3174 | zig_convert_builtin(zig_f##w, floatun, uint32_t, ) \ |
| 3150 | zig_convert_builtin(zig_##Type, float, int64_t, ) \ | 3175 | zig_convert_builtin(zig_f##w, float, int64_t, ) \ |
| 3151 | zig_convert_builtin(zig_##Type, floatun, uint64_t, ) \ | 3176 | zig_convert_builtin(zig_f##w, floatun, uint64_t, ) \ |
| 3152 | zig_convert_builtin(zig_##Type, float, zig_i128, ) \ | 3177 | zig_convert_builtin(zig_f##w, float, zig_i128, ) \ |
| 3153 | zig_convert_builtin(zig_##Type, floatun, zig_u128, ) \ | 3178 | zig_convert_builtin(zig_f##w, floatun, zig_u128, ) \ |
| 3154 | zig_expand_concat(zig_float_negate_builtin_, zig_has_##Type)(Type) \ | 3179 | zig_expand_concat(zig_float_negate_builtin_, zig_has_f##w)(w) \ |
| 3155 | zig_expand_concat(zig_float_less_builtin_, zig_has_##Type)(Type, cmp) \ | 3180 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, cmp) \ |
| 3156 | zig_expand_concat(zig_float_less_builtin_, zig_has_##Type)(Type, ne) \ | 3181 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, ne) \ |
| 3157 | zig_expand_concat(zig_float_less_builtin_, zig_has_##Type)(Type, eq) \ | 3182 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, eq) \ |
| 3158 | zig_expand_concat(zig_float_less_builtin_, zig_has_##Type)(Type, lt) \ | 3183 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, lt) \ |
| 3159 | zig_expand_concat(zig_float_less_builtin_, zig_has_##Type)(Type, le) \ | 3184 | zig_expand_concat(zig_float_less_builtin_, zig_has_f##w)(f##w, le) \ |
| 3160 | zig_expand_concat(zig_float_greater_builtin_, zig_has_##Type)(Type, gt) \ | 3185 | zig_expand_concat(zig_float_greater_builtin_, zig_has_f##w)(f##w, gt) \ |
| 3161 | zig_expand_concat(zig_float_greater_builtin_, zig_has_##Type)(Type, ge) \ | 3186 | zig_expand_concat(zig_float_greater_builtin_, zig_has_f##w)(f##w, ge) \ |
| 3162 | zig_expand_concat(zig_float_binary_builtin_, zig_has_##Type)(Type, add, +) \ | 3187 | zig_expand_concat(zig_float_binary_builtin_, zig_has_f##w)(f##w, add, +) \ |
| 3163 | zig_expand_concat(zig_float_binary_builtin_, zig_has_##Type)(Type, sub, -) \ | 3188 | zig_expand_concat(zig_float_binary_builtin_, zig_has_f##w)(f##w, sub, -) \ |
| 3164 | zig_expand_concat(zig_float_binary_builtin_, zig_has_##Type)(Type, mul, *) \ | 3189 | zig_expand_concat(zig_float_binary_builtin_, zig_has_f##w)(f##w, mul, *) \ |
| 3165 | zig_expand_concat(zig_float_binary_builtin_, zig_has_##Type)(Type, div, /) \ | 3190 | zig_expand_concat(zig_float_binary_builtin_, zig_has_f##w)(f##w, div, /) \ |
| 3166 | zig_extern zig_##Type zig_libc_name_##Type(sqrt)(zig_##Type); \ | 3191 | zig_extern zig_f##w zig_libc_name_f##w(sqrt)(zig_f##w); \ |
| 3167 | zig_extern zig_##Type zig_libc_name_##Type(sin)(zig_##Type); \ | 3192 | zig_extern zig_f##w zig_libc_name_f##w(sin)(zig_f##w); \ |
| 3168 | zig_extern zig_##Type zig_libc_name_##Type(cos)(zig_##Type); \ | 3193 | zig_extern zig_f##w zig_libc_name_f##w(cos)(zig_f##w); \ |
| 3169 | zig_extern zig_##Type zig_libc_name_##Type(tan)(zig_##Type); \ | 3194 | zig_extern zig_f##w zig_libc_name_f##w(tan)(zig_f##w); \ |
| 3170 | zig_extern zig_##Type zig_libc_name_##Type(exp)(zig_##Type); \ | 3195 | zig_extern zig_f##w zig_libc_name_f##w(exp)(zig_f##w); \ |
| 3171 | zig_extern zig_##Type zig_libc_name_##Type(exp2)(zig_##Type); \ | 3196 | zig_extern zig_f##w zig_libc_name_f##w(exp2)(zig_f##w); \ |
| 3172 | zig_extern zig_##Type zig_libc_name_##Type(log)(zig_##Type); \ | 3197 | zig_extern zig_f##w zig_libc_name_f##w(log)(zig_f##w); \ |
| 3173 | zig_extern zig_##Type zig_libc_name_##Type(log2)(zig_##Type); \ | 3198 | zig_extern zig_f##w zig_libc_name_f##w(log2)(zig_f##w); \ |
| 3174 | zig_extern zig_##Type zig_libc_name_##Type(log10)(zig_##Type); \ | 3199 | zig_extern zig_f##w zig_libc_name_f##w(log10)(zig_f##w); \ |
| 3175 | zig_extern zig_##Type zig_libc_name_##Type(fabs)(zig_##Type); \ | 3200 | zig_extern zig_f##w zig_libc_name_f##w(fabs)(zig_f##w); \ |
| 3176 | zig_extern zig_##Type zig_libc_name_##Type(floor)(zig_##Type); \ | 3201 | zig_extern zig_f##w zig_libc_name_f##w(floor)(zig_f##w); \ |
| 3177 | zig_extern zig_##Type zig_libc_name_##Type(ceil)(zig_##Type); \ | 3202 | zig_extern zig_f##w zig_libc_name_f##w(ceil)(zig_f##w); \ |
| 3178 | zig_extern zig_##Type zig_libc_name_##Type(round)(zig_##Type); \ | 3203 | zig_extern zig_f##w zig_libc_name_f##w(round)(zig_f##w); \ |
| 3179 | zig_extern zig_##Type zig_libc_name_##Type(trunc)(zig_##Type); \ | 3204 | zig_extern zig_f##w zig_libc_name_f##w(trunc)(zig_f##w); \ |
| 3180 | zig_extern zig_##Type zig_libc_name_##Type(fmod)(zig_##Type, zig_##Type); \ | 3205 | zig_extern zig_f##w zig_libc_name_f##w(fmod)(zig_f##w, zig_f##w); \ |
| 3181 | zig_extern zig_##Type zig_libc_name_##Type(fmin)(zig_##Type, zig_##Type); \ | 3206 | zig_extern zig_f##w zig_libc_name_f##w(fmin)(zig_f##w, zig_f##w); \ |
| 3182 | zig_extern zig_##Type zig_libc_name_##Type(fmax)(zig_##Type, zig_##Type); \ | 3207 | zig_extern zig_f##w zig_libc_name_f##w(fmax)(zig_f##w, zig_f##w); \ |
| 3183 | zig_extern zig_##Type zig_libc_name_##Type(fma)(zig_##Type, zig_##Type, zig_##Type); \ | 3208 | zig_extern zig_f##w zig_libc_name_f##w(fma)(zig_f##w, zig_f##w, zig_f##w); \ |
| 3184 | \ | 3209 | \ |
| 3185 | static inline zig_##Type zig_div_trunc_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 3210 | static inline zig_f##w zig_div_trunc_f##w(zig_f##w lhs, zig_f##w rhs) { \ |
| 3186 | return zig_libc_name_##Type(trunc)(zig_div_##Type(lhs, rhs)); \ | 3211 | return zig_libc_name_f##w(trunc)(zig_div_f##w(lhs, rhs)); \ |
| 3187 | } \ | 3212 | } \ |
| 3188 | \ | 3213 | \ |
| 3189 | static inline zig_##Type zig_div_floor_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 3214 | static inline zig_f##w zig_div_floor_f##w(zig_f##w lhs, zig_f##w rhs) { \ |
| 3190 | return zig_libc_name_##Type(floor)(zig_div_##Type(lhs, rhs)); \ | 3215 | return zig_libc_name_f##w(floor)(zig_div_f##w(lhs, rhs)); \ |
| 3191 | } \ | 3216 | } \ |
| 3192 | \ | 3217 | \ |
| 3193 | static inline zig_##Type zig_mod_##Type(zig_##Type lhs, zig_##Type rhs) { \ | 3218 | static inline zig_f##w zig_mod_f##w(zig_f##w lhs, zig_f##w rhs) { \ |
| 3194 | return zig_sub_##Type(lhs, zig_mul_##Type(zig_div_floor_##Type(lhs, rhs), rhs)); \ | 3219 | return zig_sub_f##w(lhs, zig_mul_f##w(zig_div_floor_f##w(lhs, rhs), rhs)); \ |
| 3195 | } | 3220 | } |
| 3196 | zig_float_builtins(f16) | 3221 | zig_float_builtins(16) |
| 3197 | zig_float_builtins(f32) | 3222 | zig_float_builtins(32) |
| 3198 | zig_float_builtins(f64) | 3223 | zig_float_builtins(64) |
| 3199 | zig_float_builtins(f80) | 3224 | zig_float_builtins(80) |
| 3200 | zig_float_builtins(f128) | 3225 | zig_float_builtins(128) |
| 3201 | | 3226 | |
| 3202 | #if _MSC_VER && (_M_IX86 || _M_X64) | 3227 | #if _MSC_VER && (_M_IX86 || _M_X64) |
| 3203 | | 3228 | |
| 3204 | // TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 | 3229 | // TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 |
| 3205 | | 3230 | |
| 3206 | #define zig_msvc_atomics(ZigType, Type, suffix) \ | 3231 | #define zig_msvc_atomics(ZigType, Type, SigType, suffix) \ |
| 3207 | static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \ | 3232 | static inline bool zig_msvc_cmpxchg_##ZigType(Type volatile* obj, Type* expected, Type desired) { \ |
| 3208 | Type comparand = *expected; \ | 3233 | Type comparand = *expected; \ |
| 3209 | Type initial = _InterlockedCompareExchange##suffix(obj, desired, comparand); \ | 3234 | Type initial = _InterlockedCompareExchange##suffix((SigType volatile*)obj, (SigType)desired, (SigType)comparand); \ |
| 3210 | bool exchanged = initial == comparand; \ | 3235 | bool exchanged = initial == comparand; \ |
| 3211 | if (!exchanged) { \ | 3236 | if (!exchanged) { \ |
| 3212 | *expected = initial; \ | 3237 | *expected = initial; \ |
| ... | @@ -3214,10 +3239,10 @@ zig_float_builtins(f128) | ... | @@ -3214,10 +3239,10 @@ zig_float_builtins(f128) |
| 3214 | return exchanged; \ | 3239 | return exchanged; \ |
| 3215 | } \ | 3240 | } \ |
| 3216 | static inline Type zig_msvc_atomicrmw_xchg_##ZigType(Type volatile* obj, Type value) { \ | 3241 | static inline Type zig_msvc_atomicrmw_xchg_##ZigType(Type volatile* obj, Type value) { \ |
| 3217 | return _InterlockedExchange##suffix(obj, value); \ | 3242 | return _InterlockedExchange##suffix((SigType volatile*)obj, (SigType)value); \ |
| 3218 | } \ | 3243 | } \ |
| 3219 | static inline Type zig_msvc_atomicrmw_add_##ZigType(Type volatile* obj, Type value) { \ | 3244 | static inline Type zig_msvc_atomicrmw_add_##ZigType(Type volatile* obj, Type value) { \ |
| 3220 | return _InterlockedExchangeAdd##suffix(obj, value); \ | 3245 | return _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)value); \ |
| 3221 | } \ | 3246 | } \ |
| 3222 | static inline Type zig_msvc_atomicrmw_sub_##ZigType(Type volatile* obj, Type value) { \ | 3247 | static inline Type zig_msvc_atomicrmw_sub_##ZigType(Type volatile* obj, Type value) { \ |
| 3223 | bool success = false; \ | 3248 | bool success = false; \ |
| ... | @@ -3231,13 +3256,13 @@ zig_float_builtins(f128) | ... | @@ -3231,13 +3256,13 @@ zig_float_builtins(f128) |
| 3231 | return prev; \ | 3256 | return prev; \ |
| 3232 | } \ | 3257 | } \ |
| 3233 | static inline Type zig_msvc_atomicrmw_or_##ZigType(Type volatile* obj, Type value) { \ | 3258 | static inline Type zig_msvc_atomicrmw_or_##ZigType(Type volatile* obj, Type value) { \ |
| 3234 | return _InterlockedOr##suffix(obj, value); \ | 3259 | return _InterlockedOr##suffix((SigType volatile*)obj, (SigType)value); \ |
| 3235 | } \ | 3260 | } \ |
| 3236 | static inline Type zig_msvc_atomicrmw_xor_##ZigType(Type volatile* obj, Type value) { \ | 3261 | static inline Type zig_msvc_atomicrmw_xor_##ZigType(Type volatile* obj, Type value) { \ |
| 3237 | return _InterlockedXor##suffix(obj, value); \ | 3262 | return _InterlockedXor##suffix((SigType volatile*)obj, (SigType)value); \ |
| 3238 | } \ | 3263 | } \ |
| 3239 | static inline Type zig_msvc_atomicrmw_and_##ZigType(Type volatile* obj, Type value) { \ | 3264 | static inline Type zig_msvc_atomicrmw_and_##ZigType(Type volatile* obj, Type value) { \ |
| 3240 | return _InterlockedAnd##suffix(obj, value); \ | 3265 | return _InterlockedAnd##suffix((SigType volatile*)obj, (SigType)value); \ |
| 3241 | } \ | 3266 | } \ |
| 3242 | static inline Type zig_msvc_atomicrmw_nand_##ZigType(Type volatile* obj, Type value) { \ | 3267 | static inline Type zig_msvc_atomicrmw_nand_##ZigType(Type volatile* obj, Type value) { \ |
| 3243 | bool success = false; \ | 3268 | bool success = false; \ |
| ... | @@ -3273,22 +3298,22 @@ zig_float_builtins(f128) | ... | @@ -3273,22 +3298,22 @@ zig_float_builtins(f128) |
| 3273 | return prev; \ | 3298 | return prev; \ |
| 3274 | } \ | 3299 | } \ |
| 3275 | static inline void zig_msvc_atomic_store_##ZigType(Type volatile* obj, Type value) { \ | 3300 | static inline void zig_msvc_atomic_store_##ZigType(Type volatile* obj, Type value) { \ |
| 3276 | _InterlockedExchange##suffix(obj, value); \ | 3301 | (void)_InterlockedExchange##suffix((SigType volatile*)obj, (SigType)value); \ |
| 3277 | } \ | 3302 | } \ |
| 3278 | static inline Type zig_msvc_atomic_load_##ZigType(Type volatile* obj) { \ | 3303 | static inline Type zig_msvc_atomic_load_##ZigType(Type volatile* obj) { \ |
| 3279 | return _InterlockedOr##suffix(obj, 0); \ | 3304 | return _InterlockedExchangeAdd##suffix((SigType volatile*)obj, (SigType)0); \ |
| 3280 | } | 3305 | } |
| 3281 | | 3306 | |
| 3282 | zig_msvc_atomics( u8, uint8_t, 8) | 3307 | zig_msvc_atomics( u8, uint8_t, char, 8) |
| 3283 | zig_msvc_atomics( i8, int8_t, 8) | 3308 | zig_msvc_atomics( i8, int8_t, char, 8) |
| 3284 | zig_msvc_atomics(u16, uint16_t, 16) | 3309 | zig_msvc_atomics(u16, uint16_t, short, 16) |
| 3285 | zig_msvc_atomics(i16, int16_t, 16) | 3310 | zig_msvc_atomics(i16, int16_t, short, 16) |
| 3286 | zig_msvc_atomics(u32, uint32_t, ) | 3311 | zig_msvc_atomics(u32, uint32_t, long, ) |
| 3287 | zig_msvc_atomics(i32, int32_t, ) | 3312 | zig_msvc_atomics(i32, int32_t, long, ) |
| 3288 | | 3313 | |
| 3289 | #if _M_X64 | 3314 | #if _M_X64 |
| 3290 | zig_msvc_atomics(u64, uint64_t, 64) | 3315 | zig_msvc_atomics(u64, uint64_t, __int64, 64) |
| 3291 | zig_msvc_atomics(i64, int64_t, 64) | 3316 | zig_msvc_atomics(i64, int64_t, __int64, 64) |
| 3292 | #endif | 3317 | #endif |
| 3293 | | 3318 | |
| 3294 | #define zig_msvc_flt_atomics(Type, ReprType, suffix) \ | 3319 | #define zig_msvc_flt_atomics(Type, ReprType, suffix) \ |
| ... | @@ -3336,9 +3361,9 @@ zig_msvc_atomics(i64, int64_t, 64) | ... | @@ -3336,9 +3361,9 @@ zig_msvc_atomics(i64, int64_t, 64) |
| 3336 | return expected; \ | 3361 | return expected; \ |
| 3337 | } | 3362 | } |
| 3338 | | 3363 | |
| 3339 | zig_msvc_flt_atomics(f32, uint32_t, ) | 3364 | zig_msvc_flt_atomics(f32, long, ) |
| 3340 | #if _M_X64 | 3365 | #if _M_X64 |
| 3341 | zig_msvc_flt_atomics(f64, uint64_t, 64) | 3366 | zig_msvc_flt_atomics(f64, int64_t, 64) |
| 3342 | #endif | 3367 | #endif |
| 3343 | | 3368 | |
| 3344 | #if _M_IX86 | 3369 | #if _M_IX86 |
| ... | @@ -3349,56 +3374,52 @@ static inline void zig_msvc_atomic_barrier() { | ... | @@ -3349,56 +3374,52 @@ static inline void zig_msvc_atomic_barrier() { |
| 3349 | } | 3374 | } |
| 3350 | } | 3375 | } |
| 3351 | | 3376 | |
| 3352 | static inline void* zig_msvc_atomicrmw_xchg_p32(void** obj, void* arg) { | 3377 | static inline void* zig_msvc_atomicrmw_xchg_p32(void volatile* obj, void* arg) { |
| 3353 | return _InterlockedExchangePointer(obj, arg); | 3378 | return _InterlockedExchangePointer(obj, arg); |
| 3354 | } | 3379 | } |
| 3355 | | 3380 | |
| 3356 | static inline void zig_msvc_atomic_store_p32(void** obj, void* arg) { | 3381 | static inline void zig_msvc_atomic_store_p32(void volatile* obj, void* arg) { |
| 3357 | _InterlockedExchangePointer(obj, arg); | 3382 | (void)_InterlockedExchangePointer(obj, arg); |
| 3358 | } | 3383 | } |
| 3359 | | 3384 | |
| 3360 | static inline void* zig_msvc_atomic_load_p32(void** obj) { | 3385 | static inline void* zig_msvc_atomic_load_p32(void volatile* obj) { |
| 3361 | return (void*)_InterlockedOr((void*)obj, 0); | 3386 | return (void*)_InterlockedExchangeAdd(obj, 0); |
| 3362 | } | 3387 | } |
| 3363 | | 3388 | |
| 3364 | static inline bool zig_msvc_cmpxchg_p32(void** obj, void** expected, void* desired) { | 3389 | static inline bool zig_msvc_cmpxchg_p32(void volatile* obj, void* expected, void* desired) { |
| 3365 | void* comparand = *expected; | 3390 | void* comparand = *(void**)expected; |
| 3366 | void* initial = _InterlockedCompareExchangePointer(obj, desired, comparand); | 3391 | void* initial = _InterlockedCompareExchangePointer(obj, desired, comparand); |
| 3367 | bool exchanged = initial == comparand; | 3392 | bool success = initial == comparand; |
| 3368 | if (!exchanged) { | 3393 | if (!success) *(void**)expected = initial; |
| 3369 | *expected = initial; | 3394 | return success; |
| 3370 | } | | |
| 3371 | return exchanged; | | |
| 3372 | } | 3395 | } |
| 3373 | #else /* _M_IX86 */ | 3396 | #else /* _M_IX86 */ |
| 3374 | static inline void* zig_msvc_atomicrmw_xchg_p64(void** obj, void* arg) { | 3397 | static inline void* zig_msvc_atomicrmw_xchg_p64(void volatile* obj, void* arg) { |
| 3375 | return _InterlockedExchangePointer(obj, arg); | 3398 | return _InterlockedExchangePointer(obj, arg); |
| 3376 | } | 3399 | } |
| 3377 | | 3400 | |
| 3378 | static inline void zig_msvc_atomic_store_p64(void** obj, void* arg) { | 3401 | static inline void zig_msvc_atomic_store_p64(void volatile* obj, void* arg) { |
| 3379 | _InterlockedExchangePointer(obj, arg); | 3402 | (void)_InterlockedExchangePointer(obj, arg); |
| 3380 | } | 3403 | } |
| 3381 | | 3404 | |
| 3382 | static inline void* zig_msvc_atomic_load_p64(void** obj) { | 3405 | static inline void* zig_msvc_atomic_load_p64(void volatile* obj) { |
| 3383 | return (void*)_InterlockedOr64((void*)obj, 0); | 3406 | return (void*)_InterlockedExchangeAdd64(obj, 0); |
| 3384 | } | 3407 | } |
| 3385 | | 3408 | |
| 3386 | static inline bool zig_msvc_cmpxchg_p64(void** obj, void** expected, void* desired) { | 3409 | static inline bool zig_msvc_cmpxchg_p64(void volatile* obj, void* expected, void* desired) { |
| 3387 | void* comparand = *expected; | 3410 | void* comparand = *(void**)expected; |
| 3388 | void* initial = _InterlockedCompareExchangePointer(obj, desired, comparand); | 3411 | void* initial = _InterlockedCompareExchangePointer(obj, desired, comparand); |
| 3389 | bool exchanged = initial == comparand; | 3412 | bool success = initial == comparand; |
| 3390 | if (!exchanged) { | 3413 | if (!success) *(void**)expected = initial; |
| 3391 | *expected = initial; | 3414 | return success; |
| 3392 | } | | |
| 3393 | return exchanged; | | |
| 3394 | } | 3415 | } |
| 3395 | | 3416 | |
| 3396 | static inline bool zig_msvc_cmpxchg_u128(zig_u128 volatile* obj, zig_u128* expected, zig_u128 desired) { | 3417 | static inline bool zig_msvc_cmpxchg_u128(zig_u128 volatile* obj, zig_u128* expected, zig_u128 desired) { |
| 3397 | return _InterlockedCompareExchange128((int64_t volatile*)obj, desired.hi, desired.lo, (int64_t*)expected); | 3418 | return _InterlockedCompareExchange128((__int64 volatile*)obj, (__int64)zig_hi_u128(desired), (__int64)zig_lo_u128(desired), (__int64*)expected); |
| 3398 | } | 3419 | } |
| 3399 | | 3420 | |
| 3400 | static inline bool zig_msvc_cmpxchg_i128(zig_i128 volatile* obj, zig_i128* expected, zig_i128 desired) { | 3421 | static inline bool zig_msvc_cmpxchg_i128(zig_i128 volatile* obj, zig_i128* expected, zig_i128 desired) { |
| 3401 | return _InterlockedCompareExchange128((int64_t volatile*)obj, desired.hi, desired.lo, (uint64_t*)expected); | 3422 | return _InterlockedCompareExchange128((__int64 volatile*)obj, (__int64)zig_hi_i128(desired), (__int64)zig_lo_i128(desired), (__int64*)expected); |
| 3402 | } | 3423 | } |
| 3403 | | 3424 | |
| 3404 | #define zig_msvc_atomics_128xchg(Type) \ | 3425 | #define zig_msvc_atomics_128xchg(Type) \ |
| ... | @@ -3471,16 +3492,16 @@ static inline void* zig_x86_windows_teb(void) { | ... | @@ -3471,16 +3492,16 @@ static inline void* zig_x86_windows_teb(void) { |
| 3471 | #if (_MSC_VER && (_M_IX86 || _M_X64)) || defined(__i386__) || defined(__x86_64__) | 3492 | #if (_MSC_VER && (_M_IX86 || _M_X64)) || defined(__i386__) || defined(__x86_64__) |
| 3472 | | 3493 | |
| 3473 | static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) { | 3494 | static inline void zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) { |
| 3474 | uint32_t cpu_info[4]; | | |
| 3475 | #if _MSC_VER | 3495 | #if _MSC_VER |
| | 3496 | int cpu_info[4]; |
| 3476 | __cpuidex(cpu_info, leaf_id, subid); | 3497 | __cpuidex(cpu_info, leaf_id, subid); |
| | 3498 | *eax = (uint32_t)cpu_info[0]; |
| | 3499 | *ebx = (uint32_t)cpu_info[1]; |
| | 3500 | *ecx = (uint32_t)cpu_info[2]; |
| | 3501 | *edx = (uint32_t)cpu_info[3]; |
| 3477 | #else | 3502 | #else |
| 3478 | __cpuid_count(leaf_id, subid, cpu_info[0], cpu_info[1], cpu_info[2], cpu_info[3]); | 3503 | __cpuid_count(leaf_id, subid, *eax, *ebx, *ecx, *edx); |
| 3479 | #endif | 3504 | #endif |
| 3480 | *eax = cpu_info[0]; | | |
| 3481 | *ebx = cpu_info[1]; | | |
| 3482 | *ecx = cpu_info[2]; | | |
| 3483 | *edx = cpu_info[3]; | | |
| 3484 | } | 3505 | } |
| 3485 | | 3506 | |
| 3486 | static inline uint32_t zig_x86_get_xcr0(void) { | 3507 | static inline uint32_t zig_x86_get_xcr0(void) { |