141 Commits

Author SHA1 Message Date
Andrew Kelley
5bd69c655d zig.h: support GCC compilers that lack __has_builtin 2023-01-03 03:21:53 -05:00
kcbanner
45a55df12c cbe: fixups for -Wstrict-prototypes 2023-01-02 13:56:32 -07:00
kcbanner
cac652f81b cbe: fixup cpuid on non-msvc 2023-01-02 13:56:17 -07:00
kcbanner
ccf0ab0ef6 cbe: use callconv(.C) for zig.g stub functions, use zig.h function for windows teb instead of syscall 2023-01-02 13:56:11 -07:00
kcbanner
6cab3c304e cbe: be more explicit about x86 special cases 2023-01-02 13:55:45 -07:00
kcbanner
676e4f3824 cbe: changes to get zig2.c compiling under msvc
- Add cpuid / getXCR0 functions for the cbe to use instead of asm blocks
- Don't cast between 128 bit types during truncation
- Fixup truncation to use functions for shifts / adds
- Fixup float casts for undefined values
- Add test for 128 bit integer truncation
2023-01-01 16:44:29 -05:00
kcbanner
f07d33f54b cbe: fixes for compiling zig2.c under msvc
- add zig_mul_i128
- render slice structs in static initializers without casts / c99 style init
- add negative numbers and u128 to 128-bit multiply test
2023-01-01 16:44:29 -05:00
kcbanner
55c3551bef cbe: fixup 64 bit float atomics 2023-01-01 16:44:29 -05:00
kcbanner
7a20e7589e stage1: update zig1.wasm 2023-01-01 16:44:29 -05:00
kcbanner
5d59799641 cbe: add msvc flt atomics, re-enable test 2023-01-01 16:44:29 -05:00
kcbanner
6ed049fe36 cbe: all behaviour tests now pass on msvc
- Fix zig_clz_u128 not respecting the bits argument. This was crashing the compile-rt addxf3 tests with the cbe
- Instead of redering a negation for negative 128 bit int literals, render the literal as twos complement. This allows
rendering int representations of floats correctly (specifically f80).
2023-01-01 16:44:29 -05:00
kcbanner
7b999dae73 cbe: special float macros passthrough to builtins if available, but fallback to conversion from repr if not 2023-01-01 16:44:29 -05:00
kcbanner
5470708a89 cbe: implement 128 bit atomic operations with cmpxchg loops
- Enable 128 bit atomic int tests for the cbe only
2023-01-01 16:44:29 -05:00
kcbanner
d63b8d21b3 cbe: implement missing atomic builtings using cmpxchg loops 2023-01-01 16:44:29 -05:00
kcbanner
047fe58a53 cbe: fix msvc cmpxchg implementations 2023-01-01 16:44:28 -05:00
kcbanner
4f8f7b749c cbe: fixup incorrect bits value in 128 bit add/sub 2023-01-01 16:44:28 -05:00
kcbanner
b6f0af57a2 cbe: fix shl/shr
- zig_shr_u128 was actually shifting left
- handle shifting by zero explicitly (shifting u64 by 64 is undefined behaviour)
2023-01-01 16:44:28 -05:00
kcbanner
2d34477dbb cbe: msvc atomics
- Implement most atomic operations for msvc
- Disable "atomicrmw with floats" test for cbe
2023-01-01 16:44:28 -05:00
kcbanner
f155ef2f4b cbe: implementing 128 bit math functions for !zig_has_int128
- Add addo_(i|u)128, subo_(i|u)128, mulo_(i|u)128,
- Move zig_shlo_(i|u)128 into common code
- Fixup zig_shls_i128 passing rhs as 128
2023-01-01 16:44:28 -05:00
kcbanner
fbd3459a52 compiler_rt: fixup divti3 and fixunshfti 2023-01-01 16:44:28 -05:00
kcbanner
7fb3683c32 cbe: more msvc compatibility work
- Add .StaticInitializer to ValueRenderLocation to indicate that the emitted values
must be constant expressions (no function calls, struct casting).
- Add new path for special float types (nan, inf) that works in constant expressions
- Implement windows.teb() using a syscall for .stage2_c because x64 MSVC
doesn't support any kind of inline asm
2023-01-01 16:44:28 -05:00
kcbanner
7f3bc45772 cbe: nan builtins on msvc, fixup C2099 errors in static initializers
- Map the __builtin_nan(f|l)? functions to nan(f|l)? on msvc
- MSVC throws C2099 when initializing a struct with cast syntax
in a global initializer.  Added zig_as_init_  to handle this case,
 and generate it only in static initializers for > 64 bit ints.
