5303 Commits

Author SHA1 Message Date
Andrew Kelley
413b789e06 std.os.linux.arm-eabi: upgrade to new fn ptr semantics 2022-05-05 22:29:25 -07:00
Andrew Kelley
496eb69273 CI: add non-LLVM backends to the test matrix
We can't yet run the behavior tests with stage3, but at least we can run
them with stage2, and we can use the proper test matrix.

This commit also adds use_llvm and ofmt to the zig build system.
2022-05-05 22:29:25 -07:00
Jakub Konka
9985699943 libstd: map sparcv9 to qemu-sparc64 for test-runner 2022-05-05 20:00:13 +02:00
Andrew Kelley
0bebb688fb stage2: change max int align from 8 to 16 for more ISAs
These targets now have a similar disagreement with LLVM about the
alignment of 128-bit integers as x86_64:
 * riscv64
 * powerpc64
 * powerpc64le
 * mips64
 * mips64el
 * sparcv9

See #2987
2022-05-04 19:11:02 -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
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
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
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
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
76b7f56725 std.os.windows: upgrade to new function pointer semantics 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
1a1f62a0ce std: enable real start code always for LLVM backend 2022-05-02 22:06:02 -07: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
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
60c2972c5d stage2: fix comptime fixed-width float division 2022-05-01 15:02:06 -07:00
r00ster
f65ca80bbe std.heap: Fix typo 2022-05-01 14:41:12 -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
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
Natalia Cholewa
0e49142ce4 std.SegmentedList: add constIterator 2022-04-29 14:48:49 -04:00
Stephen Gregoratto
2409041e62 Seccomp fixups re: #10717
- Add type annotation for AUDIT.current.
- Make unsupported archs a compile error.
2022-04-28 23:41:25 -04:00
Andrew Kelley
a242906696 compiler-rt: restore stage1 workaround
18d6523888ef08bc66eb808075d13c5e00b8fcf4 regressed compiler-rt tests for
stage1 because it removed a workaround. I updated the comment to better
explain what exactly the workaround is so that it won't happen again.
2022-04-28 20:39:33 -07:00
Andrew Kelley
18d6523888 compiler-rt: upgrade to stage2 fn ptr semantics 2022-04-28 17:11:14 -07:00
Andrew Kelley
c5e847744c Revert "Merge pull request #11214 from iddev5/ay-build-runner"
This reverts commit 75c9936737a6ba991d4ef187ddc9d51bc0ad0998, reversing
changes made to 7f13f5cd5f5a518638b15d7225eae2d88ec1efb5.

I don't think `runZigBuild` belongs in std.testing. We already have
`test/standalone/*` for this.

Additionally test names should explain what they are testing rather than
referencing GitHub issue numbers.
2022-04-28 14:12:32 -07:00
Andrew Kelley
3052597a73 Revert "std.testing: add writeZigFile for TmpDir"
This reverts commit 7f13f5cd5f5a518638b15d7225eae2d88ec1efb5.

I'd like to review this one before it goes in. This is an awfully
specific API that I don't think belongs in std.testing. Also I don't
want any code snippets in doc strings. We have doctests for that.
2022-04-28 11:20:53 -07:00
Andrew Kelley
9181c98225 std.build: fix dll-export-fns API
We have a pattern using `?bool` for the -f/-fno- style flags.

Fixup for 8e3add8736be683b450c2754bedb064811baed0e.
2022-04-28 11:13:33 -07:00
Andrew Kelley
360ecc1a2f
Merge pull request #11532 from ziglang/compiler-rt-math
compiler-rt math functions reorg
2022-04-28 13:34:38 -04:00
Jakub Konka
d5fcb50988 fmt: fix formatting of lib/std/x/net/bpf.zig 2022-04-28 18:34:37 +02:00
Veikka Tuominen
6d48600ea0
Merge pull request #10717 from gh-fork-dump/seccomp-bits
Add Seccomp bits for linux
2022-04-28 18:54:09 +03:00
Veikka Tuominen
75c9936737
Merge pull request #11214 from iddev5/ay-build-runner
std: explicitly handle error.UnexpectedExitCode in build_runner
2022-04-28 18:38:44 +03:00
matu3ba
7f13f5cd5f
std.testing: add writeZigFile for TmpDir
* remove need for manual string concatenation for building binaries in test blocks
* include small program snippet to show how to get binary path with subslicing
2022-04-28 18:37:30 +03:00
Erik Hugne
8e3add8736
std.build: make no_dll_export_fns accessible in build step 2022-04-28 18:34:15 +03:00
Erik Hugne
f7bc8900bf std.coff: parse out codebase and entrypoint from optionalheader 2022-04-28 18:31:20 +03:00
Andrew Kelley
f7f03c699d compiler-rt: provide actual sincos implementations 2022-04-27 22:37:07 -07:00
Andrew Kelley
0b2ed45f5f compiler-rt: inline sin and cos into sincos
This avoids the optimizer turning sincos into a recursive call to
itself.
2022-04-27 20:24:08 -07:00
Andrew Kelley
0ffe82e624 std: use float builtins instead of std.math 2022-04-27 19:35:28 -07:00
Andrew Kelley
1cd799317b compiler-rt: remove invalid test
This was leftover from testing std.math.sin
2022-04-27 18:28:33 -07:00
Andrew Kelley
51f8ce1825 compiler-rt: fix powerpc f128 suffix 2022-04-27 18:26:47 -07:00
Andrew Kelley
1ac21cdec5 compiler-rt: avoid symbol conflicts
Weak aliases don't work on Windows, so we avoid exporting the `l` alias
on this platform for functions we know will collide.
2022-04-27 18:14:44 -07:00
Andrew Kelley
09f1d62bdf add new builtin function @tan
The reason for having `@tan` is that we already have `@sin` and `@cos`
because some targets have machine code instructions for them, but in the
case that the implementation needs to go into compiler-rt, sin, cos, and
tan all share a common dependency which includes a table of data. To
avoid duplicating this table of data, we promote tan to become a builtin
alongside sin and cos.

