4590 Commits

Author SHA1 Message Date
Robin Voetter
1e09157b53 big ints: Fix set(signed int minimum) panic 2021-10-16 11:32:05 +02:00
Robin Voetter
efa4f76c8b big ints: Saturating left shift + tests 2021-10-16 11:32:05 +02:00
Andrew Kelley
0536c25578 std.os: another workaround for stage1 @minimum behavior
This is a companion commit to 0915d24e6b34b67d358c1309e9bc8516416f1008.
2021-10-15 14:43:57 -07:00
Andrew Kelley
0915d24e6b std.os: add workarounds for stage1 @minimum implementation 2021-10-15 11:46:47 -07:00
Miles Alan
411e9ca4ad
Fix bug where std.math.asinh64 doesn't respect signedness for negative values (#9940)
* std: Correct math.asinh64 to return correct signedness for negative values

* std: Add tests for negative values for math.asinh32 and math.asinh64
2021-10-15 13:55:40 -04:00
Sizhe Zhao
f3ab092f67
std.os.windows: Fix typo (#9951) 2021-10-15 14:44:05 +02:00
Andrew Kelley
55eea3b045 stage2: implement @minimum and @maximum, including vectors
* std.os: take advantage of `@minimum`. It's probably time to
   deprecate `std.min` and `std.max`.
 * New AIR instructions: min and max
 * Introduce SIMD vector support to stage2
 * Add `@Type` support for vectors
 * Sema: add `checkSimdBinOp` which can be re-used for other arithmatic
   operators that want to support vectors.
 * Implement coercion from vectors to arrays.
   - In backends this is handled with bitcast for vector to array,
     however maybe we want to reduce the amount of branching by
     introducing an explicit AIR instruction for it in the future.
 * LLVM backend: implement lowering vector types
 * Sema: Implement `slice.ptr` at comptime
 * Value: improve `numberMin` and `numberMax` to support floats in
   addition to integers, and make them behave properly in the presence
   of NaN.
2021-10-14 21:17:30 -07:00
Andrew Kelley
b0f80ef0d5 stage2: remove use of builtin.stage2_arch workaround
The LLVM backend no longer needs this hack! However, the other backends
still do. So there are still some traces of this workaround in use for now.
2021-10-13 18:43:43 -07:00
Sizhe Zhao
a5ecffa461 rand: remove workaround for issue #1770 2021-10-10 16:25:12 +00:00
Koakuma
d7a5b12f94 SPARCv9: fix timeval definition 2021-10-10 09:13:18 +07:00
Koakuma
569802160e Linux: fix socket constants for SPARCv9 2021-10-10 09:13:18 +07:00
Koakuma
834202bf98 SPARCv9: Fix freeAndExit implementation
This fixes the wrong branch target and register check.
(https://github.com/ziglang/zig/issues/9801)
2021-10-10 09:13:17 +07:00
Lee Cannon
8e1aa72c69
add test step to build.zig generated by init-exe (#9919)
* added simple test

* Update lib/std/special/init-exe/build.zig

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2021-10-09 00:17:49 -07:00
tgschultz
526191bfaf Better documentation, use of len field instead of function, @bitSizeOf instead of meta.bitCout 2021-10-09 03:15:34 -04:00
Andrew Kelley
9ed599b4e3 stage2: LLVM backend: miscompilation fixes
* work around a stage1 miscompilation leading to the wrong integer
   comparison predicate being emitted.
 * fix the bug of not annotating callsites with the calling convention
   of the callee, leading to undefined behavior.
 * add the `nobuiltin` attribute when building freestanding libc or
   compiler_rt libraries to prevent e.g. memcpy from being "optimized"
   into a call to itself.
 * compiler-rt: change a call to be comptime to make the generated LLVM
   IR simpler and easier to study.

I still can't enable the widening tests due to the compiler-rt compare
function being miscompiled in some not-yet-diagnosed way.
2021-10-05 20:36:04 -07:00
Andrew Kelley
01ad6c0b02 freestanding libc: don't rely on compiler_rt symbols we don't have yet
Previous commit made fmal depend on __extendxftf2 and __trunctfxf2 but
we don't have implementations of those yet.
2021-10-05 18:19:31 -07:00
Andrew Kelley
5518a0aff2 freestanding libc: export fmal
libc requires this to use `long double` which is sometimes the same as
f128, sometimes not.

Also for an unknown reason, aarch64 is getting an invalid result for the
`@mulAdd` behavior test for f128. See #9900.
2021-10-05 16:56:46 -07:00
Andrew Kelley
4ee91bb8a8 stage1: work around LLVM's buggy fma lowering
* move fmaq from freestanding libc to compiler_rt, unconditionally
   exported weak_odr.
 * stage1: add fmaf, fmal, fmaq as symbols that compiler-rt might
   generate calls to.
 * stage1: lower `@mulAdd` directly to a call to `fmaq` instead of to
   the LLVM intrinsic because LLVM will lower it to `fmal` even when the
   target's `long double` is not equivalent to `f128`.

This commit is intended to fix the test suite which is failing on the
previous commit.
2021-10-05 14:22:38 -07:00
Andrew Kelley
2fe7b06f3d add support for f128 @mulAdd
std: add f128 implementations of fma, frexp, and ilogb. Expose `fmal` in
zig's freestanding libc. This makes `@mulAdd` work correctly for f128.

Fixes a CI regression from yesterday, where I added a usage of f128
`@mulAdd` into the self-hosted compiler.
2021-10-05 12:32:26 -07:00
Andrew Kelley
6115cf2240 migrate from std.Target.current to @import("builtin").target
closes #9388
closes #9321
2021-10-04 23:48:55 -07:00
Andrew Kelley
78902db68b stage2: fix comptime @bitCast
Before, Sema for comptime `@bitCast` would return the same Value but
change the Type. This gave invalid results because, for example, an
integer Value when the Type is a float would be interpreted numerically,
but `@bitCast` needs it to reinterpret how they would be stored in
memory.

This requires a mechanism to serialize a Value to a byte buffer and
deserialize a Value from a byte buffer.

Not done yet, but needs to happen: comptime dereferencing a pointer
to a Decl needs to perform a comptime bitcast on the loaded value.
Currently the value is silently wrong in the same way that `@bitCast`
was silently wrong before this commit.

The logic in Value for handling readFromMemory for large integers is
only correct for small integers. It needs to be fleshed out for proper
big integers.

As part of this change:
 * std.math.big.Int: initial implementations of readTwosComplement and
   writeTwosComplement. They only support bit_count <= 128 so far and
   panic otherwise.
 * compiler-rt: move the compareXf2 exports over to the stage2 section.
   Even with the improvements in this commit, I'm still seeing test
   failures in the widening behavior tests; more investigation is
   needed.
2021-10-04 23:30:04 -07:00
Sreehari Sreedev
598db831f3 FileProtocol: add Reader, Writer, SeekableStream 2021-10-04 22:29:53 -04:00
Andrew Kelley
d4ebfa8763
Merge pull request #9880 from squeek502/deflate-construct-errors
deflate: Better Huffman.construct errors and error handling
2021-10-04 15:31:08 -04:00
Matthew Borkowski
66204b7806 deflate.zig: check for distances past beginning of output stream 2021-10-04 15:30:37 -04:00
alichraghi
5125788e33 add phi constant 2021-10-04 15:27:25 -04:00
Robin Voetter
95fe86e3db big ints: Fix tests for 32-bit architectures 2021-10-04 11:25:29 +02:00
Robin Voetter
a1e02f33ad fmt 2021-10-04 11:25:29 +02:00
Robin Voetter
3dc47b8161 Apply new big int wrap/saturate to Value.zig 2021-10-04 11:25:29 +02:00
Robin Voetter
a62ce87f1f big ints: mulWrap tests 2021-10-04 11:25:29 +02:00
Robin Voetter
b352564b36 big ints: Some extra comments 2021-10-04 11:25:29 +02:00
Robin Voetter
ebcdfebaa6 big ints: saturate() tests 2021-10-04 11:25:29 +02:00
Robin Voetter
bbd50248f2 big ints: saturate() function 2021-10-04 11:25:29 +02:00
Robin Voetter
fdf13fb819 big ints: Wrapping multiplication 2021-10-04 11:25:29 +02:00
Robin Voetter
41e9c1bac1 big ints: Allow llmulaccum to wrap 2021-10-04 11:25:29 +02:00
Robin Voetter
5907b3e383 big ints: Improve karatsuba multiplication 2021-10-04 11:25:29 +02:00
Robin Voetter
15351f206f big.int: truncate tests 2021-10-04 11:25:29 +02:00
Robin Voetter
692827baa7 big ints: [add|sub]Sat tests 2021-10-04 11:25:29 +02:00
Robin Voetter
52721d3a7e big ints: [add|sub]Wrap tests 2021-10-04 11:25:29 +02:00
Robin Voetter
bb53f4f15a big ints: implement normal/wrapping/saturating subtraction in terms of addition 2021-10-04 11:25:29 +02:00
Robin Voetter
16991f920b big ints: saturating addition 2021-10-04 11:25:29 +02:00
Robin Voetter
f1b3a90ef6 big ints: setTwosCompIntLimit
This function can be used to initialize a big integer to either the upper
or lower limit of a 2s-complement integer. Note that the result is still
in sign-magnitude representation, though in order to convert it into twos
complement all one has to do is take the absolute value.
2021-10-04 11:25:29 +02:00
Robin Voetter
dc1f698545 big ints: unify add/sub with their wrapping variants 2021-10-04 11:25:29 +02:00
Robin Voetter
a36ef84deb big ints: Basic wrapping multiplication 2021-10-04 11:25:29 +02:00
Robin Voetter
69be6ba8ee Comptime wrapping addition/subtraction 2021-10-04 11:25:29 +02:00
Robin Voetter
fdb37743fa big ints: addWrap, subWrap + fix Managed.truncate allocation size 2021-10-04 11:25:29 +02:00
Robin Voetter
b58cf6dab6 big ints: 2s complement truncate 2021-10-04 11:25:29 +02:00
Robin Voetter
616b23c815 big ints: split lladd/llsub into carry variants
lladd is now implemented in terms of lladdcarry, which returns the carry limb.
Similarly, llsub is implemented using llsubcarry, which returns the borrow limb.
2021-10-04 11:25:29 +02:00
Nathan Michaels
4916e26be4 Document some functions in std.math. 2021-10-02 16:06:03 -04:00
Ryan Liptak
36f1f4f9fe deflate: Update fuzzed test cases and add InvalidTree test cases 2021-10-02 03:38:03 -07:00
Andrew Kelley
7a2624c3e4 std: disable ArrayBitSet test on aarch64
See #9879. This regressed with the release of LLVM 13.0.0.
2021-10-01 22:32:13 -07:00