- Change float initialization to emit the integer representation
in global initializers to avoid C2099 caused by calling nan.
2023-01-01 16:44:28 -05:00
kcbanner
c675a8e35c cbe: handle msvc not supporting long double 2023-01-01 16:44:28 -05:00
kcbanner
e836477ccf cbe: fixup f80 casting on msvc 2023-01-01 16:44:27 -05:00
kcbanner
7225a0043e cbe: handle msvc struct casting quirk
MSVC can't explicitly cast a struct to a typedef of itself (ie. f128 to i128). Added a
set of macros to handle float casting, and to not produce a cast for this specific
case on MSVC. A better approach would probably be to know if the cast is redundant
and not do it.
2023-01-01 16:44:27 -05:00
kcbanner
a43fdc1620 cbe: first set of changes for msvc compatibility
- Forward declare int builtins, so the definitions aren't assumed incorrectly
- Add define to handle MSVC not support static const in function parameter array lengths
- Fixup several spots where int128 support was assumed.
- Support zig_align
- Support zig_export
- Stub out some missing non-builtin functions
- Added StringLiteral to automatically split string literals when they get to 16380 in size,
which is the maxmimum pre-concatenation string literal size on MSVC.
2023-01-01 16:44:27 -05:00
Jacob Young
a2854f71dc zig.h: fix and add builtin fallbacks 2022-12-09 13:40:55 -05:00
Andrew Kelley
ee2fb5b2ab zig.h: fix f16 has builtin check 2022-12-06 12:27:28 -07:00
Jacob Young
4a701490d4 zig.h: avoid using _Float16 when __builtin_inff16 isn't available 2022-12-06 12:15:05 -07:00
Jacob Young
bd4a1f38fa zig.h: fix shlo breakage on smaller bitwidths 2022-12-06 12:15:05 -07:00
Jacob Young
fad2142ecf zig.h: fix shift ub for a shlo by 0 2022-12-06 12:15:04 -07:00
Jacob Young
6d1292552e cbe: implement function alignment 2022-12-03 08:40:08 -05:00
Jacob Young
7fb6eb3d14 cbe: implement multiple exports of a symbols 2022-12-03 08:21:03 -05:00
Andrew Kelley
29e8e67a7e CBE: use bool, true, false, instead of zig_ prefixes
In general the C backend should lower to human-maintainable C code
whenever possible. Directly using C types that one would use when
writing C code is one part of the strategy.

The concern with including stdint.h is C89 compatibility. Well, we can
just check the C std lib version before deciding to include that header.
2022-12-02 16:12:49 -07:00
Andrew Kelley
665eba93c1 CBE: eliminate zig_void
C void is perfectly fine.
2022-12-02 00:46:27 -05:00
Jacob Young
cf7a4de7f1 zig.h: fix disastrous typo 2022-11-30 15:48:44 -07:00
Andrew Kelley
4ec27a4e25 C backend: implement vector reduce and overflow intrinsics 2022-11-22 23:33:58 -07:00
Andrew Kelley
0b28133ec2 zig.h: avoid binary literals
gcc -pedantic complains about these
2022-11-22 22:33:16 -07:00
Jacob Young
b5b507a742 zig.h: match float comparison signatures from compiler rt 2022-11-15 23:33:48 -05:00
Andrew Kelley
20e8c2df4e zig.h: remove redundant definition of u16/i16 2022-11-13 16:50:20 -07:00
Andrew Kelley
77e7d97725 C backend: improve ergonomics of zig.h a little bit
Partially implements #13528. Enough to unblock the wasi-bootstrap
branch.
2022-11-13 16:50:16 -07:00