18241 Commits

Author SHA1 Message Date
Andrew Kelley
2f6a01d0c3 stage1: fix @sizeOf for 128-bit integer types 2022-05-04 17:34:17 -07:00
Andrew Kelley
f21c11a7f7 stage2: change x86_64 max int alignment from 8 to 16
For x86_64, LLVMABIAlignmentOfType(i128) reports 8. However I think 16
is a better number for two reasons:
1. Better machine code when loading into SIMD register.
2. The C ABI wants 16 for extern structs.
2022-05-04 17:34:17 -07:00
Andrew Kelley
5b1c0d922c stage2: improve semantics of atomic operations
ZIR instructions updated: atomic_load, atomic_rmw, atomic_store, cmpxchg
These no longer construct a pointer type as the result location. This
solves a TODO that was preventing the pointer from possibly being
volatile, as well as properly handling allowzero and addrspace.
It also allows the pointer to be over-aligned, which may be needed
depending on the target. As a consequence, the element type needs to be
communicated in the ZIR. This is done by strategically making one of the
operands be ResultLoc.ty instead of ResultLoc.coerced_ty if possible, or
otherwise explicitly adding elem_type into the ZIR encoding, such as in
the case of atomic_load.

The pointer type of atomic operations is now checked in Sema by coercing
it to an expected pointer type, that maybe over-aligned according to
target requirements.

Together with the previous commit, Zig now has smaller alignment for
large integers, depending on the target, and yet still has type safety
for atomic operations that specially require higher alignment.
2022-05-04 17:34:16 -07:00
Andrew Kelley
259f784241 stage2: improve @sizeOf and @alignOf integers
Prior to this commit, the logic for ABI size and ABI alignment for
integers was naive and incorrect. This results in wasted hardware as
well as undefined behavior in the LLVM backend when we memset an
incorrect number of bytes to 0xaa due to disagreeing with LLVM about the
ABI size of integers.

This commit introduces a "max int align" value which is different per
Target. This value is used to derive the ABI size and alignment of all
integers.

