8761 Commits

Author SHA1 Message Date
Luuk de Gram
10fe24c043 wasm: Implement trunc/wrap for 128 bit integers
This also implments wrapping for arbitrary integer widths between 64 and 128.
`@truncate` was fixed where the wasm types between operand and result differentiated.
We solved this by first casting and then wrapping.
2022-05-18 07:43:33 +02:00
Luuk de Gram
ea073a6b76 wasm: Support 128bit integers for max/min/ctz/clz
`airMaxMin` was slightly updated to automatically support 128 bit integers,
by using the `cmp` function, instead of doing it manually. This makes the function
more maintanable as well.

`ctz` and `clz` now support 128 bit integers, while updating the previous implementation
also.
2022-05-18 07:43:33 +02:00
Luuk de Gram
502f5d8246 wasm: Fix C-ABI for 128 bit integers
We now pass the correct wasm type when the return type is a 128-bit integer.
When a function accepts a 128-bit integer, we now allocate space on the virtual stack
and store both arguments within that space as currently all following instructions
assume the 128 bit integer doesn't live in a local, but the stack.
2022-05-18 07:43:33 +02:00
Luuk de Gram
03a3ea2c15 wasm: 128 bit intcast and binary operations
Also fixes some bugs in 128-bit binary comparisons where we checked
if the lsb were equal, rather than msb.
2022-05-18 07:43:33 +02:00
Luuk de Gram
167d3089ea wasm: Support 128bit add/sub wrapping operands 2022-05-18 07:43:33 +02:00
Luuk de Gram
59d3714b8d wasm: 128bit integer cmp support
This implements support for all compare operations on a 128bit integer,
for both signed and unsigned integers.

The new implementation is almost more efficient as it requires no control-flow,
unlike the old implementation which used a block with breaks.
2022-05-18 07:43:33 +02:00
Luuk de Gram
c0ad0606df wasm: Support 128bit integer coercion
The Wasm backend now correctly supports coercing a smaller integer
into a 128bit integer. Regardless of signedness.
2022-05-18 07:43:33 +02:00
Andrew Kelley
df74c45fa7
Merge pull request #11501 from Vexu/stage2-err-return-trace
stage2: error return traces
2022-05-17 03:27:03 -04:00
Jakub Konka
3fde14035b
Merge pull request #11658 from koachan/sparc64-codegen
stage2: sparc64: Make basic test harness run
2022-05-17 09:20:02 +02:00
Veikka Tuominen
0a7f3be42e Sema: improve index out of bounds panic message 2022-05-16 17:42:51 -07:00
Veikka Tuominen
ab4ec35b8b stage2: add runtime safety for unwrapping error 2022-05-16 17:42:51 -07:00
Veikka Tuominen
e369752430 Sema: do not call returnError when returning payload of error union 2022-05-16 17:42:51 -07:00
Veikka Tuominen
53a5aee3b3 stage2: enable error return tracing on llvm backend 2022-05-16 17:42:51 -07:00
Veikka Tuominen
66c3988e5e stage2: disable error return tracing on unsupported targets 2022-05-16 17:42:51 -07:00
Veikka Tuominen
eee8fffec7 stage2: implement error return traces 2022-05-16 17:42:51 -07:00
Andrew Kelley
f33b3fc3ea zig.h: add casts for overflow arithmetic operations
This avoids the following error:

```
error: incompatible pointer types passing 'int64_t *' (aka 'long long *') to parameter of type 'long *'
    overflow = __builtin_saddl_overflow(lhs, rhs, res);
                                                  ^~~
```

My previous understanding was that this error would not occur because
prior to this line we check that int64_t is equivalent to long, like
this:

```c
```

However, it appears that this is still a warning in C if int64_t is
primarily aliased to `long long`, even though `long` and `long long` are
the same thing.
2022-05-16 14:30:28 -07:00
Jakub Konka
7f96ca101a arm: sub_with_overflow should always track V flag 2022-05-16 13:55:26 -07:00
Jakub Konka
852c820841 aarch64: sub_with_overflow should always track V flag 2022-05-16 13:55:26 -07:00
Andrew Kelley
a84be7e988 zig.h: improve overflow shl
* zig_addo_u128: fix type-o
 * redo the shift-left overflow inline functions. no need to depend on
   compiler-rt.