ZIR: The tag enum is at capacity so this commit moves
`field_call_bind_named` to be `extended`. I measured this as one of
the least used tags in the zig codebase.

Fix libc math suffix for `f32` being wrong in both stage1 and stage2.
stage1: add missing libc prefix for float functions.
2022-04-27 16:45:23 -07:00
Andrew Kelley
087aedfa38 stage2: fix recent LLVM backend code
* std.math.snan: fix compilation error. Also make it and nan inline.
 * LLVM: use a proper enum type for float op instead of enum literal.
   Also various cleanups.
 * LLVM: use LLVMBuildVectorSplat for vector splat AIR instruction.
   - also the bindings had parameter order wrong
 * LLVM: additionally handle f16 lowering. For now all targets report OK
   but I think we will need to add some exceptions to this list.
2022-04-27 14:18:34 -07:00
Andrew Kelley
41dd2beaac compiler-rt: math functions reorg
* unify the logic for exporting math functions from compiler-rt,
   with the appropriate suffixes and prefixes.
   - add all missing f128 and f80 exports. Functions with missing
     implementations call other functions and have TODO comments.
   - also add f16 functions
 * move math functions from freestanding libc to compiler-rt (#7265)
 * enable all the f128 and f80 code in the stage2 compiler and behavior
   tests (#11161).
 * update std lib to use builtins rather than `std.math`.
2022-04-27 12:20:44 -07:00
Isaac Freund
6f4343b61a std: replace usage of std.meta.bitCount() with @bitSizeOf() 2022-04-27 11:10:52 +02:00
Isaac Freund
6c0719fd5f std.meta: deprecate bitCount() for @bitSizeOf() 2022-04-27 11:10:52 +02:00
Jimmi Holst Christensen
cea310c908 Remove usage of inline for from print_targets.cmdTargets
This function was one of the biggest zig functions in a debug build of
the compiler.

  $ bloaty stage3-debug/bin/zig -d symbols --tsv -n 10000000 |
      rg -v '(llvm|clang|std|lld|\(anonymous namespace\))::|\[section ' |
      sort -h -k 3

  ...
  translate_c.ast.renderNode                    86168   86219
  main.buildOutputType                         177959  178004
  InfoTable                                    184832  184870
  AArch64SVEIntrinsicMap                       188544  188596
  print_targets.cmdTargets__anon_4735          319156  319216
  __static_initialization_and_destruction_0()  486666  489582
  MatchTable1                                  621884  621997
  OperandMatchTable                           1139622 1139861
  MatchTable0                                 1899764 1900141
2022-04-26 17:52:21 -04:00
protty
18f3034629
std.Thread: ResetEvent improvements (#11523)
* std: start removing redundant ResetEvents

* src: fix other uses of std.Thread.ResetEvent

* src: add builtin.sanitize_thread for tsan detection

* atomic: add Atomic.fence for proper fencing with tsan

* Thread: remove the other ResetEvent's and rewrite the current one

* Thread: ResetEvent docs

* zig fmt + WaitGroup.reset() fix

* src: fix build issues for ResetEvent + tsan

* Thread: ResetEvent tests

* Thread: ResetEvent module doc

* Atomic: replace llvm *p memory constraint with *m

* panicking: handle spurious wakeups in futex.wait() when waiting for abort()

* zig fmt
2022-04-26 16:48:56 -05:00