| ... | @@ -1749,11 +1749,27 @@ static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, zig_u8 bits) { | ... | @@ -1749,11 +1749,27 @@ static inline zig_i128 zig_bit_reverse_i128(zig_i128 val, zig_u8 bits) { |
| 1749 | #define __builtin_infl() zig_msvc_flt_infl | 1749 | #define __builtin_infl() zig_msvc_flt_infl |
| 1750 | #endif | 1750 | #endif |
| 1751 | | 1751 | |
| | 1752 | #define zig_has_float_builtins (zig_has_builtin(nan) && zig_has_builtin(nans) && zig_has_builtin(inf)) |
| | 1753 | #if zig_has_float_builtins |
| | 1754 | #define zig_as_special_f16(sign, name, arg, repr) sign zig_as_f16(__builtin_##name, )(arg) |
| | 1755 | #define zig_as_special_f32(sign, name, arg, repr) sign zig_as_f32(__builtin_##name, )(arg) |
| | 1756 | #define zig_as_special_f64(sign, name, arg, repr) sign zig_as_f64(__builtin_##name, )(arg) |
| | 1757 | #define zig_as_special_f80(sign, name, arg, repr) sign zig_as_f80(__builtin_##name, )(arg) |
| | 1758 | #define zig_as_special_f128(sign, name, arg, repr) sign zig_as_f128(__builtin_##name, )(arg) |
| | 1759 | #define zig_as_special_c_longdouble(sign, name, arg, repr) sign zig_as_c_longdouble(__builtin_##name, )(arg) |
| | 1760 | #else |
| | 1761 | #define zig_as_special_f16(sign, name, arg, repr) zig_float_from_repr_f16(repr) |
| | 1762 | #define zig_as_special_f32(sign, name, arg, repr) zig_float_from_repr_f32(repr) |
| | 1763 | #define zig_as_special_f64(sign, name, arg, repr) zig_float_from_repr_f64(repr) |
| | 1764 | #define zig_as_special_f80(sign, name, arg, repr) zig_float_from_repr_f80(repr) |
| | 1765 | #define zig_as_special_f128(sign, name, arg, repr) zig_float_from_repr_f128(repr) |
| | 1766 | #define zig_as_special_c_longdouble(sign, name, arg, repr) zig_float_from_repr_c_longdouble(repr) |
| | 1767 | #endif |
| | 1768 | |
| 1752 | #define zig_has_f16 1 | 1769 | #define zig_has_f16 1 |
| 1753 | #define zig_bitSizeOf_f16 16 | 1770 | #define zig_bitSizeOf_f16 16 |
| 1754 | #define zig_libc_name_f16(name) __##name##h | 1771 | #define zig_libc_name_f16(name) __##name##h |
| 1755 | #define zig_as_special_constant_f16(sign, name, arg, repr) zig_as_special_f16(sign, name, arg, repr) | 1772 | #define zig_as_special_constant_f16(sign, name, arg, repr) zig_as_special_f16(sign, name, arg, repr) |
| 1756 | #define zig_as_special_f16(sign, name, arg, repr) sign zig_as_f16(__builtin_##name, )(arg) | | |
| 1757 | #if FLT_MANT_DIG == 11 | 1773 | #if FLT_MANT_DIG == 11 |
| 1758 | typedef float zig_f16; | 1774 | typedef float zig_f16; |
| 1759 | #define zig_as_f16(fp, repr) fp##f | 1775 | #define zig_as_f16(fp, repr) fp##f |
| ... | @@ -1790,7 +1806,6 @@ typedef zig_i16 zig_f16; | ... | @@ -1790,7 +1806,6 @@ typedef zig_i16 zig_f16; |
| 1790 | #else | 1806 | #else |
| 1791 | #define zig_as_special_constant_f32(sign, name, arg, repr) zig_as_special_f32(sign, name, arg, repr) | 1807 | #define zig_as_special_constant_f32(sign, name, arg, repr) zig_as_special_f32(sign, name, arg, repr) |
| 1792 | #endif | 1808 | #endif |
| 1793 | #define zig_as_special_f32(sign, name, arg, repr) sign zig_as_f32(__builtin_##name, )(arg) | | |
| 1794 | #if FLT_MANT_DIG == 24 | 1809 | #if FLT_MANT_DIG == 24 |
| 1795 | typedef float zig_f32; | 1810 | typedef float zig_f32; |
| 1796 | #define zig_as_f32(fp, repr) fp##f | 1811 | #define zig_as_f32(fp, repr) fp##f |
| ... | @@ -1824,7 +1839,6 @@ typedef zig_i32 zig_f32; | ... | @@ -1824,7 +1839,6 @@ typedef zig_i32 zig_f32; |
| 1824 | #else | 1839 | #else |
| 1825 | #define zig_as_special_constant_f64(sign, name, arg, repr) zig_as_special_f64(sign, name, arg, repr) | 1840 | #define zig_as_special_constant_f64(sign, name, arg, repr) zig_as_special_f64(sign, name, arg, repr) |
| 1826 | #endif | 1841 | #endif |
| 1827 | #define zig_as_special_f64(sign, name, arg, repr) sign zig_as_f64(__builtin_##name, )(arg) | | |
| 1828 | #if FLT_MANT_DIG == 53 | 1842 | #if FLT_MANT_DIG == 53 |
| 1829 | typedef float zig_f64; | 1843 | typedef float zig_f64; |
| 1830 | #define zig_as_f64(fp, repr) fp##f | 1844 | #define zig_as_f64(fp, repr) fp##f |
| ... | @@ -1857,7 +1871,6 @@ typedef zig_i64 zig_f64; | ... | @@ -1857,7 +1871,6 @@ typedef zig_i64 zig_f64; |
| 1857 | #define zig_bitSizeOf_f80 80 | 1871 | #define zig_bitSizeOf_f80 80 |
| 1858 | #define zig_libc_name_f80(name) __##name##x | 1872 | #define zig_libc_name_f80(name) __##name##x |
| 1859 | #define zig_as_special_constant_f80(sign, name, arg, repr) zig_as_special_f80(sign, name, arg, repr) | 1873 | #define zig_as_special_constant_f80(sign, name, arg, repr) zig_as_special_f80(sign, name, arg, repr) |
| 1860 | #define zig_as_special_f80(sign, name, arg, repr) sign zig_as_f80(__builtin_##name, )(arg) | | |
| 1861 | #if FLT_MANT_DIG == 64 | 1874 | #if FLT_MANT_DIG == 64 |
| 1862 | typedef float zig_f80; | 1875 | typedef float zig_f80; |
| 1863 | #define zig_as_f80(fp, repr) fp##f | 1876 | #define zig_as_f80(fp, repr) fp##f |
| ... | @@ -1893,7 +1906,6 @@ typedef zig_i128 zig_f80; | ... | @@ -1893,7 +1906,6 @@ typedef zig_i128 zig_f80; |
| 1893 | #define zig_bitSizeOf_f128 128 | 1906 | #define zig_bitSizeOf_f128 128 |
| 1894 | #define zig_libc_name_f128(name) name##q | 1907 | #define zig_libc_name_f128(name) name##q |
| 1895 | #define zig_as_special_constant_f128(sign, name, arg, repr) zig_as_special_f128(sign, name, arg, repr) | 1908 | #define zig_as_special_constant_f128(sign, name, arg, repr) zig_as_special_f128(sign, name, arg, repr) |
| 1896 | #define zig_as_special_f128(sign, name, arg, repr) sign zig_as_f128(__builtin_##name, )(arg) | | |
| 1897 | #if FLT_MANT_DIG == 113 | 1909 | #if FLT_MANT_DIG == 113 |
| 1898 | typedef float zig_f128; | 1910 | typedef float zig_f128; |
| 1899 | #define zig_as_f128(fp, repr) fp##f | 1911 | #define zig_as_f128(fp, repr) fp##f |
| ... | @@ -1930,8 +1942,7 @@ typedef zig_i128 zig_f128; | ... | @@ -1930,8 +1942,7 @@ typedef zig_i128 zig_f128; |
| 1930 | #define zig_has_c_longdouble 1 | 1942 | #define zig_has_c_longdouble 1 |
| 1931 | #define zig_libc_name_c_longdouble(name) name##l | 1943 | #define zig_libc_name_c_longdouble(name) name##l |
| 1932 | #define zig_as_special_constant_c_longdouble(sign, name, arg, repr) zig_as_special_c_longdouble(sign, name, arg, repr) | 1944 | #define zig_as_special_constant_c_longdouble(sign, name, arg, repr) zig_as_special_c_longdouble(sign, name, arg, repr) |
| 1933 | #define zig_as_special_c_longdouble(sign, name, arg, repr) sign __builtin_##name##l(arg) | 1945 | #if !_MSC_VER // TODO: Is there a better way to detect long double == double on msvc? |
| 1934 | #if !_MSC_VER // TODO: Is there a better way to detect this is just double? | | |
| 1935 | typedef long double zig_c_longdouble; | 1946 | typedef long double zig_c_longdouble; |
| 1936 | #define zig_as_c_longdouble(fp, repr) fp##l | 1947 | #define zig_as_c_longdouble(fp, repr) fp##l |
| 1937 | #else | 1948 | #else |
| ... | @@ -1947,6 +1958,87 @@ typedef zig_i128 zig_c_longdouble; | ... | @@ -1947,6 +1958,87 @@ typedef zig_i128 zig_c_longdouble; |
| 1947 | #define zig_as_special_constant_c_longdouble(sign, name, arg, repr) repr | 1958 | #define zig_as_special_constant_c_longdouble(sign, name, arg, repr) repr |
| 1948 | #endif | 1959 | #endif |
| 1949 | | 1960 | |
| | 1961 | #if !zig_has_float_builtins |
| | 1962 | #define zig_float_from_repr(Type, ReprType) \ |
| | 1963 | static inline zig_##Type zig_float_from_repr_##Type(zig_##ReprType repr) { \ |
| | 1964 | return *((zig_##Type*)&repr); \ |
| | 1965 | } |
| | 1966 | |
| | 1967 | zig_float_from_repr(f16, u16) |
| | 1968 | zig_float_from_repr(f32, u32) |
| | 1969 | zig_float_from_repr(f64, u64) |
| | 1970 | zig_float_from_repr(f80, u128) |
| | 1971 | zig_float_from_repr(f128, u128) |
| | 1972 | zig_float_from_repr(c_longdouble, u128) |
| | 1973 | #endif |
| | 1974 | |
| | 1975 | /* #define zig_float_from_repr(Type) *((zig_##Type*)&repr) */ |
| | 1976 | |
| | 1977 | /* #define zig_float_inf_builtin_0(Type, ReprType) \ */ |
| | 1978 | /* static inline zig_##Type zig_as_special_inf_##Type(zig_##ReprType repr) { \ */ |
| | 1979 | /* return zig_float_from_repr(Type); \ */ |
| | 1980 | /* } */ |
| | 1981 | /* #define zig_float_inf_builtin_1(Type, ReprType) \ */ |
| | 1982 | /* static inline zig_##Type zig_as_special_inf_##Type(zig_##ReprType repr) { \ */ |
| | 1983 | /* return __builtin_inf(); \ */ |
| | 1984 | /* } */ |
| | 1985 | /* #define zig_float_nan_builtin_0(Type, ReprType) \ */ |
| | 1986 | /* static inline zig_##Type zig_as_special_nan_##Type(const char* arg, zig_##ReprType repr) { \ */ |
| | 1987 | /* return zig_float_from_repr(Type); \ */ |
| | 1988 | /* } */ |
| | 1989 | /* #define zig_float_nan_builtin_1(Type, ReprType) \ */ |
| | 1990 | /* static inline zig_##Type zig_as_special_nan_##Type(const char* arg, zig_##ReprType repr) { \ */ |
| | 1991 | /* return __builtin_nan(arg); \ */ |
| | 1992 | /* } */ |
| | 1993 | /* #define zig_float_nans_builtin_0(Type, ReprType) \ */ |
| | 1994 | /* static inline zig_##Type zig_as_special_nans_##Type(const char* arg, zig_##ReprType repr) { \ */ |
| | 1995 | /* return zig_float_from_repr(Type); \ */ |
| | 1996 | /* } */ |
| | 1997 | /* #define zig_float_nans_builtin_1(Type, ReprType) \ */ |
| | 1998 | /* static inline zig_##Type zig_as_special_nans_##Type(const char* arg, zig_##ReprType repr) { \ */ |
| | 1999 | /* return __builtin_nans(arg); \ */ |
| | 2000 | /* } */ |
| | 2001 | |
| | 2002 | /* #define zig_float_special_builtins(Type, ReprType) \ */ |
| | 2003 | /* zig_expand_concat(zig_float_inf_builtin_, zig_has_builtin(inf))(Type, ReprType) \ */ |
| | 2004 | /* zig_expand_concat(zig_float_nan_builtin_, zig_has_builtin(nan))(Type, ReprType) \ */ |
| | 2005 | /* zig_expand_concat(zig_float_nans_builtin_, zig_has_builtin(nans))(Type, ReprType) */ |
| | 2006 | |
| | 2007 | /* #if zig_has_builtin(nan) */ |
| | 2008 | /* #define zig_as_special_nan(arg, repr) __builtin_nan(arg); */ |
| | 2009 | /* #define zig_as_special_nan_f16(arg, repr) __builtin_nan(arg); */ |
| | 2010 | /* #define zig_as_special_nan_f32(arg, repr) __builtin_nan(arg); */ |
| | 2011 | /* #define zig_as_special_nan_f64(arg, repr) __builtin_nan(arg); */ |
| | 2012 | /* #define zig_as_special_nan_f80(arg, repr) __builtin_nan(arg); */ |
| | 2013 | /* #define zig_as_special_nan_f128(arg, repr) __builtin_nan(arg); */ |
| | 2014 | /* #else */ |
| | 2015 | /* zig_float_special_builtins(); */ |
| | 2016 | /* #endif */ |
| | 2017 | |
| | 2018 | /* #if zig_has_f16 */ |
| | 2019 | /* zig_float_special_builtins(f16, u16) */ |
| | 2020 | /* #endif */ |
| | 2021 | |
| | 2022 | /* #if zig_has_f32 */ |
| | 2023 | /* zig_float_special_builtins(f32, u32) */ |
| | 2024 | /* #endif */ |
| | 2025 | |
| | 2026 | /* #if zig_has_f64 */ |
| | 2027 | /* zig_float_special_builtins(f64, u64) */ |
| | 2028 | /* #endif */ |
| | 2029 | |
| | 2030 | /* #if zig_has_f80 */ |
| | 2031 | /* zig_float_special_builtins(f80, u128) */ |
| | 2032 | /* #endif */ |
| | 2033 | |
| | 2034 | /* #if zig_has_f128 */ |
| | 2035 | /* zig_float_special_builtins(f128, u128) */ |
| | 2036 | /* #endif */ |
| | 2037 | |
| | 2038 | /* #if zig_has_c_longdouble */ |
| | 2039 | /* zig_float_special_builtins(c_longdouble, u128) */ |
| | 2040 | /* #endif */ |
| | 2041 | |
| 1950 | #if zig_bitSizeOf_c_longdouble == 16 | 2042 | #if zig_bitSizeOf_c_longdouble == 16 |
| 1951 | #define zig_compiler_rt_abbrev_c_longdouble zig_compiler_rt_abbrev_f16 | 2043 | #define zig_compiler_rt_abbrev_c_longdouble zig_compiler_rt_abbrev_f16 |
| 1952 | #elif zig_bitSizeOf_c_longdouble == 32 | 2044 | #elif zig_bitSizeOf_c_longdouble == 32 |
| ... | @@ -2100,7 +2192,7 @@ zig_float_builtins(c_longdouble) | ... | @@ -2100,7 +2192,7 @@ zig_float_builtins(c_longdouble) |
| 2100 | #if _MSC_VER && (_M_IX86 || _M_X64) | 2192 | #if _MSC_VER && (_M_IX86 || _M_X64) |
| 2101 | #include <intrin.h> | 2193 | #include <intrin.h> |
| 2102 | | 2194 | |
| 2103 | // TODO: zig_msvc_atomic_load should just load 32 bit without interlocked on x86, and just load 64 bit without interlocked on x64 | 2195 | // TODO: zig_msvc_atomic_load should load 32 bit without interlocked on x86, and load 64 bit without interlocked on x64 |
| 2104 | | 2196 | |
| 2105 | #define zig_msvc_atomics(Type, suffix) \ | 2197 | #define zig_msvc_atomics(Type, suffix) \ |
| 2106 | static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \ | 2198 | static inline bool zig_msvc_cmpxchg_##Type(zig_##Type volatile* obj, zig_##Type* expected, zig_##Type desired) { \ |