2022-05-16 13:55:26 -07:00
Luuk de Gram
160aa4c11d wasm: Improve shl_with_overflow
This re-implements the shl_with_overflow operation from scratch,
making it a lot more robust and outputs the equal code to the LLVM backend.
2022-05-16 13:55:26 -07:00
Luuk de Gram
0a2d3d4155 wasm: Improve overflow add/sub for ints <= 64bits
The implementation for add_with_overflow and sub_with_overflow is now a lot
more robust and takes account for signed integers and arbitrary integer bitsizes.
The final output is equal to that of the LLVM backend.
2022-05-16 13:55:26 -07:00
Jakub Konka
b94d165b69 x64: fix capacity prealloc limit in lowerToMrEnc helper 2022-05-16 13:55:26 -07:00
Andrew Kelley
03ed0f0d28 C backend: implement overflow arithmetic
Most of the work here was additions to zig.h. The lowering code is
mainly responsible for calling the correct function name depending on
the operand type.

Some of the compiler-rt calls here are not implemented yet and are
non-standard symbols due to the C programming language not needing them.

After this commit, the behavior tests with -ofmt=c are passing again.
2022-05-16 13:55:26 -07:00
William Sengir
a5ea22d069 LLVM: correctly pad result tuple of airOverflow 2022-05-16 13:55:26 -07:00
William Sengir
afc714d5e5 stage2: implement runtime safety checks for shl_exact 2022-05-16 13:55:26 -07:00
William Sengir
c2980f332e Sema: implement integer overflow safety for add, sub, mul 2022-05-16 13:55:26 -07:00
William Sengir
eb06c78a8a Sema: vectorize overflow arithmetic 2022-05-16 13:55:26 -07:00
William Sengir
86a928ce61 stage2: perform comptime vectorization of *_with_overflow in Value 2022-05-16 13:55:26 -07:00
William Sengir
e8117bab6f stage2: clean up creation of boolean Values 2022-05-16 13:55:26 -07:00
William Sengir
6b5c87957b stage2: handle vectors in Value.intFitsInType 2022-05-16 13:55:26 -07:00
William Sengir
ca1ab38d3a stage2: add global Type constant for u1 2022-05-16 13:55:26 -07:00
William Sengir
c2cb9b7cad stage2: vectorize shl_with_overflow in LLVM backend 2022-05-16 13:55:26 -07:00
William Sengir
c641fb8f05 stage2: fix {add,sub,mul}_with_overflow vectorization in LLVM backend 2022-05-16 13:55:26 -07:00
Koakuma
b618dbdf69 stage2: sparc64: Implement SPARCv9 mulx 2022-05-16 23:30:54 +07:00
Koakuma
7245aad689 stage2: sparc64: Implement airBinOp for addition 2022-05-16 23:30:54 +07:00
Koakuma
67a1fedf84 stage2: sparc64: Implement airUnwrapErrErr 2022-05-16 23:30:54 +07:00
Koakuma
77eef33c04 stage2: sparc64: Implement airStructFieldPtrIndex 2022-05-16 23:30:54 +07:00
Koakuma
26116211ec stage2: sparc64: Implement inline memcpy for genSetStack 2022-05-16 23:30:54 +07:00
Koakuma
7822426ff2 stage2: sparc64: Implement airSliceElemVal 2022-05-16 23:30:54 +07:00
Koakuma
ccf438e4de stage2: sparc64: Replace freezeRegs with RegisterLock 2022-05-16 23:30:54 +07:00
Koakuma
26e3d36d74 stage2: sparc64: Implement airSliceLen 2022-05-16 23:30:54 +07:00
Koakuma
8ea80fdf7a stage2: sparc64: Implement airLoop 2022-05-16 23:30:47 +07:00
Koakuma
e4a725c597 stage2: sparc64: Implement airBitCast 2022-05-16 23:17:11 +07:00
Koakuma
0c8ce9ed9d stage2: sparc64: Implement airCmp 2022-05-16 23:17:11 +07:00
Koakuma
ae2d6b7eea stage2: sparc64: Add BPr support for airCondBr 2022-05-16 23:17:11 +07:00
Koakuma
e057ff2496 stage2: sparc64: Implement SPARCv9 bpr 2022-05-16 23:17:11 +07:00
Koakuma
8f8853cd4f stage2: sparc64: Implement airLoad/airStore 2022-05-16 23:17:06 +07:00
Koakuma
0b54649cac stage2: sparc64: Implement error value generation 2022-05-16 22:48:49 +07:00
Koakuma
3ab6634370 stage2: sparc64: Implement airAlloc 2022-05-16 22:48:49 +07:00
Koakuma
339b0517b3 stage2: sparc64: Implement SPARCv9 bpcc 2022-05-16 22:48:49 +07:00