This commit makes an interesting change from stage1, which treats
128-bit integers as 16-bytes aligned for x86_64-linux. stage1 is
incorrect. The maximum integer alignment on this system is only 8 bytes.
This change breaks the behavior test called "128-bit cmpxchg" because on
that target, 128-bit cmpxchg does require a 16-bytes aligned pointer to
a 128 bit integer. However, this alignment property does not belong on
*all* 128 bit integers - only on the pointer type in the `@cmpxchg`
builtin function prototype. The user can then use an alignment override
annotation on a 128-bit integer variable or struct field to obtain such
a pointer.
2022-05-04 17:34:16 -07:00
Andrew Kelley
080e870a71
Merge pull request #11572 from ziglang/test-harness
test: improve test/batch sequence iterator and move all tests into cases/ parent dir
2022-05-04 20:28:34 -04:00
Jakub Konka
3624e1ef48 test: move compile errors and incremental tests into common dir 2022-05-04 23:51:16 +02:00
Jakub Konka
9d79b740bc test: improve test batch/sequence iterator
With this improved iterator, type of test is now inferred from
the filename, enabling us to put all cases in one common parent
directory, and iterate over that, thus automating a lot of tasks.
2022-05-04 23:21:35 +02:00
Andrew Kelley
a839ccc153
Merge pull request #11575 from ifreund/musl123
musl: update to 1.2.3
2022-05-04 16:36:57 -04:00
Isaac Freund
2477a95d29
tools/gen_stubs: sort output by section/symbol name
This will make future diffs smaller and easier to review.
2022-05-04 18:38:45 +02:00
Jay Petacat
28ef79ea80
std: Single-threaded panicImpl sleep is unreachable (#11569)
Adding `unreachable` prevents the futex code from being inspected during
a single-threaded build. Without futex, first draft BYOS packages don't
need to implement `nanosleep` to get a single-threaded "hello world"
program working.

Use of `assert()` did not achieve the desired effect of avoiding futex
in a single-threaded build.
2022-05-04 09:43:27 -05:00
Andrew Kelley
3ed9ef3e6b Sema: fix bigIntToFloat
The implementation had the `@mulAdd` parameters mixed up.
2022-05-03 21:50:00 -07:00
Isaac Freund
f4131cf8a6
musl: update to 1.2.3
This was a bit trickier than it should be due to symbol conflicts with
zig's compiler-rt implementation. We attempt to use weak linkage in
our compiler-rt, but this does not seem to be working in all cases. I
manually disabled export of the problematic compiler-rt math functions
in order to cross compile musl's libc.so for all targets as input to
`tools/gen_stubs.zig`.

Other than that, this update went fairly smoothly. Quite a few
additional symbols were added to the blacklist in `tools/gen_stubs.zig`
due to recent reorganization of zig's compiler-rt.
2022-05-04 01:00:57 +02:00
Andrew Kelley
b6930825b0 github issue templates enhancements
Make the honey traps links instead of actual templates
2022-05-03 14:04:15 -07:00
Andrew Kelley
3cfde183f3
Merge pull request #11571 from ziglang/stage2-test-behavior
progress towards stage2 behavior tests for all targets passing with the LLVM backend
2022-05-03 14:58:46 -04:00
Andrew Kelley
6317da8da4
Merge pull request #11566 from tiehuis/master
add new float-parser based on eisel-lemire algorithm
2022-05-03 14:56:05 -04:00
Jakub Konka
d48789467d x86_64: use math.zig to check isPowerOfTwo and calc log2_int 2022-05-03 16:39:21 +02:00
Marc Tiehuis
2947a2faab export __floatuntikf for PowerPC
PPC __floatuntikf is equivalent to X86 __floatuntitf.
2022-05-03 20:12:29 +12:00
Marc Tiehuis
02209d8a5f fix aarch64 f16 nan parse test failure 2022-05-03 19:04:16 +12:00
Andrew Kelley
aa3c3f66da test runner: enable arg processing for stage2 builds 2022-05-02 22:14:17 -07:00
Andrew Kelley
ea7142c43f LLVM: set module PIC, PIE, and CodeModel
Some simple code from stage1 ported over to stage2.
2022-05-02 22:14:17 -07:00
Andrew Kelley
defda6202a LLVM: insert workaround for aarch64-windows f16 CodeView crash 2022-05-02 22:14:17 -07:00
Andrew Kelley
76b7f56725 std.os.windows: upgrade to new function pointer semantics 2022-05-02 22:14:17 -07:00
Andrew Kelley
48d2f226cb Sema: allow exporting optionals and pointers 2022-05-02 22:14:17 -07:00
Andrew Kelley
65389dc280 stage2: improve inline asm stage1 compatibility
* outputs can have names and be referenced with template replacements
   the same as inputs.
 * fix print_air.zig not decoding correctly.
 * LLVM backend: use a table for template names for simplicity
2022-05-02 22:14:17 -07:00
Marc Tiehuis
5fbda2c579 temporary fix for stage2/stage1 f128 rounding discrepency
This is only to get tests running again. The root issue should be fixed
in stage1 so rounding is consistent between stages.
2022-05-03 17:14:01 +12:00
Andrew Kelley
b95942744c std.pdb: fix incorrect use of packed struct 2022-05-02 22:06:02 -07:00
Andrew Kelley
d98869da43 behavior tests: fix wrong packed struct test case
Packed structs are defined to have the same alignment and size as their
backing integer.
2022-05-02 22:06:02 -07:00
Andrew Kelley
1a1f62a0ce std: enable real start code always for LLVM backend 2022-05-02 22:06:02 -07:00
Marc Tiehuis
bbfe2234c8 update AstGen float literal parsing 2022-05-03 16:46:40 +12:00
Marc Tiehuis
2085a4af56 add new float-parser based on eisel-lemire algorithm
The previous float-parsing method was lacking in a lot of areas. This
commit introduces a state-of-the art implementation that is both
accurate and fast to std.

Code is derived from working repo https://github.com/tiehuis/zig-parsefloat.
This includes more test-cases and performance numbers that are present
in this commit.

* Accuracy

The primary testing regime has been using test-data found at
https://github.com/tiehuis/parse-number-fxx-test-data. This is a fork of
upstream with support for f128 test-cases added. This data has been
verified against other independent implementations and represents
accurate round-to-even IEEE-754 floating point semantics.

* Performance

Compared to the existing parseFloat implementation there is ~5-10x
performance improvement using the above corpus. (f128 parsing excluded
in below measurements).

** Old

    $ time ./test_all_fxx_data
    3520298/5296694 succeeded (1776396 fail)

    ________________________________________________________
    Executed in   28.68 secs    fish           external
       usr time   28.48 secs    0.00 micros   28.48 secs
       sys time    0.08 secs  694.00 micros    0.08 secs

** This Implementation

    $ time ./test_all_fxx_data
    5296693/5296694 succeeded (1 fail)

    ________________________________________________________
    Executed in    4.54 secs    fish           external
       usr time    4.37 secs  515.00 micros    4.37 secs
       sys time    0.10 secs  171.00 micros    0.10 secs

Further performance numbers can be seen using the
https://github.com/tiehuis/simple_fastfloat_benchmark/ repository, which
compares against some other well-known string-to-float conversion
functions. A breakdown can be found here:

0d9f020f1a/PERFORMANCE.md (commit-b15406a0d2e18b50a4b62fceb5a6a3bb60ca5706)

In summary, we are within 20% of the C++ reference implementation and
have about ~600-700MB/s throughput on a Intel I5-6500 3.5Ghz.

* F128 Support

Finally, f128 is now completely supported with full accuracy. This does
use a slower path which is possible to improve in future.

* Behavioural Changes

There are a few behavioural changes to note.

 - `parseHexFloat` is now redundant and these are now supported directly
   in `parseFloat`.
 - We implement round-to-even in all parsing routines. This is as
   specified by IEEE-754. Previous code used different rounding
   mechanisms (standard was round-to-zero, hex-parsing looked to use
   round-up) so there may be subtle differences.

Closes #2207.
Fixes #11169.
2022-05-03 16:46:40 +12:00
Frank Denis
098bee0e56
edwards25519 fixes (#11568)
* edwards25519: fix X coordinate of the base point

Reported by @OfekShochat -- Thanks!

* edwards25519: reduce public scalar when the top bit is set, not cleared

This is an optimization for the unexpected case of a scalar
larger than the field size.

Fixes #11563

* edwards25519: add a test implicit reduction of invalid scalars
2022-05-03 05:28:34 +02:00
Jakub Konka
f648a1b043 test: regression fix: skip stage1 if not enabled 2022-05-02 21:22:07 -04:00
Lee Cannon
3679d737f8 Allocator: correct PanicFree function name 2022-05-02 15:29:27 -04:00
r00ster91
bb55276f06 Avoid some unnecessary underscores in constant names 2022-05-02 15:29:04 -04:00
Andrew Kelley
9af4cada73 Sema: coerce comptime_float to fixed-width float
Instead of doing heterogeneous comparison at comptime. This makes the
following test pass (as it already does for stage1):

```zig
test {
    const x: f64 = 12.34;
    expect(x == 12.34);
}
```

There is already behavior test coverage for this, however, other bugs in
`std.fmt.parseFloat` are masking the failures.

From a language specification perspective, this makes sense because it
makes comptime comparisons with comptime_float work the same way they
work with runtime comparisons.
2022-05-02 12:16:23 -07:00
Andrew Kelley
a3f56154d0 stage1: disable new behavior tests
Oops, I forgot to check if the new behavior tests are passing for
stage1.
2022-05-01 22:11:57 -07:00
Andrew Kelley
1387d2f5ac zig build: use CacheMode.whole for build_runner.zig
Maybe after we have incremental compilation metadata serialization
and non-LLVM backends, it will make sense to switch this back. For now,
however, this makes successive `zig build` commands much faster.
2022-05-01 15:43:52 -07:00
Andrew Kelley
82b96ca0de disable failing behavior tests
Oops, I forgot to run the non-LLVM backend tests on that last commit.
2022-05-01 15:35:35 -07:00
Andrew Kelley
60c2972c5d stage2: fix comptime fixed-width float division 2022-05-01 15:02:06 -07:00
Andrew Kelley
615a983517 cmake: default install prefix to ./stage1 2022-05-01 14:05:01 -07:00
r00ster
f65ca80bbe std.heap: Fix typo 2022-05-01 14:41:12 -04:00
Daniele Cocca
d127c1d59e CBE: handle returning undefined for ErrorUnion
Just like for Struct in 8238d4b33585a715c58ab559cd001dd3ea1db55b, in the
case of ErrorUnion struct we need to return a compound literal "(T){...}"
instead of just "{}", which is invalid code when used in e.g. a "return"
expression.
2022-04-30 13:29:21 -04:00
sin-ack
032c722d20
Sema: Fix many-pointer array concatenation at comptime (#11512)
* Sema: Correctly determine whether array_cat lhs and rhs are single ptrs

Many-pointers are also not single-pointers and wouldn't be considered
here. This commit makes the conditions use the appropriately-named
isSinglePointer instead.

* Sema: Correctly obtain ArrayInfo for many-pointer concatenation

Many-pointers at comptime have a known size like slices and can be used
in array concatenation. This fixes a stage1 regression.

* test: Add comptime manyptr concatenation test

Co-authored-by: sin-ack <sin-ack@users.noreply.github.com>
2022-04-29 22:53:06 -04:00
InKryption
609896a6e8
std.MultiArrayList: add functions addOne, pop, and popOrNull (#11553)
Update basic usage test to account for these, and by extension for addOneAssumeCapacity.
2022-04-29 22:51:53 -04:00
Andrew Kelley
cc39d453c4
Merge pull request #11549 from Vexu/stage2-fixes
Stage2: fix comptime unreachable, adjust Zir.Extended
2022-04-29 22:50:53 -04:00
Jimmi Holst Christensen
a0a2ce92ca std: Do not allocate the result for ChildProcess.init
Instead, just return ChildProcess directly. This structure does not
require a stable address, so we can put it on the stack just fine. If
someone wants it on the heap they should do.

  const proc = try allocator.create(ChildProcess);
  proc.* = ChildProcess.init(args, allocator);
2022-04-29 22:50:34 -04:00
Veikka Tuominen
596f7df02e Zir: turn extended func into func_extended 2022-04-30 01:06:01 +03:00
Veikka Tuominen
1d455896cb Zir: move more common instructions out of extended 2022-04-30 01:06:01 +03:00
Veikka Tuominen
a6f254ec3e stage2: fix comptime unreachable 2022-04-30 01:05:48 +03:00
Natalia Cholewa
0e49142ce4 std.SegmentedList: add constIterator 2022-04-29 14:48:49 -04:00