diff --git a/.forgejo/workflows/ci.yaml b/.forgejo/workflows/ci.yaml index 64085d1da6..961198ffbe 100644 --- a/.forgejo/workflows/ci.yaml +++ b/.forgejo/workflows/ci.yaml @@ -17,6 +17,27 @@ permissions: contents: read jobs: + aarch64-freebsd-debug: + runs-on: [self-hosted, aarch64-freebsd] + steps: + - name: Checkout + uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28 + with: + fetch-depth: 0 + - name: Build and Test + run: sh ci/aarch64-freebsd-debug.sh + timeout-minutes: 300 + aarch64-freebsd-release: + runs-on: [self-hosted, aarch64-freebsd] + steps: + - name: Checkout + uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28 + with: + fetch-depth: 0 + - name: Build and Test + run: sh ci/aarch64-freebsd-release.sh + timeout-minutes: 240 + aarch64-linux-debug: runs-on: [self-hosted, aarch64-linux] steps: @@ -38,6 +59,27 @@ jobs: run: sh ci/aarch64-linux-release.sh timeout-minutes: 120 + aarch64-netbsd-debug: + runs-on: [self-hosted, aarch64-netbsd] + steps: + - name: Checkout + uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28 + with: + fetch-depth: 0 + - name: Build and Test + run: sh ci/aarch64-netbsd-debug.sh + timeout-minutes: 300 + aarch64-netbsd-release: + runs-on: [self-hosted, aarch64-netbsd] + steps: + - name: Checkout + uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28 + with: + fetch-depth: 0 + - name: Build and Test + run: sh ci/aarch64-netbsd-release.sh + timeout-minutes: 240 + aarch64-macos-debug: runs-on: [self-hosted, aarch64-macos] steps: @@ -111,7 +153,7 @@ jobs: fetch-depth: 0 - name: Build and Test run: sh ci/riscv64-linux-debug.sh - timeout-minutes: 600 + timeout-minutes: 660 riscv64-linux-release: if: github.event_name != 'pull_request' runs-on: [self-hosted, riscv64-linux] @@ -197,6 +239,27 @@ jobs: run: sh ci/x86_64-linux-release.sh timeout-minutes: 360 + x86_64-netbsd-debug: + runs-on: [self-hosted, x86_64-netbsd] + steps: + - name: Checkout + uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28 + with: + fetch-depth: 0 + - name: Build and Test + run: sh ci/x86_64-netbsd-debug.sh + timeout-minutes: 120 + x86_64-netbsd-release: + runs-on: [self-hosted, x86_64-netbsd] + steps: + - name: Checkout + uses: https://codeberg.org/ziglang/checkout@19af6bac491e2534a4687a50ee84fa7f13258d28 + with: + fetch-depth: 0 + - name: Build and Test + run: sh ci/x86_64-netbsd-release.sh + timeout-minutes: 120 + x86_64-openbsd-debug: runs-on: [self-hosted, x86_64-openbsd] steps: diff --git a/CMakeLists.txt b/CMakeLists.txt index fe8660559c..af1f64bd83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -205,181 +205,6 @@ set(ZIG_CPP_SOURCES set(ZIG_STAGE2_SOURCES "${ZIG_CONFIG_ZIG_OUT}" lib/compiler_rt.zig - lib/compiler_rt/absv.zig - lib/compiler_rt/absvdi2.zig - lib/compiler_rt/absvsi2.zig - lib/compiler_rt/absvti2.zig - lib/compiler_rt/adddf3.zig - lib/compiler_rt/addf3.zig - lib/compiler_rt/addsf3.zig - lib/compiler_rt/addtf3.zig - lib/compiler_rt/addvsi3.zig - lib/compiler_rt/addvdi3.zig - lib/compiler_rt/addxf3.zig - lib/compiler_rt/arm.zig - lib/compiler_rt/atomics.zig - lib/compiler_rt/aulldiv.zig - lib/compiler_rt/aullrem.zig - lib/compiler_rt/bswap.zig - lib/compiler_rt/clear_cache.zig - lib/compiler_rt/cmp.zig - lib/compiler_rt/cmpdf2.zig - lib/compiler_rt/cmpsf2.zig - lib/compiler_rt/cmptf2.zig - lib/compiler_rt/cmpxf2.zig - lib/compiler_rt/common.zig - lib/compiler_rt/comparef.zig - lib/compiler_rt/cos.zig - lib/compiler_rt/count0bits.zig - lib/compiler_rt/divdf3.zig - lib/compiler_rt/divsf3.zig - lib/compiler_rt/divtf3.zig - lib/compiler_rt/divti3.zig - lib/compiler_rt/divxf3.zig - lib/compiler_rt/emutls.zig - lib/compiler_rt/exp.zig - lib/compiler_rt/exp2.zig - lib/compiler_rt/extenddftf2.zig - lib/compiler_rt/extenddfxf2.zig - lib/compiler_rt/extendf.zig - lib/compiler_rt/extendhfsf2.zig - lib/compiler_rt/extendhftf2.zig - lib/compiler_rt/extendhfxf2.zig - lib/compiler_rt/extendsfdf2.zig - lib/compiler_rt/extendsftf2.zig - lib/compiler_rt/extendsfxf2.zig - lib/compiler_rt/extendxftf2.zig - lib/compiler_rt/fabs.zig - lib/compiler_rt/fixdfdi.zig - lib/compiler_rt/fixdfsi.zig - lib/compiler_rt/fixdfti.zig - lib/compiler_rt/fixhfdi.zig - lib/compiler_rt/fixhfsi.zig - lib/compiler_rt/fixhfti.zig - lib/compiler_rt/fixsfdi.zig - lib/compiler_rt/fixsfsi.zig - lib/compiler_rt/fixsfti.zig - lib/compiler_rt/fixtfdi.zig - lib/compiler_rt/fixtfsi.zig - lib/compiler_rt/fixtfti.zig - lib/compiler_rt/fixunsdfdi.zig - lib/compiler_rt/fixunsdfsi.zig - lib/compiler_rt/fixunsdfti.zig - lib/compiler_rt/fixunshfdi.zig - lib/compiler_rt/fixunshfsi.zig - lib/compiler_rt/fixunshfti.zig - lib/compiler_rt/fixunssfdi.zig - lib/compiler_rt/fixunssfsi.zig - lib/compiler_rt/fixunssfti.zig - lib/compiler_rt/fixunstfdi.zig - lib/compiler_rt/fixunstfsi.zig - lib/compiler_rt/fixunstfti.zig - lib/compiler_rt/fixunsxfdi.zig - lib/compiler_rt/fixunsxfsi.zig - lib/compiler_rt/fixunsxfti.zig - lib/compiler_rt/fixxfdi.zig - lib/compiler_rt/fixxfsi.zig - lib/compiler_rt/fixxfti.zig - lib/compiler_rt/float_from_int.zig - lib/compiler_rt/floatdidf.zig - lib/compiler_rt/floatdihf.zig - lib/compiler_rt/floatdisf.zig - lib/compiler_rt/floatditf.zig - lib/compiler_rt/floatdixf.zig - lib/compiler_rt/floatsidf.zig - lib/compiler_rt/floatsihf.zig - lib/compiler_rt/floatsisf.zig - lib/compiler_rt/floatsitf.zig - lib/compiler_rt/floatsixf.zig - lib/compiler_rt/floattidf.zig - lib/compiler_rt/floattihf.zig - lib/compiler_rt/floattisf.zig - lib/compiler_rt/floattitf.zig - lib/compiler_rt/floattixf.zig - lib/compiler_rt/floatundidf.zig - lib/compiler_rt/floatundihf.zig - lib/compiler_rt/floatundisf.zig - lib/compiler_rt/floatunditf.zig - lib/compiler_rt/floatundixf.zig - lib/compiler_rt/floatunsidf.zig - lib/compiler_rt/floatunsihf.zig - lib/compiler_rt/floatunsisf.zig - lib/compiler_rt/floatunsitf.zig - lib/compiler_rt/floatunsixf.zig - lib/compiler_rt/floatuntidf.zig - lib/compiler_rt/floatuntihf.zig - lib/compiler_rt/floatuntisf.zig - lib/compiler_rt/floatuntitf.zig - lib/compiler_rt/floatuntixf.zig - lib/compiler_rt/floor_ceil.zig - lib/compiler_rt/fma.zig - lib/compiler_rt/fmax.zig - lib/compiler_rt/fmin.zig - lib/compiler_rt/fmod.zig - lib/compiler_rt/gedf2.zig - lib/compiler_rt/gesf2.zig - lib/compiler_rt/getf2.zig - lib/compiler_rt/gexf2.zig - lib/compiler_rt/int.zig - lib/compiler_rt/int_from_float.zig - lib/compiler_rt/log.zig - lib/compiler_rt/log10.zig - lib/compiler_rt/log2.zig - lib/compiler_rt/modti3.zig - lib/compiler_rt/mulXi3.zig - lib/compiler_rt/muldf3.zig - lib/compiler_rt/mulf3.zig - lib/compiler_rt/mulo.zig - lib/compiler_rt/mulsf3.zig - lib/compiler_rt/multf3.zig - lib/compiler_rt/mulvsi3.zig - lib/compiler_rt/mulxf3.zig - lib/compiler_rt/negXi2.zig - lib/compiler_rt/negdf2.zig - lib/compiler_rt/negsf2.zig - lib/compiler_rt/negtf2.zig - lib/compiler_rt/negv.zig - lib/compiler_rt/negxf2.zig - lib/compiler_rt/os_version_check.zig - lib/compiler_rt/parity.zig - lib/compiler_rt/popcount.zig - lib/compiler_rt/rem_pio2.zig - lib/compiler_rt/rem_pio2_large.zig - lib/compiler_rt/rem_pio2f.zig - lib/compiler_rt/round.zig - lib/compiler_rt/shift.zig - lib/compiler_rt/sin.zig - lib/compiler_rt/sincos.zig - lib/compiler_rt/sqrt.zig - lib/compiler_rt/stack_probe.zig - lib/compiler_rt/subdf3.zig - lib/compiler_rt/subsf3.zig - lib/compiler_rt/subtf3.zig - lib/compiler_rt/subvdi3.zig - lib/compiler_rt/subvsi3.zig - lib/compiler_rt/subxf3.zig - lib/compiler_rt/tan.zig - lib/compiler_rt/trig.zig - lib/compiler_rt/trunc.zig - lib/compiler_rt/truncdfhf2.zig - lib/compiler_rt/truncdfsf2.zig - lib/compiler_rt/truncf.zig - lib/compiler_rt/truncsfhf2.zig - lib/compiler_rt/trunctfdf2.zig - lib/compiler_rt/trunctfhf2.zig - lib/compiler_rt/trunctfsf2.zig - lib/compiler_rt/trunctfxf2.zig - lib/compiler_rt/truncxfdf2.zig - lib/compiler_rt/truncxfhf2.zig - lib/compiler_rt/truncxfsf2.zig - lib/compiler_rt/udivmod.zig - lib/compiler_rt/udivmodei4.zig - lib/compiler_rt/udivmodti4.zig - lib/compiler_rt/udivti3.zig - lib/compiler_rt/umodti3.zig - lib/compiler_rt/unorddf2.zig - lib/compiler_rt/unordsf2.zig - lib/compiler_rt/unordtf2.zig lib/std/BitStack.zig lib/std/Build.zig lib/std/Build/Cache.zig @@ -408,9 +233,6 @@ set(ZIG_STAGE2_SOURCES lib/std/Target/wasm.zig lib/std/Target/x86.zig lib/std/Thread.zig - lib/std/Thread/Futex.zig - lib/std/Thread/Mutex.zig - lib/std/Thread/WaitGroup.zig lib/std/array_hash_map.zig lib/std/array_list.zig lib/std/ascii.zig @@ -441,7 +263,7 @@ set(ZIG_STAGE2_SOURCES lib/std/hash/wyhash.zig lib/std/hash_map.zig lib/std/heap.zig - lib/std/heap/arena_allocator.zig + lib/std/heap/ArenaAllocator.zig lib/std/json.zig lib/std/leb128.zig lib/std/log.zig @@ -508,7 +330,6 @@ set(ZIG_STAGE2_SOURCES src/Air/Liveness.zig src/Air/Liveness/Verify.zig src/Air/print.zig - src/Air/types_resolved.zig src/Builtin.zig src/Compilation.zig src/Compilation/Config.zig @@ -522,6 +343,7 @@ set(ZIG_STAGE2_SOURCES src/Sema.zig src/Sema/bitcast.zig src/Sema/comptime_ptr_access.zig + src/Sema/type_resolution.zig src/Type.zig src/Value.zig src/Zcu.zig @@ -538,7 +360,8 @@ set(ZIG_STAGE2_SOURCES src/codegen/aarch64/Mir.zig src/codegen/aarch64/Select.zig src/codegen/c.zig - src/codegen/c/Type.zig + src/codegen/c/type.zig + src/codegen/c/type/render_defs.zig src/codegen/llvm.zig src/codegen/llvm/bindings.zig src/crash_report.zig @@ -553,6 +376,7 @@ set(ZIG_STAGE2_SOURCES src/libs/libunwind.zig src/link.zig src/link/C.zig + src/link/ConstPool.zig src/link/Coff.zig src/link/Dwarf.zig src/link/Elf.zig @@ -784,10 +608,10 @@ if(MSVC) set(ZIG2_LINK_FLAGS "/STACK:16777216 /FORCE:MULTIPLE") else() set(ZIG_WASM2C_COMPILE_FLAGS "-std=c99 -O2") - set(ZIG1_COMPILE_FLAGS "-std=c99 -Os") - set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-sanitize=undefined -fno-stack-protector") + set(ZIG1_COMPILE_FLAGS "-std=c99 -Os -fno-strict-aliasing") + set(ZIG2_COMPILE_FLAGS "-std=c99 -O0 -fno-sanitize=undefined -fno-stack-protector -fno-strict-aliasing") # Must match the condition in build.zig. - if(ZIG_HOST_TARGET_ARCH MATCHES "^powerpc(64)?(le)?$") + if(ZIG_HOST_TARGET_ARCH MATCHES "^(arm|thumb)(eb)?$" OR ZIG_HOST_TARGET_ARCH MATCHES "^powerpc(64)?(le)?$") set(ZIG1_COMPILE_FLAGS "${ZIG1_COMPILE_FLAGS} -ffunction-sections -fdata-sections") set(ZIG2_COMPILE_FLAGS "${ZIG2_COMPILE_FLAGS} -ffunction-sections -fdata-sections") endif() @@ -801,6 +625,12 @@ else() else() set(ZIG2_LINK_FLAGS "-Wl,-z,stack-size=0x10000000") endif() + # Prevent GCC from miscompiling 'zig2.c'. See also 'workaround_gcc_sra_miscomp' in 'bootstrap.c'. + if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND + CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "13.0" AND + CMAKE_C_COMPILER_VERSION VERSION_LESS_EQUAL "15.2") + set(ZIG2_COMPILE_FLAGS "${ZIG2_COMPILE_FLAGS} -fno-tree-sra") + endif() endif() set(ZIG1_WASM_MODULE "${PROJECT_SOURCE_DIR}/stage1/zig1.wasm") diff --git a/README.md b/README.md index b9acf00abd..2dea88df21 100644 --- a/README.md +++ b/README.md @@ -616,17 +616,17 @@ a few releases old, or may be missing newer targets such as aarch64 and RISC-V. [ziglang/qemu-static](https://codeberg.org/ziglang/qemu-static) offers static binaries of the latest QEMU version. -##### Testing Non-Native glibc Targets +##### Testing Non-Native libc Targets -Testing foreign architectures with dynamically linked glibc is one step trickier. -This requires enabling `--glibc-runtimes /path/to/glibc/multi/install/glibcs`. -This path is obtained by building glibc for multiple architectures. This -process for me took an entire day to complete and takes up 65 GiB on my hard -drive. The CI server does not provide this test coverage. +Testing foreign architectures with dynamically linked libc is one step trickier. +This requires enabling `--libc-runtimes /path/to/libcs`. This path is obtained +by building glibc and musl for multiple architectures. This process for me took +an entire day to complete and takes up 65 GiB on my hard drive. -[Instructions for producing this path](https://codeberg.org/ziglang/infra/src/branch/master/building-libcs.md#linux-glibc) (just the part with `build-many-glibcs.py`). +[Instructions for producing this path.](https://codeberg.org/ziglang/infra/src/branch/master/building-libcs.md) -It is understood that most contributors will not have these tests enabled. +It is understood that most contributors will not have these tests enabled. The +CI machines provide coverage for these. #### Testing Windows from a Linux Machine with Wine diff --git a/bootstrap.c b/bootstrap.c index 1f17fc8455..ad4ccec54a 100644 --- a/bootstrap.c +++ b/bootstrap.c @@ -102,6 +102,26 @@ int main(int argc, char **argv) { const char *cc = get_c_compiler(); const char *host_triple = get_host_triple(); + // GCC versions 13.0--14.1 have a miscompilation where some bytes of a union may get clobbered + // depending on the union layout and the order in which types are defined. This miscompilation + // affects the output of the C backend, and thus can affect the bootstrap process. Specifically, + // we observe that using the self-hosted x86_64 backend in 'zig2' will cause all function calls + // to be relocated incorrectly, causing immediate crashes on any binary produced by it. + // + // The only reliable workaround for this bug is to disable the optimization pass containing it, + // so here we check for a CLI flag requesting that workaround. + // + // The upstream bug is fixed in GCC version 15.2 onwards (and was also backported to the 13 and + // 14 branches). Once this bug is no longer widespread, we can remove this CLI flag. + // + // Upstream bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119085 + bool workaround_gcc_sra_miscomp = false; + for (int i = 1; i < argc; ++i) { + if (!strcmp(argv[i], "--workaround-gcc-sra-miscomp")) { + workaround_gcc_sra_miscomp = true; + } + } + { const char *child_argv[] = { cc, "-o", "zig-wasm2c", "stage1/wasm2c.c", "-O2", "-std=c99", NULL, @@ -116,7 +136,7 @@ int main(int argc, char **argv) { } { const char *child_argv[] = { - cc, "-o", "zig1", "zig1.c", "stage1/wasi.c", "-std=c99", "-Os", "-lm", NULL, + cc, "-o", "zig1", "zig1.c", "stage1/wasi.c", "-std=c99", "-Os", "-fno-strict-aliasing", "-lm", NULL, }; print_and_run(child_argv); } @@ -143,6 +163,7 @@ int main(int argc, char **argv) { "pub const skip_non_native = false;\n" "pub const debug_gpa = false;\n" "pub const dev = .core;\n" + "pub const io_mode: enum { threaded, evented } = .threaded;\n" "pub const value_interpret_mode = .direct;\n" , zig_version); if (written < 100) @@ -192,6 +213,8 @@ int main(int argc, char **argv) { #if defined(__GNUC__) "-pthread", #endif + "-fno-strict-aliasing", + workaround_gcc_sra_miscomp ? "-fno-tree-sra" : NULL, NULL, }; print_and_run(child_argv); diff --git a/build.zig b/build.zig index 9835714efd..4e6efa41a6 100644 --- a/build.zig +++ b/build.zig @@ -13,6 +13,7 @@ const DevEnv = @import("src/dev.zig").Env; const zig_version: std.SemanticVersion = .{ .major = 0, .minor = 16, .patch = 0 }; const stack_size = 46 * 1024 * 1024; +const IoMode = enum { threaded, evented }; const ValueInterpretMode = enum { direct, by_name }; pub fn build(b: *std.Build) !void { @@ -29,7 +30,7 @@ pub fn build(b: *std.Build) !void { const use_zig_libcxx = b.option(bool, "use-zig-libcxx", "If libc++ is needed, use zig's bundled version, don't try to integrate with the system") orelse false; const test_step = b.step("test", "Run all the tests"); - const skip_install_lib_files = b.option(bool, "no-lib", "skip copying of lib/ files and langref to installation prefix. Useful for development") orelse false; + const skip_install_lib_files = b.option(bool, "no-lib", "skip copying of lib/ files and langref to installation prefix. Useful for development") orelse only_c; const skip_install_langref = b.option(bool, "no-langref", "skip copying of langref to the installation prefix") orelse skip_install_lib_files; const std_docs = b.option(bool, "std-docs", "include standard library autodocs") orelse false; const no_bin = b.option(bool, "no-bin", "skip emitting compiler binary") orelse false; @@ -84,6 +85,7 @@ pub fn build(b: *std.Build) !void { docs_step.dependOn(std_docs_step); const no_matrix = b.option(bool, "no-matrix", "Limit test matrix to exactly one target configuration") orelse false; + const fuzz_only = b.option(bool, "fuzz-only", "Limit test matrix to one target suitable for fuzzing") orelse false; const skip_debug = b.option(bool, "skip-debug", "Main test suite skips debug builds") orelse false; const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse no_matrix; const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release; @@ -188,6 +190,7 @@ pub fn build(b: *std.Build) !void { const strip = b.option(bool, "strip", "Omit debug information"); const valgrind = b.option(bool, "valgrind", "Enable valgrind integration"); const pie = b.option(bool, "pie", "Produce a Position Independent Executable"); + const io_mode = b.option(IoMode, "io-mode", "How the compiler performs IO") orelse .threaded; const value_interpret_mode = b.option(ValueInterpretMode, "value-interpret-mode", "How the compiler translates between 'std.builtin' types and its internal datastructures") orelse .direct; const value_tracing = b.option(bool, "value-tracing", "Enable extra state tracking to help troubleshoot bugs in the compiler (using the std.debug.Trace API)") orelse false; @@ -236,6 +239,7 @@ pub fn build(b: *std.Build) !void { exe_options.addOption(bool, "llvm_has_xtensa", llvm_has_xtensa); exe_options.addOption(bool, "debug_gpa", debug_gpa); exe_options.addOption(DevEnv, "dev", b.option(DevEnv, "dev", "Build a compiler with a reduced feature set for development of specific features") orelse if (only_c) .bootstrap else .full); + exe_options.addOption(IoMode, "io_mode", io_mode); exe_options.addOption(ValueInterpretMode, "value_interpret_mode", value_interpret_mode); if (link_libc) { @@ -367,14 +371,22 @@ pub fn build(b: *std.Build) !void { &[_][]const u8{ tracy_path, "public", "TracyClient.cpp" }, ); - const tracy_c_flags: []const []const u8 = &.{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" }; + const tracy_c_flags: []const []const u8 = &.{ + "-DTRACY_ENABLE=1", + "-fno-sanitize=undefined", + "-DTRACY_FIBERS", + }; exe.root_module.addIncludePath(.{ .cwd_relative = tracy_path }); - exe.root_module.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags }); - if (!enable_llvm) { - exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no }); - } + exe.root_module.addCSourceFile(.{ + .file = .{ .cwd_relative = client_cpp }, + .flags = tracy_c_flags[0..switch (io_mode) { + .threaded => 2, + .evented => 3, + }], + }); exe.root_module.link_libc = true; + exe.root_module.link_libcpp = true; if (target.result.os.tag == .windows) { exe.root_module.linkSystemLibrary("dbghelp", .{}); @@ -406,6 +418,13 @@ pub fn build(b: *std.Build) !void { } const optimization_modes = chosen_opt_modes_buf[0..chosen_mode_index]; + const test_only: ?tests.ModuleTestOptions.TestOnly = if (no_matrix) + .default + else if (fuzz_only) + .{ .fuzz = optimize } + else + null; + const fmt_include_paths = &.{ "lib", "src", "test", "tools", "build.zig", "build.zig.zon" }; const fmt_exclude_paths = &.{ "test/cases", "test/behavior/zon" }; const do_fmt = b.addFmt(.{ @@ -461,7 +480,7 @@ pub fn build(b: *std.Build) !void { .include_paths = &.{}, .skip_single_threaded = skip_single_threaded, .skip_non_native = skip_non_native, - .test_default_only = no_matrix, + .test_only = test_only, .skip_spirv = skip_spirv, .skip_wasm = skip_wasm, .skip_freebsd = skip_freebsd, @@ -472,27 +491,7 @@ pub fn build(b: *std.Build) !void { .skip_linux = skip_linux, .skip_llvm = skip_llvm, .skip_libc = skip_libc, - .max_rss = switch (b.graph.host.result.os.tag) { - .freebsd => 2_000_000_000, - .linux => switch (b.graph.host.result.cpu.arch) { - .aarch64 => 659_809_075, - .loongarch64 => 598_902_374, - .powerpc64le => 627_431_833, - .riscv64 => 827_043_430, - .s390x => 580_596_121, - .x86_64 => 3_290_894_745, - else => 3_300_000_000, - }, - .macos => switch (b.graph.host.result.cpu.arch) { - .aarch64 => 767_736_217, - else => 800_000_000, - }, - .windows => switch (b.graph.host.result.cpu.arch) { - .x86_64 => 603_070_054, - else => 700_000_000, - }, - else => 3_300_000_000, - }, + .max_rss = 4_000_000_000, })); test_modules_step.dependOn(tests.addModuleTests(b, .{ @@ -506,7 +505,7 @@ pub fn build(b: *std.Build) !void { .include_paths = &.{}, .skip_single_threaded = true, .skip_non_native = skip_non_native, - .test_default_only = no_matrix, + .test_only = test_only, .skip_spirv = skip_spirv, .skip_wasm = skip_wasm, .skip_freebsd = skip_freebsd, @@ -518,23 +517,7 @@ pub fn build(b: *std.Build) !void { .skip_llvm = skip_llvm, .skip_libc = true, .no_builtin = true, - .max_rss = switch (b.graph.host.result.os.tag) { - .freebsd => 800_000_000, - .linux => switch (b.graph.host.result.cpu.arch) { - .aarch64 => 639_565_414, - .loongarch64 => 598_884_352, - .powerpc64le => 597_897_625, - .riscv64 => 636_429_516, - .s390x => 574_166_630, - .x86_64 => 978_463_129, - else => 900_000_000, - }, - .macos => switch (b.graph.host.result.cpu.arch) { - .aarch64 => 701_413_785, - else => 800_000_000, - }, - else => 900_000_000, - }, + .max_rss = 4_000_000_000, })); test_modules_step.dependOn(tests.addModuleTests(b, .{ @@ -543,12 +526,12 @@ pub fn build(b: *std.Build) !void { .test_extra_targets = test_extra_targets, .root_src = "lib/c.zig", .name = "zigc", - .desc = "Run the zigc tests", + .desc = "Run the zig libc implementation unit tests", .optimize_modes = optimization_modes, .include_paths = &.{}, .skip_single_threaded = true, .skip_non_native = skip_non_native, - .test_default_only = no_matrix, + .test_only = test_only, .skip_spirv = skip_spirv, .skip_wasm = skip_wasm, .skip_freebsd = skip_freebsd, @@ -560,7 +543,7 @@ pub fn build(b: *std.Build) !void { .skip_llvm = skip_llvm, .skip_libc = true, .no_builtin = true, - .max_rss = 900_000_000, + .max_rss = 4_000_000_000, })); test_modules_step.dependOn(tests.addModuleTests(b, .{ @@ -574,7 +557,7 @@ pub fn build(b: *std.Build) !void { .include_paths = &.{}, .skip_single_threaded = skip_single_threaded, .skip_non_native = skip_non_native, - .test_default_only = no_matrix, + .test_only = test_only, .skip_spirv = skip_spirv, .skip_wasm = skip_wasm, .skip_freebsd = skip_freebsd, @@ -585,22 +568,7 @@ pub fn build(b: *std.Build) !void { .skip_linux = skip_linux, .skip_llvm = skip_llvm, .skip_libc = skip_libc, - .max_rss = switch (b.graph.host.result.os.tag) { - .freebsd => switch (b.graph.host.result.cpu.arch) { - .x86_64 => 3_756_422_348, - else => 3_800_000_000, - }, - .linux => 6_800_000_000, - .macos => switch (b.graph.host.result.cpu.arch) { - .aarch64 => 8_273_795_481, - else => 8_300_000_000, - }, - .windows => switch (b.graph.host.result.cpu.arch) { - .x86_64 => 3_750_236_160, - else => 3_800_000_000, - }, - else => 8_300_000_000, - }, + .max_rss = 9_300_000_000, })); const unit_tests_step = b.step("test-unit", "Run the compiler source unit tests"); @@ -616,7 +584,7 @@ pub fn build(b: *std.Build) !void { .use_llvm = use_llvm, .use_lld = use_llvm, .zig_lib_dir = b.path("lib"), - .max_rss = 2_500_000_000, + .max_rss = 2_700_000_000, }); if (link_libc) { unit_tests.root_module.link_libc = true; @@ -643,30 +611,7 @@ pub fn build(b: *std.Build) !void { .skip_linux = skip_linux, .skip_llvm = skip_llvm, .skip_release = skip_release, - .max_rss = switch (b.graph.host.result.os.tag) { - .freebsd => switch (b.graph.host.result.cpu.arch) { - .x86_64 => 727_221_862, - else => 800_000_000, - }, - .linux => switch (b.graph.host.result.cpu.arch) { - .aarch64 => 1_318_185_369, - .loongarch64 => 1_422_904_524, - .powerpc64le => 560_870_604, - .riscv64 => 449_924_710, - .s390x => 1_946_743_603, - .x86_64 => 2_389_779_251, - else => 2_200_000_000, - }, - .macos => switch (b.graph.host.result.cpu.arch) { - .aarch64 => 1_813_612_134, - else => 1_900_000_000, - }, - .windows => switch (b.graph.host.result.cpu.arch) { - .x86_64 => 386_287_616, - else => 400_000_000, - }, - else => 2_200_000_000, - }, + .max_rss = 3_300_000_000, })); test_step.dependOn(tests.addLinkTests(b, enable_macos_sdk, enable_ios_sdk, enable_symlinks_windows)); test_step.dependOn(tests.addStackTraceTests(b, test_filters, skip_non_native)); @@ -717,7 +662,7 @@ pub fn build(b: *std.Build) !void { .test_filters = test_filters, .test_target_filters = test_target_filters, .skip_wasm = skip_wasm, - .max_rss = 2_496_066_355, + .max_rss = 3_500_000_000, })) |test_libc_step| test_step.dependOn(test_libc_step); } @@ -751,6 +696,7 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void { exe_options.addOption(u32, "tracy_callstack_depth", 0); exe_options.addOption(bool, "value_tracing", false); exe_options.addOption(DevEnv, "dev", .bootstrap); + exe_options.addOption(IoMode, "io_mode", .threaded); // zig1 chooses to interpret values by name. The tradeoff is as follows: // @@ -821,13 +767,13 @@ fn addCompilerMod(b: *std.Build, options: AddCompilerModOptions) *std.Build.Modu fn addCompilerStep(b: *std.Build, options: AddCompilerModOptions) *std.Build.Step.Compile { const exe = b.addExecutable(.{ .name = "zig", - .max_rss = 7_900_000_000, + .max_rss = 8_700_000_000, .root_module = addCompilerMod(b, options), }); exe.stack_size = stack_size; // Must match the condition in CMakeLists.txt. - const function_data_sections = options.target.result.cpu.arch.isPowerPC(); + const function_data_sections = options.target.result.cpu.arch.isArm() or options.target.result.cpu.arch.isPowerPC(); exe.link_function_sections = function_data_sections; exe.link_data_sections = function_data_sections; @@ -1534,6 +1480,7 @@ fn generateLangRef(b: *std.Build) std.Build.LazyPath { defer dir.close(io); var wf = b.addWriteFiles(); + b.step("test-docs", "Test code snippets from the docs").dependOn(&wf.step); var it = dir.iterateAssumeFirstIteration(); while (it.next(io) catch @panic("failed to read dir")) |entry| { diff --git a/ci/aarch64-freebsd-debug.sh b/ci/aarch64-freebsd-debug.sh new file mode 100755 index 0000000000..87ffb31102 --- /dev/null +++ b/ci/aarch64-freebsd-debug.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# Requires cmake ninja-build + +set -x +set -e + +TARGET="aarch64-freebsd-none" +MCPU="baseline" +CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5" +PREFIX="$HOME/deps/$CACHE_BASENAME" +ZIG="$PREFIX/bin/zig" + +# Override the cache directories because they won't actually help other CI runs +# which will be testing alternate versions of zig, and ultimately would just +# fill up space on the hard drive for no reason. +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" + +mkdir build-debug +cd build-debug + +export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" + +cmake .. \ + -DCMAKE_INSTALL_PREFIX="stage3-debug" \ + -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DCMAKE_BUILD_TYPE=Debug \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -DZIG_NO_LIB=ON \ + -GNinja \ + -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \ + -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE +# https://github.com/ziglang/zig/issues/22213 + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +stage3-debug/bin/zig build test docs \ + --maxrss ${ZSF_MAX_RSS:-0} \ + -Dstatic-llvm \ + -Dskip-non-native \ + --search-prefix "$PREFIX" \ + --zig-lib-dir "$PWD/../lib" \ + --test-timeout 2m + +stage3-debug/bin/zig build \ + --prefix stage4-debug \ + -Denable-llvm \ + -Dno-lib \ + -Dtarget=$TARGET \ + -Duse-zig-libcxx \ + -Dversion-string="$(stage3-debug/bin/zig version)" + +stage4-debug/bin/zig test ../test/behavior.zig diff --git a/ci/aarch64-freebsd-release.sh b/ci/aarch64-freebsd-release.sh new file mode 100755 index 0000000000..d5911241d6 --- /dev/null +++ b/ci/aarch64-freebsd-release.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# Requires cmake ninja-build + +set -x +set -e + +TARGET="aarch64-freebsd-none" +MCPU="baseline" +CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5" +PREFIX="$HOME/deps/$CACHE_BASENAME" +ZIG="$PREFIX/bin/zig" + +# Override the cache directories because they won't actually help other CI runs +# which will be testing alternate versions of zig, and ultimately would just +# fill up space on the hard drive for no reason. +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" + +mkdir build-release +cd build-release + +export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" + +cmake .. \ + -DCMAKE_INSTALL_PREFIX="stage3-release" \ + -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DCMAKE_BUILD_TYPE=Release \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -DZIG_NO_LIB=ON \ + -GNinja \ + -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \ + -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE +# https://github.com/ziglang/zig/issues/22213 + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +stage3-release/bin/zig build test docs \ + --maxrss ${ZSF_MAX_RSS:-0} \ + -Dstatic-llvm \ + -Dskip-non-native \ + --search-prefix "$PREFIX" \ + --zig-lib-dir "$PWD/../lib" \ + --test-timeout 2m + +# Ensure that stage3 and stage4 are byte-for-byte identical. +stage3-release/bin/zig build \ + --prefix stage4-release \ + -Denable-llvm \ + -Dno-lib \ + -Doptimize=ReleaseFast \ + -Dstrip \ + -Dtarget=$TARGET \ + -Duse-zig-libcxx \ + -Dversion-string="$(stage3-release/bin/zig version)" + +# diff returns an error code if the files differ. +echo "If the following command fails, it means nondeterminism has been" +echo "introduced, making stage3 and stage4 no longer byte-for-byte identical." +diff stage3-release/bin/zig stage4-release/bin/zig diff --git a/ci/aarch64-netbsd-debug.sh b/ci/aarch64-netbsd-debug.sh new file mode 100755 index 0000000000..4f5eb0d410 --- /dev/null +++ b/ci/aarch64-netbsd-debug.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# Requires cmake ninja-build + +set -x +set -e + +TARGET="aarch64-netbsd-none" +MCPU="baseline" +CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5" +PREFIX="$HOME/deps/$CACHE_BASENAME" +ZIG="$PREFIX/bin/zig" + +# Override the cache directories because they won't actually help other CI runs +# which will be testing alternate versions of zig, and ultimately would just +# fill up space on the hard drive for no reason. +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" + +mkdir build-debug +cd build-debug + +export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" + +cmake .. \ + -DCMAKE_INSTALL_PREFIX="stage3-debug" \ + -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DCMAKE_BUILD_TYPE=Debug \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -DZIG_NO_LIB=ON \ + -GNinja \ + -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \ + -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE +# https://github.com/ziglang/zig/issues/22213 + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +stage3-debug/bin/zig build test docs \ + --maxrss ${ZSF_MAX_RSS:-0} \ + -Dstatic-llvm \ + -Dskip-non-native \ + --search-prefix "$PREFIX" \ + --zig-lib-dir "$PWD/../lib" \ + --test-timeout 4m + +stage3-debug/bin/zig build \ + --prefix stage4-debug \ + -Denable-llvm \ + -Dno-lib \ + -Dtarget=$TARGET \ + -Duse-zig-libcxx \ + -Dversion-string="$(stage3-debug/bin/zig version)" + +stage4-debug/bin/zig test ../test/behavior.zig diff --git a/ci/aarch64-netbsd-release.sh b/ci/aarch64-netbsd-release.sh new file mode 100755 index 0000000000..d9d9477904 --- /dev/null +++ b/ci/aarch64-netbsd-release.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# Requires cmake ninja-build + +set -x +set -e + +TARGET="aarch64-netbsd-none" +MCPU="baseline" +CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5" +PREFIX="$HOME/deps/$CACHE_BASENAME" +ZIG="$PREFIX/bin/zig" + +# Override the cache directories because they won't actually help other CI runs +# which will be testing alternate versions of zig, and ultimately would just +# fill up space on the hard drive for no reason. +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" + +mkdir build-release +cd build-release + +export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" + +cmake .. \ + -DCMAKE_INSTALL_PREFIX="stage3-release" \ + -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DCMAKE_BUILD_TYPE=Release \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -DZIG_NO_LIB=ON \ + -GNinja \ + -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \ + -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE +# https://github.com/ziglang/zig/issues/22213 + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +stage3-release/bin/zig build test docs \ + --maxrss ${ZSF_MAX_RSS:-0} \ + -Dstatic-llvm \ + -Dskip-non-native \ + --search-prefix "$PREFIX" \ + --zig-lib-dir "$PWD/../lib" \ + --test-timeout 4m + +# Ensure that stage3 and stage4 are byte-for-byte identical. +stage3-release/bin/zig build \ + --prefix stage4-release \ + -Denable-llvm \ + -Dno-lib \ + -Doptimize=ReleaseFast \ + -Dstrip \ + -Dtarget=$TARGET \ + -Duse-zig-libcxx \ + -Dversion-string="$(stage3-release/bin/zig version)" + +# diff returns an error code if the files differ. +echo "If the following command fails, it means nondeterminism has been" +echo "introduced, making stage3 and stage4 no longer byte-for-byte identical." +diff stage3-release/bin/zig stage4-release/bin/zig diff --git a/ci/x86_64-linux-debug-llvm.sh b/ci/x86_64-linux-debug-llvm.sh index 2696ac60e7..96bb795e18 100755 --- a/ci/x86_64-linux-debug-llvm.sh +++ b/ci/x86_64-linux-debug-llvm.sh @@ -11,7 +11,7 @@ CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31" PREFIX="$HOME/deps/$CACHE_BASENAME" ZIG="$PREFIX/bin/zig" -export PATH="$HOME/deps/wasmtime-v38.0.3-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.0/bin:$HOME/local/bin:$PATH" +export PATH="$HOME/deps/wasmtime-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.1.1/bin:$HOME/local/bin:$PATH" # Override the cache directories because they won't actually help other CI runs # which will be testing alternate versions of zig, and ultimately would just @@ -54,7 +54,9 @@ stage3-debug/bin/zig build \ stage3-debug/bin/zig build test docs \ --maxrss ${ZSF_MAX_RSS:-0} \ -Dlldb=$HOME/deps/lldb-zig/Debug-e0a42bb34/bin/lldb \ + -Dlibc-test-path=$HOME/deps/libc-test-f2bac77 \ -fqemu \ + --libc-runtimes $HOME/deps/glibc-2.43-musl-1.2.5 \ -fwasmtime \ -Dstatic-llvm \ -Dskip-freebsd \ diff --git a/ci/x86_64-linux-debug.sh b/ci/x86_64-linux-debug.sh index baba340333..aeaf5b8678 100755 --- a/ci/x86_64-linux-debug.sh +++ b/ci/x86_64-linux-debug.sh @@ -11,7 +11,7 @@ CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31" PREFIX="$HOME/deps/$CACHE_BASENAME" ZIG="$PREFIX/bin/zig" -export PATH="$HOME/deps/wasmtime-v38.0.3-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.0/bin:$HOME/local/bin:$PATH" +export PATH="$HOME/deps/wasmtime-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.1.1/bin:$HOME/local/bin:$PATH" # Override the cache directories because they won't actually help other CI runs # which will be testing alternate versions of zig, and ultimately would just @@ -54,6 +54,7 @@ stage3-debug/bin/zig build test docs \ --maxrss ${ZSF_MAX_RSS:-0} \ -Dlldb=$HOME/deps/lldb-zig/Debug-e0a42bb34/bin/lldb \ -fqemu \ + --libc-runtimes $HOME/deps/glibc-2.43-musl-1.2.5 \ -fwasmtime \ -Dstatic-llvm \ -Dskip-freebsd \ diff --git a/ci/x86_64-linux-release.sh b/ci/x86_64-linux-release.sh index 56ce115e80..b1f6b84dcd 100755 --- a/ci/x86_64-linux-release.sh +++ b/ci/x86_64-linux-release.sh @@ -11,7 +11,7 @@ CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31" PREFIX="$HOME/deps/$CACHE_BASENAME" ZIG="$PREFIX/bin/zig" -export PATH="$HOME/deps/wasmtime-v38.0.3-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.0/bin:$HOME/local/bin:$PATH" +export PATH="$HOME/deps/wasmtime-v42.0.1-x86_64-linux:$HOME/deps/qemu-linux-x86_64-10.2.1.1/bin:$HOME/local/bin:$PATH" # Override the cache directories because they won't actually help other CI runs # which will be testing alternate versions of zig, and ultimately would just @@ -21,7 +21,8 @@ export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" # Test building from source without LLVM. cc -o bootstrap bootstrap.c -./bootstrap +# See comments in bootstrap.c for an explanation of the flag given here. +./bootstrap --workaround-gcc-sra-miscomp ./zig2 build -Dno-lib ./zig-out/bin/zig test test/behavior.zig @@ -59,7 +60,9 @@ stage3-release/bin/zig build \ stage3-release/bin/zig build test docs \ --maxrss ${ZSF_MAX_RSS:-0} \ -Dlldb=$HOME/deps/lldb-zig/Release-e0a42bb34/bin/lldb \ + -Dlibc-test-path=$HOME/deps/libc-test-f2bac77 \ -fqemu \ + --libc-runtimes $HOME/deps/glibc-2.43-musl-1.2.5 \ -fwasmtime \ -Dstatic-llvm \ -Dtarget=native-native-musl \ diff --git a/ci/x86_64-netbsd-debug.sh b/ci/x86_64-netbsd-debug.sh new file mode 100755 index 0000000000..68e9081f3b --- /dev/null +++ b/ci/x86_64-netbsd-debug.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +# Requires cmake ninja-build + +set -x +set -e + +TARGET="x86_64-netbsd-none" +MCPU="baseline" +CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5" +PREFIX="$HOME/deps/$CACHE_BASENAME" +ZIG="$PREFIX/bin/zig" + +# Override the cache directories because they won't actually help other CI runs +# which will be testing alternate versions of zig, and ultimately would just +# fill up space on the hard drive for no reason. +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" + +mkdir build-debug +cd build-debug + +export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" + +cmake .. \ + -DCMAKE_INSTALL_PREFIX="stage3-debug" \ + -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DCMAKE_BUILD_TYPE=Debug \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -DZIG_NO_LIB=ON \ + -GNinja \ + -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \ + -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE +# https://github.com/ziglang/zig/issues/22213 + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +stage3-debug/bin/zig build test docs \ + --maxrss ${ZSF_MAX_RSS:-0} \ + -Dstatic-llvm \ + -Dskip-non-native \ + --search-prefix "$PREFIX" \ + --zig-lib-dir "$PWD/../lib" \ + --test-timeout 2m + +stage3-debug/bin/zig build \ + --prefix stage4-debug \ + -Denable-llvm \ + -Dno-lib \ + -Dtarget=$TARGET \ + -Duse-zig-libcxx \ + -Dversion-string="$(stage3-debug/bin/zig version)" + +stage4-debug/bin/zig test ../test/behavior.zig diff --git a/ci/x86_64-netbsd-release.sh b/ci/x86_64-netbsd-release.sh new file mode 100755 index 0000000000..225a527686 --- /dev/null +++ b/ci/x86_64-netbsd-release.sh @@ -0,0 +1,68 @@ +#!/bin/sh + +# Requires cmake ninja-build + +set -x +set -e + +TARGET="x86_64-netbsd-none" +MCPU="baseline" +CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.16.0-dev.2287+eb3f16db5" +PREFIX="$HOME/deps/$CACHE_BASENAME" +ZIG="$PREFIX/bin/zig" + +# Override the cache directories because they won't actually help other CI runs +# which will be testing alternate versions of zig, and ultimately would just +# fill up space on the hard drive for no reason. +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" + +mkdir build-release +cd build-release + +export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" +export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" + +cmake .. \ + -DCMAKE_INSTALL_PREFIX="stage3-release" \ + -DCMAKE_PREFIX_PATH="$PREFIX" \ + -DCMAKE_BUILD_TYPE=Release \ + -DZIG_TARGET_TRIPLE="$TARGET" \ + -DZIG_TARGET_MCPU="$MCPU" \ + -DZIG_STATIC=ON \ + -DZIG_NO_LIB=ON \ + -GNinja \ + -DCMAKE_C_LINKER_DEPFILE_SUPPORTED=FALSE \ + -DCMAKE_CXX_LINKER_DEPFILE_SUPPORTED=FALSE +# https://github.com/ziglang/zig/issues/22213 + +# Now cmake will use zig as the C/C++ compiler. We reset the environment variables +# so that installation and testing do not get affected by them. +unset CC +unset CXX + +ninja install + +stage3-release/bin/zig build test docs \ + --maxrss ${ZSF_MAX_RSS:-0} \ + -Dstatic-llvm \ + -Dskip-non-native \ + --search-prefix "$PREFIX" \ + --zig-lib-dir "$PWD/../lib" \ + --test-timeout 2m + +# Ensure that stage3 and stage4 are byte-for-byte identical. +stage3-release/bin/zig build \ + --prefix stage4-release \ + -Denable-llvm \ + -Dno-lib \ + -Doptimize=ReleaseFast \ + -Dstrip \ + -Dtarget=$TARGET \ + -Duse-zig-libcxx \ + -Dversion-string="$(stage3-release/bin/zig version)" + +# diff returns an error code if the files differ. +echo "If the following command fails, it means nondeterminism has been" +echo "introduced, making stage3 and stage4 no longer byte-for-byte identical." +diff stage3-release/bin/zig stage4-release/bin/zig diff --git a/ci/x86_64-windows-debug.ps1 b/ci/x86_64-windows-debug.ps1 index e6ba8b0861..d1031386c5 100644 --- a/ci/x86_64-windows-debug.ps1 +++ b/ci/x86_64-windows-debug.ps1 @@ -1,21 +1,10 @@ $TARGET = "x86_64-windows-gnu" -$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31" $MCPU = "baseline" -$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip" -$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME" +$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31" $ZIG = "$PREFIX_PATH\bin\zig.exe" $ZIG_LIB_DIR = "$(Get-Location)\lib" $ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 } -if (!(Test-Path "$PREFIX_PATH.zip")) { - Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL" - Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip" - - Write-Output "Extracting..." - Add-Type -AssemblyName System.IO.Compression.FileSystem ; - [System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..") -} - function CheckLastExitCode { if (!$?) { exit 1 @@ -35,7 +24,7 @@ Set-Location -Path 'build-debug' # CMake gives a syntax error when file paths with backward slashes are used. # Here, we use forward slashes only to work around this. -& cmake .. ` +cmake .. ` -GNinja ` -DCMAKE_INSTALL_PREFIX="stage3-debug" ` -DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" ` @@ -54,7 +43,7 @@ ninja install CheckLastExitCode Write-Output "Main test suite..." -& "stage3-debug\bin\zig.exe" build test docs ` +stage3-debug\bin\zig build test docs ` --maxrss $ZSF_MAX_RSS ` --zig-lib-dir "$ZIG_LIB_DIR" ` --search-prefix "$PREFIX_PATH" ` @@ -66,39 +55,38 @@ Write-Output "Main test suite..." CheckLastExitCode Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..." -& "stage3-debug\bin\zig.exe" test ` - ..\test\behavior.zig ` - --zig-lib-dir "$ZIG_LIB_DIR" ` - -ofmt=c ` - -femit-bin="test-x86_64-windows-msvc.c" ` - --test-no-exec ` - -target x86_64-windows-msvc ` - -lc -CheckLastExitCode - -& "stage3-debug\bin\zig.exe" build-obj ` +stage3-debug\bin\zig build-obj ` --zig-lib-dir "$ZIG_LIB_DIR" ` -ofmt=c ` -OReleaseSmall ` --name compiler_rt ` -femit-bin="compiler_rt-x86_64-windows-msvc.c" ` - --dep build_options ` -target x86_64-windows-msvc ` - -Mroot="..\lib\compiler_rt.zig" ` - -Mbuild_options="config.zig" + -lc ` + ..\lib\compiler_rt.zig CheckLastExitCode -Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" +stage3-debug\bin\zig test ` + --zig-lib-dir "$ZIG_LIB_DIR" ` + -ofmt=c ` + -femit-bin="behavior-x86_64-windows-msvc.c" ` + --test-no-exec ` + -target x86_64-windows-msvc ` + -lc ` + ..\test\behavior.zig CheckLastExitCode -Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" ` +Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" +CheckLastExitCode + +Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" ` -DevCmdArguments '-arch=x64 -no_logo' ` -StartInPath $(Get-Location) CheckLastExitCode Write-Output "Build and run behavior tests with msvc..." -& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib +cl /I..\lib /W3 /Z7 behavior-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /link /nologo /debug /subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib CheckLastExitCode -& .\test-x86_64-windows-msvc.exe +.\behavior-x86_64-windows-msvc CheckLastExitCode diff --git a/ci/x86_64-windows-release.ps1 b/ci/x86_64-windows-release.ps1 index e22e3af1c7..e24432e076 100644 --- a/ci/x86_64-windows-release.ps1 +++ b/ci/x86_64-windows-release.ps1 @@ -1,21 +1,10 @@ $TARGET = "x86_64-windows-gnu" -$ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31" $MCPU = "baseline" -$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip" -$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME" +$PREFIX_PATH = "$($Env:USERPROFILE)\deps\zig+llvm+lld+clang-$TARGET-0.16.0-dev.104+689461e31" $ZIG = "$PREFIX_PATH\bin\zig.exe" $ZIG_LIB_DIR = "$(Get-Location)\lib" $ZSF_MAX_RSS = if ($Env:ZSF_MAX_RSS) { $Env:ZSF_MAX_RSS } else { 0 } -if (!(Test-Path "$PREFIX_PATH.zip")) { - Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL" - Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$PREFIX_PATH.zip" - - Write-Output "Extracting..." - Add-Type -AssemblyName System.IO.Compression.FileSystem ; - [System.IO.Compression.ZipFile]::ExtractToDirectory("$PREFIX_PATH.zip", "$PREFIX_PATH\..") -} - function CheckLastExitCode { if (!$?) { exit 1 @@ -35,7 +24,7 @@ Set-Location -Path 'build-release' # CMake gives a syntax error when file paths with backward slashes are used. # Here, we use forward slashes only to work around this. -& cmake .. ` +cmake .. ` -GNinja ` -DCMAKE_INSTALL_PREFIX="stage3-release" ` -DCMAKE_PREFIX_PATH="$($PREFIX_PATH -Replace "\\", "/")" ` @@ -54,7 +43,7 @@ ninja install CheckLastExitCode Write-Output "Main test suite..." -& "stage3-release\bin\zig.exe" build test docs ` +stage3-release\bin\zig.exe build test docs ` --maxrss $ZSF_MAX_RSS ` --zig-lib-dir "$ZIG_LIB_DIR" ` --search-prefix "$PREFIX_PATH" ` @@ -67,7 +56,7 @@ CheckLastExitCode # Ensure that stage3 and stage4 are byte-for-byte identical. Write-Output "Build and compare stage4..." -& "stage3-release\bin\zig.exe" build ` +stage3-release\bin\zig.exe build ` --prefix stage4-release ` -Denable-llvm ` -Dno-lib ` @@ -85,39 +74,38 @@ Compare-Object (Get-Content stage3-release\bin\zig.exe) (Get-Content stage4-rele CheckLastExitCode Write-Output "Build x86_64-windows-msvc behavior tests using the C backend..." -& "stage3-release\bin\zig.exe" test ` - ..\test\behavior.zig ` - --zig-lib-dir "$ZIG_LIB_DIR" ` - -ofmt=c ` - -femit-bin="test-x86_64-windows-msvc.c" ` - --test-no-exec ` - -target x86_64-windows-msvc ` - -lc -CheckLastExitCode - -& "stage3-release\bin\zig.exe" build-obj ` +stage3-release\bin\zig.exe build-obj ` --zig-lib-dir "$ZIG_LIB_DIR" ` -ofmt=c ` -OReleaseSmall ` --name compiler_rt ` -femit-bin="compiler_rt-x86_64-windows-msvc.c" ` - --dep build_options ` -target x86_64-windows-msvc ` - -Mroot="..\lib\compiler_rt.zig" ` - -Mbuild_options="config.zig" + -lc ` + ..\lib\compiler_rt.zig CheckLastExitCode -Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" +stage3-release\bin\zig.exe test ` + --zig-lib-dir "$ZIG_LIB_DIR" ` + -ofmt=c ` + -femit-bin="behavior-x86_64-windows-msvc.c" ` + --test-no-exec ` + -target x86_64-windows-msvc ` + -lc ` + ..\test\behavior.zig CheckLastExitCode -Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" ` +Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" +CheckLastExitCode + +Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\18\BuildTools" ` -DevCmdArguments '-arch=x64 -no_logo' ` -StartInPath $(Get-Location) CheckLastExitCode Write-Output "Build and run behavior tests with msvc..." -& cl.exe -I..\lib test-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /W3 /Z7 -link -nologo -debug -subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib +cl /I..\lib /W3 /Z7 behavior-x86_64-windows-msvc.c compiler_rt-x86_64-windows-msvc.c /link /nologo /debug /subsystem:console kernel32.lib ntdll.lib libcmt.lib ws2_32.lib CheckLastExitCode -& .\test-x86_64-windows-msvc.exe +.\behavior-x86_64-windows-msvc CheckLastExitCode diff --git a/doc/langref.html.in b/doc/langref.html.in index 3671047ec0..7118d01c91 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -128,6 +128,7 @@ } .table-wrapper { width: 100%; + margin: 1em auto; overflow-x: auto; } @@ -2102,8 +2103,9 @@ or less than {#syntax#}1 << 29{#endsyntax#}.

- In Zig, a pointer type has an alignment value. If the value is equal to the - alignment of the underlying type, it can be omitted from the type: + Pointer types may explicitly specify an alignment in bytes. If it is not + specified, the alignment is assumed to be equal to the alignment of the + underlying type.

{#code|test_variable_alignment.zig#} @@ -3471,6 +3473,42 @@ void do_a_thing(struct Foo *foo) { without rounding (i.e. the integer's precision does not exceed the float's significand precision). Larger integer types that cannot be safely coerced must be explicitly casted with {#link|@floatFromInt#}.

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Float TypeLargest Integer Types
{#syntax#}f16{#endsyntax#}{#syntax#}i12{#endsyntax#} and {#syntax#}u11{#endsyntax#}
{#syntax#}f32{#endsyntax#}{#syntax#}i25{#endsyntax#} and {#syntax#}u24{#endsyntax#}
{#syntax#}f64{#endsyntax#}{#syntax#}i54{#endsyntax#} and {#syntax#}u53{#endsyntax#}
{#syntax#}f80{#endsyntax#}{#syntax#}i65{#endsyntax#} and {#syntax#}u64{#endsyntax#}
{#syntax#}f128{#endsyntax#}{#syntax#}i114{#endsyntax#} and {#syntax#}u113{#endsyntax#}
{#syntax#}c_longdouble{#endsyntax#}Varies by target
+
{#code|test_int_to_float_coercion.zig#} {#code|test_failed_int_to_float_coercion.zig#} @@ -4828,7 +4866,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val {#header_close#} {#header_open|@errorFromInt#} -
{#syntax#}@errorFromInt(value: std.meta.Int(.unsigned, @bitSizeOf(anyerror))) anyerror{#endsyntax#}
+
{#syntax#}@errorFromInt(value: @Int(.unsigned, @bitSizeOf(anyerror))) anyerror{#endsyntax#}

Converts from the integer representation of an error into {#link|The Global Error Set#} type.

@@ -5069,7 +5107,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val {#header_close#} {#header_open|@intFromError#} -
{#syntax#}@intFromError(err: anytype) std.meta.Int(.unsigned, @bitSizeOf(anyerror)){#endsyntax#}
+
{#syntax#}@intFromError(err: anytype) @Int(.unsigned, @bitSizeOf(anyerror)){#endsyntax#}

Supports the following types:

@@ -6330,7 +6368,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val

Zig has a general purpose allocator available to be imported - with {#syntax#}std.heap.GeneralPurposeAllocator{#endsyntax#}. However, it is still recommended to + with {#syntax#}std.heap.DebugAllocator{#endsyntax#}. However, it is still recommended to follow the {#link|Choosing an Allocator#} guide.

diff --git a/doc/langref/builtin.CallModifier struct.zig b/doc/langref/builtin.CallModifier struct.zig index 60fc4f2ac4..2626441a9e 100644 --- a/doc/langref/builtin.CallModifier struct.zig +++ b/doc/langref/builtin.CallModifier struct.zig @@ -2,9 +2,6 @@ pub const CallModifier = enum { /// Equivalent to function call syntax. auto, - /// Equivalent to async keyword used with function call syntax. - async_kw, - /// Prevents tail call optimization. This guarantees that the return /// address will point to the callsite, as opposed to the callsite's /// callsite. If the call is otherwise required to be tail-called @@ -17,7 +14,7 @@ pub const CallModifier = enum { /// Asserts that the function call will not suspend. This allows a /// non-async function to call an async function. - no_async, + no_suspend, /// Guarantees that the call will be generated with tail call optimization. /// If this is not possible, a compile error is emitted instead. diff --git a/doc/langref/cImport_builtin.zig b/doc/langref/cImport_builtin.zig index daed710f9d..e0cdf7bc27 100644 --- a/doc/langref/cImport_builtin.zig +++ b/doc/langref/cImport_builtin.zig @@ -4,6 +4,7 @@ const c = @cImport({ @cInclude("stdio.h"); }); pub fn main() void { + if (@import("builtin").os.tag == .netbsd) return; // https://github.com/Vexu/arocc/issues/960 _ = c.printf("hello\n"); } diff --git a/doc/langref/error_union_parsing_u64.zig b/doc/langref/error_union_parsing_u64.zig index 9e55e247f2..b710d159ac 100644 --- a/doc/langref/error_union_parsing_u64.zig +++ b/doc/langref/error_union_parsing_u64.zig @@ -35,7 +35,7 @@ fn charToDigit(c: u8) u8 { test "parse u64" { const result = try parseU64("1234", 10); - try std.testing.expect(result == 1234); + try std.testing.expectEqual(1234, result); } // test diff --git a/doc/langref/result_location_interfering_with_swap.zig b/doc/langref/result_location_interfering_with_swap.zig index 6182d4818a..7442d2fa33 100644 --- a/doc/langref/result_location_interfering_with_swap.zig +++ b/doc/langref/result_location_interfering_with_swap.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "attempt to swap array elements with array initializer" { var arr: [2]u32 = .{ 1, 2 }; arr = .{ arr[1], arr[0] }; @@ -6,8 +6,8 @@ test "attempt to swap array elements with array initializer" { // arr[0] = arr[1]; // arr[1] = arr[0]; // So this fails! - try expect(arr[0] == 2); // succeeds - try expect(arr[1] == 1); // fails + try expectEqual(2, arr[0]); // succeeds + try expectEqual(1, arr[1]); // fails } // test_error= diff --git a/doc/langref/test_TypeOf_builtin.zig b/doc/langref/test_TypeOf_builtin.zig index 2c833363fd..6ce5f09844 100644 --- a/doc/langref/test_TypeOf_builtin.zig +++ b/doc/langref/test_TypeOf_builtin.zig @@ -1,11 +1,11 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "no runtime side effects" { var data: i32 = 0; const T = @TypeOf(foo(i32, &data)); - try comptime expect(T == i32); - try expect(data == 0); + try comptime expectEqual(i32, T); + try expectEqual(0, data); } fn foo(comptime T: type, ptr: *T) T { diff --git a/doc/langref/test_allocator.zig b/doc/langref/test_allocator.zig index ff0e18a507..35e1bd701f 100644 --- a/doc/langref/test_allocator.zig +++ b/doc/langref/test_allocator.zig @@ -1,13 +1,13 @@ const std = @import("std"); const Allocator = std.mem.Allocator; -const expect = std.testing.expect; +const expectEqualStrings = std.testing.expectEqualStrings; test "using an allocator" { var buffer: [100]u8 = undefined; var fba = std.heap.FixedBufferAllocator.init(&buffer); const allocator = fba.allocator(); const result = try concat(allocator, "foo", "bar"); - try expect(std.mem.eql(u8, "foobar", result)); + try expectEqualStrings("foobar", result); } fn concat(allocator: Allocator, a: []const u8, b: []const u8) ![]u8 { diff --git a/doc/langref/test_allowzero.zig b/doc/langref/test_allowzero.zig index 0798322bb0..a5002f7d8c 100644 --- a/doc/langref/test_allowzero.zig +++ b/doc/langref/test_allowzero.zig @@ -1,11 +1,11 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "allowzero" { var zero: usize = 0; // var to make to runtime-known _ = &zero; // suppress 'var is never mutated' error const ptr: *allowzero i32 = @ptrFromInt(zero); - try expect(@intFromPtr(ptr) == 0); + try expectEqual(0, @intFromPtr(ptr)); } // test diff --git a/doc/langref/test_anonymous_struct.zig b/doc/langref/test_anonymous_struct.zig index 82d4f62203..037ca1dd48 100644 --- a/doc/langref/test_anonymous_struct.zig +++ b/doc/langref/test_anonymous_struct.zig @@ -1,5 +1,6 @@ const std = @import("std"); const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "fully anonymous struct" { try check(.{ @@ -11,11 +12,11 @@ test "fully anonymous struct" { } fn check(args: anytype) !void { - try expect(args.int == 1234); - try expect(args.float == 12.34); + try expectEqual(1234, args.int); + try expectEqual(12.34, args.float); try expect(args.b); - try expect(args.s[0] == 'h'); - try expect(args.s[1] == 'i'); + try expectEqual('h', args.s[0]); + try expectEqual('i', args.s[1]); } // test diff --git a/doc/langref/test_anonymous_union.zig b/doc/langref/test_anonymous_union.zig index bb8311d5eb..f0ce2980fa 100644 --- a/doc/langref/test_anonymous_union.zig +++ b/doc/langref/test_anonymous_union.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Number = union { int: i32, @@ -9,8 +9,8 @@ const Number = union { test "anonymous union literal syntax" { const i: Number = .{ .int = 42 }; const f = makeNumber(); - try expect(i.int == 42); - try expect(f.float == 12.34); + try expectEqual(42, i.int); + try expectEqual(12.34, f.float); } fn makeNumber() Number { diff --git a/doc/langref/test_arrays.zig b/doc/langref/test_arrays.zig index 0c479dbce1..fa8d2ed3d3 100644 --- a/doc/langref/test_arrays.zig +++ b/doc/langref/test_arrays.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; const assert = @import("std").debug.assert; const mem = @import("std").mem; @@ -29,7 +29,7 @@ test "iterate over an array" { for (message) |byte| { sum += byte; } - try expect(sum == 'h' + 'e' + 'l' * 2 + 'o'); + try expectEqual('h' + 'e' + 'l' * 2 + 'o', sum); } // modifiable array @@ -39,8 +39,8 @@ test "modify an array" { for (&some_integers, 0..) |*item, i| { item.* = @intCast(i); } - try expect(some_integers[10] == 10); - try expect(some_integers[99] == 99); + try expectEqual(10, some_integers[10]); + try expectEqual(99, some_integers[99]); } // array concatenation works if the values are known @@ -91,8 +91,8 @@ const Point = struct { }; test "compile-time array initialization" { - try expect(fancy_array[4].x == 4); - try expect(fancy_array[4].y == 8); + try expectEqual(4, fancy_array[4].x); + try expectEqual(8, fancy_array[4].y); } // call a function to initialize an array @@ -104,9 +104,9 @@ fn makePoint(x: i32) Point { }; } test "array initialization with function calls" { - try expect(more_points[4].x == 3); - try expect(more_points[4].y == 6); - try expect(more_points.len == 10); + try expectEqual(3, more_points[4].x); + try expectEqual(6, more_points[4].y); + try expectEqual(10, more_points.len); } // test diff --git a/doc/langref/test_basic_slices.zig b/doc/langref/test_basic_slices.zig index 3d3c7c6d7c..2801314835 100644 --- a/doc/langref/test_basic_slices.zig +++ b/doc/langref/test_basic_slices.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; const expectEqualSlices = @import("std").testing.expectEqualSlices; test "basic slices" { @@ -12,14 +12,14 @@ test "basic slices" { try expectEqualSlices(i32, slice, alt_slice); - try expect(@TypeOf(slice) == []i32); - try expect(&slice[0] == &array[0]); - try expect(slice.len == array.len); + try expectEqual([]i32, @TypeOf(slice)); + try expectEqual(&array[0], &slice[0]); + try expectEqual(array.len, slice.len); // If you slice with comptime-known start and end positions, the result is // a pointer to an array, rather than a slice. const array_ptr = array[0..array.len]; - try expect(@TypeOf(array_ptr) == *[array.len]i32); + try expectEqual(*[array.len]i32, @TypeOf(array_ptr)); // You can perform a slice-by-length by slicing twice. This allows the compiler // to perform some optimisations like recognising a comptime-known length when @@ -28,13 +28,13 @@ test "basic slices" { _ = &runtime_start; const length = 2; const array_ptr_len = array[runtime_start..][0..length]; - try expect(@TypeOf(array_ptr_len) == *[length]i32); + try expectEqual(*[length]i32, @TypeOf(array_ptr_len)); // Using the address-of operator on a slice gives a single-item pointer. - try expect(@TypeOf(&slice[0]) == *i32); + try expectEqual(*i32, @TypeOf(&slice[0])); // Using the `ptr` field gives a many-item pointer. - try expect(@TypeOf(slice.ptr) == [*]i32); - try expect(@intFromPtr(slice.ptr) == @intFromPtr(&slice[0])); + try expectEqual([*]i32, @TypeOf(slice.ptr)); + try expectEqual(@intFromPtr(slice.ptr), @intFromPtr(&slice[0])); // Slices have array bounds checking. If you try to access something out // of bounds, you'll get a safety check failure: @@ -47,8 +47,8 @@ test "basic slices" { const empty1 = &[0]u8{}; // If the type is known you can use this short hand: const empty2: []u8 = &.{}; - try expect(empty1.len == 0); - try expect(empty2.len == 0); + try expectEqual(0, empty1.len); + try expectEqual(0, empty2.len); // A zero-length initialization can always be used to create an empty slice, even if the slice is mutable. // This is because the pointed-to data is zero bits long, so its immutability is irrelevant. diff --git a/doc/langref/test_bitOffsetOf_offsetOf.zig b/doc/langref/test_bitOffsetOf_offsetOf.zig index ed4faebf5f..e2eb49f8a3 100644 --- a/doc/langref/test_bitOffsetOf_offsetOf.zig +++ b/doc/langref/test_bitOffsetOf_offsetOf.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const BitField = packed struct { a: u3, @@ -9,13 +9,13 @@ const BitField = packed struct { test "offsets of non-byte-aligned fields" { comptime { - try expect(@bitOffsetOf(BitField, "a") == 0); - try expect(@bitOffsetOf(BitField, "b") == 3); - try expect(@bitOffsetOf(BitField, "c") == 6); + try expectEqual(0, @bitOffsetOf(BitField, "a")); + try expectEqual(3, @bitOffsetOf(BitField, "b")); + try expectEqual(6, @bitOffsetOf(BitField, "c")); - try expect(@offsetOf(BitField, "a") == 0); - try expect(@offsetOf(BitField, "b") == 0); - try expect(@offsetOf(BitField, "c") == 0); + try expectEqual(0, @offsetOf(BitField, "a")); + try expectEqual(0, @offsetOf(BitField, "b")); + try expectEqual(0, @offsetOf(BitField, "c")); } } diff --git a/doc/langref/test_call_builtin.zig b/doc/langref/test_call_builtin.zig index 8caecf73c4..cc465f2e45 100644 --- a/doc/langref/test_call_builtin.zig +++ b/doc/langref/test_call_builtin.zig @@ -1,7 +1,7 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "noinline function call" { - try expect(@call(.auto, add, .{ 3, 9 }) == 12); + try expectEqual(12, @call(.auto, add, .{ 3, 9 })); } fn add(a: i32, b: i32) i32 { diff --git a/doc/langref/test_coerce_error_subset_to_superset.zig b/doc/langref/test_coerce_error_subset_to_superset.zig index d46c761e4e..58279a1323 100644 --- a/doc/langref/test_coerce_error_subset_to_superset.zig +++ b/doc/langref/test_coerce_error_subset_to_superset.zig @@ -12,7 +12,7 @@ const AllocationError = error{ test "coerce subset to superset" { const err = foo(AllocationError.OutOfMemory); - try std.testing.expect(err == FileOpenError.OutOfMemory); + try std.testing.expectEqual(FileOpenError.OutOfMemory, err); } fn foo(err: AllocationError) FileOpenError { diff --git a/doc/langref/test_coerce_large_to_small.zig b/doc/langref/test_coerce_large_to_small.zig index 62111af979..2c7b390e66 100644 --- a/doc/langref/test_coerce_large_to_small.zig +++ b/doc/langref/test_coerce_large_to_small.zig @@ -1,10 +1,10 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "coercing large integer type to smaller one when value is comptime-known to fit" { const x: u64 = 255; const y: u8 = x; - try expect(y == 255); + try expectEqual(255, y); } // test diff --git a/doc/langref/test_coerce_optional_wrapped_error_union.zig b/doc/langref/test_coerce_optional_wrapped_error_union.zig index c41dd0b1d0..bddd2e1acd 100644 --- a/doc/langref/test_coerce_optional_wrapped_error_union.zig +++ b/doc/langref/test_coerce_optional_wrapped_error_union.zig @@ -1,12 +1,12 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "coerce to optionals wrapped in error union" { const x: anyerror!?i32 = 1234; const y: anyerror!?i32 = null; - try expect((try x).? == 1234); - try expect((try y) == null); + try expectEqual(1234, (try x).?); + try expectEqual(null, (try y)); } // test diff --git a/doc/langref/test_coerce_optionals.zig b/doc/langref/test_coerce_optionals.zig index 415bb2344b..2698f35cf0 100644 --- a/doc/langref/test_coerce_optionals.zig +++ b/doc/langref/test_coerce_optionals.zig @@ -1,12 +1,12 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "coerce to optionals" { const x: ?i32 = 1234; const y: ?i32 = null; - try expect(x.? == 1234); - try expect(y == null); + try expectEqual(1234, x.?); + try expectEqual(null, y); } // test diff --git a/doc/langref/test_coerce_slices_arrays_and_pointers.zig b/doc/langref/test_coerce_slices_arrays_and_pointers.zig index 67b2687163..f79fb8f767 100644 --- a/doc/langref/test_coerce_slices_arrays_and_pointers.zig +++ b/doc/langref/test_coerce_slices_arrays_and_pointers.zig @@ -1,5 +1,7 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; +const expectEqualStrings = std.testing.expectEqualStrings; +const expectEqualSlices = std.testing.expectEqualSlices; // You can assign constant pointers to arrays to a slice with // const modifier on the element type. Useful in particular for @@ -7,48 +9,48 @@ const expect = std.testing.expect; test "*const [N]T to []const T" { const x1: []const u8 = "hello"; const x2: []const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; - try expect(std.mem.eql(u8, x1, x2)); + try expectEqualStrings(x1, x2); const y: []const f32 = &[2]f32{ 1.2, 3.4 }; - try expect(y[0] == 1.2); + try expectEqual(1.2, y[0]); } // Likewise, it works when the destination type is an error union. test "*const [N]T to E![]const T" { const x1: anyerror![]const u8 = "hello"; const x2: anyerror![]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; - try expect(std.mem.eql(u8, try x1, try x2)); + try expectEqualStrings(try x1, try x2); const y: anyerror![]const f32 = &[2]f32{ 1.2, 3.4 }; - try expect((try y)[0] == 1.2); + try expectEqual(1.2, (try y)[0]); } // Likewise, it works when the destination type is an optional. test "*const [N]T to ?[]const T" { const x1: ?[]const u8 = "hello"; const x2: ?[]const u8 = &[5]u8{ 'h', 'e', 'l', 'l', 111 }; - try expect(std.mem.eql(u8, x1.?, x2.?)); + try expectEqualStrings(x1.?, x2.?); const y: ?[]const f32 = &[2]f32{ 1.2, 3.4 }; - try expect(y.?[0] == 1.2); + try expectEqual(1.2, y.?[0]); } // In this cast, the array length becomes the slice length. test "*[N]T to []T" { var buf: [5]u8 = "hello".*; const x: []u8 = &buf; - try expect(std.mem.eql(u8, x, "hello")); + try expectEqualStrings("hello", x); const buf2 = [2]f32{ 1.2, 3.4 }; const x2: []const f32 = &buf2; - try expect(std.mem.eql(f32, x2, &[2]f32{ 1.2, 3.4 })); + try expectEqualSlices(f32, &[2]f32{ 1.2, 3.4 }, x2); } // Single-item pointers to arrays can be coerced to many-item pointers. test "*[N]T to [*]T" { var buf: [5]u8 = "hello".*; const x: [*]u8 = &buf; - try expect(x[4] == 'o'); + try expectEqual('o', x[4]); // x[5] would be an uncaught out of bounds pointer dereference! } @@ -56,7 +58,7 @@ test "*[N]T to [*]T" { test "*[N]T to ?[*]T" { var buf: [5]u8 = "hello".*; const x: ?[*]u8 = &buf; - try expect(x.?[4] == 'o'); + try expectEqual('o', x.?[4]); } // Single-item pointers can be cast to len-1 single-item arrays. @@ -64,14 +66,14 @@ test "*T to *[1]T" { var x: i32 = 1234; const y: *[1]i32 = &x; const z: [*]i32 = y; - try expect(z[0] == 1234); + try expectEqual(1234, z[0]); } // Sentinel-terminated slices can be coerced into sentinel-terminated pointers test "[:x]T to [*:x]T" { const buf: [:0]const u8 = "hello"; const buf2: [*:0]const u8 = buf; - try expect(buf2[4] == 'o'); + try expectEqual('o', buf2[4]); } // test diff --git a/doc/langref/test_coerce_to_error_union.zig b/doc/langref/test_coerce_to_error_union.zig index 2789a92198..4c42e24afb 100644 --- a/doc/langref/test_coerce_to_error_union.zig +++ b/doc/langref/test_coerce_to_error_union.zig @@ -1,11 +1,11 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "coercion to error unions" { const x: anyerror!i32 = 1234; const y: anyerror!i32 = error.Failure; - try expect((try x) == 1234); + try expectEqual(1234, (try x)); try std.testing.expectError(error.Failure, y); } diff --git a/doc/langref/test_coerce_tuples_arrays.zig b/doc/langref/test_coerce_tuples_arrays.zig index 6d0e63e15c..0005d33e8b 100644 --- a/doc/langref/test_coerce_tuples_arrays.zig +++ b/doc/langref/test_coerce_tuples_arrays.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Tuple = struct { u8, u8 }; test "coercion from homogeneous tuple to array" { diff --git a/doc/langref/test_coerce_unions_enums.zig b/doc/langref/test_coerce_unions_enums.zig index 0a782b4c54..94655c2e9d 100644 --- a/doc/langref/test_coerce_unions_enums.zig +++ b/doc/langref/test_coerce_unions_enums.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const E = enum { one, @@ -28,22 +28,22 @@ const U2 = union(enum) { test "coercion between unions and enums" { const u = U{ .two = 12.34 }; const e: E = u; // coerce union to enum - try expect(e == E.two); + try expectEqual(E.two, e); const three = E.three; const u_2: U = three; // coerce enum to union - try expect(u_2 == E.three); + try expectEqual(E.three, u_2); const u_3: U = .three; // coerce enum literal to union - try expect(u_3 == E.three); + try expectEqual(E.three, u_3); const u_4: U2 = .a; // coerce enum literal to union with inferred enum tag type. - try expect(u_4.tag() == 1); + try expectEqual(1, u_4.tag()); // The following example is invalid. // error: coercion from enum '@EnumLiteral()' to union 'test_coerce_unions_enum.U2' must initialize 'f32' field 'b' //var u_5: U2 = .b; - //try expect(u_5.tag() == 2); + //try expectEqual(2, u_5.tag()); } // test diff --git a/doc/langref/test_comptime_evaluation.zig b/doc/langref/test_comptime_evaluation.zig index 832814e595..521aa14edd 100644 --- a/doc/langref/test_comptime_evaluation.zig +++ b/doc/langref/test_comptime_evaluation.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; const CmdFn = struct { name: []const u8, @@ -32,9 +32,9 @@ fn performFn(comptime prefix_char: u8, start_value: i32) i32 { } test "perform fn" { - try expect(performFn('t', 1) == 6); - try expect(performFn('o', 0) == 1); - try expect(performFn('w', 99) == 99); + try expectEqual(6, performFn('t', 1)); + try expectEqual(1, performFn('o', 0)); + try expectEqual(99, performFn('w', 99)); } // test diff --git a/doc/langref/test_comptime_invalid_error_code.zig b/doc/langref/test_comptime_invalid_error_code.zig index ebc6314764..e4fedf5812 100644 --- a/doc/langref/test_comptime_invalid_error_code.zig +++ b/doc/langref/test_comptime_invalid_error_code.zig @@ -1,8 +1,5 @@ comptime { - const err = error.AnError; - const number = @intFromError(err) + 10; - const invalid_err = @errorFromInt(number); - _ = invalid_err; + _ = @errorFromInt(12345); } -// test_error=integer value '11' represents no error +// test_error=integer value '12345' represents no error diff --git a/doc/langref/test_comptime_max_with_bool.zig b/doc/langref/test_comptime_max_with_bool.zig index 4d05cbbff0..2bcd16cb39 100644 --- a/doc/langref/test_comptime_max_with_bool.zig +++ b/doc/langref/test_comptime_max_with_bool.zig @@ -8,7 +8,7 @@ fn max(comptime T: type, a: T, b: T) T { } } test "try to compare bools" { - try @import("std").testing.expect(max(bool, false, true) == true); + try @import("std").testing.expectEqual(true, max(bool, false, true)); } // test diff --git a/doc/langref/test_comptime_pointer_conversion.zig b/doc/langref/test_comptime_pointer_conversion.zig index 6151e992c0..0c8e5a44eb 100644 --- a/doc/langref/test_comptime_pointer_conversion.zig +++ b/doc/langref/test_comptime_pointer_conversion.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "comptime @ptrFromInt" { comptime { @@ -6,8 +6,8 @@ test "comptime @ptrFromInt" { // ptr is never dereferenced. const ptr: *i32 = @ptrFromInt(0xdeadbee0); const addr = @intFromPtr(ptr); - try expect(@TypeOf(addr) == usize); - try expect(addr == 0xdeadbee0); + try expectEqual(usize, @TypeOf(addr)); + try expectEqual(0xdeadbee0, addr); } } diff --git a/doc/langref/test_comptime_pointers.zig b/doc/langref/test_comptime_pointers.zig index 784ddfd9f5..9c3b219c07 100644 --- a/doc/langref/test_comptime_pointers.zig +++ b/doc/langref/test_comptime_pointers.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "comptime pointers" { comptime { @@ -6,7 +6,7 @@ test "comptime pointers" { const ptr = &x; ptr.* += 1; x += 1; - try expect(ptr.* == 3); + try expectEqual(3, ptr.*); } } diff --git a/doc/langref/test_comptime_variables.zig b/doc/langref/test_comptime_variables.zig index 49d92ea025..b551590d17 100644 --- a/doc/langref/test_comptime_variables.zig +++ b/doc/langref/test_comptime_variables.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "comptime vars" { var x: i32 = 1; @@ -8,8 +8,8 @@ test "comptime vars" { x += 1; y += 1; - try expect(x == 2); - try expect(y == 2); + try expectEqual(2, x); + try expectEqual(2, y); if (y != 2) { // This compile error never triggers because y is a comptime variable, diff --git a/doc/langref/test_container-level_comptime_expressions.zig b/doc/langref/test_container-level_comptime_expressions.zig index 8f324a3553..78d5cb4cbb 100644 --- a/doc/langref/test_container-level_comptime_expressions.zig +++ b/doc/langref/test_container-level_comptime_expressions.zig @@ -31,7 +31,7 @@ fn sum(numbers: []const i32) i32 { } test "variable values" { - try @import("std").testing.expect(sum_of_first_25_primes == 1060); + try @import("std").testing.expectEqual(1060, sum_of_first_25_primes); } // test diff --git a/doc/langref/test_container_level_variables.zig b/doc/langref/test_container_level_variables.zig index ade379ec79..372fda1863 100644 --- a/doc/langref/test_container_level_variables.zig +++ b/doc/langref/test_container_level_variables.zig @@ -2,8 +2,8 @@ var y: i32 = add(10, x); const x: i32 = add(12, 34); test "container level variables" { - try expect(x == 46); - try expect(y == 56); + try expectEqual(46, x); + try expectEqual(56, y); } fn add(a: i32, b: i32) i32 { @@ -11,6 +11,6 @@ fn add(a: i32, b: i32) i32 { } const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; // test diff --git a/doc/langref/test_defer.zig b/doc/langref/test_defer.zig index 80aebc9d66..8c674f3aaf 100644 --- a/doc/langref/test_defer.zig +++ b/doc/langref/test_defer.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const print = std.debug.print; fn deferExample() !usize { @@ -9,14 +9,14 @@ fn deferExample() !usize { defer a = 2; a = 1; } - try expect(a == 2); + try expectEqual(2, a); a = 5; return a; } test "defer basics" { - try expect((try deferExample()) == 5); + try expectEqual(5, (try deferExample())); } // test diff --git a/doc/langref/test_empty_block.zig b/doc/langref/test_empty_block.zig index cab1b03767..c12f9baefb 100644 --- a/doc/langref/test_empty_block.zig +++ b/doc/langref/test_empty_block.zig @@ -1,12 +1,12 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test { const a = {}; const b = void{}; - try expect(@TypeOf(a) == void); - try expect(@TypeOf(b) == void); - try expect(a == b); + try expectEqual(void, @TypeOf(a)); + try expectEqual(void, @TypeOf(b)); + try expectEqual(a, b); } // test diff --git a/doc/langref/test_enum_literals.zig b/doc/langref/test_enum_literals.zig index 6acf858c30..e28c1d0d49 100644 --- a/doc/langref/test_enum_literals.zig +++ b/doc/langref/test_enum_literals.zig @@ -1,5 +1,6 @@ const std = @import("std"); const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Color = enum { auto, @@ -10,7 +11,7 @@ const Color = enum { test "enum literals" { const color1: Color = .auto; const color2 = Color.auto; - try expect(color1 == color2); + try expectEqual(color1, color2); } test "switch using enum literals" { diff --git a/doc/langref/test_enums.zig b/doc/langref/test_enums.zig index 4e0b3896f2..55a4f87d3b 100644 --- a/doc/langref/test_enums.zig +++ b/doc/langref/test_enums.zig @@ -1,4 +1,6 @@ const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; +const expectEqualStrings = @import("std").testing.expectEqualStrings; const mem = @import("std").mem; // Declare an enum. @@ -20,9 +22,9 @@ const Value = enum(u2) { // Now you can cast between u2 and Value. // The ordinal value starts from 0, counting up by 1 from the previous member. test "enum ordinal value" { - try expect(@intFromEnum(Value.zero) == 0); - try expect(@intFromEnum(Value.one) == 1); - try expect(@intFromEnum(Value.two) == 2); + try expectEqual(0, @intFromEnum(Value.zero)); + try expectEqual(1, @intFromEnum(Value.one)); + try expectEqual(2, @intFromEnum(Value.two)); } // You can override the ordinal value for an enum. @@ -32,9 +34,9 @@ const Value2 = enum(u32) { million = 1000000, }; test "set enum ordinal value" { - try expect(@intFromEnum(Value2.hundred) == 100); - try expect(@intFromEnum(Value2.thousand) == 1000); - try expect(@intFromEnum(Value2.million) == 1000000); + try expectEqual(100, @intFromEnum(Value2.hundred)); + try expectEqual(1000, @intFromEnum(Value2.thousand)); + try expectEqual(1000000, @intFromEnum(Value2.million)); } // You can also override only some values. @@ -46,11 +48,11 @@ const Value3 = enum(u4) { e, }; test "enum implicit ordinal values and overridden values" { - try expect(@intFromEnum(Value3.a) == 0); - try expect(@intFromEnum(Value3.b) == 8); - try expect(@intFromEnum(Value3.c) == 9); - try expect(@intFromEnum(Value3.d) == 4); - try expect(@intFromEnum(Value3.e) == 5); + try expectEqual(0, @intFromEnum(Value3.a)); + try expectEqual(8, @intFromEnum(Value3.b)); + try expectEqual(9, @intFromEnum(Value3.c)); + try expectEqual(4, @intFromEnum(Value3.d)); + try expectEqual(5, @intFromEnum(Value3.e)); } // Enums can have methods, the same as structs and unions. @@ -84,7 +86,7 @@ test "enum switch" { Foo.number => "this is a number", Foo.none => "this is a none", }; - try expect(mem.eql(u8, what_is_it, "this is a number")); + try expectEqualStrings(what_is_it, "this is a number"); } // @typeInfo can be used to access the integer tag type of an enum. @@ -95,18 +97,18 @@ const Small = enum { four, }; test "std.meta.Tag" { - try expect(@typeInfo(Small).@"enum".tag_type == u2); + try expectEqual(u2, @typeInfo(Small).@"enum".tag_type); } // @typeInfo tells us the field count and the fields names: test "@typeInfo" { - try expect(@typeInfo(Small).@"enum".fields.len == 4); - try expect(mem.eql(u8, @typeInfo(Small).@"enum".fields[1].name, "two")); + try expectEqual(4, @typeInfo(Small).@"enum".fields.len); + try expectEqualStrings(@typeInfo(Small).@"enum".fields[1].name, "two"); } // @tagName gives a [:0]const u8 representation of an enum value: test "@tagName" { - try expect(mem.eql(u8, @tagName(Small.three), "three")); + try expectEqualStrings(@tagName(Small.three), "three"); } // test diff --git a/doc/langref/test_error_union.zig b/doc/langref/test_error_union.zig index 0cc01ec4a4..41ff85339b 100644 --- a/doc/langref/test_error_union.zig +++ b/doc/langref/test_error_union.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "error union" { var foo: anyerror!i32 = undefined; @@ -10,10 +10,10 @@ test "error union" { foo = error.SomeError; // Use compile-time reflection to access the payload type of an error union: - try comptime expect(@typeInfo(@TypeOf(foo)).error_union.payload == i32); + try comptime expectEqual(i32, @typeInfo(@TypeOf(foo)).error_union.payload); // Use compile-time reflection to access the error set type of an error union: - try comptime expect(@typeInfo(@TypeOf(foo)).error_union.error_set == anyerror); + try comptime expectEqual(anyerror, @typeInfo(@TypeOf(foo)).error_union.error_set); } // test diff --git a/doc/langref/test_fibonacci_comptime_overflow.zig b/doc/langref/test_fibonacci_comptime_overflow.zig index f06b37feed..1621e5884f 100644 --- a/doc/langref/test_fibonacci_comptime_overflow.zig +++ b/doc/langref/test_fibonacci_comptime_overflow.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; fn fibonacci(index: u32) u32 { //if (index < 2) return index; @@ -6,7 +6,7 @@ fn fibonacci(index: u32) u32 { } test "fibonacci" { - try comptime expect(fibonacci(7) == 13); + try comptime expectEqual(13, fibonacci(7)); } // test_error=overflow of integer type diff --git a/doc/langref/test_fibonacci_recursion.zig b/doc/langref/test_fibonacci_recursion.zig index ba0b809fcc..3a366fbbd2 100644 --- a/doc/langref/test_fibonacci_recursion.zig +++ b/doc/langref/test_fibonacci_recursion.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; fn fibonacci(index: u32) u32 { if (index < 2) return index; @@ -7,10 +7,10 @@ fn fibonacci(index: u32) u32 { test "fibonacci" { // test fibonacci at run-time - try expect(fibonacci(7) == 13); + try expectEqual(13, fibonacci(7)); // test fibonacci at compile-time - try comptime expect(fibonacci(7) == 13); + try comptime expectEqual(13, fibonacci(7)); } // test diff --git a/doc/langref/test_field_builtin.zig b/doc/langref/test_field_builtin.zig index 52ce702c72..feca7c9298 100644 --- a/doc/langref/test_field_builtin.zig +++ b/doc/langref/test_field_builtin.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const expectEqual = std.testing.expectEqual; const Point = struct { x: u32, @@ -8,23 +9,20 @@ const Point = struct { }; test "field access by string" { - const expect = std.testing.expect; var p = Point{ .x = 0, .y = 0 }; @field(p, "x") = 4; @field(p, "y") = @field(p, "x") + 1; - try expect(@field(p, "x") == 4); - try expect(@field(p, "y") == 5); + try expectEqual(4, @field(p, "x")); + try expectEqual(5, @field(p, "y")); } test "decl access by string" { - const expect = std.testing.expect; - - try expect(@field(Point, "z") == 1); + try expectEqual(1, @field(Point, "z")); @field(Point, "z") = 2; - try expect(@field(Point, "z") == 2); + try expectEqual(2, @field(Point, "z")); } // test diff --git a/doc/langref/test_fn_reflection.zig b/doc/langref/test_fn_reflection.zig index cc4dd50b33..7c462bbfc5 100644 --- a/doc/langref/test_fn_reflection.zig +++ b/doc/langref/test_fn_reflection.zig @@ -3,8 +3,8 @@ const math = std.math; const testing = std.testing; test "fn reflection" { - try testing.expect(@typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.? == bool); - try testing.expect(@typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.? == testing.TmpDir); + try testing.expectEqual(bool, @typeInfo(@TypeOf(testing.expect)).@"fn".params[0].type.?); + try testing.expectEqual(testing.TmpDir, @typeInfo(@TypeOf(testing.tmpDir)).@"fn".return_type.?); try testing.expect(@typeInfo(@TypeOf(math.Log2Int)).@"fn".is_generic); } diff --git a/doc/langref/test_fn_type_inference.zig b/doc/langref/test_fn_type_inference.zig index 494fdea482..227a402ec4 100644 --- a/doc/langref/test_fn_type_inference.zig +++ b/doc/langref/test_fn_type_inference.zig @@ -1,15 +1,15 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; fn addFortyTwo(x: anytype) @TypeOf(x) { return x + 42; } test "fn type inference" { - try expect(addFortyTwo(1) == 43); - try expect(@TypeOf(addFortyTwo(1)) == comptime_int); + try expectEqual(43, addFortyTwo(1)); + try expectEqual(comptime_int, @TypeOf(addFortyTwo(1))); const y: i64 = 2; - try expect(addFortyTwo(y) == 44); - try expect(@TypeOf(addFortyTwo(y)) == i64); + try expectEqual(44, addFortyTwo(y)); + try expectEqual(i64, @TypeOf(addFortyTwo(y))); } // test diff --git a/doc/langref/test_for.zig b/doc/langref/test_for.zig index 62751f9fbc..d2d40db58f 100644 --- a/doc/langref/test_for.zig +++ b/doc/langref/test_for.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "for basics" { const items = [_]i32{ 4, 5, 3, 4, 0 }; @@ -12,22 +12,22 @@ test "for basics" { } sum += value; } - try expect(sum == 16); + try expectEqual(16, sum); // To iterate over a portion of a slice, reslice. for (items[0..1]) |value| { sum += value; } - try expect(sum == 20); + try expectEqual(20, sum); // To access the index of iteration, specify a second condition as well // as a second capture value. var sum2: i32 = 0; for (items, 0..) |_, i| { - try expect(@TypeOf(i) == usize); + try expectEqual(usize, @TypeOf(i)); sum2 += @as(i32, @intCast(i)); } - try expect(sum2 == 10); + try expectEqual(10, sum2); // To iterate over consecutive integers, use the range syntax. // Unbounded range is always a compile error. @@ -35,7 +35,7 @@ test "for basics" { for (0..5) |i| { sum3 += i; } - try expect(sum3 == 10); + try expectEqual(10, sum3); } test "multi object for" { @@ -50,7 +50,7 @@ test "multi object for" { count += i + j; } - try expect(count == 21); + try expectEqual(21, count); } test "for reference" { @@ -62,9 +62,9 @@ test "for reference" { value.* += 1; } - try expect(items[0] == 4); - try expect(items[1] == 5); - try expect(items[2] == 3); + try expectEqual(4, items[0]); + try expectEqual(5, items[1]); + try expectEqual(3, items[2]); } test "for else" { @@ -79,10 +79,10 @@ test "for else" { sum += value.?; } } else blk: { - try expect(sum == 12); + try expectEqual(12, sum); break :blk sum; }; - try expect(result == 12); + try expectEqual(12, result); } // test diff --git a/doc/langref/test_for_nested_break.zig b/doc/langref/test_for_nested_break.zig index 301facbcfe..38fed8900a 100644 --- a/doc/langref/test_for_nested_break.zig +++ b/doc/langref/test_for_nested_break.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "nested break" { var count: usize = 0; @@ -9,7 +9,7 @@ test "nested break" { break :outer; } } - try expect(count == 1); + try expectEqual(1, count); } test "nested continue" { @@ -21,7 +21,7 @@ test "nested continue" { } } - try expect(count == 8); + try expectEqual(8, count); } // test diff --git a/doc/langref/test_functions.zig b/doc/langref/test_functions.zig index 7b70961ab3..e86183ad50 100644 --- a/doc/langref/test_functions.zig +++ b/doc/langref/test_functions.zig @@ -1,7 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); const native_arch = builtin.cpu.arch; -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; // Functions are declared like this fn add(a: i8, b: i8) i8 { @@ -57,8 +57,8 @@ fn doOp(fnCall: Call2Op, op1: i8, op2: i8) i8 { } test "function" { - try expect(doOp(add, 5, 6) == 11); - try expect(doOp(sub2, 5, 6) == -1); + try expectEqual(11, doOp(add, 5, 6)); + try expectEqual(-1, doOp(sub2, 5, 6)); } // test diff --git a/doc/langref/test_global_assembly.zig b/doc/langref/test_global_assembly.zig index a5d5f3ca5f..b7cc6d466b 100644 --- a/doc/langref/test_global_assembly.zig +++ b/doc/langref/test_global_assembly.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; comptime { asm ( @@ -14,7 +14,7 @@ comptime { extern fn my_func(a: i32, b: i32) i32; test "global assembly" { - try expect(my_func(12, 34) == 46); + try expectEqual(46, my_func(12, 34)); } // test diff --git a/doc/langref/test_if.zig b/doc/langref/test_if.zig index 4ea6e66377..61dfcaa04d 100644 --- a/doc/langref/test_if.zig +++ b/doc/langref/test_if.zig @@ -4,13 +4,14 @@ // * anyerror!T const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "if expression" { // If expressions are used instead of a ternary expression. const a: u32 = 5; const b: u32 = 4; const result = if (a != b) 47 else 3089; - try expect(result == 47); + try expectEqual(result, 47); } test "if boolean" { @@ -32,7 +33,7 @@ test "if error union" { const a: anyerror!u32 = 0; if (a) |value| { - try expect(value == 0); + try expectEqual(value, 0); } else |err| { _ = err; unreachable; @@ -43,17 +44,17 @@ test "if error union" { _ = value; unreachable; } else |err| { - try expect(err == error.BadValue); + try expectEqual(err, error.BadValue); } // The else and |err| capture is strictly required. if (a) |value| { - try expect(value == 0); + try expectEqual(value, 0); } else |_| {} // To check only the error value, use an empty block expression. if (b) |_| {} else |err| { - try expect(err == error.BadValue); + try expectEqual(err, error.BadValue); } // Access the value by reference using a pointer capture. @@ -65,7 +66,7 @@ test "if error union" { } if (c) |value| { - try expect(value == 9); + try expectEqual(value, 9); } else |_| { unreachable; } diff --git a/doc/langref/test_if_optionals.zig b/doc/langref/test_if_optionals.zig index e19d181c78..fef9ae3b62 100644 --- a/doc/langref/test_if_optionals.zig +++ b/doc/langref/test_if_optionals.zig @@ -1,11 +1,12 @@ const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "if optional" { // If expressions test for null. const a: ?u32 = 0; if (a) |value| { - try expect(value == 0); + try expectEqual(0, value); } else { unreachable; } @@ -19,7 +20,7 @@ test "if optional" { // The else is not required. if (a) |value| { - try expect(value == 0); + try expectEqual(0, value); } // To test against null only, use the binary equality operator. @@ -34,7 +35,7 @@ test "if optional" { } if (c) |value| { - try expect(value == 2); + try expectEqual(2, value); } else { unreachable; } @@ -46,7 +47,7 @@ test "if error union with optional" { const a: anyerror!?u32 = 0; if (a) |optional_value| { - try expect(optional_value.? == 0); + try expectEqual(0, optional_value.?); } else |err| { _ = err; unreachable; @@ -54,7 +55,7 @@ test "if error union with optional" { const b: anyerror!?u32 = null; if (b) |optional_value| { - try expect(optional_value == null); + try expectEqual(null, optional_value); } else |_| { unreachable; } @@ -64,7 +65,7 @@ test "if error union with optional" { _ = optional_value; unreachable; } else |err| { - try expect(err == error.BadValue); + try expectEqual(error.BadValue, err); } // Access the value by reference by using a pointer capture each time. @@ -78,7 +79,7 @@ test "if error union with optional" { } if (d) |optional_value| { - try expect(optional_value.? == 9); + try expectEqual(9, optional_value.?); } else |_| { unreachable; } diff --git a/doc/langref/test_incorrect_pointer_alignment.zig b/doc/langref/test_incorrect_pointer_alignment.zig index d404b330fb..daa583e6ba 100644 --- a/doc/langref/test_incorrect_pointer_alignment.zig +++ b/doc/langref/test_incorrect_pointer_alignment.zig @@ -3,7 +3,7 @@ const std = @import("std"); test "pointer alignment safety" { var array align(4) = [_]u32{ 0x11111111, 0x11111111 }; const bytes = std.mem.sliceAsBytes(array[0..]); - try std.testing.expect(foo(bytes) == 0x11111111); + try std.testing.expectEqual(0x11111111, foo(bytes)); } fn foo(bytes: []u8) u32 { const slice4 = bytes[1..5]; diff --git a/doc/langref/test_inline_else.zig b/doc/langref/test_inline_else.zig index e535115935..8972bd8c6b 100644 --- a/doc/langref/test_inline_else.zig +++ b/doc/langref/test_inline_else.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const SliceTypeA = extern struct { len: usize, @@ -42,8 +42,8 @@ fn withSwitch(any: AnySlice) usize { test "inline for and inline else similarity" { const any = AnySlice{ .c = "hello" }; - try expect(withFor(any) == 5); - try expect(withSwitch(any) == 5); + try expectEqual(5, withFor(any)); + try expectEqual(5, withSwitch(any)); } // test diff --git a/doc/langref/test_inline_for.zig b/doc/langref/test_inline_for.zig index fbf75de2ea..4bc35b8043 100644 --- a/doc/langref/test_inline_for.zig +++ b/doc/langref/test_inline_for.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "inline for loop" { const nums = [_]i32{ 2, 4, 6 }; @@ -12,7 +12,7 @@ test "inline for loop" { }; sum += typeNameLength(T); } - try expect(sum == 9); + try expectEqual(9, sum); } fn typeNameLength(comptime T: type) usize { diff --git a/doc/langref/test_inline_switch_union_tag.zig b/doc/langref/test_inline_switch_union_tag.zig index dcefd4b0a1..4fe0147c81 100644 --- a/doc/langref/test_inline_switch_union_tag.zig +++ b/doc/langref/test_inline_switch_union_tag.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const U = union(enum) { a: u32, @@ -21,7 +21,7 @@ fn getNum(u: U) u32 { test "test" { const u = U{ .b = 42 }; - try expect(getNum(u) == 42); + try expectEqual(42, getNum(u)); } // test diff --git a/doc/langref/test_inline_while.zig b/doc/langref/test_inline_while.zig index 3422b647e9..5cc7166529 100644 --- a/doc/langref/test_inline_while.zig +++ b/doc/langref/test_inline_while.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "inline while loop" { comptime var i = 0; @@ -12,7 +12,7 @@ test "inline while loop" { }; sum += typeNameLength(T); } - try expect(sum == 9); + try expectEqual(9, sum); } fn typeNameLength(comptime T: type) usize { diff --git a/doc/langref/test_integer_pointer_conversion.zig b/doc/langref/test_integer_pointer_conversion.zig index 98653cc7e2..f2c67f8719 100644 --- a/doc/langref/test_integer_pointer_conversion.zig +++ b/doc/langref/test_integer_pointer_conversion.zig @@ -1,10 +1,10 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "@intFromPtr and @ptrFromInt" { const ptr: *i32 = @ptrFromInt(0xdeadbee0); const addr = @intFromPtr(ptr); - try expect(@TypeOf(addr) == usize); - try expect(addr == 0xdeadbee0); + try expectEqual(usize, @TypeOf(addr)); + try expectEqual(0xdeadbee0, addr); } // test diff --git a/doc/langref/test_integer_widening.zig b/doc/langref/test_integer_widening.zig index 8b5b5fdb88..08627d999f 100644 --- a/doc/langref/test_integer_widening.zig +++ b/doc/langref/test_integer_widening.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const mem = std.mem; test "integer widening" { @@ -10,13 +10,13 @@ test "integer widening" { const d: u64 = c; const e: u64 = d; const f: u128 = e; - try expect(f == a); + try expectEqual(f, a); } test "implicit unsigned integer to signed integer" { const a: u8 = 250; const b: i16 = a; - try expect(b == 250); + try expectEqual(250, b); } test "float widening" { @@ -24,7 +24,7 @@ test "float widening" { const b: f32 = a; const c: f64 = b; const d: f128 = c; - try expect(d == a); + try expectEqual(d, a); } // test diff --git a/doc/langref/test_labeled_break.zig b/doc/langref/test_labeled_break.zig index 0310b997e3..52a902d358 100644 --- a/doc/langref/test_labeled_break.zig +++ b/doc/langref/test_labeled_break.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "labeled break from labeled block expression" { var y: i32 = 123; @@ -8,8 +8,8 @@ test "labeled break from labeled block expression" { y += 1; break :blk y; }; - try expect(x == 124); - try expect(y == 124); + try expectEqual(124, x); + try expectEqual(124, y); } // test diff --git a/doc/langref/test_misaligned_pointer.zig b/doc/langref/test_misaligned_pointer.zig index 11795ce090..b635d87c59 100644 --- a/doc/langref/test_misaligned_pointer.zig +++ b/doc/langref/test_misaligned_pointer.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const BitField = packed struct { a: u3, @@ -14,7 +14,7 @@ var bit_field = BitField{ }; test "pointer to non-byte-aligned field" { - try expect(bar(&bit_field.b) == 2); + try expectEqual(2, bar(&bit_field.b)); } fn bar(x: *const u3) u3 { diff --git a/doc/langref/test_missized_packed_struct.zig b/doc/langref/test_missized_packed_struct.zig index 791f97cc31..df323244d4 100644 --- a/doc/langref/test_missized_packed_struct.zig +++ b/doc/langref/test_missized_packed_struct.zig @@ -3,4 +3,4 @@ test "missized packed struct" { _ = S{ .a = 4, .b = 2 }; } -// test_error=backing integer type 'u32' has bit size 32 but the struct fields have a total bit size of 24 +// test_error=backing integer bit width does not match total bit width of fields diff --git a/doc/langref/test_multidimensional_arrays.zig b/doc/langref/test_multidimensional_arrays.zig index c88e8cb16a..6c7fefcaea 100644 --- a/doc/langref/test_multidimensional_arrays.zig +++ b/doc/langref/test_multidimensional_arrays.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; const mat4x5 = [4][5]f32{ @@ -13,20 +12,20 @@ test "multidimensional arrays" { try expectEqual(mat4x5[1], [_]f32{ 0.0, 1.0, 0.0, 1.0, 0.0 }); // Access the 2D array by indexing the outer array, and then the inner array. - try expect(mat4x5[3][4] == 9.9); + try expectEqual(9.9, mat4x5[3][4]); // Here we iterate with for loops. for (mat4x5, 0..) |row, row_index| { for (row, 0..) |cell, column_index| { if (row_index == column_index) { - try expect(cell == 1.0); + try expectEqual(1.0, cell); } } } // Initialize a multidimensional array to zeros. const all_zero: [4][5]f32 = .{.{0} ** 5} ** 4; - try expect(all_zero[0][0] == 0); + try expectEqual(0, all_zero[0][0]); } // test diff --git a/doc/langref/test_namespaced_container_level_variable.zig b/doc/langref/test_namespaced_container_level_variable.zig index 22f56d7d13..f35aa90d8e 100644 --- a/doc/langref/test_namespaced_container_level_variable.zig +++ b/doc/langref/test_namespaced_container_level_variable.zig @@ -1,9 +1,9 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "namespaced container level variable" { - try expect(foo() == 1235); - try expect(foo() == 1236); + try expectEqual(1235, foo()); + try expectEqual(1236, foo()); } const S = struct { diff --git a/doc/langref/test_noreturn_from_exit.zig b/doc/langref/test_noreturn_from_exit.zig index 4c5277d2e6..22ea8b4f49 100644 --- a/doc/langref/test_noreturn_from_exit.zig +++ b/doc/langref/test_noreturn_from_exit.zig @@ -1,14 +1,14 @@ const std = @import("std"); const builtin = @import("builtin"); const native_arch = builtin.cpu.arch; -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const WINAPI: std.builtin.CallingConvention = if (native_arch == .x86) .{ .x86_stdcall = .{} } else .c; extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(WINAPI) noreturn; test "foo" { const value = bar() catch ExitProcess(1); - try expect(value == 1234); + try expectEqual(1234, value); } fn bar() anyerror!u32 { diff --git a/doc/langref/test_null_terminated_array.zig b/doc/langref/test_null_terminated_array.zig index c89ed59bbd..53ba0d0c65 100644 --- a/doc/langref/test_null_terminated_array.zig +++ b/doc/langref/test_null_terminated_array.zig @@ -1,21 +1,21 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "0-terminated sentinel array" { const array = [_:0]u8{ 1, 2, 3, 4 }; - try expect(@TypeOf(array) == [4:0]u8); - try expect(array.len == 4); - try expect(array[4] == 0); + try expectEqual([4:0]u8, @TypeOf(array)); + try expectEqual(4, array.len); + try expectEqual(0, array[4]); } test "extra 0s in 0-terminated sentinel array" { // The sentinel value may appear earlier, but does not influence the compile-time 'len'. const array = [_:0]u8{ 1, 0, 0, 4 }; - try expect(@TypeOf(array) == [4:0]u8); - try expect(array.len == 4); - try expect(array[4] == 0); + try expectEqual([4:0]u8, @TypeOf(array)); + try expectEqual(4, array.len); + try expectEqual(0, array[4]); } // test diff --git a/doc/langref/test_null_terminated_slice.zig b/doc/langref/test_null_terminated_slice.zig index 9f14f9bc1d..44fad5671d 100644 --- a/doc/langref/test_null_terminated_slice.zig +++ b/doc/langref/test_null_terminated_slice.zig @@ -1,11 +1,11 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "0-terminated slice" { const slice: [:0]const u8 = "hello"; - try expect(slice.len == 5); - try expect(slice[5] == 0); + try expectEqual(5, slice.len); + try expectEqual(0, slice[5]); } // test diff --git a/doc/langref/test_null_terminated_slicing.zig b/doc/langref/test_null_terminated_slicing.zig index e5a248bed3..b1d5263976 100644 --- a/doc/langref/test_null_terminated_slicing.zig +++ b/doc/langref/test_null_terminated_slicing.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "0-terminated slicing" { var array = [_]u8{ 3, 2, 1, 0, 3, 2, 1, 0 }; @@ -7,8 +7,8 @@ test "0-terminated slicing" { _ = &runtime_length; const slice = array[0..runtime_length :0]; - try expect(@TypeOf(slice) == [:0]u8); - try expect(slice.len == 3); + try expectEqual([:0]u8, @TypeOf(slice)); + try expectEqual(3, slice.len); } // test diff --git a/doc/langref/test_optional_pointer.zig b/doc/langref/test_optional_pointer.zig index acad240fd2..dc3d3bbfda 100644 --- a/doc/langref/test_optional_pointer.zig +++ b/doc/langref/test_optional_pointer.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "optional pointers" { // Pointers cannot be null. If you want a null pointer, use the optional @@ -8,11 +8,11 @@ test "optional pointers" { var x: i32 = 1; ptr = &x; - try expect(ptr.?.* == 1); + try expectEqual(1, ptr.?.*); // Optional pointers are the same size as normal pointers, because pointer // value 0 is used as the null value. - try expect(@sizeOf(?*i32) == @sizeOf(*i32)); + try expectEqual(@sizeOf(?*i32), @sizeOf(*i32)); } // test diff --git a/doc/langref/test_optional_type.zig b/doc/langref/test_optional_type.zig index 594198b49e..97a87c21f2 100644 --- a/doc/langref/test_optional_type.zig +++ b/doc/langref/test_optional_type.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "optional type" { // Declare an optional and coerce from null: @@ -8,7 +8,7 @@ test "optional type" { foo = 1234; // Use compile-time reflection to access the child type of the optional: - try comptime expect(@typeInfo(@TypeOf(foo)).optional.child == i32); + try comptime expectEqual(i32, @typeInfo(@TypeOf(foo)).optional.child); } // test diff --git a/doc/langref/test_overaligned_packed_struct.zig b/doc/langref/test_overaligned_packed_struct.zig index 8bf52b3297..7c67800192 100644 --- a/doc/langref/test_overaligned_packed_struct.zig +++ b/doc/langref/test_overaligned_packed_struct.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const S = packed struct { a: u32, @@ -9,7 +9,7 @@ test "overaligned pointer to packed struct" { var foo: S align(4) = .{ .a = 1, .b = 2 }; const ptr: *align(4) S = &foo; const ptr_to_b = &ptr.b; - try expect(ptr_to_b.* == 2); + try expectEqual(2, ptr_to_b.*); } // test diff --git a/doc/langref/test_packed_struct_equality.zig b/doc/langref/test_packed_struct_equality.zig index d1c755af19..1449d05652 100644 --- a/doc/langref/test_packed_struct_equality.zig +++ b/doc/langref/test_packed_struct_equality.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "packed struct equality" { const S = packed struct { @@ -8,7 +8,7 @@ test "packed struct equality" { }; const x: S = .{ .a = 1, .b = 2 }; const y: S = .{ .b = 2, .a = 1 }; - try expect(x == y); + try expectEqual(x, y); } // test diff --git a/doc/langref/test_packed_struct_field_address.zig b/doc/langref/test_packed_struct_field_address.zig index 979c0377f6..756d36c3a9 100644 --- a/doc/langref/test_packed_struct_field_address.zig +++ b/doc/langref/test_packed_struct_field_address.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const BitField = packed struct { a: u3, @@ -14,8 +14,8 @@ var bit_field = BitField{ }; test "pointers of sub-byte-aligned fields share addresses" { - try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.b)); - try expect(@intFromPtr(&bit_field.a) == @intFromPtr(&bit_field.c)); + try expectEqual(@intFromPtr(&bit_field.a), @intFromPtr(&bit_field.b)); + try expectEqual(@intFromPtr(&bit_field.a), @intFromPtr(&bit_field.c)); } // test diff --git a/doc/langref/test_packed_structs.zig b/doc/langref/test_packed_structs.zig index da1f259d5e..7e46f852a0 100644 --- a/doc/langref/test_packed_structs.zig +++ b/doc/langref/test_packed_structs.zig @@ -1,6 +1,6 @@ const std = @import("std"); const native_endian = @import("builtin").target.cpu.arch.endian(); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Full = packed struct { number: u16, @@ -17,23 +17,23 @@ test "@bitCast between packed structs" { } fn doTheTest() !void { - try expect(@sizeOf(Full) == 2); - try expect(@sizeOf(Divided) == 2); + try expectEqual(2, @sizeOf(Full)); + try expectEqual(2, @sizeOf(Divided)); const full = Full{ .number = 0x1234 }; const divided: Divided = @bitCast(full); - try expect(divided.half1 == 0x34); - try expect(divided.quarter3 == 0x2); - try expect(divided.quarter4 == 0x1); + try expectEqual(0x34, divided.half1); + try expectEqual(0x2, divided.quarter3); + try expectEqual(0x1, divided.quarter4); const ordered: [2]u8 = @bitCast(full); switch (native_endian) { .big => { - try expect(ordered[0] == 0x12); - try expect(ordered[1] == 0x34); + try expectEqual(0x12, ordered[0]); + try expectEqual(0x34, ordered[1]); }, .little => { - try expect(ordered[0] == 0x34); - try expect(ordered[1] == 0x12); + try expectEqual(0x34, ordered[0]); + try expectEqual(0x12, ordered[1]); }, } } diff --git a/doc/langref/test_pass_by_reference_or_value.zig b/doc/langref/test_pass_by_reference_or_value.zig index 0bde07747e..e35ccf8ce4 100644 --- a/doc/langref/test_pass_by_reference_or_value.zig +++ b/doc/langref/test_pass_by_reference_or_value.zig @@ -11,10 +11,10 @@ fn foo(point: Point) i32 { return point.x + point.y; } -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "pass struct to function" { - try expect(foo(Point{ .x = 1, .y = 2 }) == 3); + try expectEqual(3, foo(Point{ .x = 1, .y = 2 })); } // test diff --git a/doc/langref/test_peer_type_resolution.zig b/doc/langref/test_peer_type_resolution.zig index ad0b9f35cb..9bbac881e3 100644 --- a/doc/langref/test_peer_type_resolution.zig +++ b/doc/langref/test_peer_type_resolution.zig @@ -1,20 +1,20 @@ const std = @import("std"); -const expect = std.testing.expect; -const mem = std.mem; +const expectEqual = std.testing.expectEqual; +const expectEqualStrings = std.testing.expectEqualStrings; test "peer resolve int widening" { const a: i8 = 12; const b: i16 = 34; const c = a + b; - try expect(c == 46); - try expect(@TypeOf(c) == i16); + try expectEqual(46, c); + try expectEqual(i16, @TypeOf(c)); } test "peer resolve arrays of different size to const slice" { - try expect(mem.eql(u8, boolToStr(true), "true")); - try expect(mem.eql(u8, boolToStr(false), "false")); - try comptime expect(mem.eql(u8, boolToStr(true), "true")); - try comptime expect(mem.eql(u8, boolToStr(false), "false")); + try expectEqualStrings("true", boolToStr(true)); + try expectEqualStrings("false", boolToStr(false)); + try comptime expectEqualStrings("true", boolToStr(true)); + try comptime expectEqualStrings("false", boolToStr(false)); } fn boolToStr(b: bool) []const u8 { return if (b) "true" else "false"; @@ -27,16 +27,16 @@ test "peer resolve array and const slice" { fn testPeerResolveArrayConstSlice(b: bool) !void { const value1 = if (b) "aoeu" else @as([]const u8, "zz"); const value2 = if (b) @as([]const u8, "zz") else "aoeu"; - try expect(mem.eql(u8, value1, "aoeu")); - try expect(mem.eql(u8, value2, "zz")); + try expectEqualStrings("aoeu", value1); + try expectEqualStrings("zz", value2); } test "peer type resolution: ?T and T" { - try expect(peerTypeTAndOptionalT(true, false).? == 0); - try expect(peerTypeTAndOptionalT(false, false).? == 3); + try expectEqual(0, peerTypeTAndOptionalT(true, false).?); + try expectEqual(3, peerTypeTAndOptionalT(false, false).?); comptime { - try expect(peerTypeTAndOptionalT(true, false).? == 0); - try expect(peerTypeTAndOptionalT(false, false).? == 3); + try expectEqual(0, peerTypeTAndOptionalT(true, false).?); + try expectEqual(3, peerTypeTAndOptionalT(false, false).?); } } fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { @@ -48,11 +48,11 @@ fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { } test "peer type resolution: *[0]u8 and []const u8" { - try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); - try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); + try expectEqual(0, peerTypeEmptyArrayAndSlice(true, "hi").len); + try expectEqual(1, peerTypeEmptyArrayAndSlice(false, "hi").len); comptime { - try expect(peerTypeEmptyArrayAndSlice(true, "hi").len == 0); - try expect(peerTypeEmptyArrayAndSlice(false, "hi").len == 1); + try expectEqual(0, peerTypeEmptyArrayAndSlice(true, "hi").len); + try expectEqual(1, peerTypeEmptyArrayAndSlice(false, "hi").len); } } fn peerTypeEmptyArrayAndSlice(a: bool, slice: []const u8) []const u8 { @@ -66,14 +66,14 @@ test "peer type resolution: *[0]u8, []const u8, and anyerror![]u8" { { var data = "hi".*; const slice = data[0..]; - try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); - try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); + try expectEqual(0, (try peerTypeEmptyArrayAndSliceAndError(true, slice)).len); + try expectEqual(1, (try peerTypeEmptyArrayAndSliceAndError(false, slice)).len); } comptime { var data = "hi".*; const slice = data[0..]; - try expect((try peerTypeEmptyArrayAndSliceAndError(true, slice)).len == 0); - try expect((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); + try expectEqual(0, (try peerTypeEmptyArrayAndSliceAndError(true, slice)).len); + try expectEqual(1, (try peerTypeEmptyArrayAndSliceAndError(false, slice)).len); } } fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { @@ -87,8 +87,8 @@ fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) anyerror![]u8 { test "peer type resolution: *const T and ?*T" { const a: *const usize = @ptrFromInt(0x123456780); const b: ?*usize = @ptrFromInt(0x123456780); - try expect(a == b); - try expect(b == a); + try expectEqual(a, b); + try expectEqual(b, a); } test "peer type resolution: error union switch" { @@ -104,7 +104,7 @@ test "peer type resolution: error union switch" { error.B => 1, error.C => null, }; - try expect(@TypeOf(b) == ?u32); + try expectEqual(?u32, @TypeOf(b)); // The non-error and error cases are only peers if the error case is just a switch expression; // the pattern `x catch |err| blk: { switch (err) {...} }` does not consider the unwrapped `x` @@ -114,7 +114,7 @@ test "peer type resolution: error union switch" { error.B => 1, error.C => null, }; - try expect(@TypeOf(c) == ?u32); + try expectEqual(?u32, @TypeOf(c)); } // test diff --git a/doc/langref/test_pointer_arithmetic.zig b/doc/langref/test_pointer_arithmetic.zig index 2157428502..457db08ba2 100644 --- a/doc/langref/test_pointer_arithmetic.zig +++ b/doc/langref/test_pointer_arithmetic.zig @@ -1,19 +1,19 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "pointer arithmetic with many-item pointer" { const array = [_]i32{ 1, 2, 3, 4 }; var ptr: [*]const i32 = &array; - try expect(ptr[0] == 1); + try expectEqual(1, ptr[0]); ptr += 1; - try expect(ptr[0] == 2); + try expectEqual(2, ptr[0]); // slicing a many-item pointer without an end is equivalent to // pointer arithmetic: `ptr[start..] == ptr + start` - try expect(ptr[1..] == ptr + 1); + try expectEqual(ptr[1..], ptr + 1); // subtraction between any two pointers except slices based on element size is supported - try expect(&ptr[1] - &ptr[0] == 1); + try expectEqual(1, &ptr[1] - &ptr[0]); } test "pointer arithmetic with slices" { @@ -22,14 +22,14 @@ test "pointer arithmetic with slices" { _ = &length; // suppress 'var is never mutated' error var slice = array[length..array.len]; - try expect(slice[0] == 1); - try expect(slice.len == 4); + try expectEqual(1, slice[0]); + try expectEqual(4, slice.len); slice.ptr += 1; // now the slice is in an bad state since len has not been updated - try expect(slice[0] == 2); - try expect(slice.len == 4); + try expectEqual(2, slice[0]); + try expectEqual(4, slice.len); } // test diff --git a/doc/langref/test_pointer_casting.zig b/doc/langref/test_pointer_casting.zig index 359d1dc838..0a3fde2efe 100644 --- a/doc/langref/test_pointer_casting.zig +++ b/doc/langref/test_pointer_casting.zig @@ -1,23 +1,23 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "pointer casting" { const bytes align(@alignOf(u32)) = [_]u8{ 0x12, 0x12, 0x12, 0x12 }; const u32_ptr: *const u32 = @ptrCast(&bytes); - try expect(u32_ptr.* == 0x12121212); + try expectEqual(0x12121212, u32_ptr.*); // Even this example is contrived - there are better ways to do the above than // pointer casting. For example, using a slice narrowing cast: const u32_value = std.mem.bytesAsSlice(u32, bytes[0..])[0]; - try expect(u32_value == 0x12121212); + try expectEqual(0x12121212, u32_value); // And even another way, the most straightforward way to do it: - try expect(@as(u32, @bitCast(bytes)) == 0x12121212); + try expectEqual(0x12121212, @as(u32, @bitCast(bytes))); } test "pointer child type" { // pointer types have a `child` field which tells you the type they point to. - try expect(@typeInfo(*u32).pointer.child == u32); + try expectEqual(u32, @typeInfo(*u32).pointer.child); } // test diff --git a/doc/langref/test_pointer_coerce_const_optional.zig b/doc/langref/test_pointer_coerce_const_optional.zig index f955820593..fccb4806b4 100644 --- a/doc/langref/test_pointer_coerce_const_optional.zig +++ b/doc/langref/test_pointer_coerce_const_optional.zig @@ -1,11 +1,11 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqualStrings = std.testing.expectEqualStrings; const mem = std.mem; test "cast *[1][*:0]const u8 to []const ?[*:0]const u8" { const window_name = [1][*:0]const u8{"window name"}; const x: []const ?[*:0]const u8 = &window_name; - try expect(mem.eql(u8, mem.span(x[0].?), "window name")); + try expectEqualStrings("window name", mem.span(x[0].?)); } // test diff --git a/doc/langref/test_pointer_to_non-byte_aligned_field.zig b/doc/langref/test_pointer_to_non-byte_aligned_field.zig index 336337caee..fcf45e74f4 100644 --- a/doc/langref/test_pointer_to_non-byte_aligned_field.zig +++ b/doc/langref/test_pointer_to_non-byte_aligned_field.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const BitField = packed struct { a: u3, @@ -15,7 +15,7 @@ var foo = BitField{ test "pointer to non-byte-aligned field" { const ptr = &foo.b; - try expect(ptr.* == 2); + try expectEqual(2, ptr.*); } // test diff --git a/doc/langref/test_reduce_builtin.zig b/doc/langref/test_reduce_builtin.zig index 82b78b8380..b411b05eea 100644 --- a/doc/langref/test_reduce_builtin.zig +++ b/doc/langref/test_reduce_builtin.zig @@ -1,15 +1,15 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "vector @reduce" { const V = @Vector(4, i32); const value = V{ 1, -1, 1, -1 }; const result = value > @as(V, @splat(0)); // result is { true, false, true, false }; - try comptime expect(@TypeOf(result) == @Vector(4, bool)); + try comptime expectEqual(@Vector(4, bool), @TypeOf(result)); const is_all_true = @reduce(.And, result); - try comptime expect(@TypeOf(is_all_true) == bool); - try expect(is_all_true == false); + try comptime expectEqual(bool, @TypeOf(is_all_true)); + try expectEqual(false, is_all_true); } // test diff --git a/doc/langref/test_round_builtin.zig b/doc/langref/test_round_builtin.zig index a317ca79f0..e28b7d5dab 100644 --- a/doc/langref/test_round_builtin.zig +++ b/doc/langref/test_round_builtin.zig @@ -1,10 +1,10 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "@round" { - try expect(@round(1.4) == 1); - try expect(@round(1.5) == 2); - try expect(@round(-1.4) == -1); - try expect(@round(-2.5) == -3); + try expectEqual(1, @round(1.4)); + try expectEqual(2, @round(1.5)); + try expectEqual(-1, @round(-1.4)); + try expectEqual(-3, @round(-2.5)); } // test diff --git a/doc/langref/test_sentinel_mismatch.zig b/doc/langref/test_sentinel_mismatch.zig index afa1fd295d..df60680351 100644 --- a/doc/langref/test_sentinel_mismatch.zig +++ b/doc/langref/test_sentinel_mismatch.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "sentinel mismatch" { var array = [_]u8{ 3, 2, 1, 0 }; diff --git a/doc/langref/test_shuffle_builtin.zig b/doc/langref/test_shuffle_builtin.zig index c73d1bbfab..1b319d2f47 100644 --- a/doc/langref/test_shuffle_builtin.zig +++ b/doc/langref/test_shuffle_builtin.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqualStrings = std.testing.expectEqualStrings; test "vector @shuffle" { const a = @Vector(7, u8){ 'o', 'l', 'h', 'e', 'r', 'z', 'w' }; @@ -9,12 +9,12 @@ test "vector @shuffle" { // Notice that we can re-order, duplicate, or omit elements of the input vector const mask1 = @Vector(5, i32){ 2, 3, 1, 1, 0 }; const res1: @Vector(5, u8) = @shuffle(u8, a, undefined, mask1); - try expect(std.mem.eql(u8, &@as([5]u8, res1), "hello")); + try expectEqualStrings("hello", &@as([5]u8, res1)); // Combining two vectors const mask2 = @Vector(6, i32){ -1, 0, 4, 1, -2, -3 }; const res2: @Vector(6, u8) = @shuffle(u8, a, b, mask2); - try expect(std.mem.eql(u8, &@as([6]u8, res2), "world!")); + try expectEqualStrings("world!", &@as([6]u8, res2)); } // test diff --git a/doc/langref/test_simple_union.zig b/doc/langref/test_simple_union.zig index 899666de07..f257575adb 100644 --- a/doc/langref/test_simple_union.zig +++ b/doc/langref/test_simple_union.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Payload = union { int: i64, @@ -8,9 +8,9 @@ const Payload = union { }; test "simple union" { var payload = Payload{ .int = 1234 }; - try expect(payload.int == 1234); + try expectEqual(1234, payload.int); payload = Payload{ .float = 12.34 }; - try expect(payload.float == 12.34); + try expectEqual(12.34, payload.float); } // test diff --git a/doc/langref/test_single_item_pointer.zig b/doc/langref/test_single_item_pointer.zig index 79252b1fa0..0171147d82 100644 --- a/doc/langref/test_single_item_pointer.zig +++ b/doc/langref/test_single_item_pointer.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "address of syntax" { // Get the address of a variable: @@ -6,17 +6,17 @@ test "address of syntax" { const x_ptr = &x; // Dereference a pointer: - try expect(x_ptr.* == 1234); + try expectEqual(1234, x_ptr.*); // When you get the address of a const variable, you get a const single-item pointer. - try expect(@TypeOf(x_ptr) == *const i32); + try expectEqual(*const i32, @TypeOf(x_ptr)); // If you want to mutate the value, you'd need an address of a mutable variable: var y: i32 = 5678; const y_ptr = &y; - try expect(@TypeOf(y_ptr) == *i32); + try expectEqual(*i32, @TypeOf(y_ptr)); y_ptr.* += 1; - try expect(y_ptr.* == 5679); + try expectEqual(5679, y_ptr.*); } test "pointer array access" { @@ -25,11 +25,11 @@ test "pointer array access" { // does not support pointer arithmetic. var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; const ptr = &array[2]; - try expect(@TypeOf(ptr) == *u8); + try expectEqual(*u8, @TypeOf(ptr)); - try expect(array[2] == 3); + try expectEqual(3, array[2]); ptr.* += 1; - try expect(array[2] == 4); + try expectEqual(4, array[2]); } test "slice syntax" { @@ -39,11 +39,11 @@ test "slice syntax" { // Convert to array pointer using slice syntax: const x_array_ptr = x_ptr[0..1]; - try expect(@TypeOf(x_array_ptr) == *[1]i32); + try expectEqual(*[1]i32, @TypeOf(x_array_ptr)); // Coerce to many-item pointer: const x_many_ptr: [*]i32 = x_array_ptr; - try expect(x_many_ptr[0] == 1234); + try expectEqual(1234, x_many_ptr[0]); } // test diff --git a/doc/langref/test_slice_bounds.zig b/doc/langref/test_slice_bounds.zig index 23022a2757..8de31a7d32 100644 --- a/doc/langref/test_slice_bounds.zig +++ b/doc/langref/test_slice_bounds.zig @@ -1,15 +1,15 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "pointer slicing" { var array = [_]u8{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var start: usize = 2; // var to make it runtime-known _ = &start; // suppress 'var is never mutated' error const slice = array[start..4]; - try expect(slice.len == 2); + try expectEqual(2, slice.len); - try expect(array[3] == 4); + try expectEqual(4, array[3]); slice[1] += 1; - try expect(array[3] == 5); + try expectEqual(5, array[3]); } // test diff --git a/doc/langref/test_slices.zig b/doc/langref/test_slices.zig index e1a51e4651..a5ac8cb926 100644 --- a/doc/langref/test_slices.zig +++ b/doc/langref/test_slices.zig @@ -1,6 +1,6 @@ const std = @import("std"); -const expect = std.testing.expect; -const mem = std.mem; +const expectEqual = std.testing.expectEqual; +const expectEqualStrings = std.testing.expectEqualStrings; const fmt = std.fmt; test "using slices for strings" { @@ -23,13 +23,13 @@ test "using slices for strings" { // Generally, you can use UTF-8 and not worry about whether something is a // string. If you don't need to deal with individual characters, no need // to decode. - try expect(mem.eql(u8, hello_world, "hello 世界")); + try expectEqualStrings("hello 世界", hello_world); } test "slice pointer" { var array: [10]u8 = undefined; const ptr = &array; - try expect(@TypeOf(ptr) == *[10]u8); + try expectEqual(*[10]u8, @TypeOf(ptr)); // A pointer to an array can be sliced just like an array: var start: usize = 0; @@ -37,16 +37,16 @@ test "slice pointer" { _ = .{ &start, &end }; const slice = ptr[start..end]; // The slice is mutable because we sliced a mutable pointer. - try expect(@TypeOf(slice) == []u8); + try expectEqual([]u8, @TypeOf(slice)); slice[2] = 3; - try expect(array[2] == 3); + try expectEqual(3, array[2]); // Again, slicing with comptime-known indexes will produce another pointer // to an array: const ptr2 = slice[2..3]; - try expect(ptr2.len == 1); - try expect(ptr2[0] == 3); - try expect(@TypeOf(ptr2) == *[1]u8); + try expectEqual(1, ptr2.len); + try expectEqual(3, ptr2[0]); + try expectEqual(*[1]u8, @TypeOf(ptr2)); } // test diff --git a/doc/langref/test_splat_builtin.zig b/doc/langref/test_splat_builtin.zig index d11556b1a3..d00240620e 100644 --- a/doc/langref/test_splat_builtin.zig +++ b/doc/langref/test_splat_builtin.zig @@ -1,16 +1,16 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqualSlices = std.testing.expectEqualSlices; test "vector @splat" { const scalar: u32 = 5; const result: @Vector(4, u32) = @splat(scalar); - try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 })); + try expectEqualSlices(u32, &[_]u32{ 5, 5, 5, 5 }, &@as([4]u32, result)); } test "array @splat" { const scalar: u32 = 5; const result: [4]u32 = @splat(scalar); - try expect(std.mem.eql(u32, &@as([4]u32, result), &[_]u32{ 5, 5, 5, 5 })); + try expectEqualSlices(u32, &[_]u32{ 5, 5, 5, 5 }, &@as([4]u32, result)); } // test diff --git a/doc/langref/test_src_builtin.zig b/doc/langref/test_src_builtin.zig index 10199be68e..7286f8f5a8 100644 --- a/doc/langref/test_src_builtin.zig +++ b/doc/langref/test_src_builtin.zig @@ -1,5 +1,6 @@ const std = @import("std"); const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "@src" { try doTheTest(); @@ -8,8 +9,8 @@ test "@src" { fn doTheTest() !void { const src = @src(); - try expect(src.line == 9); - try expect(src.column == 17); + try expectEqual(10, src.line); + try expectEqual(17, src.column); try expect(std.mem.endsWith(u8, src.fn_name, "doTheTest")); try expect(std.mem.endsWith(u8, src.file, "test_src_builtin.zig")); } diff --git a/doc/langref/test_static_local_variable.zig b/doc/langref/test_static_local_variable.zig index 4531a96a37..58b4505be4 100644 --- a/doc/langref/test_static_local_variable.zig +++ b/doc/langref/test_static_local_variable.zig @@ -1,9 +1,9 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "static local variable" { - try expect(foo() == 1235); - try expect(foo() == 1236); + try expectEqual(1235, foo()); + try expectEqual(1236, foo()); } fn foo() i32 { diff --git a/doc/langref/test_struct_result.zig b/doc/langref/test_struct_result.zig index cb8ecf0673..62b32ecf10 100644 --- a/doc/langref/test_struct_result.zig +++ b/doc/langref/test_struct_result.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Point = struct { x: i32, y: i32 }; @@ -8,8 +8,8 @@ test "anonymous struct literal" { .x = 13, .y = 67, }; - try expect(pt.x == 13); - try expect(pt.y == 67); + try expectEqual(13, pt.x); + try expectEqual(67, pt.y); } // test diff --git a/doc/langref/test_structs.zig b/doc/langref/test_structs.zig index b62fd3578d..414dd8be48 100644 --- a/doc/langref/test_structs.zig +++ b/doc/langref/test_structs.zig @@ -34,12 +34,12 @@ const Vec3 = struct { test "dot product" { const v1 = Vec3.init(1.0, 0.0, 0.0); const v2 = Vec3.init(0.0, 1.0, 0.0); - try expect(v1.dot(v2) == 0.0); + try expectEqual(0.0, v1.dot(v2)); // Other than being available to call with dot syntax, struct methods are // not special. You can reference them as any other declaration inside // the struct: - try expect(Vec3.dot(v1, v2) == 0.0); + try expectEqual(0.0, Vec3.dot(v1, v2)); } // Structs can have declarations. @@ -48,8 +48,8 @@ const Empty = struct { pub const PI = 3.14; }; test "struct namespaced variable" { - try expect(Empty.PI == 3.14); - try expect(@sizeOf(Empty) == 0); + try expectEqual(3.14, Empty.PI); + try expectEqual(0, @sizeOf(Empty)); // Empty structs can be instantiated the same as usual. const does_nothing: Empty = .{}; @@ -69,7 +69,7 @@ test "field parent pointer" { .y = 0.5678, }; setYBasedOnX(&point.x, 0.9); - try expect(point.y == 0.9); + try expectEqual(0.9, point.y); } // Structs can be returned from functions. @@ -89,19 +89,19 @@ fn LinkedList(comptime T: type) type { test "linked list" { // Functions called at compile-time are memoized. - try expect(LinkedList(i32) == LinkedList(i32)); + try expectEqual(LinkedList(i32), LinkedList(i32)); const list = LinkedList(i32){ .first = null, .last = null, .len = 0, }; - try expect(list.len == 0); + try expectEqual(0, list.len); // Since types are first class values you can instantiate the type // by assigning it to a variable: const ListOfInts = LinkedList(i32); - try expect(ListOfInts == LinkedList(i32)); + try expectEqual(LinkedList(i32), ListOfInts); var node = ListOfInts.Node{ .prev = null, @@ -117,10 +117,10 @@ test "linked list" { // When using a pointer to a struct, fields can be accessed directly, // without explicitly dereferencing the pointer. // So you can do - try expect(list2.first.?.data == 1234); - // instead of try expect(list2.first.?.*.data == 1234); + try expectEqual(1234, list2.first.?.data); + // instead of try expectEqual(1234, list2.first.?.*.data); } -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; // test diff --git a/doc/langref/test_switch.zig b/doc/langref/test_switch.zig index 33fabbdfcd..d6e67c1587 100644 --- a/doc/langref/test_switch.zig +++ b/doc/langref/test_switch.zig @@ -1,6 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "switch simple" { const a: u64 = 10; @@ -40,7 +40,7 @@ test "switch simple" { else => 9, }; - try expect(b == 1); + try expectEqual(1, b); } // Switch expressions can be used outside a function: diff --git a/doc/langref/test_switch_modify_tagged_union.zig b/doc/langref/test_switch_modify_tagged_union.zig index 96433900f0..ba5cc5193e 100644 --- a/doc/langref/test_switch_modify_tagged_union.zig +++ b/doc/langref/test_switch_modify_tagged_union.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const ComplexTypeTag = enum { ok, @@ -18,7 +18,7 @@ test "modify tagged union in switch" { ComplexTypeTag.not_ok => unreachable, } - try expect(c.ok == 43); + try expectEqual(43, c.ok); } // test diff --git a/doc/langref/test_switch_tagged_union.zig b/doc/langref/test_switch_tagged_union.zig index 2644817b47..568092dad9 100644 --- a/doc/langref/test_switch_tagged_union.zig +++ b/doc/langref/test_switch_tagged_union.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "switch on tagged union" { const Point = struct { @@ -31,8 +31,8 @@ test "switch on tagged union" { Item.d => 8, }; - try expect(b == 6); - try expect(a.c.x == 2); + try expectEqual(6, b); + try expectEqual(2, a.c.x); } // test diff --git a/doc/langref/test_tagName.zig b/doc/langref/test_tagName.zig index 8b0aa1cb28..1190089433 100644 --- a/doc/langref/test_tagName.zig +++ b/doc/langref/test_tagName.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqualSlices = std.testing.expectEqualSlices; const Small2 = union(enum) { a: i32, @@ -7,7 +7,7 @@ const Small2 = union(enum) { c: u8, }; test "@tagName" { - try expect(std.mem.eql(u8, @tagName(Small2.a), "a")); + try expectEqualSlices(u8, "a", @tagName(Small2.a)); } // test diff --git a/doc/langref/test_tagged_union.zig b/doc/langref/test_tagged_union.zig index d118d7e6bd..9efc18cc28 100644 --- a/doc/langref/test_tagged_union.zig +++ b/doc/langref/test_tagged_union.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const ComplexTypeTag = enum { ok, @@ -12,10 +12,10 @@ const ComplexType = union(ComplexTypeTag) { test "switch on tagged union" { const c = ComplexType{ .ok = 42 }; - try expect(@as(ComplexTypeTag, c) == ComplexTypeTag.ok); + try expectEqual(ComplexTypeTag.ok, @as(ComplexTypeTag, c)); switch (c) { - .ok => |value| try expect(value == 42), + .ok => |value| try expectEqual(42, value), .not_ok => unreachable, } @@ -29,7 +29,7 @@ test "switch on tagged union" { } test "get tag type" { - try expect(std.meta.Tag(ComplexType) == ComplexTypeTag); + try expectEqual(ComplexTypeTag, std.meta.Tag(ComplexType)); } // test diff --git a/doc/langref/test_tagged_union_with_tag_values.zig b/doc/langref/test_tagged_union_with_tag_values.zig index c079b5eac3..229a31d678 100644 --- a/doc/langref/test_tagged_union_with_tag_values.zig +++ b/doc/langref/test_tagged_union_with_tag_values.zig @@ -1,5 +1,5 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const Tagged = union(enum(u32)) { int: i64 = 123, @@ -8,10 +8,10 @@ const Tagged = union(enum(u32)) { test "tag values" { const int: Tagged = .{ .int = -40 }; - try expect(@intFromEnum(int) == 123); + try expectEqual(123, @intFromEnum(int)); const boolean: Tagged = .{ .boolean = false }; - try expect(@intFromEnum(boolean) == 67); + try expectEqual(67, @intFromEnum(boolean)); } // test diff --git a/doc/langref/test_this_builtin.zig b/doc/langref/test_this_builtin.zig index 5cad4e2553..54cad56fdf 100644 --- a/doc/langref/test_this_builtin.zig +++ b/doc/langref/test_this_builtin.zig @@ -1,10 +1,10 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "@This()" { var items = [_]i32{ 1, 2, 3, 4 }; const list = List(i32){ .items = items[0..] }; - try expect(list.length() == 4); + try expectEqual(4, list.length()); } fn List(comptime T: type) type { diff --git a/doc/langref/test_truncate_builtin.zig b/doc/langref/test_truncate_builtin.zig index a893db8206..73484fc41e 100644 --- a/doc/langref/test_truncate_builtin.zig +++ b/doc/langref/test_truncate_builtin.zig @@ -1,10 +1,10 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "integer truncation" { const a: u16 = 0xabcd; const b: u8 = @truncate(a); - try expect(b == 0xcd); + try expectEqual(0xcd, b); } // test diff --git a/doc/langref/test_tuples.zig b/doc/langref/test_tuples.zig index 54e05e77e7..2d075b324f 100644 --- a/doc/langref/test_tuples.zig +++ b/doc/langref/test_tuples.zig @@ -1,5 +1,6 @@ const std = @import("std"); const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "tuple" { const values = .{ @@ -8,14 +9,14 @@ test "tuple" { true, "hi", } ++ .{false} ** 2; - try expect(values[0] == 1234); - try expect(values[4] == false); + try expectEqual(1234, values[0]); + try expectEqual(false, values[4]); inline for (values, 0..) |v, i| { if (i != 2) continue; try expect(v); } - try expect(values.len == 6); - try expect(values.@"3"[0] == 'h'); + try expectEqual(6, values.len); + try expectEqual('h', values.@"3"[0]); } // test diff --git a/doc/langref/test_variable_alignment.zig b/doc/langref/test_variable_alignment.zig index ea0024f988..d0a4560fa2 100644 --- a/doc/langref/test_variable_alignment.zig +++ b/doc/langref/test_variable_alignment.zig @@ -1,15 +1,20 @@ const std = @import("std"); const builtin = @import("builtin"); const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "variable alignment" { var x: i32 = 1234; - const align_of_i32 = @alignOf(@TypeOf(x)); - try expect(@TypeOf(&x) == *i32); - try expect(*i32 == *align(align_of_i32) i32); - if (builtin.target.cpu.arch == .x86_64) { - try expect(@typeInfo(*i32).pointer.alignment == 4); - } + + try expectEqual(*i32, @TypeOf(&x)); + + try expect(@intFromPtr(&x) % @alignOf(i32) == 0); + + // The implicitly-aligned pointer can be coerced to be explicitly-aligned to + // the alignment of the underlying type `i32`: + const ptr: *align(@alignOf(i32)) i32 = &x; + + try expectEqual(1234, ptr.*); } // test diff --git a/doc/langref/test_variable_func_alignment.zig b/doc/langref/test_variable_func_alignment.zig index e0aa949cee..bd97756c45 100644 --- a/doc/langref/test_variable_func_alignment.zig +++ b/doc/langref/test_variable_func_alignment.zig @@ -1,14 +1,14 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; var foo: u8 align(4) = 100; test "global variable alignment" { - try expect(@typeInfo(@TypeOf(&foo)).pointer.alignment == 4); - try expect(@TypeOf(&foo) == *align(4) u8); + try expectEqual(4, @typeInfo(@TypeOf(&foo)).pointer.alignment); + try expectEqual(*align(4) u8, @TypeOf(&foo)); const as_pointer_to_array: *align(4) [1]u8 = &foo; const as_slice: []align(4) u8 = as_pointer_to_array; const as_unaligned_slice: []u8 = as_slice; - try expect(as_unaligned_slice[0] == 100); + try expectEqual(100, as_unaligned_slice[0]); } fn derp() align(@sizeOf(usize) * 2) i32 { @@ -18,17 +18,17 @@ fn noop1() align(1) void {} fn noop4() align(4) void {} test "function alignment" { - try expect(derp() == 1234); - try expect(@TypeOf(derp) == fn () i32); - try expect(@TypeOf(&derp) == *align(@sizeOf(usize) * 2) const fn () i32); + try expectEqual(1234, derp()); + try expectEqual(fn () i32, @TypeOf(derp)); + try expectEqual(*align(@sizeOf(usize) * 2) const fn () i32, @TypeOf(&derp)); noop1(); - try expect(@TypeOf(noop1) == fn () void); - try expect(@TypeOf(&noop1) == *align(1) const fn () void); + try expectEqual(fn () void, @TypeOf(noop1)); + try expectEqual(*align(1) const fn () void, @TypeOf(&noop1)); noop4(); - try expect(@TypeOf(noop4) == fn () void); - try expect(@TypeOf(&noop4) == *align(4) const fn () void); + try expectEqual(fn () void, @TypeOf(noop4)); + try expectEqual(*align(4) const fn () void, @TypeOf(&noop4)); } // test diff --git a/doc/langref/test_variadic_function.zig b/doc/langref/test_variadic_function.zig index e5d9777f64..f1c389b551 100644 --- a/doc/langref/test_variadic_function.zig +++ b/doc/langref/test_variadic_function.zig @@ -4,7 +4,7 @@ const testing = std.testing; pub extern "c" fn printf(format: [*:0]const u8, ...) c_int; test "variadic function" { - try testing.expect(printf("Hello, world!\n") == 14); + try testing.expectEqual(14, printf("Hello, world!\n")); try testing.expect(@typeInfo(@TypeOf(printf)).@"fn".is_var_args); } diff --git a/doc/langref/test_volatile.zig b/doc/langref/test_volatile.zig index 2c33faddf5..b493dd0b94 100644 --- a/doc/langref/test_volatile.zig +++ b/doc/langref/test_volatile.zig @@ -1,8 +1,8 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "volatile" { const mmio_ptr: *volatile u8 = @ptrFromInt(0x12345678); - try expect(@TypeOf(mmio_ptr) == *volatile u8); + try expectEqual(*volatile u8, @TypeOf(mmio_ptr)); } // test diff --git a/doc/langref/test_wasmMemoryGrow_builtin.zig b/doc/langref/test_wasmMemoryGrow_builtin.zig index 7f2dc3e149..e18d5d1b75 100644 --- a/doc/langref/test_wasmMemoryGrow_builtin.zig +++ b/doc/langref/test_wasmMemoryGrow_builtin.zig @@ -1,13 +1,13 @@ const std = @import("std"); const native_arch = @import("builtin").target.cpu.arch; -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; test "@wasmMemoryGrow" { if (native_arch != .wasm32) return error.SkipZigTest; const prev = @wasmMemorySize(0); - try expect(prev == @wasmMemoryGrow(0, 1)); - try expect(prev + 1 == @wasmMemorySize(0)); + try expectEqual(@wasmMemoryGrow(0, 1), prev); + try expectEqual(@wasmMemorySize(0), prev + 1); } // test diff --git a/doc/langref/test_while.zig b/doc/langref/test_while.zig index 45b27bc716..a9771410e2 100644 --- a/doc/langref/test_while.zig +++ b/doc/langref/test_while.zig @@ -1,11 +1,11 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "while basic" { var i: usize = 0; while (i < 10) { i += 1; } - try expect(i == 10); + try expectEqual(10, i); } // test diff --git a/doc/langref/test_while_break.zig b/doc/langref/test_while_break.zig index d30d481548..c433337d9f 100644 --- a/doc/langref/test_while_break.zig +++ b/doc/langref/test_while_break.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "while break" { var i: usize = 0; @@ -7,7 +7,7 @@ test "while break" { break; i += 1; } - try expect(i == 10); + try expectEqual(10, i); } // test diff --git a/doc/langref/test_while_continue.zig b/doc/langref/test_while_continue.zig index afe794223a..22f5ba1a75 100644 --- a/doc/langref/test_while_continue.zig +++ b/doc/langref/test_while_continue.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "while continue" { var i: usize = 0; @@ -8,7 +8,7 @@ test "while continue" { continue; break; } - try expect(i == 10); + try expectEqual(10, i); } // test diff --git a/doc/langref/test_while_continue_expression.zig b/doc/langref/test_while_continue_expression.zig index 3831f91c05..2ebc7c8345 100644 --- a/doc/langref/test_while_continue_expression.zig +++ b/doc/langref/test_while_continue_expression.zig @@ -1,9 +1,10 @@ +const expectEqual = @import("std").testing.expectEqual; const expect = @import("std").testing.expect; test "while loop continue expression" { var i: usize = 0; while (i < 10) : (i += 1) {} - try expect(i == 10); + try expectEqual(10, i); } test "while loop continue expression, more complicated" { diff --git a/doc/langref/test_while_error_capture.zig b/doc/langref/test_while_error_capture.zig index b687d1a5e7..739db0229e 100644 --- a/doc/langref/test_while_error_capture.zig +++ b/doc/langref/test_while_error_capture.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "while error union capture" { var sum1: u32 = 0; @@ -6,7 +6,7 @@ test "while error union capture" { while (eventuallyErrorSequence()) |value| { sum1 += value; } else |err| { - try expect(err == error.ReachedZero); + try expectEqual(error.ReachedZero, err); } } diff --git a/doc/langref/test_while_null_capture.zig b/doc/langref/test_while_null_capture.zig index dd412ffccd..13fc7e062d 100644 --- a/doc/langref/test_while_null_capture.zig +++ b/doc/langref/test_while_null_capture.zig @@ -1,4 +1,4 @@ -const expect = @import("std").testing.expect; +const expectEqual = @import("std").testing.expectEqual; test "while null capture" { var sum1: u32 = 0; @@ -6,7 +6,7 @@ test "while null capture" { while (eventuallyNullSequence()) |value| { sum1 += value; } - try expect(sum1 == 3); + try expectEqual(3, sum1); // null capture with an else block var sum2: u32 = 0; @@ -14,7 +14,7 @@ test "while null capture" { while (eventuallyNullSequence()) |value| { sum2 += value; } else { - try expect(sum2 == 3); + try expectEqual(3, sum2); } // null capture with a continue expression @@ -24,7 +24,7 @@ test "while null capture" { while (eventuallyNullSequence()) |value| : (i += 1) { sum3 += value; } - try expect(i == 3); + try expectEqual(3, i); } var numbers_left: u32 = undefined; diff --git a/doc/langref/test_wraparound_semantics.zig b/doc/langref/test_wraparound_semantics.zig index 491b0907f6..18c3ce44a6 100644 --- a/doc/langref/test_wraparound_semantics.zig +++ b/doc/langref/test_wraparound_semantics.zig @@ -1,14 +1,14 @@ const std = @import("std"); -const expect = std.testing.expect; +const expectEqual = std.testing.expectEqual; const minInt = std.math.minInt; const maxInt = std.math.maxInt; test "wraparound addition and subtraction" { const x: i32 = maxInt(i32); const min_val = x +% 1; - try expect(min_val == minInt(i32)); + try expectEqual(minInt(i32), min_val); const max_val = min_val -% 1; - try expect(max_val == maxInt(i32)); + try expectEqual(maxInt(i32), max_val); } // test diff --git a/doc/langref/testing_detect_leak.zig b/doc/langref/testing_detect_leak.zig index fd72fc9bba..d15e7b6b1c 100644 --- a/doc/langref/testing_detect_leak.zig +++ b/doc/langref/testing_detect_leak.zig @@ -6,7 +6,7 @@ test "detect leak" { // missing `defer list.deinit(gpa);` try list.append(gpa, '☔'); - try std.testing.expect(list.items.len == 1); + try std.testing.expectEqual(1, list.items.len); } // test_error=1 tests leaked memory diff --git a/doc/langref/testing_introduction.zig b/doc/langref/testing_introduction.zig index 6a46c8d688..22bd70a5ad 100644 --- a/doc/langref/testing_introduction.zig +++ b/doc/langref/testing_introduction.zig @@ -7,12 +7,16 @@ test "expect addOne adds one to 41" { // It will return an error if its argument is false to indicate a failure. // `try` is used to return an error to the test runner to notify it that the test failed. try std.testing.expect(addOne(41) == 42); + + // However, in most cases it is more convenient to use a more specific function like `expectEqual`. + // This gives you much clearer and more helpful error messages when a test fails. + try std.testing.expectEqual(42, addOne(41)); } test addOne { // A test name can also be written using an identifier. // This is a doctest, and serves as documentation for `addOne`. - try std.testing.expect(addOne(41) == 42); + try std.testing.expectEqual(42, addOne(41)); } /// The function `addOne` adds one to the number given as its argument. diff --git a/doc/langref/verbose_cimport_flag.zig b/doc/langref/verbose_cimport_flag.zig index 82b8307378..3adc37b507 100644 --- a/doc/langref/verbose_cimport_flag.zig +++ b/doc/langref/verbose_cimport_flag.zig @@ -3,6 +3,7 @@ const c = @cImport({ @cInclude("stdio.h"); }); pub fn main() void { + if (@import("builtin").os.tag == .netbsd) return; // https://github.com/Vexu/arocc/issues/960 _ = c; } diff --git a/lib/build-web/fuzz.zig b/lib/build-web/fuzz.zig index 5fe0de2f7a..21eb3f868a 100644 --- a/lib/build-web/fuzz.zig +++ b/lib/build-web/fuzz.zig @@ -1,5 +1,6 @@ // Server timestamp. var start_fuzzing_timestamp: i64 = undefined; +var start_fuzzing_n_runs: u64 = undefined; const js = struct { extern "fuzz" fn requestSources() void; @@ -36,6 +37,7 @@ pub fn sourceIndexMessage(msg_bytes: []u8) error{OutOfMemory}!void { const source_locations: []const Coverage.SourceLocation = @alignCast(std.mem.bytesAsSlice(Coverage.SourceLocation, msg_bytes[source_locations_start..source_locations_end])); start_fuzzing_timestamp = header.start_timestamp; + start_fuzzing_n_runs = header.start_n_runs; try updateCoverageSources(directories, files, source_locations, string_bytes); js.ready(); } @@ -271,7 +273,7 @@ fn updateStats() error{OutOfMemory}!void { const avg_speed: f64 = speed: { const ns_elapsed: f64 = @floatFromInt(nsSince(start_fuzzing_timestamp)); - const n_runs: f64 = @floatFromInt(hdr.n_runs); + const n_runs: f64 = @floatFromInt(hdr.n_runs -% start_fuzzing_n_runs); break :speed n_runs / (ns_elapsed / std.time.ns_per_s); }; diff --git a/lib/build-web/time_report.zig b/lib/build-web/time_report.zig index c19a5abcc9..f6e641432c 100644 --- a/lib/build-web/time_report.zig +++ b/lib/build-web/time_report.zig @@ -42,10 +42,10 @@ pub fn genericResultMessage(msg_bytes: []u8) error{OutOfMemory}!void { if (msg.step_idx >= step_list.*.len) @panic("malformed GenericResult message"); const inner_html = try std.fmt.allocPrint(gpa, \\{[step_name]f} - \\{[stat_total_time]D} + \\{[stat_total_time]f} , .{ .step_name = fmtEscapeHtml(step_list.*[msg.step_idx].name), - .stat_total_time = msg.ns_total, + .stat_total_time = std.Io.Duration{ .nanoseconds = msg.ns_total }, }); defer gpa.free(inner_html); js.updateGeneric(msg.step_idx, inner_html.ptr, inner_html.len); @@ -139,16 +139,16 @@ pub fn compileResultMessage(msg_bytes: []u8) error{ OutOfMemory, WriteFailed }!v \\{[stat_imported_files]d} \\{[stat_generic_instances]d} \\{[stat_inline_calls]d} - \\{[stat_compilation_time]D} - \\{[cpu_time_parse]D} - \\{[cpu_time_astgen]D} - \\{[cpu_time_sema]D} - \\{[cpu_time_codegen]D} - \\{[cpu_time_link]D} - \\{[real_time_files]D} - \\{[real_time_decls]D} - \\{[real_time_llvm_emit]D} - \\{[real_time_link_flush]D} + \\{[stat_compilation_time]f} + \\{[cpu_time_parse]f} + \\{[cpu_time_astgen]f} + \\{[cpu_time_sema]f} + \\{[cpu_time_codegen]f} + \\{[cpu_time_link]f} + \\{[real_time_files]f} + \\{[real_time_decls]f} + \\{[real_time_llvm_emit]f} + \\{[real_time_link_flush]f} \\
{[llvm_pass_timings]f}
\\ , .{ @@ -157,17 +157,17 @@ pub fn compileResultMessage(msg_bytes: []u8) error{ OutOfMemory, WriteFailed }!v .stat_imported_files = stats.n_imported_files, .stat_generic_instances = stats.n_generic_instances, .stat_inline_calls = stats.n_inline_calls, - .stat_compilation_time = hdr.ns_total, + .stat_compilation_time = std.Io.Duration{ .nanoseconds = hdr.ns_total }, - .cpu_time_parse = stats.cpu_ns_parse, - .cpu_time_astgen = stats.cpu_ns_astgen, - .cpu_time_sema = stats.cpu_ns_sema, - .cpu_time_codegen = stats.cpu_ns_codegen, - .cpu_time_link = stats.cpu_ns_link, - .real_time_files = stats.real_ns_files, - .real_time_decls = stats.real_ns_decls, - .real_time_llvm_emit = stats.real_ns_llvm_emit, - .real_time_link_flush = stats.real_ns_link_flush, + .cpu_time_parse = std.Io.Duration{ .nanoseconds = stats.cpu_ns_parse }, + .cpu_time_astgen = std.Io.Duration{ .nanoseconds = stats.cpu_ns_astgen }, + .cpu_time_sema = std.Io.Duration{ .nanoseconds = stats.cpu_ns_sema }, + .cpu_time_codegen = std.Io.Duration{ .nanoseconds = stats.cpu_ns_codegen }, + .cpu_time_link = std.Io.Duration{ .nanoseconds = stats.cpu_ns_link }, + .real_time_files = std.Io.Duration{ .nanoseconds = stats.real_ns_files }, + .real_time_decls = std.Io.Duration{ .nanoseconds = stats.real_ns_decls }, + .real_time_llvm_emit = std.Io.Duration{ .nanoseconds = stats.real_ns_llvm_emit }, + .real_time_link_flush = std.Io.Duration{ .nanoseconds = stats.real_ns_link_flush }, .llvm_pass_timings = fmtEscapeHtml(llvm_pass_timings), }); @@ -180,18 +180,18 @@ pub fn compileResultMessage(msg_bytes: []u8) error{ OutOfMemory, WriteFailed }!v try file_table_html.writer.print( \\ \\ {f} - \\ {D} - \\ {D} - \\ {D} - \\ {D} + \\ {f} + \\ {f} + \\ {f} + \\ {f} \\ \\ , .{ fmtEscapeHtml(file.name), - file.ns_sema, - file.ns_codegen, - file.ns_link, - file.ns_sema + file.ns_codegen + file.ns_link, + std.Io.Duration{ .nanoseconds = file.ns_sema }, + std.Io.Duration{ .nanoseconds = file.ns_codegen }, + std.Io.Duration{ .nanoseconds = file.ns_link }, + std.Io.Duration{ .nanoseconds = file.ns_sema + file.ns_codegen + file.ns_link }, }); } if (slowest_files.len > max_table_rows) { @@ -210,20 +210,20 @@ pub fn compileResultMessage(msg_bytes: []u8) error{ OutOfMemory, WriteFailed }!v \\ {f} \\ {f} \\ {d} - \\ {D} - \\ {D} - \\ {D} - \\ {D} + \\ {f} + \\ {f} + \\ {f} + \\ {f} \\ \\ , .{ fmtEscapeHtml(decl.file_name), fmtEscapeHtml(decl.name), decl.sema_count, - decl.ns_sema, - decl.ns_codegen, - decl.ns_link, - decl.ns_sema + decl.ns_codegen + decl.ns_link, + std.Io.Duration{ .nanoseconds = decl.ns_sema }, + std.Io.Duration{ .nanoseconds = decl.ns_codegen }, + std.Io.Duration{ .nanoseconds = decl.ns_link }, + std.Io.Duration{ .nanoseconds = decl.ns_sema + decl.ns_codegen + decl.ns_link }, }); } if (slowest_decls.len > max_table_rows) { @@ -265,7 +265,7 @@ pub fn runTestResultMessage(msg_bytes: []u8) error{OutOfMemory}!void { if (test_ns == std.math.maxInt(u64)) { try table_html.appendSlice(gpa, ""); // didn't run } else { - try table_html.print(gpa, "{D}", .{test_ns}); + try table_html.print(gpa, "{f}", .{std.Io.Duration{ .nanoseconds = test_ns }}); } try table_html.appendSlice(gpa, "\n"); } diff --git a/lib/c.zig b/lib/c.zig index dce7ae5608..63597e3022 100644 --- a/lib/c.zig +++ b/lib/c.zig @@ -1,7 +1,9 @@ -//! This is Zig's multi-target implementation of libc. +//! Multi-target implementation of libc, providing ABI compatibility with +//! bundled libcs. //! -//! When `builtin.link_libc` is true, we need to export all the functions and -//! provide a libc API compatible with the target (e.g. musl, wasi-libc, ...). +//! mingw-w64 libc is not fully statically linked, so some symbols don't need +//! to be exported. However, a future enhancement could be eliminating Zig's +//! dependency on msvcrt dll even when linking libc and targeting Windows. const builtin = @import("builtin"); const std = @import("std"); @@ -13,31 +15,70 @@ pub const panic = if (builtin.is_test) else std.debug.no_panic; -// NOTE: `libzigc` aims to be a standalone libc and provide ABI compatibility with its bundled libc's. -// Some of them like `mingw` are not fully statically linked so some symbols don't need to be exported. +/// It is possible that this libc is being linked into a different test +/// compilation, as opposed to being tested itself. In such case, +/// `builtin.link_libc` will be `true` along with `builtin.is_test`. +/// +/// When we don't have a complete libc, `builtin.link_libc` will be `false` and +/// we will be missing externally provided symbols, such as `_errno` from +/// ucrtbase.dll. In such case, we must avoid analyzing otherwise exported +/// functions because it would cause undefined symbol usage. +/// +/// Unfortunately such logic cannot be automatically done in this function body +/// since `func` will always be analyzed by the time we get here, so `comptime` +/// blocks will need to each check for `builtin.link_libc` and skip exports +/// when the exported functions have libc dependencies not provided by this +/// compilation unit. +pub inline fn symbol(comptime func: *const anyopaque, comptime name: []const u8) void { + @export(func, .{ + .name = name, + // Normally, libc goes into a static archive, making all symbols + // overridable. However, Zig supports including the libc functions as part + // of the Zig Compilation Unit, so to support this use case we make all + // symbols weak. + .linkage = .weak, + // For WebAssembly, hidden visibility allows the symbol to be resolved to + // other modules, but will not export it to the host runtime. + .visibility = .hidden, + }); +} + +/// Given a low-level syscall return value, sets errno and returns `-1`, or on +/// success returns the result. +pub fn errno(syscall_return_value: usize) c_int { + return switch (builtin.os.tag) { + .linux => { + const signed: isize = @bitCast(syscall_return_value); + const casted: c_int = @intCast(signed); + if (casted < 0) { + @branchHint(.unlikely); + std.c._errno().* = -casted; + return -1; + } + return casted; + }, + else => comptime unreachable, + }; +} comptime { - _ = @import("c/inttypes.zig"); _ = @import("c/ctype.zig"); - _ = @import("c/stdlib.zig"); + _ = @import("c/inttypes.zig"); + if (!builtin.target.isMinGW()) { + _ = @import("c/malloc.zig"); + } _ = @import("c/math.zig"); + _ = @import("c/search.zig"); + _ = @import("c/stdlib.zig"); _ = @import("c/string.zig"); _ = @import("c/strings.zig"); + + _ = @import("c/sys/capability.zig"); + _ = @import("c/sys/file.zig"); + _ = @import("c/sys/mman.zig"); + _ = @import("c/sys/reboot.zig"); + _ = @import("c/sys/utsname.zig"); + + _ = @import("c/unistd.zig"); _ = @import("c/wchar.zig"); - - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { - // Files specific to musl and wasi-libc. - } - - if (builtin.target.isMuslLibC()) { - // Files specific to musl. - } - - if (builtin.target.isWasiLibC()) { - // Files specific to wasi-libc. - } - - if (builtin.target.isMinGW()) { - // Files specific to MinGW-w64. - } } diff --git a/lib/c/common.zig b/lib/c/common.zig deleted file mode 100644 index 4419b65cc6..0000000000 --- a/lib/c/common.zig +++ /dev/null @@ -1,15 +0,0 @@ -const builtin = @import("builtin"); -const std = @import("std"); - -pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) - .internal -else - .strong; - -/// Determines the symbol's visibility to other objects. -/// For WebAssembly this allows the symbol to be resolved to other modules, but will not -/// export it to the host runtime. -pub const visibility: std.builtin.SymbolVisibility = if (linkage != .internal) - .hidden -else - .default; diff --git a/lib/c/ctype.zig b/lib/c/ctype.zig index 5fd5669fae..9316ee102f 100644 --- a/lib/c/ctype.zig +++ b/lib/c/ctype.zig @@ -1,57 +1,57 @@ -const std = @import("std"); -const common = @import("common.zig"); const builtin = @import("builtin"); +const std = @import("std"); +const symbol = @import("../c.zig").symbol; comptime { if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { // Functions specific to musl and wasi-libc. - @export(&isalnum, .{ .name = "isalnum", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isalpha, .{ .name = "isalpha", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isblank, .{ .name = "isblank", .linkage = common.linkage, .visibility = common.visibility }); - @export(&iscntrl, .{ .name = "iscntrl", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isdigit, .{ .name = "isdigit", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isgraph, .{ .name = "isgraph", .linkage = common.linkage, .visibility = common.visibility }); - @export(&islower, .{ .name = "islower", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isprint, .{ .name = "isprint", .linkage = common.linkage, .visibility = common.visibility }); - @export(&ispunct, .{ .name = "ispunct", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isspace, .{ .name = "isspace", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isupper, .{ .name = "isupper", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isxdigit, .{ .name = "isxdigit", .linkage = common.linkage, .visibility = common.visibility }); - @export(&tolower, .{ .name = "tolower", .linkage = common.linkage, .visibility = common.visibility }); - @export(&toupper, .{ .name = "toupper", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&isalnum, "isalnum"); + symbol(&isalpha, "isalpha"); + symbol(&isblank, "isblank"); + symbol(&iscntrl, "iscntrl"); + symbol(&isdigit, "isdigit"); + symbol(&isgraph, "isgraph"); + symbol(&islower, "islower"); + symbol(&isprint, "isprint"); + symbol(&ispunct, "ispunct"); + symbol(&isspace, "isspace"); + symbol(&isupper, "isupper"); + symbol(&isxdigit, "isxdigit"); + symbol(&tolower, "tolower"); + symbol(&toupper, "toupper"); - @export(&__isalnum_l, .{ .name = "__isalnum_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isalpha_l, .{ .name = "__isalpha_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isblank_l, .{ .name = "__isblank_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__iscntrl_l, .{ .name = "__iscntrl_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isdigit_l, .{ .name = "__isdigit_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isgraph_l, .{ .name = "__isgraph_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__islower_l, .{ .name = "__islower_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isprint_l, .{ .name = "__isprint_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ispunct_l, .{ .name = "__ispunct_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isspace_l, .{ .name = "__isspace_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isupper_l, .{ .name = "__isupper_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isxdigit_l, .{ .name = "__isxdigit_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__tolower_l, .{ .name = "__tolower_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__toupper_l, .{ .name = "__toupper_l", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__isalnum_l, "__isalnum_l"); + symbol(&__isalpha_l, "__isalpha_l"); + symbol(&__isblank_l, "__isblank_l"); + symbol(&__iscntrl_l, "__iscntrl_l"); + symbol(&__isdigit_l, "__isdigit_l"); + symbol(&__isgraph_l, "__isgraph_l"); + symbol(&__islower_l, "__islower_l"); + symbol(&__isprint_l, "__isprint_l"); + symbol(&__ispunct_l, "__ispunct_l"); + symbol(&__isspace_l, "__isspace_l"); + symbol(&__isupper_l, "__isupper_l"); + symbol(&__isxdigit_l, "__isxdigit_l"); + symbol(&__tolower_l, "__tolower_l"); + symbol(&__toupper_l, "__toupper_l"); - @export(&__isalnum_l, .{ .name = "isalnum_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isalpha_l, .{ .name = "isalpha_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isblank_l, .{ .name = "isblank_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__iscntrl_l, .{ .name = "iscntrl_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isdigit_l, .{ .name = "isdigit_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isgraph_l, .{ .name = "isgraph_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__islower_l, .{ .name = "islower_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isprint_l, .{ .name = "isprint_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ispunct_l, .{ .name = "ispunct_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isspace_l, .{ .name = "isspace_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isupper_l, .{ .name = "isupper_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__isxdigit_l, .{ .name = "isxdigit_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__tolower_l, .{ .name = "tolower_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__toupper_l, .{ .name = "toupper_l", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__isalnum_l, "isalnum_l"); + symbol(&__isalpha_l, "isalpha_l"); + symbol(&__isblank_l, "isblank_l"); + symbol(&__iscntrl_l, "iscntrl_l"); + symbol(&__isdigit_l, "isdigit_l"); + symbol(&__isgraph_l, "isgraph_l"); + symbol(&__islower_l, "islower_l"); + symbol(&__isprint_l, "isprint_l"); + symbol(&__ispunct_l, "ispunct_l"); + symbol(&__isspace_l, "isspace_l"); + symbol(&__isupper_l, "isupper_l"); + symbol(&__isxdigit_l, "isxdigit_l"); + symbol(&__tolower_l, "tolower_l"); + symbol(&__toupper_l, "toupper_l"); - @export(&isascii, .{ .name = "isascii", .linkage = common.linkage, .visibility = common.visibility }); - @export(&toascii, .{ .name = "toascii", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&isascii, "isascii"); + symbol(&toascii, "toascii"); } } diff --git a/lib/c/inttypes.zig b/lib/c/inttypes.zig index 39b2c9ba88..7bdcae873e 100644 --- a/lib/c/inttypes.zig +++ b/lib/c/inttypes.zig @@ -1,14 +1,16 @@ -const std = @import("std"); -const common = @import("common.zig"); const builtin = @import("builtin"); + +const std = @import("std"); const intmax_t = std.c.intmax_t; const imaxdiv_t = std.c.imaxdiv_t; +const symbol = @import("../c.zig").symbol; + comptime { if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { // Functions specific to musl and wasi-libc. - @export(&imaxabs, .{ .name = "imaxabs", .linkage = common.linkage, .visibility = common.visibility }); - @export(&imaxdiv, .{ .name = "imaxdiv", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&imaxabs, "imaxabs"); + symbol(&imaxdiv, "imaxdiv"); } } diff --git a/lib/c/malloc.zig b/lib/c/malloc.zig new file mode 100644 index 0000000000..083825e438 --- /dev/null +++ b/lib/c/malloc.zig @@ -0,0 +1,197 @@ +//! Based on wrapping a stateless Zig Allocator implementation, appropriate for: +//! - ReleaseFast and ReleaseSmall optimization modes, with multi-threading +//! enabled. +//! - WebAssembly or Linux in single-threaded release modes. +//! +//! Because the libc APIs don't have client alignment and size tracking, in +//! order to take advantage of Zig allocator implementations, additional +//! metadata must be stored in the allocations. +//! +//! This implementation stores the metadata just before the pointer returned +//! from `malloc`, just like many libc malloc implementations do, including +//! musl. This has the downside of causing fragmentation for allocations with +//! higher alignment, however most of that memory can be recovered by +//! preemptively putting the gap onto the freelist. +const builtin = @import("builtin"); + +const std = @import("std"); +const assert = std.debug.assert; +const Alignment = std.mem.Alignment; +const alignment_bytes = @max(@alignOf(std.c.max_align_t), @sizeOf(Header)); +const alignment: Alignment = .fromByteUnits(alignment_bytes); + +const symbol = @import("../c.zig").symbol; + +comptime { + // Dependency on external errno location. + if (builtin.link_libc) { + symbol(&malloc, "malloc"); + symbol(&aligned_alloc, "aligned_alloc"); + symbol(&posix_memalign, "posix_memalign"); + symbol(&calloc, "calloc"); + symbol(&realloc, "realloc"); + symbol(&reallocarray, "reallocarray"); + symbol(&free, "free"); + symbol(&malloc_usable_size, "malloc_usable_size"); + + symbol(&valloc, "valloc"); + symbol(&memalign, "memalign"); + } +} + +const no_context: *anyopaque = undefined; +const no_ra: usize = undefined; +const vtable = switch (builtin.cpu.arch) { + .wasm32, .wasm64 => std.heap.WasmAllocator.vtable, + else => if (builtin.single_threaded) std.heap.BrkAllocator.vtable else std.heap.SmpAllocator.vtable, +}; + +/// Needed because libc memory allocators don't provide old alignment and size +/// which are required by Zig memory allocators. +const Header = packed struct(u64) { + alignment: Alignment, + /// Does not include the extra alignment bytes added. + size: Size, + canary: Canary = magic, + + comptime { + assert(@sizeOf(Header) <= alignment_bytes); + } + + const safety = switch (builtin.mode) { + .Debug, .ReleaseSafe => true, + .ReleaseFast, .ReleaseSmall => false, + }; + const max_addr_bits = switch (safety) { + true => 48, // Ensures space for Canary bits. + false => 64, + }; + const Size = @Int(.unsigned, @min(max_addr_bits, 64 - @bitSizeOf(Alignment), @bitSizeOf(usize))); + const Canary = @Int(.unsigned, 64 - @bitSizeOf(Alignment) - @bitSizeOf(Size)); + const magic: Canary = switch (safety) { + true => @truncate(@as(u64, 0x76fa65bebb3d7a39)), // statically chosen entropy + false => 0, + }; + + fn get(base: [*]align(alignment_bytes) u8) Header { + const header: *Header = @ptrCast(base - @sizeOf(Header)); + assert(header.canary == magic); + return header.*; + } + + fn set(base: [*]align(alignment_bytes) u8, a: Alignment, size: Size) [*]align(alignment_bytes) u8 { + const header: *Header = @ptrCast(base - @sizeOf(Header)); + header.* = .{ .alignment = a, .size = size }; + return base; + } +}; + +fn malloc(n: usize) callconv(.c) ?[*]align(alignment_bytes) u8 { + const size = std.math.cast(Header.Size, n) orelse return nomem(); + const ptr: [*]align(alignment_bytes) u8 = @alignCast( + vtable.alloc(no_context, n + alignment_bytes, alignment, no_ra) orelse return nomem(), + ); + const base = ptr + alignment_bytes; + return Header.set(base, alignment, size); +} + +fn aligned_alloc(alloc_alignment: usize, n: usize) callconv(.c) ?[*]align(alignment_bytes) u8 { + return aligned_alloc_inner(alloc_alignment, n) orelse return nomem(); +} + +/// Avoids setting errno so it can be called by `posix_memalign`. +fn aligned_alloc_inner(alloc_alignment: usize, n: usize) ?[*]align(alignment_bytes) u8 { + const size = std.math.cast(Header.Size, n) orelse return null; + const max_align = alignment.max(.fromByteUnits(alloc_alignment)); + const max_align_bytes = max_align.toByteUnits(); + const ptr: [*]align(alignment_bytes) u8 = @alignCast( + vtable.alloc(no_context, n + max_align_bytes, max_align, no_ra) orelse return null, + ); + const base: [*]align(alignment_bytes) u8 = @alignCast(ptr + max_align_bytes); + return Header.set(base, max_align, size); +} + +fn calloc(elems: usize, len: usize) callconv(.c) ?[*]align(alignment_bytes) u8 { + const n = std.math.mul(usize, elems, len) catch return nomem(); + const base = malloc(n) orelse return null; + @memset(base[0..n], 0); + return base; +} + +fn realloc(opt_old_base: ?[*]align(alignment_bytes) u8, n: usize) callconv(.c) ?[*]align(alignment_bytes) u8 { + if (n == 0) { + free(opt_old_base); + return null; + } + const old_base = opt_old_base orelse return malloc(n); + const new_size = std.math.cast(Header.Size, n) orelse return nomem(); + const old_header: Header = .get(old_base); + const old_size = old_header.size; + const old_alignment = old_header.alignment; + const old_alignment_bytes = old_alignment.toByteUnits(); + const old_ptr = old_base - old_alignment_bytes; + const old_slice = old_ptr[0 .. old_size + old_alignment_bytes]; + const new_base: [*]align(alignment_bytes) u8 = if (vtable.remap( + no_context, + old_slice, + old_alignment, + n + old_alignment_bytes, + no_ra, + )) |new_ptr| @alignCast(new_ptr + old_alignment_bytes) else b: { + const new_ptr: [*]align(alignment_bytes) u8 = @alignCast( + vtable.alloc(no_context, n + old_alignment_bytes, old_alignment, no_ra) orelse + return nomem(), + ); + const new_base: [*]align(alignment_bytes) u8 = @alignCast(new_ptr + old_alignment_bytes); + const copy_len = @min(new_size, old_size); + @memcpy(new_base[0..copy_len], old_base[0..copy_len]); + vtable.free(no_context, old_slice, old_alignment, no_ra); + break :b new_base; + }; + return Header.set(new_base, old_alignment, new_size); +} + +fn reallocarray(opt_base: ?[*]align(alignment_bytes) u8, elems: usize, len: usize) callconv(.c) ?[*]align(alignment_bytes) u8 { + const n = std.math.mul(usize, elems, len) catch return nomem(); + return realloc(opt_base, n); +} + +fn free(opt_old_base: ?[*]align(alignment_bytes) u8) callconv(.c) void { + const old_base = opt_old_base orelse return; + const old_header: Header = .get(old_base); + const old_size = old_header.size; + const old_alignment = old_header.alignment; + const old_alignment_bytes = old_alignment.toByteUnits(); + const old_ptr = old_base - old_alignment_bytes; + const old_slice = old_ptr[0 .. old_size + old_alignment_bytes]; + vtable.free(no_context, old_slice, old_alignment, no_ra); +} + +fn malloc_usable_size(opt_old_base: ?[*]align(alignment_bytes) u8) callconv(.c) usize { + const old_base = opt_old_base orelse return 0; + const old_header: Header = .get(old_base); + const old_size = old_header.size; + return old_size; +} + +fn valloc(n: usize) callconv(.c) ?[*]align(alignment_bytes) u8 { + return aligned_alloc(std.heap.pageSize(), n); +} + +fn memalign(alloc_alignment: usize, n: usize) callconv(.c) ?[*]align(alignment_bytes) u8 { + return aligned_alloc(alloc_alignment, n); +} + +fn posix_memalign(result: *?[*]align(alignment_bytes) u8, alloc_alignment: usize, n: usize) callconv(.c) c_int { + if (alloc_alignment < @sizeOf(*anyopaque)) return @intFromEnum(std.c.E.INVAL); + result.* = aligned_alloc_inner(alloc_alignment, n) orelse return @intFromEnum(std.c.E.NOMEM); + return 0; +} + +/// Libc memory allocation functions must set errno in addition to returning +/// `null`. +fn nomem() ?[*]align(alignment_bytes) u8 { + @branchHint(.cold); + std.c._errno().* = @intFromEnum(std.c.E.NOMEM); + return null; +} diff --git a/lib/c/math.zig b/lib/c/math.zig index 8a6c91be2e..501df810d6 100644 --- a/lib/c/math.zig +++ b/lib/c/math.zig @@ -1,85 +1,233 @@ -const std = @import("std"); -const common = @import("common.zig"); const builtin = @import("builtin"); +const std = @import("std"); +const math = std.math; + +const symbol = @import("../c.zig").symbol; + comptime { if (builtin.target.isMinGW()) { - @export(&isnan, .{ .name = "isnan", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isnan, .{ .name = "__isnan", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isnanf, .{ .name = "isnanf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isnanf, .{ .name = "__isnanf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isnanl, .{ .name = "isnanl", .linkage = common.linkage, .visibility = common.visibility }); - @export(&isnanl, .{ .name = "__isnanl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&isnan, "isnan"); + symbol(&isnan, "__isnan"); + symbol(&isnanf, "isnanf"); + symbol(&isnanf, "__isnanf"); + symbol(&isnanl, "isnanl"); + symbol(&isnanl, "__isnanl"); - @export(&std.math.nan(f64), .{ .name = "__QNAN", .linkage = common.linkage, .visibility = common.visibility }); - @export(&std.math.snan(f64), .{ .name = "__SNAN", .linkage = common.linkage, .visibility = common.visibility }); - @export(&std.math.inf(f64), .{ .name = "__INF", .linkage = common.linkage, .visibility = common.visibility }); - @export(&std.math.floatTrueMin(f64), .{ .name = "__DENORM", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&math.floatTrueMin(f64), "__DENORM"); + symbol(&math.inf(f64), "__INF"); + symbol(&math.nan(f64), "__QNAN"); + symbol(&math.snan(f64), "__SNAN"); - @export(&std.math.nan(f32), .{ .name = "__QNANF", .linkage = common.linkage, .visibility = common.visibility }); - @export(&std.math.snan(f32), .{ .name = "__SNANF", .linkage = common.linkage, .visibility = common.visibility }); - @export(&std.math.inf(f32), .{ .name = "__INFF", .linkage = common.linkage, .visibility = common.visibility }); - @export(&std.math.floatTrueMin(f32), .{ .name = "__DENORMF", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&math.floatTrueMin(f32), "__DENORMF"); + symbol(&math.inf(f32), "__INFF"); + symbol(&math.nan(f32), "__QNANF"); + symbol(&math.snan(f32), "__SNANF"); - @export(&std.math.nan(c_longdouble), .{ .name = "__QNANL", .linkage = common.linkage, .visibility = common.visibility }); - @export(&std.math.snan(c_longdouble), .{ .name = "__SNANL", .linkage = common.linkage, .visibility = common.visibility }); - @export(&std.math.inf(c_longdouble), .{ .name = "__INFL", .linkage = common.linkage, .visibility = common.visibility }); - @export(&std.math.floatTrueMin(c_longdouble), .{ .name = "__DENORML", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&math.floatTrueMin(c_longdouble), "__DENORML"); + symbol(&math.inf(c_longdouble), "__INFL"); + symbol(&math.nan(c_longdouble), "__QNANL"); + symbol(&math.snan(c_longdouble), "__SNANL"); } if (builtin.target.isMinGW() or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { - @export(&nan, .{ .name = "nan", .linkage = common.linkage, .visibility = common.visibility }); - @export(&nanf, .{ .name = "nanf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&nanl, .{ .name = "nanl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&coshf, "coshf"); + symbol(&hypotf, "hypotf"); + symbol(&hypotl, "hypotl"); + symbol(&nan, "nan"); + symbol(&nanf, "nanf"); + symbol(&nanl, "nanl"); } if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { - @export(&acos, .{ .name = "acos", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&acos, "acos"); + symbol(&acosf, "acosf"); + symbol(&atan, "atan"); + symbol(&atanf, "atanf"); + symbol(&atanl, "atanl"); + symbol(&cbrt, "cbrt"); + symbol(&cbrtf, "cbrtf"); + symbol(&cosh, "cosh"); + symbol(&exp10, "exp10"); + symbol(&exp10f, "exp10f"); + symbol(&hypot, "hypot"); + symbol(&pow, "pow"); + symbol(&pow10, "pow10"); + symbol(&pow10f, "pow10f"); } if (builtin.target.isMuslLibC()) { - @export(©signf, .{ .name = "copysignf", .linkage = common.linkage, .visibility = common.visibility }); - @export(©sign, .{ .name = "copysign", .linkage = common.linkage, .visibility = common.visibility }); + symbol(©sign, "copysign"); + symbol(©signf, "copysignf"); + symbol(&rint, "rint"); } - @export(©signl, .{ .name = "copysignl", .linkage = common.linkage, .visibility = common.visibility }); + + symbol(©signl, "copysignl"); } fn acos(x: f64) callconv(.c) f64 { + return math.acos(x); +} + +fn acosf(x: f32) callconv(.c) f32 { return std.math.acos(x); } -fn isnan(x: f64) callconv(.c) c_int { - return if (std.math.isNan(x)) 1 else 0; +fn atan(x: f64) callconv(.c) f64 { + return math.atan(x); } -fn isnanf(x: f32) callconv(.c) c_int { - return if (std.math.isNan(x)) 1 else 0; +fn atanf(x: f32) callconv(.c) f32 { + return math.atan(x); } -fn isnanl(x: c_longdouble) callconv(.c) c_int { - return if (std.math.isNan(x)) 1 else 0; +fn atanl(x: c_longdouble) callconv(.c) c_longdouble { + return switch (@typeInfo(@TypeOf(x)).float.bits) { + 16 => math.atan(@as(f16, @floatCast(x))), + 32 => math.atan(@as(f32, @floatCast(x))), + 64 => math.atan(@as(f64, @floatCast(x))), + 80 => math.atan(@as(f80, @floatCast(x))), + 128 => math.atan(@as(f128, @floatCast(x))), + else => unreachable, + }; } -fn nan(_: [*:0]const c_char) callconv(.c) f64 { - return std.math.nan(f64); +fn cbrt(x: f64) callconv(.c) f64 { + return math.cbrt(x); } -fn nanf(_: [*:0]const c_char) callconv(.c) f32 { - return std.math.nan(f32); -} - -fn nanl(_: [*:0]const c_char) callconv(.c) c_longdouble { - return std.math.nan(c_longdouble); -} - -fn copysignf(x: f32, y: f32) callconv(.c) f32 { - return std.math.copysign(x, y); +fn cbrtf(x: f32) callconv(.c) f32 { + return math.cbrt(x); } fn copysign(x: f64, y: f64) callconv(.c) f64 { - return std.math.copysign(x, y); + return math.copysign(x, y); +} + +fn copysignf(x: f32, y: f32) callconv(.c) f32 { + return math.copysign(x, y); } fn copysignl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { - return std.math.copysign(x, y); + return math.copysign(x, y); +} + +fn cosh(x: f64) callconv(.c) f64 { + return math.cosh(x); +} + +fn coshf(x: f32) callconv(.c) f32 { + return math.cosh(x); +} + +fn exp10(x: f64) callconv(.c) f64 { + return math.pow(f64, 10.0, x); +} + +fn exp10f(x: f32) callconv(.c) f32 { + return math.pow(f32, 10.0, x); +} + +fn hypot(x: f64, y: f64) callconv(.c) f64 { + return math.hypot(x, y); +} + +fn hypotf(x: f32, y: f32) callconv(.c) f32 { + return math.hypot(x, y); +} + +fn hypotl(x: c_longdouble, y: c_longdouble) callconv(.c) c_longdouble { + return math.hypot(x, y); +} + +fn isnan(x: f64) callconv(.c) c_int { + return if (math.isNan(x)) 1 else 0; +} + +fn isnanf(x: f32) callconv(.c) c_int { + return if (math.isNan(x)) 1 else 0; +} + +fn isnanl(x: c_longdouble) callconv(.c) c_int { + return if (math.isNan(x)) 1 else 0; +} + +fn nan(_: [*:0]const c_char) callconv(.c) f64 { + return math.nan(f64); +} + +fn nanf(_: [*:0]const c_char) callconv(.c) f32 { + return math.nan(f32); +} + +fn nanl(_: [*:0]const c_char) callconv(.c) c_longdouble { + return math.nan(c_longdouble); +} + +fn pow(x: f64, y: f64) callconv(.c) f64 { + return math.pow(f64, x, y); +} + +fn pow10(x: f64) callconv(.c) f64 { + return exp10(x); +} + +fn pow10f(x: f32) callconv(.c) f32 { + return exp10f(x); +} + +fn rint(x: f64) callconv(.c) f64 { + const toint: f64 = 1.0 / @as(f64, std.math.floatEps(f64)); + const a: u64 = @bitCast(x); + const e = a >> 52 & 0x7ff; + const s = a >> 63; + var y: f64 = undefined; + + if (e >= 0x3ff + 52) { + return x; + } + if (s == 1) { + y = x - toint + toint; + } else { + y = x + toint - toint; + } + if (y == 0) { + return if (s == 1) -0.0 else 0; + } + return y; +} + +test "rint" { + // Positive numbers round correctly + try std.testing.expectEqual(@as(f64, 42.0), rint(42.2)); + try std.testing.expectEqual(@as(f64, 42.0), rint(41.8)); + + // Negative numbers round correctly + try std.testing.expectEqual(@as(f64, -6.0), rint(-5.9)); + try std.testing.expectEqual(@as(f64, -6.0), rint(-6.1)); + + // No rounding needed test + try std.testing.expectEqual(@as(f64, 5.0), rint(5.0)); + try std.testing.expectEqual(@as(f64, -10.0), rint(-10.0)); + try std.testing.expectEqual(@as(f64, 0.0), rint(0.0)); + + // Very large numbers return unchanged + const large: f64 = 9007199254740992.0; // 2^53 + try std.testing.expectEqual(large, rint(large)); + try std.testing.expectEqual(-large, rint(-large)); + + // Small positive numbers round to zero + const pos_result = rint(0.3); + try std.testing.expectEqual(@as(f64, 0.0), pos_result); + try std.testing.expect(@as(u64, @bitCast(pos_result)) == 0); + + // Small negative numbers round to negative zero + const neg_result = rint(-0.3); + try std.testing.expectEqual(@as(f64, 0.0), neg_result); + const bits: u64 = @bitCast(neg_result); + try std.testing.expect((bits >> 63) == 1); + + // Exact half rounds to nearest even (banker's rounding) + try std.testing.expectEqual(@as(f64, 2.0), rint(2.5)); + try std.testing.expectEqual(@as(f64, 4.0), rint(3.5)); } diff --git a/lib/c/search.zig b/lib/c/search.zig new file mode 100644 index 0000000000..271aec873e --- /dev/null +++ b/lib/c/search.zig @@ -0,0 +1,67 @@ +const std = @import("std"); +const builtin = @import("builtin"); +const symbol = @import("../c.zig").symbol; + +comptime { + if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + symbol(&insque, "insque"); + symbol(&remque, "remque"); + } +} + +const Node = extern struct { + next: ?*Node, + prev: ?*Node, +}; + +fn insque(element: *anyopaque, pred: ?*anyopaque) callconv(.c) void { + const e: *Node = @ptrCast(@alignCast(element)); + + if (pred) |p_ptr| { + const p: *Node = @ptrCast(@alignCast(p_ptr)); + e.next = p.next; + e.prev = p; + p.next = e; + + if (e.next) |next| { + next.prev = e; + } + } else { + e.next = null; + e.prev = null; + } +} + +fn remque(element: *anyopaque) callconv(.c) void { + const e: *Node = @ptrCast(@alignCast(element)); + + if (e.next) |next| next.prev = e.prev; + if (e.prev) |prev| prev.next = e.next; +} + +test "insque and remque" { + var first = Node{ .next = null, .prev = null }; + var second = Node{ .next = null, .prev = null }; + var third = Node{ .next = null, .prev = null }; + + insque(&first, null); + try std.testing.expectEqual(@as(?*Node, null), first.next); + try std.testing.expectEqual(@as(?*Node, null), first.prev); + + insque(&second, &first); + try std.testing.expectEqual(@as(?*Node, &second), first.next); + try std.testing.expectEqual(@as(?*Node, &first), second.prev); + + insque(&third, &first); + try std.testing.expectEqual(@as(?*Node, &third), first.next); + try std.testing.expectEqual(@as(?*Node, &second), third.next); + try std.testing.expectEqual(@as(?*Node, &first), third.prev); + try std.testing.expectEqual(@as(?*Node, &third), second.prev); + + remque(&third); + try std.testing.expectEqual(@as(?*Node, &second), first.next); + try std.testing.expectEqual(@as(?*Node, &first), second.prev); + + remque(&second); + try std.testing.expectEqual(@as(?*Node, null), first.next); +} diff --git a/lib/c/stdlib.zig b/lib/c/stdlib.zig index 51ead9bee7..ccc8c08a14 100644 --- a/lib/c/stdlib.zig +++ b/lib/c/stdlib.zig @@ -1,47 +1,49 @@ -const std = @import("std"); -const common = @import("common.zig"); const builtin = @import("builtin"); + +const std = @import("std"); const assert = std.debug.assert; const div_t = std.c.div_t; const ldiv_t = std.c.ldiv_t; const lldiv_t = std.c.lldiv_t; +const symbol = @import("../c.zig").symbol; + comptime { _ = @import("stdlib/rand.zig"); _ = @import("stdlib/drand48.zig"); if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { // Functions specific to musl and wasi-libc. - @export(&abs, .{ .name = "abs", .linkage = common.linkage, .visibility = common.visibility }); - @export(&labs, .{ .name = "labs", .linkage = common.linkage, .visibility = common.visibility }); - @export(&llabs, .{ .name = "llabs", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&abs, "abs"); + symbol(&labs, "labs"); + symbol(&llabs, "llabs"); - @export(&div, .{ .name = "div", .linkage = common.linkage, .visibility = common.visibility }); - @export(&ldiv, .{ .name = "ldiv", .linkage = common.linkage, .visibility = common.visibility }); - @export(&lldiv, .{ .name = "lldiv", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&div, "div"); + symbol(&ldiv, "ldiv"); + symbol(&lldiv, "lldiv"); - @export(&atoi, .{ .name = "atoi", .linkage = common.linkage, .visibility = common.visibility }); - @export(&atol, .{ .name = "atol", .linkage = common.linkage, .visibility = common.visibility }); - @export(&atoll, .{ .name = "atoll", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&atoi, "atoi"); + symbol(&atol, "atol"); + symbol(&atoll, "atoll"); - @export(&strtol, .{ .name = "strtol", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtoll, .{ .name = "strtoll", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtoul, .{ .name = "strtoul", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtoull, .{ .name = "strtoull", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtoimax, .{ .name = "strtoimax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtoumax, .{ .name = "strtoumax", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&strtol, "strtol"); + symbol(&strtoll, "strtoll"); + symbol(&strtoul, "strtoul"); + symbol(&strtoull, "strtoull"); + symbol(&strtoimax, "strtoimax"); + symbol(&strtoumax, "strtoumax"); - @export(&strtol, .{ .name = "__strtol_internal", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtoll, .{ .name = "__strtoll_internal", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtoul, .{ .name = "__strtoul_internal", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtoull, .{ .name = "__strtoull_internal", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtoimax, .{ .name = "__strtoimax_internal", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtoumax, .{ .name = "__strtoumax_internal", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&strtol, "__strtol_internal"); + symbol(&strtoll, "__strtoll_internal"); + symbol(&strtoul, "__strtoul_internal"); + symbol(&strtoull, "__strtoull_internal"); + symbol(&strtoimax, "__strtoimax_internal"); + symbol(&strtoumax, "__strtoumax_internal"); - @export(&qsort_r, .{ .name = "qsort_r", .linkage = common.linkage, .visibility = common.visibility }); - @export(&qsort, .{ .name = "qsort", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&qsort_r, "qsort_r"); + symbol(&qsort, "qsort"); - @export(&bsearch, .{ .name = "bsearch", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&bsearch, "bsearch"); } } diff --git a/lib/c/stdlib/drand48.zig b/lib/c/stdlib/drand48.zig index b3104c7df4..266cc7af4a 100644 --- a/lib/c/stdlib/drand48.zig +++ b/lib/c/stdlib/drand48.zig @@ -1,21 +1,23 @@ //! drand48 functions are based off a 48-bit lcg prng: https://pubs.opengroup.org/onlinepubs/9799919799/functions/drand48.html -const std = @import("std"); -const common = @import("../common.zig"); const builtin = @import("builtin"); + +const std = @import("std"); const Lcg = std.Random.lcg.Wrapping(u48); +const symbol = @import("../../c.zig").symbol; + comptime { if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { - @export(&erand48, .{ .name = "erand48", .linkage = common.linkage, .visibility = common.visibility }); - @export(&jrand48, .{ .name = "jrand48", .linkage = common.linkage, .visibility = common.visibility }); - @export(&nrand48, .{ .name = "nrand48", .linkage = common.linkage, .visibility = common.visibility }); - @export(&drand48, .{ .name = "drand48", .linkage = common.linkage, .visibility = common.visibility }); - @export(&lrand48, .{ .name = "lrand48", .linkage = common.linkage, .visibility = common.visibility }); - @export(&mrand48, .{ .name = "mrand48", .linkage = common.linkage, .visibility = common.visibility }); - @export(&lcong48, .{ .name = "lcong48", .linkage = common.linkage, .visibility = common.visibility }); - @export(&seed48, .{ .name = "seed48", .linkage = common.linkage, .visibility = common.visibility }); - @export(&srand48, .{ .name = "srand48", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&erand48, "erand48"); + symbol(&jrand48, "jrand48"); + symbol(&nrand48, "nrand48"); + symbol(&drand48, "drand48"); + symbol(&lrand48, "lrand48"); + symbol(&mrand48, "mrand48"); + symbol(&lcong48, "lcong48"); + symbol(&seed48, "seed48"); + symbol(&srand48, "srand48"); } } diff --git a/lib/c/stdlib/rand.zig b/lib/c/stdlib/rand.zig index 9ca7a51967..a160a9d376 100644 --- a/lib/c/stdlib/rand.zig +++ b/lib/c/stdlib/rand.zig @@ -1,12 +1,12 @@ -const std = @import("std"); -const common = @import("../common.zig"); const builtin = @import("builtin"); +const std = @import("std"); +const symbol = @import("../../c.zig").symbol; comptime { if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { - @export(&rand, .{ .name = "rand", .linkage = common.linkage, .visibility = common.visibility }); - @export(&srand, .{ .name = "srand", .linkage = common.linkage, .visibility = common.visibility }); - @export(&rand_r, .{ .name = "rand_r", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&rand, "rand"); + symbol(&srand, "srand"); + symbol(&rand_r, "rand_r"); } } diff --git a/lib/c/string.zig b/lib/c/string.zig index e016193471..722ef0ba77 100644 --- a/lib/c/string.zig +++ b/lib/c/string.zig @@ -1,6 +1,6 @@ const builtin = @import("builtin"); const std = @import("std"); -const common = @import("common.zig"); +const symbol = @import("../c.zig").symbol; comptime { if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { @@ -8,58 +8,58 @@ comptime { // memmove implemented in compiler_rt // memset implemented in compiler_rt // memcmp implemented in compiler_rt - @export(&memchr, .{ .name = "memchr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strcpy, .{ .name = "strcpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strncpy, .{ .name = "strncpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strcat, .{ .name = "strcat", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strncat, .{ .name = "strncat", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strcmp, .{ .name = "strcmp", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strncmp, .{ .name = "strncmp", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strcoll, .{ .name = "strcoll", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strxfrm, .{ .name = "strxfrm", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strchr, .{ .name = "strchr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strrchr, .{ .name = "strrchr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strcspn, .{ .name = "strcspn", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strspn, .{ .name = "strspn", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strpbrk, .{ .name = "strpbrk", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strstr, .{ .name = "strstr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtok, .{ .name = "strtok", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&memchr, "memchr"); + symbol(&strcpy, "strcpy"); + symbol(&strncpy, "strncpy"); + symbol(&strcat, "strcat"); + symbol(&strncat, "strncat"); + symbol(&strcmp, "strcmp"); + symbol(&strncmp, "strncmp"); + symbol(&strcoll, "strcoll"); + symbol(&strxfrm, "strxfrm"); + symbol(&strchr, "strchr"); + symbol(&strrchr, "strrchr"); + symbol(&strcspn, "strcspn"); + symbol(&strspn, "strspn"); + symbol(&strpbrk, "strpbrk"); + symbol(&strstr, "strstr"); + symbol(&strtok, "strtok"); // strlen is in compiler_rt - @export(&strtok_r, .{ .name = "strtok_r", .linkage = common.linkage, .visibility = common.visibility }); - @export(&stpcpy, .{ .name = "stpcpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&stpncpy, .{ .name = "stpncpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strnlen, .{ .name = "strnlen", .linkage = common.linkage, .visibility = common.visibility }); - @export(&memmem, .{ .name = "memmem", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&strtok_r, "strtok_r"); + symbol(&stpcpy, "stpcpy"); + symbol(&stpncpy, "stpncpy"); + symbol(&strnlen, "strnlen"); + symbol(&memmem, "memmem"); - @export(&memccpy, .{ .name = "memccpy", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&memccpy, "memccpy"); - @export(&strsep, .{ .name = "strsep", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strlcat, .{ .name = "strlcat", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strlcpy, .{ .name = "strlcpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&explicit_bzero, .{ .name = "explicit_bzero", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&strsep, "strsep"); + symbol(&strlcat, "strlcat"); + symbol(&strlcpy, "strlcpy"); + symbol(&explicit_bzero, "explicit_bzero"); - @export(&strchrnul, .{ .name = "strchrnul", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strcasestr, .{ .name = "strcasestr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&memrchr, .{ .name = "memrchr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&mempcpy, .{ .name = "mempcpy", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&strchrnul, "strchrnul"); + symbol(&strcasestr, "strcasestr"); + symbol(&memrchr, "memrchr"); + symbol(&mempcpy, "mempcpy"); - @export(&__strcoll_l, .{ .name = "__strcoll_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__strxfrm_l, .{ .name = "__strxfrm_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__strcoll_l, .{ .name = "strcoll_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__strxfrm_l, .{ .name = "strxfrm_l", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__strcoll_l, "__strcoll_l"); + symbol(&__strxfrm_l, "__strxfrm_l"); + symbol(&__strcoll_l, "strcoll_l"); + symbol(&__strxfrm_l, "strxfrm_l"); // These symbols are not in the public ABI of musl/wasi. However they depend on these exports internally. - @export(&stpcpy, .{ .name = "__stpcpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&stpncpy, .{ .name = "__stpncpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strchrnul, .{ .name = "__strchrnul", .linkage = common.linkage, .visibility = common.visibility }); - @export(&memrchr, .{ .name = "__memrchr", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&stpcpy, "__stpcpy"); + symbol(&stpncpy, "__stpncpy"); + symbol(&strchrnul, "__strchrnul"); + symbol(&memrchr, "__memrchr"); } if (builtin.target.isMinGW()) { - @export(&strnlen, .{ .name = "strnlen", .linkage = common.linkage, .visibility = common.visibility }); - @export(&mempcpy, .{ .name = "mempcpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strtok_r, .{ .name = "strtok_r", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&strnlen, "strnlen"); + symbol(&mempcpy, "mempcpy"); + symbol(&strtok_r, "strtok_r"); } } diff --git a/lib/c/strings.zig b/lib/c/strings.zig index 9bebe1566f..8a052795ae 100644 --- a/lib/c/strings.zig +++ b/lib/c/strings.zig @@ -1,27 +1,27 @@ -const std = @import("std"); -const common = @import("common.zig"); const builtin = @import("builtin"); +const std = @import("std"); +const symbol = @import("../c.zig").symbol; comptime { if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { // bcmp is implemented in compiler_rt - @export(&bcopy, .{ .name = "bcopy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&bzero, .{ .name = "bzero", .linkage = common.linkage, .visibility = common.visibility }); - @export(&index, .{ .name = "index", .linkage = common.linkage, .visibility = common.visibility }); - @export(&rindex, .{ .name = "rindex", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&bcopy, "bcopy"); + symbol(&bzero, "bzero"); + symbol(&index, "index"); + symbol(&rindex, "rindex"); - @export(&ffs, .{ .name = "ffs", .linkage = common.linkage, .visibility = common.visibility }); - @export(&ffsl, .{ .name = "ffsl", .linkage = common.linkage, .visibility = common.visibility }); - @export(&ffsll, .{ .name = "ffsll", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&ffs, "ffs"); + symbol(&ffsl, "ffsl"); + symbol(&ffsll, "ffsll"); - @export(&strcasecmp, .{ .name = "strcasecmp", .linkage = common.linkage, .visibility = common.visibility }); - @export(&strncasecmp, .{ .name = "strncasecmp", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&strcasecmp, "strcasecmp"); + symbol(&strncasecmp, "strncasecmp"); - @export(&__strcasecmp_l, .{ .name = "__strcasecmp_l", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__strncasecmp_l, .{ .name = "__strncasecmp_l", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__strcasecmp_l, "__strcasecmp_l"); + symbol(&__strncasecmp_l, "__strncasecmp_l"); - @export(&__strcasecmp_l, .{ .name = "strcasecmp_l", .linkage = .weak, .visibility = common.visibility }); - @export(&__strncasecmp_l, .{ .name = "strncasecmp_l", .linkage = .weak, .visibility = common.visibility }); + symbol(&__strcasecmp_l, "strcasecmp_l"); + symbol(&__strncasecmp_l, "strncasecmp_l"); } } diff --git a/lib/c/sys/capability.zig b/lib/c/sys/capability.zig new file mode 100644 index 0000000000..dd8faad75d --- /dev/null +++ b/lib/c/sys/capability.zig @@ -0,0 +1,21 @@ +const builtin = @import("builtin"); + +const std = @import("std"); + +const symbol = @import("../../c.zig").symbol; +const errno = @import("../../c.zig").errno; + +comptime { + if (builtin.target.isMuslLibC()) { + symbol(&capsetLinux, "capset"); + symbol(&capgetLinux, "capget"); + } +} + +fn capsetLinux(hdrp: *anyopaque, datap: *anyopaque) callconv(.c) c_int { + return errno(std.os.linux.capset(@ptrCast(@alignCast(hdrp)), @ptrCast(@alignCast(datap)))); +} + +fn capgetLinux(hdrp: *anyopaque, datap: *anyopaque) callconv(.c) c_int { + return errno(std.os.linux.capget(@ptrCast(@alignCast(hdrp)), @ptrCast(@alignCast(datap)))); +} diff --git a/lib/c/sys/file.zig b/lib/c/sys/file.zig new file mode 100644 index 0000000000..fcc7711425 --- /dev/null +++ b/lib/c/sys/file.zig @@ -0,0 +1,16 @@ +const builtin = @import("builtin"); + +const std = @import("std"); + +const symbol = @import("../../c.zig").symbol; +const errno = @import("../../c.zig").errno; + +comptime { + if (builtin.target.isMuslLibC()) { + symbol(&flockLinux, "flock"); + } +} + +fn flockLinux(fd: c_int, operation: c_int) callconv(.c) c_int { + return errno(std.os.linux.flock(fd, operation)); +} diff --git a/lib/c/sys/mman.zig b/lib/c/sys/mman.zig new file mode 100644 index 0000000000..3783cc4197 --- /dev/null +++ b/lib/c/sys/mman.zig @@ -0,0 +1,62 @@ +const builtin = @import("builtin"); + +const std = @import("std"); + +const symbol = @import("../../c.zig").symbol; +const errno = @import("../../c.zig").errno; + +comptime { + if (builtin.target.isMuslLibC()) { + symbol(&madviseLinux, "madvise"); + symbol(&madviseLinux, "__madvise"); + + symbol(&mincoreLinux, "mincore"); + + symbol(&mlockLinux, "mlock"); + symbol(&mlockallLinux, "mlockall"); + + symbol(&mprotectLinux, "mprotect"); + symbol(&mprotectLinux, "__mprotect"); + + symbol(&munlockLinux, "munlock"); + symbol(&munlockallLinux, "munlockall"); + + symbol(&posix_madviseLinux, "posix_madvise"); + } +} + +fn madviseLinux(addr: *anyopaque, len: usize, advice: c_int) callconv(.c) c_int { + return errno(std.os.linux.madvise(@ptrCast(addr), len, @bitCast(advice))); +} + +fn mincoreLinux(addr: *anyopaque, len: usize, vec: [*]u8) callconv(.c) c_int { + return errno(std.os.linux.mincore(@ptrCast(addr), len, vec)); +} + +fn mlockLinux(addr: *const anyopaque, len: usize) callconv(.c) c_int { + return errno(std.os.linux.mlock(@ptrCast(addr), len)); +} + +fn mlockallLinux(flags: c_int) callconv(.c) c_int { + return errno(std.os.linux.mlockall(@bitCast(flags))); +} + +fn mprotectLinux(addr: *anyopaque, len: usize, prot: c_int) callconv(.c) c_int { + const page_size = std.heap.pageSize(); + const start = std.mem.alignBackward(usize, @intFromPtr(addr), page_size); + const aligned_len = std.mem.alignForward(usize, len, page_size); + return errno(std.os.linux.mprotect(@ptrFromInt(start), aligned_len, @bitCast(prot))); +} + +fn munlockLinux(addr: *const anyopaque, len: usize) callconv(.c) c_int { + return errno(std.os.linux.munlock(@ptrCast(addr), len)); +} + +fn munlockallLinux() callconv(.c) c_int { + return errno(std.os.linux.munlockall()); +} + +fn posix_madviseLinux(addr: *anyopaque, len: usize, advice: c_int) callconv(.c) c_int { + if (advice == std.os.linux.MADV.DONTNEED) return 0; + return @intCast(-@as(isize, @bitCast(std.os.linux.madvise(@ptrCast(addr), len, @bitCast(advice))))); +} diff --git a/lib/c/sys/reboot.zig b/lib/c/sys/reboot.zig new file mode 100644 index 0000000000..8ec4210477 --- /dev/null +++ b/lib/c/sys/reboot.zig @@ -0,0 +1,16 @@ +const builtin = @import("builtin"); + +const std = @import("std"); + +const symbol = @import("../../c.zig").symbol; +const errno = @import("../../c.zig").errno; + +comptime { + if (builtin.target.isMuslLibC()) { + symbol(&rebootLinux, "reboot"); + } +} + +fn rebootLinux(cmd: c_int) callconv(.c) c_int { + return errno(std.os.linux.reboot(.MAGIC1, .MAGIC2, @enumFromInt(cmd), null)); +} diff --git a/lib/c/sys/utsname.zig b/lib/c/sys/utsname.zig new file mode 100644 index 0000000000..5ae02adbc4 --- /dev/null +++ b/lib/c/sys/utsname.zig @@ -0,0 +1,35 @@ +const builtin = @import("builtin"); + +const std = @import("std"); + +const symbol = @import("../../c.zig").symbol; +const errno = @import("../../c.zig").errno; + +comptime { + if (builtin.target.isMuslLibC()) { + symbol(&unameLinux, "uname"); + } + + if (builtin.target.isWasiLibC()) { + symbol(&unameWasi, "uname"); + } +} + +fn unameLinux(uts: *std.os.linux.utsname) callconv(.c) c_int { + return errno(std.os.linux.uname(uts)); +} + +fn unameWasi(uts: *std.c.utsname) callconv(.c) c_int { + // note the @bitCast's for NUL termination! + uts.sysname[0..5].* = @bitCast("wasi".*); + uts.nodename[0..7].* = @bitCast("(none)".*); + uts.release[0..6].* = @bitCast("0.0.0".*); + uts.version[0..6].* = @bitCast("0.0.0".*); + uts.machine[0..7].* = @bitCast(switch (builtin.target.cpu.arch) { + .wasm32 => "wasm32", + .wasm64 => "wasm64", + else => comptime unreachable, + }.*); + uts.domainname[0..7].* = @bitCast("(none)".*); + return 0; +} diff --git a/lib/c/unistd.zig b/lib/c/unistd.zig new file mode 100644 index 0000000000..676f943f36 --- /dev/null +++ b/lib/c/unistd.zig @@ -0,0 +1,258 @@ +const builtin = @import("builtin"); + +const std = @import("std"); +const linux = std.os.linux; + +const symbol = @import("../c.zig").symbol; +const errno = @import("../c.zig").errno; + +comptime { + if (builtin.target.isMuslLibC()) { + symbol(&_exit, "_exit"); + + symbol(&accessLinux, "access"); + symbol(&acctLinux, "acct"); + symbol(&chdirLinux, "chdir"); + symbol(&chownLinux, "chown"); + symbol(&close, "close"); + symbol(&posix_close, "posix_close"); + symbol(&fchownatLinux, "fchownat"); + symbol(&lchownLinux, "lchown"); + symbol(&chrootLinux, "chroot"); + symbol(&ctermidLinux, "ctermid"); + symbol(&dupLinux, "dup"); + + symbol(&getegidLinux, "getegid"); + symbol(&geteuidLinux, "geteuid"); + symbol(&getgidLinux, "getgid"); + symbol(&getgroupsLinux, "getgroups"); + symbol(&getpgidLinux, "getpgid"); + symbol(&getpgrpLinux, "getpgrp"); + symbol(&setpgidLinux, "setpgid"); + symbol(&setpgrpLinux, "setpgrp"); + symbol(&getsidLinux, "getsid"); + symbol(&getpidLinux, "getpid"); + symbol(&getppidLinux, "getppid"); + symbol(&getuidLinux, "getuid"); + + symbol(&rmdirLinux, "rmdir"); + symbol(&linkLinux, "link"); + symbol(&linkatLinux, "linkat"); + symbol(&pipeLinux, "pipe"); + symbol(&renameatLinux, "renameat"); + symbol(&symlinkLinux, "symlink"); + symbol(&symlinkatLinux, "symlinkat"); + symbol(&syncLinux, "sync"); + symbol(&unlinkLinux, "unlink"); + symbol(&unlinkatLinux, "unlinkat"); + + symbol(&execveLinux, "execve"); + } + if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + symbol(&swab, "swab"); + } + if (builtin.target.isWasiLibC()) { + symbol(&closeWasi, "close"); + } +} + +fn _exit(exit_code: c_int) callconv(.c) noreturn { + std.c._Exit(exit_code); +} + +fn accessLinux(path: [*:0]const c_char, amode: c_int) callconv(.c) c_int { + return errno(linux.access(@ptrCast(path), @bitCast(amode))); +} + +fn acctLinux(path: [*:0]const c_char) callconv(.c) c_int { + return errno(linux.acct(@ptrCast(path))); +} + +fn chdirLinux(path: [*:0]const c_char) callconv(.c) c_int { + return errno(linux.chdir(@ptrCast(path))); +} + +fn chownLinux(path: [*:0]const c_char, uid: linux.uid_t, gid: linux.gid_t) callconv(.c) c_int { + return errno(linux.chown(@ptrCast(path), uid, gid)); +} + +fn fchownatLinux(fd: c_int, path: [*:0]const c_char, uid: linux.uid_t, gid: linux.gid_t, flags: c_int) callconv(.c) c_int { + return errno(linux.fchownat(fd, @ptrCast(path), uid, gid, @bitCast(flags))); +} + +fn lchownLinux(path: [*:0]const c_char, uid: linux.uid_t, gid: linux.gid_t) callconv(.c) c_int { + return errno(linux.lchown(@ptrCast(path), uid, gid)); +} + +fn chrootLinux(path: [*:0]const c_char) callconv(.c) c_int { + return errno(linux.chroot(@ptrCast(path))); +} + +fn ctermidLinux(maybe_path: ?[*]c_char) callconv(.c) [*:0]c_char { + const default_tty = "/dev/tty"; + + return if (maybe_path) |path| blk: { + path[0..(default_tty.len + 1)].* = @bitCast(default_tty.*); + break :blk path[0..default_tty.len :0].ptr; + } else @ptrCast(@constCast(default_tty)); +} + +fn dupLinux(fd: c_int) callconv(.c) c_int { + return errno(linux.dup(fd)); +} + +fn getegidLinux() callconv(.c) linux.gid_t { + return linux.getegid(); +} + +fn geteuidLinux() callconv(.c) linux.uid_t { + return linux.geteuid(); +} + +fn getgidLinux() callconv(.c) linux.gid_t { + return linux.getgid(); +} + +fn getgroupsLinux(size: c_int, list: ?[*]linux.gid_t) callconv(.c) c_int { + return errno(linux.getgroups(@intCast(size), list)); +} + +fn getpgidLinux(pid: linux.pid_t) callconv(.c) linux.pid_t { + return errno(linux.getpgid(pid)); +} + +fn getpgrpLinux() callconv(.c) linux.pid_t { + return @intCast(linux.getpgid(0)); // @intCast as it cannot fail +} + +fn setpgidLinux(pid: linux.pid_t, pgid: linux.pid_t) callconv(.c) c_int { + return errno(linux.setpgid(pid, pgid)); +} + +fn setpgrpLinux() callconv(.c) linux.pid_t { + return @intCast(linux.setpgid(0, 0)); // @intCast as it cannot fail +} + +fn getpidLinux() callconv(.c) linux.pid_t { + return linux.getpid(); +} + +fn getppidLinux() callconv(.c) linux.pid_t { + return linux.getppid(); +} + +fn getsidLinux(pid: linux.pid_t) callconv(.c) linux.pid_t { + return errno(linux.getsid(pid)); +} + +fn getuidLinux() callconv(.c) linux.uid_t { + return linux.getuid(); +} + +fn linkLinux(old: [*:0]const c_char, new: [*:0]const c_char) callconv(.c) c_int { + return errno(linux.link(@ptrCast(old), @ptrCast(new))); +} + +fn linkatLinux(old_fd: c_int, old: [*:0]const c_char, new_fd: c_int, new: [*:0]const c_char, flags: c_int) callconv(.c) c_int { + return errno(linux.linkat(old_fd, @ptrCast(old), new_fd, @ptrCast(new), @bitCast(flags))); +} + +fn pipeLinux(fd: *[2]c_int) callconv(.c) c_int { + return errno(linux.pipe(@ptrCast(fd))); +} + +fn renameatLinux(old_fd: c_int, old: [*:0]const c_char, new_fd: c_int, new: [*:0]const c_char) callconv(.c) c_int { + return errno(linux.renameat(old_fd, @ptrCast(old), new_fd, @ptrCast(new))); +} + +fn rmdirLinux(path: [*:0]const c_char) callconv(.c) c_int { + return errno(linux.rmdir(@ptrCast(path))); +} + +fn symlinkLinux(existing: [*:0]const c_char, new: [*:0]const c_char) callconv(.c) c_int { + return errno(linux.symlink(@ptrCast(existing), @ptrCast(new))); +} + +fn symlinkatLinux(existing: [*:0]const c_char, fd: c_int, new: [*:0]const c_char) callconv(.c) c_int { + return errno(linux.symlinkat(@ptrCast(existing), fd, @ptrCast(new))); +} + +fn syncLinux() callconv(.c) void { + linux.sync(); +} + +fn unlinkLinux(path: [*:0]const c_char) callconv(.c) c_int { + return errno(linux.unlink(@ptrCast(path))); +} + +fn unlinkatLinux(fd: c_int, path: [*:0]const c_char, flags: c_int) callconv(.c) c_int { + return errno(linux.unlinkat(fd, @ptrCast(path), @bitCast(flags))); +} + +fn execveLinux(path: [*:0]const c_char, argv: [*:null]const ?[*:0]c_char, envp: [*:null]const ?[*:0]c_char) callconv(.c) c_int { + return errno(linux.execve(@ptrCast(path), @ptrCast(argv), @ptrCast(envp))); +} + +fn swab(noalias src_ptr: *const anyopaque, noalias dest_ptr: *anyopaque, n: isize) callconv(.c) void { + var src: [*]const u8 = @ptrCast(src_ptr); + var dest: [*]u8 = @ptrCast(dest_ptr); + var i = n; + + while (i > 1) : (i -= 2) { + dest[0] = src[1]; + dest[1] = src[0]; + dest += 2; + src += 2; + } +} + +test swab { + var a: [4]u8 = undefined; + @memset(a[0..], '\x00'); + swab("abcd", &a, 4); + try std.testing.expectEqualSlices(u8, "badc", &a); + + // Partial copy + @memset(a[0..], '\x00'); + swab("abcd", &a, 2); + try std.testing.expectEqualSlices(u8, "ba\x00\x00", &a); + + // n < 1 + @memset(a[0..], '\x00'); + swab("abcd", &a, 0); + try std.testing.expectEqualSlices(u8, "\x00" ** 4, &a); + swab("abcd", &a, -1); + try std.testing.expectEqualSlices(u8, "\x00" ** 4, &a); + + // Odd n + @memset(a[0..], '\x00'); + swab("abcd", &a, 1); + try std.testing.expectEqualSlices(u8, "\x00" ** 4, &a); + swab("abcd", &a, 3); + try std.testing.expectEqualSlices(u8, "ba\x00\x00", &a); +} + +fn close(fd: std.c.fd_t) callconv(.c) c_int { + const signed: isize = @bitCast(linux.close(fd)); + if (signed < 0) { + @branchHint(.unlikely); + if (-signed == @intFromEnum(linux.E.INTR)) return 0; + std.c._errno().* = @intCast(-signed); + return -1; + } + return 0; +} + +fn posix_close(fd: std.c.fd_t, _: c_int) callconv(.c) c_int { + return close(fd); +} + +fn closeWasi(fd: std.c.fd_t) callconv(.c) c_int { + switch (std.os.wasi.fd_close(fd)) { + .SUCCESS => return 0, + else => |e| { + std.c._errno().* = @intFromEnum(e); + return -1; + }, + } +} diff --git a/lib/c/wchar.zig b/lib/c/wchar.zig index b31c450cfc..b85687e8a7 100644 --- a/lib/c/wchar.zig +++ b/lib/c/wchar.zig @@ -1,44 +1,46 @@ -const std = @import("std"); -const common = @import("common.zig"); const builtin = @import("builtin"); + +const std = @import("std"); const wint_t = std.c.wint_t; const wchar_t = std.c.wchar_t; +const symbol = @import("../c.zig").symbol; + comptime { if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { - @export(&wmemchr, .{ .name = "wmemchr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wmemcmp, .{ .name = "wmemcmp", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wmemcpy, .{ .name = "wmemcpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wmemmove, .{ .name = "wmemmove", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wmemset, .{ .name = "wmemset", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcslen, .{ .name = "wcslen", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcsnlen, .{ .name = "wcsnlen", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcscmp, .{ .name = "wcscmp", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcsncmp, .{ .name = "wcsncmp", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcpcpy, .{ .name = "wcpcpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcpncpy, .{ .name = "wcpncpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcscpy, .{ .name = "wcscpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcsncpy, .{ .name = "wcsncpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcscat, .{ .name = "wcscat", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcsncat, .{ .name = "wcsncat", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcschr, .{ .name = "wcschr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcsrchr, .{ .name = "wcsrchr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcsspn, .{ .name = "wcsspn", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcscspn, .{ .name = "wcscspn", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcspbrk, .{ .name = "wcspbrk", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcstok, .{ .name = "wcstok", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcsstr, .{ .name = "wcsstr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcswcs, .{ .name = "wcswcs", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&wmemchr, "wmemchr"); + symbol(&wmemcmp, "wmemcmp"); + symbol(&wmemcpy, "wmemcpy"); + symbol(&wmemmove, "wmemmove"); + symbol(&wmemset, "wmemset"); + symbol(&wcslen, "wcslen"); + symbol(&wcsnlen, "wcsnlen"); + symbol(&wcscmp, "wcscmp"); + symbol(&wcsncmp, "wcsncmp"); + symbol(&wcpcpy, "wcpcpy"); + symbol(&wcpncpy, "wcpncpy"); + symbol(&wcscpy, "wcscpy"); + symbol(&wcsncpy, "wcsncpy"); + symbol(&wcscat, "wcscat"); + symbol(&wcsncat, "wcsncat"); + symbol(&wcschr, "wcschr"); + symbol(&wcsrchr, "wcsrchr"); + symbol(&wcsspn, "wcsspn"); + symbol(&wcscspn, "wcscspn"); + symbol(&wcspbrk, "wcspbrk"); + symbol(&wcstok, "wcstok"); + symbol(&wcsstr, "wcsstr"); + symbol(&wcswcs, "wcswcs"); } if (builtin.target.isMinGW()) { - @export(&wmemchr, .{ .name = "wmemchr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wmemcmp, .{ .name = "wmemcmp", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wmemcpy, .{ .name = "wmemcpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wmempcpy, .{ .name = "wmempcpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wmemmove, .{ .name = "wmemmove", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wmemset, .{ .name = "wmemset", .linkage = common.linkage, .visibility = common.visibility }); - @export(&wcsnlen, .{ .name = "wcsnlen", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&wmemchr, "wmemchr"); + symbol(&wmemcmp, "wmemcmp"); + symbol(&wmemcpy, "wmemcpy"); + symbol(&wmempcpy, "wmempcpy"); + symbol(&wmemmove, "wmemmove"); + symbol(&wmemset, "wmemset"); + symbol(&wcsnlen, "wcsnlen"); } } diff --git a/lib/compiler/aro/aro/Compilation.zig b/lib/compiler/aro/aro/Compilation.zig index c5f400f1d9..44e0248b8b 100644 --- a/lib/compiler/aro/aro/Compilation.zig +++ b/lib/compiler/aro/aro/Compilation.zig @@ -107,7 +107,7 @@ pub const Environment = struct { if (parsed > max_timestamp) return error.InvalidEpoch; return .{ .provided = parsed }; } else { - const timestamp = try Io.Clock.real.now(io); + const timestamp = Io.Clock.real.now(io); const seconds = std.math.cast(u64, timestamp.toSeconds()) orelse return error.InvalidEpoch; return .{ .system = std.math.clamp(seconds, 0, max_timestamp) }; } diff --git a/lib/compiler/aro/aro/InitList.zig b/lib/compiler/aro/aro/InitList.zig index 9d8af869d7..ed7af8f998 100644 --- a/lib/compiler/aro/aro/InitList.zig +++ b/lib/compiler/aro/aro/InitList.zig @@ -22,9 +22,15 @@ const Item = struct { const InitList = @This(); -list: std.ArrayList(Item) = .empty, -node: Node.OptIndex = .null, -tok: TokenIndex = 0, +list: std.ArrayList(Item), +node: Node.OptIndex, +tok: TokenIndex, + +pub const empty: InitList = .{ + .list = .empty, + .node = .null, + .tok = 0, +}; /// Deinitialize freeing all memory. pub fn deinit(il: *InitList, gpa: Allocator) void { @@ -43,7 +49,7 @@ pub fn find(il: *InitList, gpa: Allocator, index: u64) !*InitList { if (il.list.items.len == 0) { const item = try il.list.addOne(gpa); item.* = .{ - .list = .{}, + .list = .empty, .index = index, }; return &item.list; @@ -51,7 +57,7 @@ pub fn find(il: *InitList, gpa: Allocator, index: u64) !*InitList { // Append a new value to the end of the list. const new = try il.list.addOne(gpa); new.* = .{ - .list = .{}, + .list = .empty, .index = index, }; return &new.list; @@ -70,7 +76,7 @@ pub fn find(il: *InitList, gpa: Allocator, index: u64) !*InitList { // Insert a new value into a sorted position. try il.list.insert(gpa, left, .{ - .list = .{}, + .list = .empty, .index = index, }); return &il.list.items[left].list; @@ -78,7 +84,7 @@ pub fn find(il: *InitList, gpa: Allocator, index: u64) !*InitList { test "basic usage" { const gpa = testing.allocator; - var il: InitList = .{}; + var il: InitList = .empty; defer il.deinit(gpa); { diff --git a/lib/compiler/aro/aro/Parser.zig b/lib/compiler/aro/aro/Parser.zig index fc21ee4d0b..6e60dbd623 100644 --- a/lib/compiler/aro/aro/Parser.zig +++ b/lib/compiler/aro/aro/Parser.zig @@ -3977,7 +3977,7 @@ fn initializer(p: *Parser, init_qt: QualType) Error!Result { final_init_qt = .invalid; } - var il: InitList = .{}; + var il: InitList = .empty; defer il.deinit(p.comp.gpa); try p.initializerItem(&il, final_init_qt, l_brace); @@ -4028,12 +4028,12 @@ fn initializerItem(p: *Parser, il: *InitList, init_qt: QualType, l_brace: TokenI try p.err(first_tok, .initializer_overrides, .{}); try p.err(item.il.tok, .previous_initializer, .{}); item.il.deinit(gpa); - item.il.* = .{}; + item.il.* = .empty; } try p.initializerItem(item.il, item.qt, inner_l_brace); } else { // discard further values - var tmp_il: InitList = .{}; + var tmp_il: InitList = .empty; defer tmp_il.deinit(gpa); try p.initializerItem(&tmp_il, .invalid, inner_l_brace); if (!warned_excess) try p.err(first_tok, switch (init_qt.base(p.comp).type) { diff --git a/lib/compiler/aro/aro/Preprocessor.zig b/lib/compiler/aro/aro/Preprocessor.zig index 6e36703df1..854c3afbf3 100644 --- a/lib/compiler/aro/aro/Preprocessor.zig +++ b/lib/compiler/aro/aro/Preprocessor.zig @@ -301,7 +301,7 @@ pub fn init(comp: *Compilation, source_epoch: SourceEpoch) Preprocessor { /// Initialize Preprocessor with builtin macros. pub fn initDefault(comp: *Compilation) !Preprocessor { const source_epoch: SourceEpoch = comp.environment.sourceEpoch(comp.io) catch |er| switch (er) { - error.InvalidEpoch, error.UnsupportedClock, error.Unexpected => blk: { + error.InvalidEpoch => blk: { const diagnostic: Diagnostic = .invalid_source_epoch; try comp.diagnostics.add(.{ .text = diagnostic.fmt, .kind = diagnostic.kind, .opt = diagnostic.opt, .location = null }); break :blk .default; diff --git a/lib/compiler/aro/aro/Toolchain.zig b/lib/compiler/aro/aro/Toolchain.zig index 0aa9d76fc8..9a923c0846 100644 --- a/lib/compiler/aro/aro/Toolchain.zig +++ b/lib/compiler/aro/aro/Toolchain.zig @@ -43,13 +43,13 @@ const Toolchain = @This(); driver: *Driver, /// The list of toolchain specific path prefixes to search for libraries. -library_paths: PathList = .{}, +library_paths: PathList = .empty, /// The list of toolchain specific path prefixes to search for files. -file_paths: PathList = .{}, +file_paths: PathList = .empty, /// The list of toolchain specific path prefixes to search for programs. -program_paths: PathList = .{}, +program_paths: PathList = .empty, selected_multilib: Multilib = .{}, diff --git a/lib/compiler/aro/main.zig b/lib/compiler/aro/main.zig index dcc07eaca6..eafddba877 100644 --- a/lib/compiler/aro/main.zig +++ b/lib/compiler/aro/main.zig @@ -13,7 +13,7 @@ const assembly_backend = @import("assembly_backend"); var debug_allocator: std.heap.DebugAllocator(.{ .stack_trace_frames = 0, // A unique value so that when a default-constructed - // GeneralPurposeAllocator is incorrectly passed to testing allocator, or + // DebugAllocator is incorrectly passed to testing allocator, or // vice versa, panic occurs. .canary = @truncate(0xc647026dc6875134), }) = .{}; diff --git a/lib/compiler/build_runner.zig b/lib/compiler/build_runner.zig index 7efee4bac4..b760fd0c4c 100644 --- a/lib/compiler/build_runner.zig +++ b/lib/compiler/build_runner.zig @@ -30,14 +30,6 @@ pub fn main(init: process.Init.Minimal) !void { defer _ = debug_gpa_state.deinit(); const gpa = debug_gpa_state.allocator(); - // ...but we'll back our arena by `std.heap.page_allocator` for efficiency. - var single_threaded_arena: std.heap.ArenaAllocator = .init(std.heap.page_allocator); - defer single_threaded_arena.deinit(); - var thread_safe_arena: std.heap.ThreadSafeAllocator = .{ .child_allocator = single_threaded_arena.allocator() }; - const arena = thread_safe_arena.allocator(); - - const args = try init.args.toSlice(arena); - var threaded: std.Io.Threaded = .init(gpa, .{ .environ = init.environ, .argv0 = .init(init.args), @@ -45,6 +37,13 @@ pub fn main(init: process.Init.Minimal) !void { defer threaded.deinit(); const io = threaded.io(); + // ...but we'll back our arena by `std.heap.page_allocator` for efficiency. + var arena_instance: std.heap.ArenaAllocator = .init(std.heap.page_allocator); + defer arena_instance.deinit(); + const arena = arena_instance.allocator(); + + const args = try init.args.toSlice(arena); + // skip my own exe name var arg_idx: usize = 1; @@ -83,7 +82,7 @@ pub fn main(init: process.Init.Minimal) !void { .io = io, .gpa = gpa, .manifest_dir = try local_cache_directory.handle.createDirPathOpen(io, "h", .{}), - .cwd = try process.getCwdAlloc(single_threaded_arena.allocator()), + .cwd = try process.currentPathAlloc(io, arena), }, .zig_exe = zig_exe, .environ_map = try init.environ.createMap(arena), @@ -307,7 +306,11 @@ pub fn main(init: process.Init.Minimal) !void { } else if (mem.eql(u8, arg, "--debug-pkg-config")) { builder.debug_pkg_config = true; } else if (mem.eql(u8, arg, "--debug-rt")) { - graph.debug_compiler_runtime_libs = true; + graph.debug_compiler_runtime_libs = .Debug; + } else if (mem.cutPrefix(u8, arg, "--debug-rt=")) |rest| { + graph.debug_compiler_runtime_libs = + std.meta.stringToEnum(std.builtin.OptimizeMode, rest) orelse + fatal("unrecognized optimization mode: '{s}'", .{rest}); } else if (mem.eql(u8, arg, "--debug-compile-errors")) { builder.debug_compile_errors = true; } else if (mem.eql(u8, arg, "--debug-incremental")) { @@ -545,7 +548,7 @@ pub fn main(init: process.Init.Minimal) !void { break :w try .init(graph.cache.cwd); }; - const now = Io.Clock.Timestamp.now(io, .awake) catch |err| fatal("failed to collect timestamp: {t}", .{err}); + const now = Io.Clock.Timestamp.now(io, .awake); run.web_server = if (webui_listen) |listen_address| ws: { if (builtin.single_threaded) unreachable; // `fatal` above @@ -618,7 +621,7 @@ pub fn main(init: process.Init.Minimal) !void { }) catch &caption_buf; var debouncing_node = main_progress_node.start(caption, 0); var in_debounce = false; - while (true) switch (try w.wait(gpa, if (in_debounce) .{ .ms = debounce_interval_ms } else .none)) { + while (true) switch (try w.wait(gpa, io, if (in_debounce) .{ .ms = debounce_interval_ms } else .none)) { .timeout => { assert(in_debounce); debouncing_node.end(); @@ -1570,6 +1573,23 @@ fn printUsage(b: *std.Build, w: *Writer) !void { \\ -fsys=[name] Enable a system integration \\ -fno-sys=[name] Disable a system integration \\ + \\ -fdarling, -fno-darling Integration with system-installed Darling to + \\ execute macOS programs on Linux hosts + \\ (default: no) + \\ -fqemu, -fno-qemu Integration with system-installed QEMU to execute + \\ foreign-architecture programs on Linux hosts + \\ (default: no) + \\ --libc-runtimes [path] Enhances QEMU integration by providing dynamic libc + \\ (e.g. glibc or musl) built for multiple foreign + \\ architectures, allowing execution of non-native + \\ programs that link with libc. + \\ -frosetta, -fno-rosetta Rely on Rosetta to execute x86_64 programs on + \\ ARM64 macOS hosts. (default: no) + \\ -fwasmtime, -fno-wasmtime Integration with system-installed wasmtime to + \\ execute WASI binaries. (default: no) + \\ -fwine, -fno-wine Integration with system-installed Wine to execute + \\ Windows programs on Linux hosts. (default: no) + \\ \\ Available System Integrations: Enabled: \\ ); @@ -1589,33 +1609,16 @@ fn printUsage(b: *std.Build, w: *Writer) !void { try w.writeAll( \\ \\General Options: + \\ -h, --help Print this help and exit + \\ -l, --list-steps Print available steps + \\ \\ -p, --prefix [path] Where to install files (default: zig-out) \\ --prefix-lib-dir [path] Where to install libraries \\ --prefix-exe-dir [path] Where to install executables \\ --prefix-include-dir [path] Where to install C header files - \\ \\ --release[=mode] Request release mode, optionally specifying a \\ preferred optimization mode: fast, safe, small \\ - \\ -fdarling, -fno-darling Integration with system-installed Darling to - \\ execute macOS programs on Linux hosts - \\ (default: no) - \\ -fqemu, -fno-qemu Integration with system-installed QEMU to execute - \\ foreign-architecture programs on Linux hosts - \\ (default: no) - \\ --libc-runtimes [path] Enhances QEMU integration by providing dynamic libc - \\ (e.g. glibc or musl) built for multiple foreign - \\ architectures, allowing execution of non-native - \\ programs that link with libc. - \\ -frosetta, -fno-rosetta Rely on Rosetta to execute x86_64 programs on - \\ ARM64 macOS hosts. (default: no) - \\ -fwasmtime, -fno-wasmtime Integration with system-installed wasmtime to - \\ execute WASI binaries. (default: no) - \\ -fwine, -fno-wine Integration with system-installed Wine to execute - \\ Windows programs on Linux hosts. (default: no) - \\ - \\ -h, --help Print this help and exit - \\ -l, --list-steps Print available steps \\ --verbose Print commands before executing them \\ --color [auto|off|on] Enable or disable colored error messages \\ --error-style [style] Control how build errors are printed @@ -1638,9 +1641,6 @@ fn printUsage(b: *std.Build, w: *Writer) !void { \\ --skip-oom-steps Instead of failing, skip steps that would exceed --maxrss \\ --test-timeout Limit execution time of unit tests, terminating if exceeded. \\ The timeout must include a unit: ns, us, ms, s, m, h - \\ --fetch[=mode] Fetch dependency tree (optionally choose laziness) and exit - \\ needed (Default) Lazy dependencies are fetched as needed - \\ all Lazy dependencies are always fetched \\ --watch Continuously rebuild when source files are modified \\ --debounce Delay before rebuilding after changed file detected \\ --webui[=ip] Enable the web interface on the given IP address @@ -1653,6 +1653,12 @@ fn printUsage(b: *std.Build, w: *Writer) !void { \\ -fincremental Enable incremental compilation \\ -fno-incremental Disable incremental compilation \\ + \\Package Management Options: + \\ --fetch[=mode] Fetch dependency tree (optionally choose laziness) and exit + \\ needed (Default) Lazy dependencies are fetched as needed + \\ all Lazy dependencies are always fetched + \\ --fork=[path] Override one or more projects from dependency tree + \\ \\Advanced Options: \\ -freference-trace[=num] How many lines of reference trace should be shown per compile error \\ -fno-reference-trace Disable reference trace diff --git a/lib/compiler/objcopy.zig b/lib/compiler/objcopy.zig index 57d019bc95..9c3fffc67f 100644 --- a/lib/compiler/objcopy.zig +++ b/lib/compiler/objcopy.zig @@ -388,8 +388,8 @@ const BinaryElfOutput = struct { pub fn parse(allocator: Allocator, in: *File.Reader, elf_hdr: elf.Header) !Self { var self: Self = .{ - .segments = .{}, - .sections = .{}, + .segments = .empty, + .sections = .empty, .allocator = allocator, .shstrtab = null, }; diff --git a/lib/compiler/resinator/cvtres.zig b/lib/compiler/resinator/cvtres.zig index 26b6620af2..6973be714c 100644 --- a/lib/compiler/resinator/cvtres.zig +++ b/lib/compiler/resinator/cvtres.zig @@ -410,7 +410,7 @@ pub const ResourceDirectoryTable = extern struct { }; pub const ResourceDirectoryEntry = extern struct { - entry: packed union { + entry: packed union(u32) { name_offset: packed struct(u32) { address: u31, /// This is undocumented in the PE/COFF spec, but the high bit diff --git a/lib/compiler/std-docs.zig b/lib/compiler/std-docs.zig index 55f49c44e2..5660e6e56d 100644 --- a/lib/compiler/std-docs.zig +++ b/lib/compiler/std-docs.zig @@ -208,6 +208,9 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void { var archiver: std.tar.Writer = .{ .underlying_writer = &response.writer }; archiver.prefix = "std"; + var path_buf: std.ArrayList(u8) = .empty; + defer path_buf.deinit(gpa); + while (try walker.next(io)) |entry| { switch (entry.kind) { .file => { @@ -227,7 +230,17 @@ fn serveSourcesTar(request: *std.http.Server.Request, context: *Context) !void { .interface = Io.File.Reader.initInterface(&.{}), .size = stat.size, }; - try archiver.writeFileTimestamp(entry.path, &file_reader, stat.mtime); + + const posix_path = if (comptime std.fs.path.sep == std.fs.path.sep_posix) + entry.path + else blk: { + path_buf.clearRetainingCapacity(); + try path_buf.appendSlice(gpa, entry.path); + std.mem.replaceScalar(u8, path_buf.items, std.fs.path.sep, std.fs.path.sep_posix); + break :blk path_buf.items; + }; + + try archiver.writeFileTimestamp(posix_path, &file_reader, stat.mtime); } { @@ -324,11 +337,10 @@ fn buildWasmBinary( .stderr = .pipe, }); - var poller = Io.poll(gpa, enum { stdout, stderr }, .{ - .stdout = child.stdout.?, - .stderr = child.stderr.?, - }); - defer poller.deinit(); + var multi_reader_buffer: Io.File.MultiReader.Buffer(2) = undefined; + var multi_reader: Io.File.MultiReader = undefined; + multi_reader.init(gpa, io, multi_reader_buffer.toStreams(), &.{ child.stdout.?, child.stderr.? }); + defer multi_reader.deinit(); try sendMessage(io, child.stdin.?, .update); try sendMessage(io, child.stdin.?, .exit); @@ -336,14 +348,23 @@ fn buildWasmBinary( var result: ?Cache.Path = null; var result_error_bundle = std.zig.ErrorBundle.empty; - const stdout = poller.reader(.stdout); + const stdout = multi_reader.fileReader(0); + const MessageHeader = std.zig.Server.Message.Header; - poll: while (true) { - const Header = std.zig.Server.Message.Header; - while (stdout.buffered().len < @sizeOf(Header)) if (!try poller.poll()) break :poll; - const header = stdout.takeStruct(Header, .little) catch unreachable; - while (stdout.buffered().len < header.bytes_len) if (!try poller.poll()) break :poll; - const body = stdout.take(header.bytes_len) catch unreachable; + var eos_err: error{EndOfStream}!void = {}; + + while (true) { + const header = stdout.interface.takeStruct(MessageHeader, .little) catch |err| switch (err) { + error.EndOfStream => break, + error.ReadFailed => return stdout.err.?, + }; + const body = stdout.interface.take(header.bytes_len) catch |err| switch (err) { + error.EndOfStream => |e| { + eos_err = e; + break; + }, + error.ReadFailed => return stdout.err.?, + }; switch (header.tag) { .zig_version => { @@ -372,11 +393,15 @@ fn buildWasmBinary( } } - const stderr = poller.reader(.stderr); - if (stderr.bufferedLen() > 0) { - std.debug.print("{s}", .{stderr.buffered()}); + try multi_reader.fillRemaining(.none); + const stderr = multi_reader.reader(1).buffered(); + + if (stderr.len > 0) { + std.debug.print("{s}", .{stderr}); } + try eos_err; + // Send EOF to stdin. child.stdin.?.close(io); child.stdin = null; @@ -386,7 +411,7 @@ fn buildWasmBinary( if (code != 0) { std.log.err( "the following command exited with error code {d}:\n{s}", - .{ code, try std.Build.Step.allocPrintCmd(arena, null, null, argv.items) }, + .{ code, try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items) }, ); return error.WasmCompilationFailed; } @@ -394,14 +419,14 @@ fn buildWasmBinary( .signal => |sig| { std.log.err( "the following command terminated with signal {t}:\n{s}", - .{ sig, try std.Build.Step.allocPrintCmd(arena, null, null, argv.items) }, + .{ sig, try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items) }, ); return error.WasmCompilationFailed; }, .stopped, .unknown => { std.log.err( "the following command terminated unexpectedly:\n{s}", - .{try std.Build.Step.allocPrintCmd(arena, null, null, argv.items)}, + .{try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items)}, ); return error.WasmCompilationFailed; }, @@ -411,14 +436,14 @@ fn buildWasmBinary( try result_error_bundle.renderToStderr(io, .{}, .auto); std.log.err("the following command failed with {d} compilation errors:\n{s}", .{ result_error_bundle.errorMessageCount(), - try std.Build.Step.allocPrintCmd(arena, null, null, argv.items), + try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items), }); return error.WasmCompilationFailed; } return result orelse { std.log.err("child process failed to report result\n{s}", .{ - try std.Build.Step.allocPrintCmd(arena, null, null, argv.items), + try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items), }); return error.WasmCompilationFailed; }; diff --git a/lib/compiler/test_runner.zig b/lib/compiler/test_runner.zig index c868bee6aa..db8958519a 100644 --- a/lib/compiler/test_runner.zig +++ b/lib/compiler/test_runner.zig @@ -17,7 +17,7 @@ var fba: std.heap.FixedBufferAllocator = .init(&fba_buffer); var fba_buffer: [8192]u8 = undefined; var stdin_buffer: [4096]u8 = undefined; var stdout_buffer: [4096]u8 = undefined; -const runner_threaded_io: Io = Io.Threaded.global_single_threaded.ioBasic(); +const runner_threaded_io: Io = Io.Threaded.global_single_threaded.io(); /// Keep in sync with logic in `std.Build.addRunArtifact` which decides whether /// the test runner will communicate with the build runner via `std.zig.Server`. @@ -38,10 +38,10 @@ pub fn main(init: std.process.Init.Minimal) void { } if (need_simple) { - return mainSimple() catch @panic("test failure"); + return mainSimple() catch |err| std.debug.panic("test failure: {t}", .{err}); } - const args = init.args.toSlice(fba.allocator()) catch @panic("unable to parse command line args"); + const args = init.args.toSlice(fba.allocator()) catch |err| std.debug.panic("unable to parse command line args: {t}", .{err}); var listen = false; var opt_cache_dir: ?[]const u8 = null; @@ -55,7 +55,7 @@ pub fn main(init: std.process.Init.Minimal) void { } else if (std.mem.startsWith(u8, arg, "--cache-dir")) { opt_cache_dir = arg["--cache-dir=".len..]; } else { - @panic("unrecognized command line argument"); + std.debug.panic("unrecognized command line argument: {s}", .{arg}); } } @@ -65,7 +65,7 @@ pub fn main(init: std.process.Init.Minimal) void { } if (listen) { - return mainServer(init) catch @panic("internal test runner failure"); + return mainServer(init) catch |err| std.debug.panic("internal test runner failure: {t}", .{err}); } else { return mainTerminal(init); } @@ -379,7 +379,7 @@ var fuzz_amount_or_instance: u64 = undefined; pub fn fuzz( context: anytype, - comptime testOne: fn (context: @TypeOf(context), []const u8) anyerror!void, + comptime testOne: fn (context: @TypeOf(context), *std.testing.Smith) anyerror!void, options: testing.FuzzInputOptions, ) anyerror!void { // Prevent this function from confusing the fuzzer by omitting its own code @@ -406,12 +406,12 @@ pub fn fuzz( const global = struct { var ctx: @TypeOf(context) = undefined; - fn test_one(input: fuzz_abi.Slice) callconv(.c) void { + fn test_one() callconv(.c) void { @disableInstrumentation(); testing.allocator_instance = .{}; defer if (testing.allocator_instance.deinit() == .leak) std.process.exit(1); log_err_count = 0; - testOne(ctx, input.toSlice()) catch |err| switch (err) { + testOne(ctx, @constCast(&testing.Smith{ .in = null })) catch |err| switch (err) { error.SkipZigTest => return, else => { const stderr = std.debug.lockStderr(&.{}).terminal(); @@ -435,13 +435,11 @@ pub fn fuzz( const prev_allocator_state = testing.allocator_instance; testing.allocator_instance = .{}; defer testing.allocator_instance = prev_allocator_state; - global.ctx = context; - fuzz_abi.fuzzer_init_test(&global.test_one, .fromSlice(builtin.test_functions[fuzz_test_index].name)); + fuzz_abi.fuzzer_set_test(&global.test_one, .fromSlice(builtin.test_functions[fuzz_test_index].name)); for (options.corpus) |elem| fuzz_abi.fuzzer_new_input(.fromSlice(elem)); - fuzz_abi.fuzzer_main(fuzz_mode, fuzz_amount_or_instance); return; } @@ -449,10 +447,12 @@ pub fn fuzz( // When the unit test executable is not built in fuzz mode, only run the // provided corpus. for (options.corpus) |input| { - try testOne(context, input); + var smith: testing.Smith = .{ .in = input }; + try testOne(context, &smith); } // In case there is no provided corpus, also use an empty // string as a smoke test. - try testOne(context, ""); + var smith: testing.Smith = .{ .in = "" }; + try testOne(context, &smith); } diff --git a/lib/compiler_rt.zig b/lib/compiler_rt.zig index 87ff89c2d9..ce8f49d17b 100644 --- a/lib/compiler_rt.zig +++ b/lib/compiler_rt.zig @@ -1,10 +1,12 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("compiler_rt/common.zig"); +const ofmt_c = builtin.object_format == .c; +const native_endian = builtin.cpu.arch.endian(); + +const std = @import("std"); /// Avoid dragging in the runtime safety mechanisms into this .o file, unless /// we're trying to test compiler-rt. -pub const panic = if (common.test_safety) +pub const panic = if (test_safety) std.debug.FullPanic(std.debug.defaultPanic) else std.debug.no_panic; @@ -15,10 +17,37 @@ else null; pub const std_options_debug_io: std.Io = if (builtin.is_test) - std.Io.Threaded.global_single_threaded.ioBasic() + std.Io.Threaded.global_single_threaded.io() else unreachable; +pub inline fn symbol(comptime func: *const anyopaque, comptime name: []const u8) void { + @export(func, .{ .name = name, .linkage = linkage, .visibility = visibility }); +} + +/// For now, we prefer weak linkage because some of the routines we implement here may also be +/// provided by system/dynamic libc. Eventually we should be more disciplined about this on a +/// per-symbol, per-target basis: https://github.com/ziglang/zig/issues/11883 +pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) + .internal +else if (ofmt_c) + .strong +else + .weak; + +/// Determines the symbol's visibility to other objects. +/// For WebAssembly this allows the symbol to be resolved to other modules, but will not +/// export it to the host runtime. +pub const visibility: std.builtin.SymbolVisibility = if (linkage == .internal or builtin.link_mode == .dynamic) + .default +else + .hidden; + +pub const test_safety = switch (builtin.zig_backend) { + .stage2_aarch64 => false, + else => builtin.is_test, +}; + comptime { // Integer routines _ = @import("compiler_rt/count0bits.zig"); @@ -29,13 +58,12 @@ comptime { _ = @import("compiler_rt/cmp.zig"); _ = @import("compiler_rt/shift.zig"); - _ = @import("compiler_rt/negXi2.zig"); + symbol(&__negsi2, "__negsi2"); + symbol(&__negdi2, "__negdi2"); + symbol(&__negti2, "__negti2"); _ = @import("compiler_rt/int.zig"); _ = @import("compiler_rt/mulXi3.zig"); - _ = @import("compiler_rt/divti3.zig"); - _ = @import("compiler_rt/udivti3.zig"); - _ = @import("compiler_rt/modti3.zig"); - _ = @import("compiler_rt/umodti3.zig"); + _ = @import("compiler_rt/udivmod.zig"); _ = @import("compiler_rt/absv.zig"); _ = @import("compiler_rt/absvsi2.zig"); @@ -80,9 +108,6 @@ comptime { _ = @import("compiler_rt/trunctfxf2.zig"); _ = @import("compiler_rt/int_from_float.zig"); - _ = @import("compiler_rt/fixhfsi.zig"); - _ = @import("compiler_rt/fixhfdi.zig"); - _ = @import("compiler_rt/fixhfti.zig"); _ = @import("compiler_rt/fixhfei.zig"); _ = @import("compiler_rt/fixsfsi.zig"); _ = @import("compiler_rt/fixsfdi.zig"); @@ -98,8 +123,8 @@ comptime { _ = @import("compiler_rt/fixtfei.zig"); _ = @import("compiler_rt/fixxfsi.zig"); _ = @import("compiler_rt/fixxfdi.zig"); - _ = @import("compiler_rt/fixxfti.zig"); _ = @import("compiler_rt/fixxfei.zig"); + _ = @import("compiler_rt/fixunshfsi.zig"); _ = @import("compiler_rt/fixunshfdi.zig"); _ = @import("compiler_rt/fixunshfti.zig"); @@ -165,16 +190,10 @@ comptime { // comparison _ = @import("compiler_rt/comparef.zig"); - _ = @import("compiler_rt/cmphf2.zig"); - _ = @import("compiler_rt/cmpsf2.zig"); _ = @import("compiler_rt/cmpdf2.zig"); _ = @import("compiler_rt/cmptf2.zig"); _ = @import("compiler_rt/cmpxf2.zig"); - _ = @import("compiler_rt/unordhf2.zig"); - _ = @import("compiler_rt/unordsf2.zig"); _ = @import("compiler_rt/unorddf2.zig"); - _ = @import("compiler_rt/unordxf2.zig"); - _ = @import("compiler_rt/unordtf2.zig"); _ = @import("compiler_rt/gehf2.zig"); _ = @import("compiler_rt/gesf2.zig"); _ = @import("compiler_rt/gedf2.zig"); @@ -208,11 +227,17 @@ comptime { _ = @import("compiler_rt/divxf3.zig"); _ = @import("compiler_rt/divtf3.zig"); - _ = @import("compiler_rt/neghf2.zig"); - _ = @import("compiler_rt/negsf2.zig"); - _ = @import("compiler_rt/negdf2.zig"); - _ = @import("compiler_rt/negtf2.zig"); - _ = @import("compiler_rt/negxf2.zig"); + symbol(&__neghf2, "__neghf2"); + if (want_aeabi) { + symbol(&__aeabi_fneg, "__aeabi_fneg"); + symbol(&__aeabi_dneg, "__aeabi_dneg"); + } else { + symbol(&__negsf2, "__negsf2"); + symbol(&__negdf2, "__negdf2"); + } + if (want_ppc_abi) symbol(&__negtf2, "__negkf2"); + symbol(&__negtf2, "__negtf2"); + symbol(&__negxf2, "__negxf2"); // other _ = @import("compiler_rt/powiXf2.zig"); @@ -253,7 +278,6 @@ comptime { // BigInt. Alphabetically sorted. _ = @import("compiler_rt/divmodei4.zig"); _ = @import("compiler_rt/udivmodei4.zig"); - _ = @import("compiler_rt/udivmodti4.zig"); // extra _ = @import("compiler_rt/os_version_check.zig"); @@ -274,19 +298,429 @@ comptime { } _ = @import("compiler_rt/memcpy.zig"); - _ = @import("compiler_rt/memset.zig"); + if (!ofmt_c) { + symbol(&memset, "memset"); + symbol(&__memset, "__memset"); + } _ = @import("compiler_rt/memmove.zig"); - _ = @import("compiler_rt/memcmp.zig"); - _ = @import("compiler_rt/bcmp.zig"); + symbol(&memcmp, "memcmp"); + symbol(&bcmp, "bcmp"); _ = @import("compiler_rt/ssp.zig"); - - _ = @import("compiler_rt/strlen.zig"); + symbol(&strlen, "strlen"); } // Temporarily used for uefi until https://github.com/ziglang/zig/issues/21630 is addressed. if (!builtin.link_libc and (builtin.os.tag == .windows or builtin.os.tag == .uefi) and (builtin.abi == .none or builtin.abi == .msvc)) { - @export(&_fltused, .{ .name = "_fltused", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&_fltused, "_fltused"); } } var _fltused: c_int = 1; + +fn strlen(s: [*:0]const c_char) callconv(.c) usize { + return std.mem.len(s); +} + +fn memcmp(vl: [*]const u8, vr: [*]const u8, n: usize) callconv(.c) c_int { + var i: usize = 0; + while (i < n) : (i += 1) { + const compared = @as(c_int, vl[i]) -% @as(c_int, vr[i]); + if (compared != 0) return compared; + } + return 0; +} + +test "memcmp" { + const arr0 = &[_]u8{ 1, 1, 1 }; + const arr1 = &[_]u8{ 1, 1, 1 }; + const arr2 = &[_]u8{ 1, 0, 1 }; + const arr3 = &[_]u8{ 1, 2, 1 }; + const arr4 = &[_]u8{ 1, 0xff, 1 }; + + try std.testing.expect(memcmp(arr0, arr1, 3) == 0); + try std.testing.expect(memcmp(arr0, arr2, 3) > 0); + try std.testing.expect(memcmp(arr0, arr3, 3) < 0); + + try std.testing.expect(memcmp(arr0, arr4, 3) < 0); + try std.testing.expect(memcmp(arr4, arr0, 3) > 0); +} + +pub const PreferredLoadStoreElement = element: { + if (std.simd.suggestVectorLength(u8)) |vec_size| { + const Vec = @Vector(vec_size, u8); + + if (@sizeOf(Vec) == vec_size and std.math.isPowerOfTwo(vec_size)) { + break :element Vec; + } + } + break :element usize; +}; + +pub const want_aeabi = switch (builtin.abi) { + .eabi, + .eabihf, + .musleabi, + .musleabihf, + .gnueabi, + .gnueabihf, + .android, + .androideabi, + => switch (builtin.cpu.arch) { + .arm, .armeb, .thumb, .thumbeb => true, + else => false, + }, + else => false, +}; + +/// These functions are required on Windows on ARM. They are provided by MSVC libc, but in libc-less +/// builds or when linking MinGW libc they are our responsibility. +/// Temporarily used for thumb-uefi until https://github.com/ziglang/zig/issues/21630 is addressed. +pub const want_windows_arm_abi = e: { + if (!builtin.cpu.arch.isArm()) break :e false; + switch (builtin.os.tag) { + .windows, .uefi => {}, + else => break :e false, + } + // The ABI is needed, but it's only our reponsibility if libc won't provide it. + break :e builtin.abi.isGnu() or !builtin.link_libc; +}; + +/// These functions are required by on Windows on x86 on some ABIs. They are provided by MSVC libc, +/// but in libc-less builds they are our responsibility. +pub const want_windows_x86_msvc_abi = e: { + if (builtin.cpu.arch != .x86) break :e false; + if (builtin.os.tag != .windows) break :e false; + switch (builtin.abi) { + .none, .msvc, .itanium => {}, + else => break :e false, + } + // The ABI is needed, but it's only our responsibility if libc won't provide it. + break :e !builtin.link_libc; +}; + +pub const want_ppc_abi = builtin.cpu.arch.isPowerPC(); + +pub const want_float_exceptions = !builtin.cpu.arch.isWasm(); + +// Libcalls that involve u128 on Windows x86-64 are expected by LLVM to use the +// calling convention of @Vector(2, u64), rather than what's standard. +pub const want_windows_v2u64_abi = builtin.os.tag == .windows and builtin.cpu.arch == .x86_64 and !ofmt_c; + +/// This governs whether to use these symbol names for f16/f32 conversions +/// rather than the standard names: +/// * __gnu_f2h_ieee +/// * __gnu_h2f_ieee +/// Known correct configurations: +/// x86_64-freestanding-none => true +/// x86_64-linux-none => true +/// x86_64-linux-gnu => true +/// x86_64-linux-musl => true +/// x86_64-linux-eabi => true +/// arm-linux-musleabihf => true +/// arm-linux-gnueabihf => true +/// arm-linux-eabihf => false +/// wasm32-wasi-musl => false +/// wasm32-freestanding-none => false +/// x86_64-windows-gnu => true +/// x86_64-windows-msvc => true +/// any-macos-any => false +pub const gnu_f16_abi = switch (builtin.cpu.arch) { + .wasm32, + .wasm64, + .riscv64, + .riscv64be, + .riscv32, + .riscv32be, + => false, + + .x86, .x86_64 => true, + + .arm, .armeb, .thumb, .thumbeb => switch (builtin.abi) { + .eabi, .eabihf => false, + else => true, + }, + + else => !builtin.os.tag.isDarwin(), +}; + +pub const want_sparc_abi = builtin.cpu.arch.isSPARC(); + +/// This seems to mostly correspond to `clang::TargetInfo::HasFloat16`. +pub fn F16T(comptime OtherType: type) type { + return switch (builtin.cpu.arch) { + .amdgcn, + .arm, + .armeb, + .thumb, + .thumbeb, + .aarch64, + .aarch64_be, + .hexagon, + .loongarch32, + .loongarch64, + .nvptx, + .nvptx64, + .riscv32, + .riscv32be, + .riscv64, + .riscv64be, + .s390x, + .spirv32, + .spirv64, + => f16, + .x86, .x86_64 => if (builtin.target.os.tag.isDarwin()) switch (OtherType) { + // Starting with LLVM 16, Darwin uses different abi for f16 + // depending on the type of the other return/argument..??? + f32, f64 => u16, + f80, f128 => f16, + else => unreachable, + } else f16, + else => u16, + }; +} + +pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { + switch (Z) { + u16 => { + // 16x16 --> 32 bit multiply + const product = @as(u32, a) * @as(u32, b); + hi.* = @intCast(product >> 16); + lo.* = @truncate(product); + }, + u32 => { + // 32x32 --> 64 bit multiply + const product = @as(u64, a) * @as(u64, b); + hi.* = @truncate(product >> 32); + lo.* = @truncate(product); + }, + u64 => { + const S = struct { + fn loWord(x: u64) u64 { + return @as(u32, @truncate(x)); + } + fn hiWord(x: u64) u64 { + return @as(u32, @truncate(x >> 32)); + } + }; + // 64x64 -> 128 wide multiply for platforms that don't have such an operation; + // many 64-bit platforms have this operation, but they tend to have hardware + // floating-point, so we don't bother with a special case for them here. + // Each of the component 32x32 -> 64 products + const plolo: u64 = S.loWord(a) * S.loWord(b); + const plohi: u64 = S.loWord(a) * S.hiWord(b); + const philo: u64 = S.hiWord(a) * S.loWord(b); + const phihi: u64 = S.hiWord(a) * S.hiWord(b); + // Sum terms that contribute to lo in a way that allows us to get the carry + const r0: u64 = S.loWord(plolo); + const r1: u64 = S.hiWord(plolo) +% S.loWord(plohi) +% S.loWord(philo); + lo.* = r0 +% (r1 << 32); + // Sum terms contributing to hi with the carry from lo + hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; + }, + u128 => { + const Word_LoMask: u64 = 0x00000000ffffffff; + const Word_HiMask: u64 = 0xffffffff00000000; + const Word_FullMask: u64 = 0xffffffffffffffff; + const S = struct { + fn Word_1(x: u128) u64 { + return @as(u32, @truncate(x >> 96)); + } + fn Word_2(x: u128) u64 { + return @as(u32, @truncate(x >> 64)); + } + fn Word_3(x: u128) u64 { + return @as(u32, @truncate(x >> 32)); + } + fn Word_4(x: u128) u64 { + return @as(u32, @truncate(x)); + } + }; + // 128x128 -> 256 wide multiply for platforms that don't have such an operation; + // many 64-bit platforms have this operation, but they tend to have hardware + // floating-point, so we don't bother with a special case for them here. + + const product11: u64 = S.Word_1(a) * S.Word_1(b); + const product12: u64 = S.Word_1(a) * S.Word_2(b); + const product13: u64 = S.Word_1(a) * S.Word_3(b); + const product14: u64 = S.Word_1(a) * S.Word_4(b); + const product21: u64 = S.Word_2(a) * S.Word_1(b); + const product22: u64 = S.Word_2(a) * S.Word_2(b); + const product23: u64 = S.Word_2(a) * S.Word_3(b); + const product24: u64 = S.Word_2(a) * S.Word_4(b); + const product31: u64 = S.Word_3(a) * S.Word_1(b); + const product32: u64 = S.Word_3(a) * S.Word_2(b); + const product33: u64 = S.Word_3(a) * S.Word_3(b); + const product34: u64 = S.Word_3(a) * S.Word_4(b); + const product41: u64 = S.Word_4(a) * S.Word_1(b); + const product42: u64 = S.Word_4(a) * S.Word_2(b); + const product43: u64 = S.Word_4(a) * S.Word_3(b); + const product44: u64 = S.Word_4(a) * S.Word_4(b); + + const sum0: u128 = @as(u128, product44); + const sum1: u128 = @as(u128, product34) +% + @as(u128, product43); + const sum2: u128 = @as(u128, product24) +% + @as(u128, product33) +% + @as(u128, product42); + const sum3: u128 = @as(u128, product14) +% + @as(u128, product23) +% + @as(u128, product32) +% + @as(u128, product41); + const sum4: u128 = @as(u128, product13) +% + @as(u128, product22) +% + @as(u128, product31); + const sum5: u128 = @as(u128, product12) +% + @as(u128, product21); + const sum6: u128 = @as(u128, product11); + + const r0: u128 = (sum0 & Word_FullMask) +% + ((sum1 & Word_LoMask) << 32); + const r1: u128 = (sum0 >> 64) +% + ((sum1 >> 32) & Word_FullMask) +% + (sum2 & Word_FullMask) +% + ((sum3 << 32) & Word_HiMask); + + lo.* = r0 +% (r1 << 64); + hi.* = (r1 >> 64) +% + (sum1 >> 96) +% + (sum2 >> 64) +% + (sum3 >> 32) +% + sum4 +% + (sum5 << 32) +% + (sum6 << 64); + }, + else => @compileError("unsupported"), + } +} + +pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeInfo(T).float.bits)) i32 { + const Z = std.meta.Int(.unsigned, @typeInfo(T).float.bits); + const integerBit = @as(Z, 1) << std.math.floatFractionalBits(T); + + const shift = @clz(significand.*) - @clz(integerBit); + significand.* <<= @as(std.math.Log2Int(Z), @intCast(shift)); + return @as(i32, 1) - shift; +} + +pub inline fn fneg(a: anytype) @TypeOf(a) { + const F = @TypeOf(a); + const bits = @typeInfo(F).float.bits; + const U = @Int(.unsigned, bits); + const sign_bit_mask = @as(U, 1) << (bits - 1); + const negated = @as(U, @bitCast(a)) ^ sign_bit_mask; + return @bitCast(negated); +} + +fn __negxf2(a: f80) callconv(.c) f80 { + return fneg(a); +} + +fn __neghf2(a: f16) callconv(.c) f16 { + return fneg(a); +} + +fn __negdf2(a: f64) callconv(.c) f64 { + return fneg(a); +} + +fn __aeabi_dneg(a: f64) callconv(.{ .arm_aapcs = .{} }) f64 { + return fneg(a); +} + +fn __negtf2(a: f128) callconv(.c) f128 { + return fneg(a); +} + +fn __negsf2(a: f32) callconv(.c) f32 { + return fneg(a); +} + +fn __aeabi_fneg(a: f32) callconv(.{ .arm_aapcs = .{} }) f32 { + return fneg(a); +} + +/// Allows to access underlying bits as two equally sized lower and higher +/// signed or unsigned integers. +pub fn HalveInt(comptime T: type, comptime signed_half: bool) type { + return extern union { + pub const bits = @divExact(@typeInfo(T).int.bits, 2); + pub const HalfTU = std.meta.Int(.unsigned, bits); + pub const HalfTS = std.meta.Int(.signed, bits); + pub const HalfT = if (signed_half) HalfTS else HalfTU; + + all: T, + s: if (native_endian == .little) + extern struct { low: HalfT, high: HalfT } + else + extern struct { high: HalfT, low: HalfT }, + }; +} + +pub fn __negsi2(a: i32) callconv(.c) i32 { + return negXi2(i32, a); +} + +pub fn __negdi2(a: i64) callconv(.c) i64 { + return negXi2(i64, a); +} + +pub fn __negti2(a: i128) callconv(.c) i128 { + return negXi2(i128, a); +} + +inline fn negXi2(comptime T: type, a: T) T { + return -a; +} + +pub fn memset(dest: ?[*]u8, c: u8, len: usize) callconv(.c) ?[*]u8 { + @setRuntimeSafety(false); + + if (len != 0) { + var d = dest.?; + var n = len; + while (true) { + d[0] = c; + n -= 1; + if (n == 0) break; + d += 1; + } + } + + return dest; +} + +pub fn __memset(dest: ?[*]u8, c: u8, n: usize, dest_n: usize) callconv(.c) ?[*]u8 { + if (dest_n < n) + @panic("buffer overflow"); + return memset(dest, c, n); +} + +pub fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.c) c_int { + @setRuntimeSafety(false); + + var index: usize = 0; + while (index != n) : (index += 1) { + if (vl[index] != vr[index]) { + return 1; + } + } + + return 0; +} + +test "bcmp" { + const base_arr = &[_]u8{ 1, 1, 1 }; + const arr1 = &[_]u8{ 1, 1, 1 }; + const arr2 = &[_]u8{ 1, 0, 1 }; + const arr3 = &[_]u8{ 1, 2, 1 }; + + try std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0); + try std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0); + try std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0); +} + +test { + _ = @import("compiler_rt/negsi2_test.zig"); + _ = @import("compiler_rt/negdi2_test.zig"); + _ = @import("compiler_rt/negti2_test.zig"); +} diff --git a/lib/compiler_rt/aarch64_outline_atomics.zig b/lib/compiler_rt/aarch64_outline_atomics.zig index 817800eb21..c03306cd1a 100644 --- a/lib/compiler_rt/aarch64_outline_atomics.zig +++ b/lib/compiler_rt/aarch64_outline_atomics.zig @@ -1,7 +1,8 @@ //! This file is generated by tools/gen_outline_atomics.zig. const builtin = @import("builtin"); const std = @import("std"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const always_has_lse = builtin.cpu.has(.aarch64, .lse); /// This default is overridden at runtime after inspecting CPU properties. @@ -2024,104 +2025,104 @@ fn __aarch64_cas16_acq_rel() align(16) callconv(.naked) void { } comptime { - @export(&__aarch64_cas1_relax, .{ .name = "__aarch64_cas1_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp1_relax, .{ .name = "__aarch64_swp1_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd1_relax, .{ .name = "__aarch64_ldadd1_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr1_relax, .{ .name = "__aarch64_ldclr1_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor1_relax, .{ .name = "__aarch64_ldeor1_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset1_relax, .{ .name = "__aarch64_ldset1_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas1_acq, .{ .name = "__aarch64_cas1_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp1_acq, .{ .name = "__aarch64_swp1_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd1_acq, .{ .name = "__aarch64_ldadd1_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr1_acq, .{ .name = "__aarch64_ldclr1_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor1_acq, .{ .name = "__aarch64_ldeor1_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset1_acq, .{ .name = "__aarch64_ldset1_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas1_rel, .{ .name = "__aarch64_cas1_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp1_rel, .{ .name = "__aarch64_swp1_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd1_rel, .{ .name = "__aarch64_ldadd1_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr1_rel, .{ .name = "__aarch64_ldclr1_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor1_rel, .{ .name = "__aarch64_ldeor1_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset1_rel, .{ .name = "__aarch64_ldset1_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas1_acq_rel, .{ .name = "__aarch64_cas1_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp1_acq_rel, .{ .name = "__aarch64_swp1_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd1_acq_rel, .{ .name = "__aarch64_ldadd1_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr1_acq_rel, .{ .name = "__aarch64_ldclr1_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor1_acq_rel, .{ .name = "__aarch64_ldeor1_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset1_acq_rel, .{ .name = "__aarch64_ldset1_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas2_relax, .{ .name = "__aarch64_cas2_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp2_relax, .{ .name = "__aarch64_swp2_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd2_relax, .{ .name = "__aarch64_ldadd2_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr2_relax, .{ .name = "__aarch64_ldclr2_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor2_relax, .{ .name = "__aarch64_ldeor2_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset2_relax, .{ .name = "__aarch64_ldset2_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas2_acq, .{ .name = "__aarch64_cas2_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp2_acq, .{ .name = "__aarch64_swp2_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd2_acq, .{ .name = "__aarch64_ldadd2_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr2_acq, .{ .name = "__aarch64_ldclr2_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor2_acq, .{ .name = "__aarch64_ldeor2_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset2_acq, .{ .name = "__aarch64_ldset2_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas2_rel, .{ .name = "__aarch64_cas2_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp2_rel, .{ .name = "__aarch64_swp2_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd2_rel, .{ .name = "__aarch64_ldadd2_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr2_rel, .{ .name = "__aarch64_ldclr2_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor2_rel, .{ .name = "__aarch64_ldeor2_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset2_rel, .{ .name = "__aarch64_ldset2_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas2_acq_rel, .{ .name = "__aarch64_cas2_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp2_acq_rel, .{ .name = "__aarch64_swp2_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd2_acq_rel, .{ .name = "__aarch64_ldadd2_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr2_acq_rel, .{ .name = "__aarch64_ldclr2_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor2_acq_rel, .{ .name = "__aarch64_ldeor2_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset2_acq_rel, .{ .name = "__aarch64_ldset2_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas4_relax, .{ .name = "__aarch64_cas4_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp4_relax, .{ .name = "__aarch64_swp4_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd4_relax, .{ .name = "__aarch64_ldadd4_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr4_relax, .{ .name = "__aarch64_ldclr4_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor4_relax, .{ .name = "__aarch64_ldeor4_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset4_relax, .{ .name = "__aarch64_ldset4_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas4_acq, .{ .name = "__aarch64_cas4_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp4_acq, .{ .name = "__aarch64_swp4_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd4_acq, .{ .name = "__aarch64_ldadd4_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr4_acq, .{ .name = "__aarch64_ldclr4_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor4_acq, .{ .name = "__aarch64_ldeor4_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset4_acq, .{ .name = "__aarch64_ldset4_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas4_rel, .{ .name = "__aarch64_cas4_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp4_rel, .{ .name = "__aarch64_swp4_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd4_rel, .{ .name = "__aarch64_ldadd4_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr4_rel, .{ .name = "__aarch64_ldclr4_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor4_rel, .{ .name = "__aarch64_ldeor4_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset4_rel, .{ .name = "__aarch64_ldset4_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas4_acq_rel, .{ .name = "__aarch64_cas4_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp4_acq_rel, .{ .name = "__aarch64_swp4_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd4_acq_rel, .{ .name = "__aarch64_ldadd4_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr4_acq_rel, .{ .name = "__aarch64_ldclr4_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor4_acq_rel, .{ .name = "__aarch64_ldeor4_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset4_acq_rel, .{ .name = "__aarch64_ldset4_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas8_relax, .{ .name = "__aarch64_cas8_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp8_relax, .{ .name = "__aarch64_swp8_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd8_relax, .{ .name = "__aarch64_ldadd8_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr8_relax, .{ .name = "__aarch64_ldclr8_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor8_relax, .{ .name = "__aarch64_ldeor8_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset8_relax, .{ .name = "__aarch64_ldset8_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas8_acq, .{ .name = "__aarch64_cas8_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp8_acq, .{ .name = "__aarch64_swp8_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd8_acq, .{ .name = "__aarch64_ldadd8_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr8_acq, .{ .name = "__aarch64_ldclr8_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor8_acq, .{ .name = "__aarch64_ldeor8_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset8_acq, .{ .name = "__aarch64_ldset8_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas8_rel, .{ .name = "__aarch64_cas8_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp8_rel, .{ .name = "__aarch64_swp8_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd8_rel, .{ .name = "__aarch64_ldadd8_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr8_rel, .{ .name = "__aarch64_ldclr8_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor8_rel, .{ .name = "__aarch64_ldeor8_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset8_rel, .{ .name = "__aarch64_ldset8_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas8_acq_rel, .{ .name = "__aarch64_cas8_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_swp8_acq_rel, .{ .name = "__aarch64_swp8_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldadd8_acq_rel, .{ .name = "__aarch64_ldadd8_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldclr8_acq_rel, .{ .name = "__aarch64_ldclr8_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldeor8_acq_rel, .{ .name = "__aarch64_ldeor8_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_ldset8_acq_rel, .{ .name = "__aarch64_ldset8_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas16_relax, .{ .name = "__aarch64_cas16_relax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas16_acq, .{ .name = "__aarch64_cas16_acq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas16_rel, .{ .name = "__aarch64_cas16_rel", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aarch64_cas16_acq_rel, .{ .name = "__aarch64_cas16_acq_rel", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__aarch64_cas1_relax, "__aarch64_cas1_relax"); + symbol(&__aarch64_swp1_relax, "__aarch64_swp1_relax"); + symbol(&__aarch64_ldadd1_relax, "__aarch64_ldadd1_relax"); + symbol(&__aarch64_ldclr1_relax, "__aarch64_ldclr1_relax"); + symbol(&__aarch64_ldeor1_relax, "__aarch64_ldeor1_relax"); + symbol(&__aarch64_ldset1_relax, "__aarch64_ldset1_relax"); + symbol(&__aarch64_cas1_acq, "__aarch64_cas1_acq"); + symbol(&__aarch64_swp1_acq, "__aarch64_swp1_acq"); + symbol(&__aarch64_ldadd1_acq, "__aarch64_ldadd1_acq"); + symbol(&__aarch64_ldclr1_acq, "__aarch64_ldclr1_acq"); + symbol(&__aarch64_ldeor1_acq, "__aarch64_ldeor1_acq"); + symbol(&__aarch64_ldset1_acq, "__aarch64_ldset1_acq"); + symbol(&__aarch64_cas1_rel, "__aarch64_cas1_rel"); + symbol(&__aarch64_swp1_rel, "__aarch64_swp1_rel"); + symbol(&__aarch64_ldadd1_rel, "__aarch64_ldadd1_rel"); + symbol(&__aarch64_ldclr1_rel, "__aarch64_ldclr1_rel"); + symbol(&__aarch64_ldeor1_rel, "__aarch64_ldeor1_rel"); + symbol(&__aarch64_ldset1_rel, "__aarch64_ldset1_rel"); + symbol(&__aarch64_cas1_acq_rel, "__aarch64_cas1_acq_rel"); + symbol(&__aarch64_swp1_acq_rel, "__aarch64_swp1_acq_rel"); + symbol(&__aarch64_ldadd1_acq_rel, "__aarch64_ldadd1_acq_rel"); + symbol(&__aarch64_ldclr1_acq_rel, "__aarch64_ldclr1_acq_rel"); + symbol(&__aarch64_ldeor1_acq_rel, "__aarch64_ldeor1_acq_rel"); + symbol(&__aarch64_ldset1_acq_rel, "__aarch64_ldset1_acq_rel"); + symbol(&__aarch64_cas2_relax, "__aarch64_cas2_relax"); + symbol(&__aarch64_swp2_relax, "__aarch64_swp2_relax"); + symbol(&__aarch64_ldadd2_relax, "__aarch64_ldadd2_relax"); + symbol(&__aarch64_ldclr2_relax, "__aarch64_ldclr2_relax"); + symbol(&__aarch64_ldeor2_relax, "__aarch64_ldeor2_relax"); + symbol(&__aarch64_ldset2_relax, "__aarch64_ldset2_relax"); + symbol(&__aarch64_cas2_acq, "__aarch64_cas2_acq"); + symbol(&__aarch64_swp2_acq, "__aarch64_swp2_acq"); + symbol(&__aarch64_ldadd2_acq, "__aarch64_ldadd2_acq"); + symbol(&__aarch64_ldclr2_acq, "__aarch64_ldclr2_acq"); + symbol(&__aarch64_ldeor2_acq, "__aarch64_ldeor2_acq"); + symbol(&__aarch64_ldset2_acq, "__aarch64_ldset2_acq"); + symbol(&__aarch64_cas2_rel, "__aarch64_cas2_rel"); + symbol(&__aarch64_swp2_rel, "__aarch64_swp2_rel"); + symbol(&__aarch64_ldadd2_rel, "__aarch64_ldadd2_rel"); + symbol(&__aarch64_ldclr2_rel, "__aarch64_ldclr2_rel"); + symbol(&__aarch64_ldeor2_rel, "__aarch64_ldeor2_rel"); + symbol(&__aarch64_ldset2_rel, "__aarch64_ldset2_rel"); + symbol(&__aarch64_cas2_acq_rel, "__aarch64_cas2_acq_rel"); + symbol(&__aarch64_swp2_acq_rel, "__aarch64_swp2_acq_rel"); + symbol(&__aarch64_ldadd2_acq_rel, "__aarch64_ldadd2_acq_rel"); + symbol(&__aarch64_ldclr2_acq_rel, "__aarch64_ldclr2_acq_rel"); + symbol(&__aarch64_ldeor2_acq_rel, "__aarch64_ldeor2_acq_rel"); + symbol(&__aarch64_ldset2_acq_rel, "__aarch64_ldset2_acq_rel"); + symbol(&__aarch64_cas4_relax, "__aarch64_cas4_relax"); + symbol(&__aarch64_swp4_relax, "__aarch64_swp4_relax"); + symbol(&__aarch64_ldadd4_relax, "__aarch64_ldadd4_relax"); + symbol(&__aarch64_ldclr4_relax, "__aarch64_ldclr4_relax"); + symbol(&__aarch64_ldeor4_relax, "__aarch64_ldeor4_relax"); + symbol(&__aarch64_ldset4_relax, "__aarch64_ldset4_relax"); + symbol(&__aarch64_cas4_acq, "__aarch64_cas4_acq"); + symbol(&__aarch64_swp4_acq, "__aarch64_swp4_acq"); + symbol(&__aarch64_ldadd4_acq, "__aarch64_ldadd4_acq"); + symbol(&__aarch64_ldclr4_acq, "__aarch64_ldclr4_acq"); + symbol(&__aarch64_ldeor4_acq, "__aarch64_ldeor4_acq"); + symbol(&__aarch64_ldset4_acq, "__aarch64_ldset4_acq"); + symbol(&__aarch64_cas4_rel, "__aarch64_cas4_rel"); + symbol(&__aarch64_swp4_rel, "__aarch64_swp4_rel"); + symbol(&__aarch64_ldadd4_rel, "__aarch64_ldadd4_rel"); + symbol(&__aarch64_ldclr4_rel, "__aarch64_ldclr4_rel"); + symbol(&__aarch64_ldeor4_rel, "__aarch64_ldeor4_rel"); + symbol(&__aarch64_ldset4_rel, "__aarch64_ldset4_rel"); + symbol(&__aarch64_cas4_acq_rel, "__aarch64_cas4_acq_rel"); + symbol(&__aarch64_swp4_acq_rel, "__aarch64_swp4_acq_rel"); + symbol(&__aarch64_ldadd4_acq_rel, "__aarch64_ldadd4_acq_rel"); + symbol(&__aarch64_ldclr4_acq_rel, "__aarch64_ldclr4_acq_rel"); + symbol(&__aarch64_ldeor4_acq_rel, "__aarch64_ldeor4_acq_rel"); + symbol(&__aarch64_ldset4_acq_rel, "__aarch64_ldset4_acq_rel"); + symbol(&__aarch64_cas8_relax, "__aarch64_cas8_relax"); + symbol(&__aarch64_swp8_relax, "__aarch64_swp8_relax"); + symbol(&__aarch64_ldadd8_relax, "__aarch64_ldadd8_relax"); + symbol(&__aarch64_ldclr8_relax, "__aarch64_ldclr8_relax"); + symbol(&__aarch64_ldeor8_relax, "__aarch64_ldeor8_relax"); + symbol(&__aarch64_ldset8_relax, "__aarch64_ldset8_relax"); + symbol(&__aarch64_cas8_acq, "__aarch64_cas8_acq"); + symbol(&__aarch64_swp8_acq, "__aarch64_swp8_acq"); + symbol(&__aarch64_ldadd8_acq, "__aarch64_ldadd8_acq"); + symbol(&__aarch64_ldclr8_acq, "__aarch64_ldclr8_acq"); + symbol(&__aarch64_ldeor8_acq, "__aarch64_ldeor8_acq"); + symbol(&__aarch64_ldset8_acq, "__aarch64_ldset8_acq"); + symbol(&__aarch64_cas8_rel, "__aarch64_cas8_rel"); + symbol(&__aarch64_swp8_rel, "__aarch64_swp8_rel"); + symbol(&__aarch64_ldadd8_rel, "__aarch64_ldadd8_rel"); + symbol(&__aarch64_ldclr8_rel, "__aarch64_ldclr8_rel"); + symbol(&__aarch64_ldeor8_rel, "__aarch64_ldeor8_rel"); + symbol(&__aarch64_ldset8_rel, "__aarch64_ldset8_rel"); + symbol(&__aarch64_cas8_acq_rel, "__aarch64_cas8_acq_rel"); + symbol(&__aarch64_swp8_acq_rel, "__aarch64_swp8_acq_rel"); + symbol(&__aarch64_ldadd8_acq_rel, "__aarch64_ldadd8_acq_rel"); + symbol(&__aarch64_ldclr8_acq_rel, "__aarch64_ldclr8_acq_rel"); + symbol(&__aarch64_ldeor8_acq_rel, "__aarch64_ldeor8_acq_rel"); + symbol(&__aarch64_ldset8_acq_rel, "__aarch64_ldset8_acq_rel"); + symbol(&__aarch64_cas16_relax, "__aarch64_cas16_relax"); + symbol(&__aarch64_cas16_acq, "__aarch64_cas16_acq"); + symbol(&__aarch64_cas16_rel, "__aarch64_cas16_rel"); + symbol(&__aarch64_cas16_acq_rel, "__aarch64_cas16_acq_rel"); } diff --git a/lib/compiler_rt/absvdi2.zig b/lib/compiler_rt/absvdi2.zig index add32608e8..408d70ad16 100644 --- a/lib/compiler_rt/absvdi2.zig +++ b/lib/compiler_rt/absvdi2.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const absv = @import("./absv.zig").absv; comptime { - @export(&__absvdi2, .{ .name = "__absvdi2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__absvdi2, "__absvdi2"); } pub fn __absvdi2(a: i64) callconv(.c) i64 { diff --git a/lib/compiler_rt/absvsi2.zig b/lib/compiler_rt/absvsi2.zig index fb527cd997..538d7f7f01 100644 --- a/lib/compiler_rt/absvsi2.zig +++ b/lib/compiler_rt/absvsi2.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const absv = @import("./absv.zig").absv; comptime { - @export(&__absvsi2, .{ .name = "__absvsi2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__absvsi2, "__absvsi2"); } pub fn __absvsi2(a: i32) callconv(.c) i32 { diff --git a/lib/compiler_rt/absvti2.zig b/lib/compiler_rt/absvti2.zig index 1b2ddaaefa..ab367d2b78 100644 --- a/lib/compiler_rt/absvti2.zig +++ b/lib/compiler_rt/absvti2.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const absv = @import("./absv.zig").absv; comptime { - @export(&__absvti2, .{ .name = "__absvti2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__absvti2, "__absvti2"); } pub fn __absvti2(a: i128) callconv(.c) i128 { diff --git a/lib/compiler_rt/adddf3.zig b/lib/compiler_rt/adddf3.zig index 98fba79bbd..7b6f252da2 100644 --- a/lib/compiler_rt/adddf3.zig +++ b/lib/compiler_rt/adddf3.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const addf3 = @import("./addf3.zig").addf3; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_aeabi) { - @export(&__aeabi_dadd, .{ .name = "__aeabi_dadd", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_dadd, "__aeabi_dadd"); } else { - @export(&__adddf3, .{ .name = "__adddf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__adddf3, "__adddf3"); } } diff --git a/lib/compiler_rt/addf3.zig b/lib/compiler_rt/addf3.zig index 60ae0165a8..91152735f4 100644 --- a/lib/compiler_rt/addf3.zig +++ b/lib/compiler_rt/addf3.zig @@ -1,7 +1,7 @@ const std = @import("std"); const math = std.math; -const common = @import("./common.zig"); -const normalize = common.normalize; +const compiler_rt = @import("../compiler_rt.zig"); +const normalize = compiler_rt.normalize; /// Ported from: /// diff --git a/lib/compiler_rt/addhf3.zig b/lib/compiler_rt/addhf3.zig index 842c88f5d4..bd13f48cac 100644 --- a/lib/compiler_rt/addhf3.zig +++ b/lib/compiler_rt/addhf3.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const addf3 = @import("./addf3.zig").addf3; comptime { - @export(&__addhf3, .{ .name = "__addhf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__addhf3, "__addhf3"); } fn __addhf3(a: f16, b: f16) callconv(.c) f16 { diff --git a/lib/compiler_rt/addsf3.zig b/lib/compiler_rt/addsf3.zig index ef1627ae7a..4878fb704d 100644 --- a/lib/compiler_rt/addsf3.zig +++ b/lib/compiler_rt/addsf3.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const addf3 = @import("./addf3.zig").addf3; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_aeabi) { - @export(&__aeabi_fadd, .{ .name = "__aeabi_fadd", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_fadd, "__aeabi_fadd"); } else { - @export(&__addsf3, .{ .name = "__addsf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__addsf3, "__addsf3"); } } diff --git a/lib/compiler_rt/addtf3.zig b/lib/compiler_rt/addtf3.zig index d4011f9238..50e699415a 100644 --- a/lib/compiler_rt/addtf3.zig +++ b/lib/compiler_rt/addtf3.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const addf3 = @import("./addf3.zig").addf3; comptime { - if (common.want_ppc_abi) { - @export(&__addtf3, .{ .name = "__addkf3", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_add, .{ .name = "_Qp_add", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__addtf3, "__addkf3"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_add, "_Qp_add"); } - @export(&__addtf3, .{ .name = "__addtf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__addtf3, "__addtf3"); } pub fn __addtf3(a: f128, b: f128) callconv(.c) f128 { diff --git a/lib/compiler_rt/addvdi3.zig b/lib/compiler_rt/addvdi3.zig index e7346b717f..a5cde2494a 100644 --- a/lib/compiler_rt/addvdi3.zig +++ b/lib/compiler_rt/addvdi3.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const testing = @import("std").testing; comptime { - @export(&__addvdi3, .{ .name = "__addvdi3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__addvdi3, "__addvdi3"); } pub fn __addvdi3(a: i64, b: i64) callconv(.c) i64 { diff --git a/lib/compiler_rt/addvsi3.zig b/lib/compiler_rt/addvsi3.zig index 468047eda1..c35b22e8df 100644 --- a/lib/compiler_rt/addvsi3.zig +++ b/lib/compiler_rt/addvsi3.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const testing = @import("std").testing; comptime { - @export(&__addvsi3, .{ .name = "__addvsi3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__addvsi3, "__addvsi3"); } pub fn __addvsi3(a: i32, b: i32) callconv(.c) i32 { diff --git a/lib/compiler_rt/addxf3.zig b/lib/compiler_rt/addxf3.zig index e1509f04f5..f57708c985 100644 --- a/lib/compiler_rt/addxf3.zig +++ b/lib/compiler_rt/addxf3.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const addf3 = @import("./addf3.zig").addf3; comptime { - @export(&__addxf3, .{ .name = "__addxf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__addxf3, "__addxf3"); } pub fn __addxf3(a: f80, b: f80) callconv(.c) f80 { diff --git a/lib/compiler_rt/arm.zig b/lib/compiler_rt/arm.zig index aa31e855dc..eecb0e5d03 100644 --- a/lib/compiler_rt/arm.zig +++ b/lib/compiler_rt/arm.zig @@ -4,49 +4,50 @@ const std = @import("std"); const builtin = @import("builtin"); const target = builtin.target; const arch = builtin.cpu.arch; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { if (!builtin.is_test) { if (arch.isArm()) { - @export(&__aeabi_unwind_cpp_pr0, .{ .name = "__aeabi_unwind_cpp_pr0", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_unwind_cpp_pr1, .{ .name = "__aeabi_unwind_cpp_pr1", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_unwind_cpp_pr2, .{ .name = "__aeabi_unwind_cpp_pr2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__aeabi_unwind_cpp_pr0, "__aeabi_unwind_cpp_pr0"); + symbol(&__aeabi_unwind_cpp_pr1, "__aeabi_unwind_cpp_pr1"); + symbol(&__aeabi_unwind_cpp_pr2, "__aeabi_unwind_cpp_pr2"); - if (common.want_windows_arm_abi) { - @export(&__aeabi_ldivmod, .{ .name = "__rt_sdiv64", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_uldivmod, .{ .name = "__rt_udiv64", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_idivmod, .{ .name = "__rt_sdiv", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_uidivmod, .{ .name = "__rt_udiv", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_arm_abi) { + symbol(&__aeabi_ldivmod, "__rt_sdiv64"); + symbol(&__aeabi_uldivmod, "__rt_udiv64"); + symbol(&__aeabi_idivmod, "__rt_sdiv"); + symbol(&__aeabi_uidivmod, "__rt_udiv"); } - @export(&__aeabi_ldivmod, .{ .name = "__aeabi_ldivmod", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_uldivmod, .{ .name = "__aeabi_uldivmod", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_idivmod, .{ .name = "__aeabi_idivmod", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_uidivmod, .{ .name = "__aeabi_uidivmod", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__aeabi_ldivmod, "__aeabi_ldivmod"); + symbol(&__aeabi_uldivmod, "__aeabi_uldivmod"); + symbol(&__aeabi_idivmod, "__aeabi_idivmod"); + symbol(&__aeabi_uidivmod, "__aeabi_uidivmod"); - @export(&__aeabi_memcpy, .{ .name = "__aeabi_memcpy", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_memcpy4, .{ .name = "__aeabi_memcpy4", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_memcpy8, .{ .name = "__aeabi_memcpy8", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__aeabi_memcpy, "__aeabi_memcpy"); + symbol(&__aeabi_memcpy4, "__aeabi_memcpy4"); + symbol(&__aeabi_memcpy8, "__aeabi_memcpy8"); - @export(&__aeabi_memmove, .{ .name = "__aeabi_memmove", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_memmove4, .{ .name = "__aeabi_memmove4", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_memmove8, .{ .name = "__aeabi_memmove8", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__aeabi_memmove, "__aeabi_memmove"); + symbol(&__aeabi_memmove4, "__aeabi_memmove4"); + symbol(&__aeabi_memmove8, "__aeabi_memmove8"); - @export(&__aeabi_memset, .{ .name = "__aeabi_memset", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_memset4, .{ .name = "__aeabi_memset4", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_memset8, .{ .name = "__aeabi_memset8", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__aeabi_memset, "__aeabi_memset"); + symbol(&__aeabi_memset4, "__aeabi_memset4"); + symbol(&__aeabi_memset8, "__aeabi_memset8"); - @export(&__aeabi_memclr, .{ .name = "__aeabi_memclr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_memclr4, .{ .name = "__aeabi_memclr4", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_memclr8, .{ .name = "__aeabi_memclr8", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__aeabi_memclr, "__aeabi_memclr"); + symbol(&__aeabi_memclr4, "__aeabi_memclr4"); + symbol(&__aeabi_memclr8, "__aeabi_memclr8"); if (builtin.os.tag == .linux or builtin.os.tag == .freebsd) { - @export(&__aeabi_read_tp, .{ .name = "__aeabi_read_tp", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__aeabi_read_tp, "__aeabi_read_tp"); } // floating-point helper functions (single+double-precision reverse subtraction, y – x), see subdf3.zig - @export(&__aeabi_frsub, .{ .name = "__aeabi_frsub", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_drsub, .{ .name = "__aeabi_drsub", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__aeabi_frsub, "__aeabi_frsub"); + symbol(&__aeabi_drsub, "__aeabi_drsub"); } } } diff --git a/lib/compiler_rt/atomics.zig b/lib/compiler_rt/atomics.zig index b87b7a6315..d6eaf4d671 100644 --- a/lib/compiler_rt/atomics.zig +++ b/lib/compiler_rt/atomics.zig @@ -1,10 +1,11 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("./common.zig"); const cpu = builtin.cpu; const arch = cpu.arch; -const linkage = common.linkage; -const visibility = common.visibility; + +const std = @import("std"); + +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; // This parameter is true iff the target architecture supports the bare minimum // to implement the atomic load/store intrinsics. @@ -225,7 +226,7 @@ fn __atomic_store_16(dst: *u128, value: u128, model: i32) callconv(.c) void { } fn wideUpdate(comptime T: type, ptr: *T, val: T, update: anytype) T { - const WideAtomic = std.meta.Int(.unsigned, smallest_atomic_fetch_exch_size * 8); + const WideAtomic = @Int(.unsigned, smallest_atomic_fetch_exch_size * 8); const addr = @intFromPtr(ptr); const wide_addr = addr & ~(@as(T, smallest_atomic_fetch_exch_size) - 1); @@ -535,81 +536,81 @@ fn __atomic_fetch_umin_16(ptr: *u128, val: u128, model: i32) callconv(.c) u128 { comptime { if (supports_atomic_ops and builtin.object_format != .c) { - @export(&__atomic_load, .{ .name = "__atomic_load", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_store, .{ .name = "__atomic_store", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_exchange, .{ .name = "__atomic_exchange", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_compare_exchange, .{ .name = "__atomic_compare_exchange", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_load, "__atomic_load"); + symbol(&__atomic_store, "__atomic_store"); + symbol(&__atomic_exchange, "__atomic_exchange"); + symbol(&__atomic_compare_exchange, "__atomic_compare_exchange"); - @export(&__atomic_fetch_add_1, .{ .name = "__atomic_fetch_add_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_add_2, .{ .name = "__atomic_fetch_add_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_add_4, .{ .name = "__atomic_fetch_add_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_add_8, .{ .name = "__atomic_fetch_add_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_add_16, .{ .name = "__atomic_fetch_add_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_fetch_add_1, "__atomic_fetch_add_1"); + symbol(&__atomic_fetch_add_2, "__atomic_fetch_add_2"); + symbol(&__atomic_fetch_add_4, "__atomic_fetch_add_4"); + symbol(&__atomic_fetch_add_8, "__atomic_fetch_add_8"); + symbol(&__atomic_fetch_add_16, "__atomic_fetch_add_16"); - @export(&__atomic_fetch_sub_1, .{ .name = "__atomic_fetch_sub_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_sub_2, .{ .name = "__atomic_fetch_sub_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_sub_4, .{ .name = "__atomic_fetch_sub_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_sub_8, .{ .name = "__atomic_fetch_sub_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_sub_16, .{ .name = "__atomic_fetch_sub_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_fetch_sub_1, "__atomic_fetch_sub_1"); + symbol(&__atomic_fetch_sub_2, "__atomic_fetch_sub_2"); + symbol(&__atomic_fetch_sub_4, "__atomic_fetch_sub_4"); + symbol(&__atomic_fetch_sub_8, "__atomic_fetch_sub_8"); + symbol(&__atomic_fetch_sub_16, "__atomic_fetch_sub_16"); - @export(&__atomic_fetch_and_1, .{ .name = "__atomic_fetch_and_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_and_2, .{ .name = "__atomic_fetch_and_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_and_4, .{ .name = "__atomic_fetch_and_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_and_8, .{ .name = "__atomic_fetch_and_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_and_16, .{ .name = "__atomic_fetch_and_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_fetch_and_1, "__atomic_fetch_and_1"); + symbol(&__atomic_fetch_and_2, "__atomic_fetch_and_2"); + symbol(&__atomic_fetch_and_4, "__atomic_fetch_and_4"); + symbol(&__atomic_fetch_and_8, "__atomic_fetch_and_8"); + symbol(&__atomic_fetch_and_16, "__atomic_fetch_and_16"); - @export(&__atomic_fetch_or_1, .{ .name = "__atomic_fetch_or_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_or_2, .{ .name = "__atomic_fetch_or_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_or_4, .{ .name = "__atomic_fetch_or_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_or_8, .{ .name = "__atomic_fetch_or_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_or_16, .{ .name = "__atomic_fetch_or_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_fetch_or_1, "__atomic_fetch_or_1"); + symbol(&__atomic_fetch_or_2, "__atomic_fetch_or_2"); + symbol(&__atomic_fetch_or_4, "__atomic_fetch_or_4"); + symbol(&__atomic_fetch_or_8, "__atomic_fetch_or_8"); + symbol(&__atomic_fetch_or_16, "__atomic_fetch_or_16"); - @export(&__atomic_fetch_xor_1, .{ .name = "__atomic_fetch_xor_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_xor_2, .{ .name = "__atomic_fetch_xor_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_xor_4, .{ .name = "__atomic_fetch_xor_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_xor_8, .{ .name = "__atomic_fetch_xor_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_xor_16, .{ .name = "__atomic_fetch_xor_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_fetch_xor_1, "__atomic_fetch_xor_1"); + symbol(&__atomic_fetch_xor_2, "__atomic_fetch_xor_2"); + symbol(&__atomic_fetch_xor_4, "__atomic_fetch_xor_4"); + symbol(&__atomic_fetch_xor_8, "__atomic_fetch_xor_8"); + symbol(&__atomic_fetch_xor_16, "__atomic_fetch_xor_16"); - @export(&__atomic_fetch_nand_1, .{ .name = "__atomic_fetch_nand_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_nand_2, .{ .name = "__atomic_fetch_nand_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_nand_4, .{ .name = "__atomic_fetch_nand_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_nand_8, .{ .name = "__atomic_fetch_nand_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_nand_16, .{ .name = "__atomic_fetch_nand_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_fetch_nand_1, "__atomic_fetch_nand_1"); + symbol(&__atomic_fetch_nand_2, "__atomic_fetch_nand_2"); + symbol(&__atomic_fetch_nand_4, "__atomic_fetch_nand_4"); + symbol(&__atomic_fetch_nand_8, "__atomic_fetch_nand_8"); + symbol(&__atomic_fetch_nand_16, "__atomic_fetch_nand_16"); - @export(&__atomic_fetch_umax_1, .{ .name = "__atomic_fetch_umax_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_umax_2, .{ .name = "__atomic_fetch_umax_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_umax_4, .{ .name = "__atomic_fetch_umax_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_umax_8, .{ .name = "__atomic_fetch_umax_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_umax_16, .{ .name = "__atomic_fetch_umax_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_fetch_umax_1, "__atomic_fetch_umax_1"); + symbol(&__atomic_fetch_umax_2, "__atomic_fetch_umax_2"); + symbol(&__atomic_fetch_umax_4, "__atomic_fetch_umax_4"); + symbol(&__atomic_fetch_umax_8, "__atomic_fetch_umax_8"); + symbol(&__atomic_fetch_umax_16, "__atomic_fetch_umax_16"); - @export(&__atomic_fetch_umin_1, .{ .name = "__atomic_fetch_umin_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_umin_2, .{ .name = "__atomic_fetch_umin_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_umin_4, .{ .name = "__atomic_fetch_umin_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_umin_8, .{ .name = "__atomic_fetch_umin_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_fetch_umin_16, .{ .name = "__atomic_fetch_umin_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_fetch_umin_1, "__atomic_fetch_umin_1"); + symbol(&__atomic_fetch_umin_2, "__atomic_fetch_umin_2"); + symbol(&__atomic_fetch_umin_4, "__atomic_fetch_umin_4"); + symbol(&__atomic_fetch_umin_8, "__atomic_fetch_umin_8"); + symbol(&__atomic_fetch_umin_16, "__atomic_fetch_umin_16"); - @export(&__atomic_load_1, .{ .name = "__atomic_load_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_load_2, .{ .name = "__atomic_load_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_load_4, .{ .name = "__atomic_load_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_load_8, .{ .name = "__atomic_load_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_load_16, .{ .name = "__atomic_load_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_load_1, "__atomic_load_1"); + symbol(&__atomic_load_2, "__atomic_load_2"); + symbol(&__atomic_load_4, "__atomic_load_4"); + symbol(&__atomic_load_8, "__atomic_load_8"); + symbol(&__atomic_load_16, "__atomic_load_16"); - @export(&__atomic_store_1, .{ .name = "__atomic_store_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_store_2, .{ .name = "__atomic_store_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_store_4, .{ .name = "__atomic_store_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_store_8, .{ .name = "__atomic_store_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_store_16, .{ .name = "__atomic_store_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_store_1, "__atomic_store_1"); + symbol(&__atomic_store_2, "__atomic_store_2"); + symbol(&__atomic_store_4, "__atomic_store_4"); + symbol(&__atomic_store_8, "__atomic_store_8"); + symbol(&__atomic_store_16, "__atomic_store_16"); - @export(&__atomic_exchange_1, .{ .name = "__atomic_exchange_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_exchange_2, .{ .name = "__atomic_exchange_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_exchange_4, .{ .name = "__atomic_exchange_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_exchange_8, .{ .name = "__atomic_exchange_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_exchange_16, .{ .name = "__atomic_exchange_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_exchange_1, "__atomic_exchange_1"); + symbol(&__atomic_exchange_2, "__atomic_exchange_2"); + symbol(&__atomic_exchange_4, "__atomic_exchange_4"); + symbol(&__atomic_exchange_8, "__atomic_exchange_8"); + symbol(&__atomic_exchange_16, "__atomic_exchange_16"); - @export(&__atomic_compare_exchange_1, .{ .name = "__atomic_compare_exchange_1", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_compare_exchange_2, .{ .name = "__atomic_compare_exchange_2", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_compare_exchange_4, .{ .name = "__atomic_compare_exchange_4", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_compare_exchange_8, .{ .name = "__atomic_compare_exchange_8", .linkage = linkage, .visibility = visibility }); - @export(&__atomic_compare_exchange_16, .{ .name = "__atomic_compare_exchange_16", .linkage = linkage, .visibility = visibility }); + symbol(&__atomic_compare_exchange_1, "__atomic_compare_exchange_1"); + symbol(&__atomic_compare_exchange_2, "__atomic_compare_exchange_2"); + symbol(&__atomic_compare_exchange_4, "__atomic_compare_exchange_4"); + symbol(&__atomic_compare_exchange_8, "__atomic_compare_exchange_8"); + symbol(&__atomic_compare_exchange_16, "__atomic_compare_exchange_16"); } } diff --git a/lib/compiler_rt/aulldiv.zig b/lib/compiler_rt/aulldiv.zig index fbfa18dfd1..4ed92f39ee 100644 --- a/lib/compiler_rt/aulldiv.zig +++ b/lib/compiler_rt/aulldiv.zig @@ -1,15 +1,13 @@ -const std = @import("std"); const builtin = @import("builtin"); -const arch = builtin.cpu.arch; -const os = builtin.os.tag; -const abi = builtin.abi; -const common = @import("common.zig"); + +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_windows_x86_msvc_abi) { + if (compiler_rt.want_windows_x86_msvc_abi) { // Don't let LLVM apply the stdcall name mangling on those MSVC builtins - @export(&_alldiv, .{ .name = "\x01__alldiv", .linkage = common.linkage, .visibility = common.visibility }); - @export(&_aulldiv, .{ .name = "\x01__aulldiv", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&_alldiv, "\x01__alldiv"); + symbol(&_aulldiv, "\x01__aulldiv"); } } diff --git a/lib/compiler_rt/aullrem.zig b/lib/compiler_rt/aullrem.zig index ea12c16a06..efb8f15b73 100644 --- a/lib/compiler_rt/aullrem.zig +++ b/lib/compiler_rt/aullrem.zig @@ -3,13 +3,14 @@ const builtin = @import("builtin"); const arch = builtin.cpu.arch; const os = builtin.os.tag; const abi = builtin.abi; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - if (common.want_windows_x86_msvc_abi) { + if (compiler_rt.want_windows_x86_msvc_abi) { // Don't let LLVM apply the stdcall name mangling on those MSVC builtins - @export(&_allrem, .{ .name = "\x01__allrem", .linkage = common.linkage, .visibility = common.visibility }); - @export(&_aullrem, .{ .name = "\x01__aullrem", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&_allrem, "\x01__allrem"); + symbol(&_aullrem, "\x01__aullrem"); } } diff --git a/lib/compiler_rt/bcmp.zig b/lib/compiler_rt/bcmp.zig deleted file mode 100644 index eb1fca21f0..0000000000 --- a/lib/compiler_rt/bcmp.zig +++ /dev/null @@ -1,30 +0,0 @@ -const std = @import("std"); -const common = @import("./common.zig"); - -comptime { - @export(&bcmp, .{ .name = "bcmp", .linkage = common.linkage, .visibility = common.visibility }); -} - -pub fn bcmp(vl: [*]allowzero const u8, vr: [*]allowzero const u8, n: usize) callconv(.c) c_int { - @setRuntimeSafety(false); - - var index: usize = 0; - while (index != n) : (index += 1) { - if (vl[index] != vr[index]) { - return 1; - } - } - - return 0; -} - -test "bcmp" { - const base_arr = &[_]u8{ 1, 1, 1 }; - const arr1 = &[_]u8{ 1, 1, 1 }; - const arr2 = &[_]u8{ 1, 0, 1 }; - const arr3 = &[_]u8{ 1, 2, 1 }; - - try std.testing.expect(bcmp(base_arr[0..], arr1[0..], base_arr.len) == 0); - try std.testing.expect(bcmp(base_arr[0..], arr2[0..], base_arr.len) != 0); - try std.testing.expect(bcmp(base_arr[0..], arr3[0..], base_arr.len) != 0); -} diff --git a/lib/compiler_rt/bitreverse.zig b/lib/compiler_rt/bitreverse.zig index 6dbeac77d9..dda620152d 100644 --- a/lib/compiler_rt/bitreverse.zig +++ b/lib/compiler_rt/bitreverse.zig @@ -1,11 +1,12 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__bitreversesi2, .{ .name = "__bitreversesi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__bitreversedi2, .{ .name = "__bitreversedi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__bitreverseti2, .{ .name = "__bitreverseti2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__bitreversesi2, "__bitreversesi2"); + symbol(&__bitreversedi2, "__bitreversedi2"); + symbol(&__bitreverseti2, "__bitreverseti2"); } inline fn bitreverseXi2(comptime T: type, a: T) T { diff --git a/lib/compiler_rt/bswap.zig b/lib/compiler_rt/bswap.zig index e6f634c66f..94c3294eaf 100644 --- a/lib/compiler_rt/bswap.zig +++ b/lib/compiler_rt/bswap.zig @@ -1,11 +1,12 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__bswapsi2, .{ .name = "__bswapsi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__bswapdi2, .{ .name = "__bswapdi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__bswapti2, .{ .name = "__bswapti2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__bswapsi2, "__bswapsi2"); + symbol(&__bswapdi2, "__bswapdi2"); + symbol(&__bswapti2, "__bswapti2"); } // bswap - byteswap diff --git a/lib/compiler_rt/clear_cache.zig b/lib/compiler_rt/clear_cache.zig index 0e3b5d371f..2a8226c130 100644 --- a/lib/compiler_rt/clear_cache.zig +++ b/lib/compiler_rt/clear_cache.zig @@ -2,7 +2,8 @@ const std = @import("std"); const builtin = @import("builtin"); const arch = builtin.cpu.arch; const os = builtin.os.tag; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; // Ported from llvm-project d32170dbd5b0d54436537b6b75beaf44324e0c28 @@ -188,7 +189,7 @@ fn clear_cache(start: usize, end: usize) callconv(.c) void { } fn exportIt() void { - @export(&clear_cache, .{ .name = "__clear_cache", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&clear_cache, "__clear_cache"); } // MIPS-only diff --git a/lib/compiler_rt/cmp.zig b/lib/compiler_rt/cmp.zig index cac23a7508..9b123f5007 100644 --- a/lib/compiler_rt/cmp.zig +++ b/lib/compiler_rt/cmp.zig @@ -1,14 +1,15 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__cmpsi2, .{ .name = "__cmpsi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__cmpdi2, .{ .name = "__cmpdi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__cmpti2, .{ .name = "__cmpti2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ucmpsi2, .{ .name = "__ucmpsi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ucmpdi2, .{ .name = "__ucmpdi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ucmpti2, .{ .name = "__ucmpti2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__cmpsi2, "__cmpsi2"); + symbol(&__cmpdi2, "__cmpdi2"); + symbol(&__cmpti2, "__cmpti2"); + symbol(&__ucmpsi2, "__ucmpsi2"); + symbol(&__ucmpdi2, "__ucmpdi2"); + symbol(&__ucmpti2, "__ucmpti2"); } // cmp - signed compare diff --git a/lib/compiler_rt/cmpdf2.zig b/lib/compiler_rt/cmpdf2.zig index ebec596f27..7a9295bcdb 100644 --- a/lib/compiler_rt/cmpdf2.zig +++ b/lib/compiler_rt/cmpdf2.zig @@ -1,19 +1,20 @@ ///! The quoted behavior definitions are from ///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const comparef = @import("./comparef.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_aeabi) { - @export(&__aeabi_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_dcmpeq, "__aeabi_dcmpeq"); + symbol(&__aeabi_dcmplt, "__aeabi_dcmplt"); + symbol(&__aeabi_dcmple, "__aeabi_dcmple"); } else { - @export(&__eqdf2, .{ .name = "__eqdf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__nedf2, .{ .name = "__nedf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ledf2, .{ .name = "__ledf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__cmpdf2, .{ .name = "__cmpdf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ltdf2, .{ .name = "__ltdf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__eqdf2, "__eqdf2"); + symbol(&__nedf2, "__nedf2"); + symbol(&__ledf2, "__ledf2"); + symbol(&__cmpdf2, "__cmpdf2"); + symbol(&__ltdf2, "__ltdf2"); } } diff --git a/lib/compiler_rt/cmphf2.zig b/lib/compiler_rt/cmphf2.zig deleted file mode 100644 index ea70e71e16..0000000000 --- a/lib/compiler_rt/cmphf2.zig +++ /dev/null @@ -1,48 +0,0 @@ -///! The quoted behavior definitions are from -///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines -const common = @import("./common.zig"); -const comparef = @import("./comparef.zig"); - -comptime { - @export(&__eqhf2, .{ .name = "__eqhf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__nehf2, .{ .name = "__nehf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__lehf2, .{ .name = "__lehf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__cmphf2, .{ .name = "__cmphf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__lthf2, .{ .name = "__lthf2", .linkage = common.linkage, .visibility = common.visibility }); -} - -/// "These functions calculate a <=> b. That is, if a is less than b, they return -1; -/// if a is greater than b, they return 1; and if a and b are equal they return 0. -/// If either argument is NaN they return 1..." -/// -/// Note that this matches the definition of `__lehf2`, `__eqhf2`, `__nehf2`, `__cmphf2`, -/// and `__lthf2`. -fn __cmphf2(a: f16, b: f16) callconv(.c) i32 { - return @intFromEnum(comparef.cmpf2(f16, comparef.LE, a, b)); -} - -/// "These functions return a value less than or equal to zero if neither argument is NaN, -/// and a is less than or equal to b." -pub fn __lehf2(a: f16, b: f16) callconv(.c) i32 { - return __cmphf2(a, b); -} - -/// "These functions return zero if neither argument is NaN, and a and b are equal." -/// Note that due to some kind of historical accident, __eqhf2 and __nehf2 are defined -/// to have the same return value. -pub fn __eqhf2(a: f16, b: f16) callconv(.c) i32 { - return __cmphf2(a, b); -} - -/// "These functions return a nonzero value if either argument is NaN, or if a and b are unequal." -/// Note that due to some kind of historical accident, __eqhf2 and __nehf2 are defined -/// to have the same return value. -pub fn __nehf2(a: f16, b: f16) callconv(.c) i32 { - return __cmphf2(a, b); -} - -/// "These functions return a value less than zero if neither argument is NaN, and a -/// is strictly less than b." -pub fn __lthf2(a: f16, b: f16) callconv(.c) i32 { - return __cmphf2(a, b); -} diff --git a/lib/compiler_rt/cmpsf2.zig b/lib/compiler_rt/cmpsf2.zig deleted file mode 100644 index 4b200198e6..0000000000 --- a/lib/compiler_rt/cmpsf2.zig +++ /dev/null @@ -1,66 +0,0 @@ -///! The quoted behavior definitions are from -///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines -const common = @import("./common.zig"); -const comparef = @import("./comparef.zig"); - -comptime { - if (common.want_aeabi) { - @export(&__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = common.linkage, .visibility = common.visibility }); - } else { - @export(&__eqsf2, .{ .name = "__eqsf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__nesf2, .{ .name = "__nesf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__lesf2, .{ .name = "__lesf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__cmpsf2, .{ .name = "__cmpsf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ltsf2, .{ .name = "__ltsf2", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -/// "These functions calculate a <=> b. That is, if a is less than b, they return -1; -/// if a is greater than b, they return 1; and if a and b are equal they return 0. -/// If either argument is NaN they return 1..." -/// -/// Note that this matches the definition of `__lesf2`, `__eqsf2`, `__nesf2`, `__cmpsf2`, -/// and `__ltsf2`. -fn __cmpsf2(a: f32, b: f32) callconv(.c) i32 { - return @intFromEnum(comparef.cmpf2(f32, comparef.LE, a, b)); -} - -/// "These functions return a value less than or equal to zero if neither argument is NaN, -/// and a is less than or equal to b." -pub fn __lesf2(a: f32, b: f32) callconv(.c) i32 { - return __cmpsf2(a, b); -} - -/// "These functions return zero if neither argument is NaN, and a and b are equal." -/// Note that due to some kind of historical accident, __eqsf2 and __nesf2 are defined -/// to have the same return value. -pub fn __eqsf2(a: f32, b: f32) callconv(.c) i32 { - return __cmpsf2(a, b); -} - -/// "These functions return a nonzero value if either argument is NaN, or if a and b are unequal." -/// Note that due to some kind of historical accident, __eqsf2 and __nesf2 are defined -/// to have the same return value. -pub fn __nesf2(a: f32, b: f32) callconv(.c) i32 { - return __cmpsf2(a, b); -} - -/// "These functions return a value less than zero if neither argument is NaN, and a -/// is strictly less than b." -pub fn __ltsf2(a: f32, b: f32) callconv(.c) i32 { - return __cmpsf2(a, b); -} - -fn __aeabi_fcmpeq(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 { - return @intFromBool(comparef.cmpf2(f32, comparef.LE, a, b) == .Equal); -} - -fn __aeabi_fcmplt(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 { - return @intFromBool(comparef.cmpf2(f32, comparef.LE, a, b) == .Less); -} - -fn __aeabi_fcmple(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 { - return @intFromBool(comparef.cmpf2(f32, comparef.LE, a, b) != .Greater); -} diff --git a/lib/compiler_rt/cmptf2.zig b/lib/compiler_rt/cmptf2.zig index 3188ecf90e..bdffc97f86 100644 --- a/lib/compiler_rt/cmptf2.zig +++ b/lib/compiler_rt/cmptf2.zig @@ -1,28 +1,29 @@ ///! The quoted behavior definitions are from ///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const comparef = @import("./comparef.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_ppc_abi) { - @export(&__eqtf2, .{ .name = "__eqkf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__netf2, .{ .name = "__nekf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__lttf2, .{ .name = "__ltkf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__letf2, .{ .name = "__lekf2", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_cmp, .{ .name = "_Qp_cmp", .linkage = common.linkage, .visibility = common.visibility }); - @export(&_Qp_feq, .{ .name = "_Qp_feq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&_Qp_fne, .{ .name = "_Qp_fne", .linkage = common.linkage, .visibility = common.visibility }); - @export(&_Qp_flt, .{ .name = "_Qp_flt", .linkage = common.linkage, .visibility = common.visibility }); - @export(&_Qp_fle, .{ .name = "_Qp_fle", .linkage = common.linkage, .visibility = common.visibility }); - @export(&_Qp_fgt, .{ .name = "_Qp_fgt", .linkage = common.linkage, .visibility = common.visibility }); - @export(&_Qp_fge, .{ .name = "_Qp_fge", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__eqtf2, "__eqkf2"); + symbol(&__netf2, "__nekf2"); + symbol(&__lttf2, "__ltkf2"); + symbol(&__letf2, "__lekf2"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_cmp, "_Qp_cmp"); + symbol(&_Qp_feq, "_Qp_feq"); + symbol(&_Qp_fne, "_Qp_fne"); + symbol(&_Qp_flt, "_Qp_flt"); + symbol(&_Qp_fle, "_Qp_fle"); + symbol(&_Qp_fgt, "_Qp_fgt"); + symbol(&_Qp_fge, "_Qp_fge"); } - @export(&__eqtf2, .{ .name = "__eqtf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__netf2, .{ .name = "__netf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__letf2, .{ .name = "__letf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__cmptf2, .{ .name = "__cmptf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__lttf2, .{ .name = "__lttf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__eqtf2, "__eqtf2"); + symbol(&__netf2, "__netf2"); + symbol(&__letf2, "__letf2"); + symbol(&__cmptf2, "__cmptf2"); + symbol(&__lttf2, "__lttf2"); } /// "These functions calculate a <=> b. That is, if a is less than b, they return -1; diff --git a/lib/compiler_rt/cmpxf2.zig b/lib/compiler_rt/cmpxf2.zig index f70de9c0b6..c6e2e375a1 100644 --- a/lib/compiler_rt/cmpxf2.zig +++ b/lib/compiler_rt/cmpxf2.zig @@ -1,14 +1,15 @@ ///! The quoted behavior definitions are from ///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const comparef = @import("./comparef.zig"); comptime { - @export(&__eqxf2, .{ .name = "__eqxf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__nexf2, .{ .name = "__nexf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__lexf2, .{ .name = "__lexf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__cmpxf2, .{ .name = "__cmpxf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ltxf2, .{ .name = "__ltxf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__eqxf2, "__eqxf2"); + symbol(&__nexf2, "__nexf2"); + symbol(&__lexf2, "__lexf2"); + symbol(&__cmpxf2, "__cmpxf2"); + symbol(&__ltxf2, "__ltxf2"); } /// "These functions calculate a <=> b. That is, if a is less than b, they return -1; diff --git a/lib/compiler_rt/common.zig b/lib/compiler_rt/common.zig deleted file mode 100644 index a9b4c2296c..0000000000 --- a/lib/compiler_rt/common.zig +++ /dev/null @@ -1,310 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const native_endian = builtin.cpu.arch.endian(); -const ofmt_c = builtin.object_format == .c; - -/// For now, we prefer weak linkage because some of the routines we implement here may also be -/// provided by system/dynamic libc. Eventually we should be more disciplined about this on a -/// per-symbol, per-target basis: https://github.com/ziglang/zig/issues/11883 -pub const linkage: std.builtin.GlobalLinkage = if (builtin.is_test) - .internal -else if (ofmt_c) - .strong -else - .weak; - -/// Determines the symbol's visibility to other objects. -/// For WebAssembly this allows the symbol to be resolved to other modules, but will not -/// export it to the host runtime. -pub const visibility: std.builtin.SymbolVisibility = if (linkage == .internal or builtin.link_mode == .dynamic) - .default -else - .hidden; - -pub const PreferredLoadStoreElement = element: { - if (std.simd.suggestVectorLength(u8)) |vec_size| { - const Vec = @Vector(vec_size, u8); - - if (@sizeOf(Vec) == vec_size and std.math.isPowerOfTwo(vec_size)) { - break :element Vec; - } - } - break :element usize; -}; - -pub const want_aeabi = switch (builtin.abi) { - .eabi, - .eabihf, - .musleabi, - .musleabihf, - .gnueabi, - .gnueabihf, - .android, - .androideabi, - => switch (builtin.cpu.arch) { - .arm, .armeb, .thumb, .thumbeb => true, - else => false, - }, - else => false, -}; - -/// These functions are required on Windows on ARM. They are provided by MSVC libc, but in libc-less -/// builds or when linking MinGW libc they are our responsibility. -/// Temporarily used for thumb-uefi until https://github.com/ziglang/zig/issues/21630 is addressed. -pub const want_windows_arm_abi = e: { - if (!builtin.cpu.arch.isArm()) break :e false; - switch (builtin.os.tag) { - .windows, .uefi => {}, - else => break :e false, - } - // The ABI is needed, but it's only our reponsibility if libc won't provide it. - break :e builtin.abi.isGnu() or !builtin.link_libc; -}; - -/// These functions are required by on Windows on x86 on some ABIs. They are provided by MSVC libc, -/// but in libc-less builds they are our responsibility. -pub const want_windows_x86_msvc_abi = e: { - if (builtin.cpu.arch != .x86) break :e false; - if (builtin.os.tag != .windows) break :e false; - switch (builtin.abi) { - .none, .msvc, .itanium => {}, - else => break :e false, - } - // The ABI is needed, but it's only our responsibility if libc won't provide it. - break :e !builtin.link_libc; -}; - -pub const want_ppc_abi = builtin.cpu.arch.isPowerPC(); - -pub const want_float_exceptions = !builtin.cpu.arch.isWasm(); - -// Libcalls that involve u128 on Windows x86-64 are expected by LLVM to use the -// calling convention of @Vector(2, u64), rather than what's standard. -pub const want_windows_v2u64_abi = builtin.os.tag == .windows and builtin.cpu.arch == .x86_64 and !ofmt_c; - -/// This governs whether to use these symbol names for f16/f32 conversions -/// rather than the standard names: -/// * __gnu_f2h_ieee -/// * __gnu_h2f_ieee -/// Known correct configurations: -/// x86_64-freestanding-none => true -/// x86_64-linux-none => true -/// x86_64-linux-gnu => true -/// x86_64-linux-musl => true -/// x86_64-linux-eabi => true -/// arm-linux-musleabihf => true -/// arm-linux-gnueabihf => true -/// arm-linux-eabihf => false -/// wasm32-wasi-musl => false -/// wasm32-freestanding-none => false -/// x86_64-windows-gnu => true -/// x86_64-windows-msvc => true -/// any-macos-any => false -pub const gnu_f16_abi = switch (builtin.cpu.arch) { - .wasm32, - .wasm64, - .riscv64, - .riscv64be, - .riscv32, - .riscv32be, - => false, - - .x86, .x86_64 => true, - - .arm, .armeb, .thumb, .thumbeb => switch (builtin.abi) { - .eabi, .eabihf => false, - else => true, - }, - - else => !builtin.os.tag.isDarwin(), -}; - -pub const want_sparc_abi = builtin.cpu.arch.isSPARC(); - -pub const test_safety = switch (builtin.zig_backend) { - .stage2_aarch64 => false, - else => builtin.is_test, -}; - -/// This seems to mostly correspond to `clang::TargetInfo::HasFloat16`. -pub fn F16T(comptime OtherType: type) type { - return switch (builtin.cpu.arch) { - .amdgcn, - .arm, - .armeb, - .thumb, - .thumbeb, - .aarch64, - .aarch64_be, - .hexagon, - .loongarch32, - .loongarch64, - .nvptx, - .nvptx64, - .riscv32, - .riscv32be, - .riscv64, - .riscv64be, - .s390x, - .spirv32, - .spirv64, - => f16, - .x86, .x86_64 => if (builtin.target.os.tag.isDarwin()) switch (OtherType) { - // Starting with LLVM 16, Darwin uses different abi for f16 - // depending on the type of the other return/argument..??? - f32, f64 => u16, - f80, f128 => f16, - else => unreachable, - } else f16, - else => u16, - }; -} - -pub fn wideMultiply(comptime Z: type, a: Z, b: Z, hi: *Z, lo: *Z) void { - switch (Z) { - u16 => { - // 16x16 --> 32 bit multiply - const product = @as(u32, a) * @as(u32, b); - hi.* = @intCast(product >> 16); - lo.* = @truncate(product); - }, - u32 => { - // 32x32 --> 64 bit multiply - const product = @as(u64, a) * @as(u64, b); - hi.* = @truncate(product >> 32); - lo.* = @truncate(product); - }, - u64 => { - const S = struct { - fn loWord(x: u64) u64 { - return @as(u32, @truncate(x)); - } - fn hiWord(x: u64) u64 { - return @as(u32, @truncate(x >> 32)); - } - }; - // 64x64 -> 128 wide multiply for platforms that don't have such an operation; - // many 64-bit platforms have this operation, but they tend to have hardware - // floating-point, so we don't bother with a special case for them here. - // Each of the component 32x32 -> 64 products - const plolo: u64 = S.loWord(a) * S.loWord(b); - const plohi: u64 = S.loWord(a) * S.hiWord(b); - const philo: u64 = S.hiWord(a) * S.loWord(b); - const phihi: u64 = S.hiWord(a) * S.hiWord(b); - // Sum terms that contribute to lo in a way that allows us to get the carry - const r0: u64 = S.loWord(plolo); - const r1: u64 = S.hiWord(plolo) +% S.loWord(plohi) +% S.loWord(philo); - lo.* = r0 +% (r1 << 32); - // Sum terms contributing to hi with the carry from lo - hi.* = S.hiWord(plohi) +% S.hiWord(philo) +% S.hiWord(r1) +% phihi; - }, - u128 => { - const Word_LoMask: u64 = 0x00000000ffffffff; - const Word_HiMask: u64 = 0xffffffff00000000; - const Word_FullMask: u64 = 0xffffffffffffffff; - const S = struct { - fn Word_1(x: u128) u64 { - return @as(u32, @truncate(x >> 96)); - } - fn Word_2(x: u128) u64 { - return @as(u32, @truncate(x >> 64)); - } - fn Word_3(x: u128) u64 { - return @as(u32, @truncate(x >> 32)); - } - fn Word_4(x: u128) u64 { - return @as(u32, @truncate(x)); - } - }; - // 128x128 -> 256 wide multiply for platforms that don't have such an operation; - // many 64-bit platforms have this operation, but they tend to have hardware - // floating-point, so we don't bother with a special case for them here. - - const product11: u64 = S.Word_1(a) * S.Word_1(b); - const product12: u64 = S.Word_1(a) * S.Word_2(b); - const product13: u64 = S.Word_1(a) * S.Word_3(b); - const product14: u64 = S.Word_1(a) * S.Word_4(b); - const product21: u64 = S.Word_2(a) * S.Word_1(b); - const product22: u64 = S.Word_2(a) * S.Word_2(b); - const product23: u64 = S.Word_2(a) * S.Word_3(b); - const product24: u64 = S.Word_2(a) * S.Word_4(b); - const product31: u64 = S.Word_3(a) * S.Word_1(b); - const product32: u64 = S.Word_3(a) * S.Word_2(b); - const product33: u64 = S.Word_3(a) * S.Word_3(b); - const product34: u64 = S.Word_3(a) * S.Word_4(b); - const product41: u64 = S.Word_4(a) * S.Word_1(b); - const product42: u64 = S.Word_4(a) * S.Word_2(b); - const product43: u64 = S.Word_4(a) * S.Word_3(b); - const product44: u64 = S.Word_4(a) * S.Word_4(b); - - const sum0: u128 = @as(u128, product44); - const sum1: u128 = @as(u128, product34) +% - @as(u128, product43); - const sum2: u128 = @as(u128, product24) +% - @as(u128, product33) +% - @as(u128, product42); - const sum3: u128 = @as(u128, product14) +% - @as(u128, product23) +% - @as(u128, product32) +% - @as(u128, product41); - const sum4: u128 = @as(u128, product13) +% - @as(u128, product22) +% - @as(u128, product31); - const sum5: u128 = @as(u128, product12) +% - @as(u128, product21); - const sum6: u128 = @as(u128, product11); - - const r0: u128 = (sum0 & Word_FullMask) +% - ((sum1 & Word_LoMask) << 32); - const r1: u128 = (sum0 >> 64) +% - ((sum1 >> 32) & Word_FullMask) +% - (sum2 & Word_FullMask) +% - ((sum3 << 32) & Word_HiMask); - - lo.* = r0 +% (r1 << 64); - hi.* = (r1 >> 64) +% - (sum1 >> 96) +% - (sum2 >> 64) +% - (sum3 >> 32) +% - sum4 +% - (sum5 << 32) +% - (sum6 << 64); - }, - else => @compileError("unsupported"), - } -} - -pub fn normalize(comptime T: type, significand: *std.meta.Int(.unsigned, @typeInfo(T).float.bits)) i32 { - const Z = std.meta.Int(.unsigned, @typeInfo(T).float.bits); - const integerBit = @as(Z, 1) << std.math.floatFractionalBits(T); - - const shift = @clz(significand.*) - @clz(integerBit); - significand.* <<= @as(std.math.Log2Int(Z), @intCast(shift)); - return @as(i32, 1) - shift; -} - -pub inline fn fneg(a: anytype) @TypeOf(a) { - const F = @TypeOf(a); - const bits = @typeInfo(F).float.bits; - const U = @Int(.unsigned, bits); - const sign_bit_mask = @as(U, 1) << (bits - 1); - const negated = @as(U, @bitCast(a)) ^ sign_bit_mask; - return @bitCast(negated); -} - -/// Allows to access underlying bits as two equally sized lower and higher -/// signed or unsigned integers. -pub fn HalveInt(comptime T: type, comptime signed_half: bool) type { - return extern union { - pub const bits = @divExact(@typeInfo(T).int.bits, 2); - pub const HalfTU = std.meta.Int(.unsigned, bits); - pub const HalfTS = std.meta.Int(.signed, bits); - pub const HalfT = if (signed_half) HalfTS else HalfTU; - - all: T, - s: if (native_endian == .little) - extern struct { low: HalfT, high: HalfT } - else - extern struct { high: HalfT, low: HalfT }, - }; -} diff --git a/lib/compiler_rt/comparef.zig b/lib/compiler_rt/comparef.zig index 76f04f430a..3e97477589 100644 --- a/lib/compiler_rt/comparef.zig +++ b/lib/compiler_rt/comparef.zig @@ -1,5 +1,149 @@ const std = @import("std"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; + +comptime { + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_fcmpun, "__aeabi_fcmpun"); + } else { + symbol(&__unordsf2, "__unordsf2"); + } + + symbol(&__unordxf2, "__unordxf2"); + + symbol(&__eqhf2, "__eqhf2"); + symbol(&__nehf2, "__nehf2"); + symbol(&__lehf2, "__lehf2"); + symbol(&__cmphf2, "__cmphf2"); + symbol(&__lthf2, "__lthf2"); + + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_fcmpeq, "__aeabi_fcmpeq"); + symbol(&__aeabi_fcmplt, "__aeabi_fcmplt"); + symbol(&__aeabi_fcmple, "__aeabi_fcmple"); + } else { + symbol(&__eqsf2, "__eqsf2"); + symbol(&__nesf2, "__nesf2"); + symbol(&__lesf2, "__lesf2"); + symbol(&__cmpsf2, "__cmpsf2"); + symbol(&__ltsf2, "__ltsf2"); + } + + if (compiler_rt.want_ppc_abi) { + symbol(&__unordtf2, "__unordkf2"); + } else if (compiler_rt.want_sparc_abi) { + // These exports are handled in cmptf2.zig because unordered comparisons + // are based on calling _Qp_cmp. + } + symbol(&__unordtf2, "__unordtf2"); + symbol(&__unordhf2, "__unordhf2"); +} + +pub fn __unordhf2(a: f16, b: f16) callconv(.c) i32 { + return unordcmp(f16, a, b); +} + +pub fn __unordtf2(a: f128, b: f128) callconv(.c) i32 { + return unordcmp(f128, a, b); +} + +/// "These functions calculate a <=> b. That is, if a is less than b, they return -1; +/// if a is greater than b, they return 1; and if a and b are equal they return 0. +/// If either argument is NaN they return 1..." +/// +/// Note that this matches the definition of `__lesf2`, `__eqsf2`, `__nesf2`, `__cmpsf2`, +/// and `__ltsf2`. +fn __cmpsf2(a: f32, b: f32) callconv(.c) i32 { + return @intFromEnum(cmpf2(f32, LE, a, b)); +} + +/// "These functions return a value less than or equal to zero if neither argument is NaN, +/// and a is less than or equal to b." +pub fn __lesf2(a: f32, b: f32) callconv(.c) i32 { + return __cmpsf2(a, b); +} + +/// "These functions return zero if neither argument is NaN, and a and b are equal." +/// Note that due to some kind of historical accident, __eqsf2 and __nesf2 are defined +/// to have the same return value. +pub fn __eqsf2(a: f32, b: f32) callconv(.c) i32 { + return __cmpsf2(a, b); +} + +/// "These functions return a nonzero value if either argument is NaN, or if a and b are unequal." +/// Note that due to some kind of historical accident, __eqsf2 and __nesf2 are defined +/// to have the same return value. +pub fn __nesf2(a: f32, b: f32) callconv(.c) i32 { + return __cmpsf2(a, b); +} + +/// "These functions return a value less than zero if neither argument is NaN, and a +/// is strictly less than b." +pub fn __ltsf2(a: f32, b: f32) callconv(.c) i32 { + return __cmpsf2(a, b); +} + +fn __aeabi_fcmpeq(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 { + return @intFromBool(cmpf2(f32, LE, a, b) == .Equal); +} + +fn __aeabi_fcmplt(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 { + return @intFromBool(cmpf2(f32, LE, a, b) == .Less); +} + +fn __aeabi_fcmple(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 { + return @intFromBool(cmpf2(f32, LE, a, b) != .Greater); +} + +/// "These functions calculate a <=> b. That is, if a is less than b, they return -1; +/// if a is greater than b, they return 1; and if a and b are equal they return 0. +/// If either argument is NaN they return 1..." +/// +/// Note that this matches the definition of `__lehf2`, `__eqhf2`, `__nehf2`, `__cmphf2`, +/// and `__lthf2`. +fn __cmphf2(a: f16, b: f16) callconv(.c) i32 { + return @intFromEnum(cmpf2(f16, LE, a, b)); +} + +/// "These functions return a value less than or equal to zero if neither argument is NaN, +/// and a is less than or equal to b." +fn __lehf2(a: f16, b: f16) callconv(.c) i32 { + return __cmphf2(a, b); +} + +/// "These functions return zero if neither argument is NaN, and a and b are equal." +/// Note that due to some kind of historical accident, __eqhf2 and __nehf2 are defined +/// to have the same return value. +fn __eqhf2(a: f16, b: f16) callconv(.c) i32 { + return __cmphf2(a, b); +} + +/// "These functions return a nonzero value if either argument is NaN, or if a and b are unequal." +/// Note that due to some kind of historical accident, __eqhf2 and __nehf2 are defined +/// to have the same return value. +fn __nehf2(a: f16, b: f16) callconv(.c) i32 { + return __cmphf2(a, b); +} + +/// "These functions return a value less than zero if neither argument is NaN, and a +/// is strictly less than b." +fn __lthf2(a: f16, b: f16) callconv(.c) i32 { + return __cmphf2(a, b); +} + +fn __unordxf2(a: f80, b: f80) callconv(.c) i32 { + return unordcmp(f80, a, b); +} + +pub fn __unordsf2(a: f32, b: f32) callconv(.c) i32 { + return unordcmp(f32, a, b); +} + +fn __aeabi_fcmpun(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 { + return unordcmp(f32, a, b); +} + pub const LE = enum(i32) { Less = -1, Equal = 0, diff --git a/lib/compiler_rt/comparesf2_test.zig b/lib/compiler_rt/comparesf2_test.zig index 65e78da99e..d42e1ca6db 100644 --- a/lib/compiler_rt/comparesf2_test.zig +++ b/lib/compiler_rt/comparesf2_test.zig @@ -5,15 +5,15 @@ const std = @import("std"); const builtin = @import("builtin"); -const __eqsf2 = @import("./cmpsf2.zig").__eqsf2; -const __lesf2 = @import("./cmpsf2.zig").__lesf2; -const __ltsf2 = @import("./cmpsf2.zig").__ltsf2; -const __nesf2 = @import("./cmpsf2.zig").__nesf2; +const __eqsf2 = @import("./comparef.zig").__eqsf2; +const __lesf2 = @import("./comparef.zig").__lesf2; +const __ltsf2 = @import("./comparef.zig").__ltsf2; +const __nesf2 = @import("./comparef.zig").__nesf2; const __gesf2 = @import("./gesf2.zig").__gesf2; const __gtsf2 = @import("./gesf2.zig").__gtsf2; -const __unordsf2 = @import("./unordsf2.zig").__unordsf2; +const __unordsf2 = @import("./comparef.zig").__unordsf2; const TestVector = struct { a: f32, diff --git a/lib/compiler_rt/cos.zig b/lib/compiler_rt/cos.zig index 3384887385..3534e7837c 100644 --- a/lib/compiler_rt/cos.zig +++ b/lib/compiler_rt/cos.zig @@ -2,22 +2,23 @@ const std = @import("std"); const math = std.math; const mem = std.mem; const expect = std.testing.expect; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const trig = @import("trig.zig"); const rem_pio2 = @import("rem_pio2.zig").rem_pio2; const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f; comptime { - @export(&__cosh, .{ .name = "__cosh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&cosf, .{ .name = "cosf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&cos, .{ .name = "cos", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__cosx, .{ .name = "__cosx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&cosq, .{ .name = "cosf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__cosh, "__cosh"); + symbol(&cosf, "cosf"); + symbol(&cos, "cos"); + symbol(&__cosx, "__cosx"); + if (compiler_rt.want_ppc_abi) { + symbol(&cosq, "cosf128"); } - @export(&cosq, .{ .name = "cosq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&cosl, .{ .name = "cosl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&cosq, "cosq"); + symbol(&cosl, "cosl"); } pub fn __cosh(a: f16) callconv(.c) f16 { @@ -39,7 +40,7 @@ pub fn cosf(x: f32) callconv(.c) f32 { if (ix <= 0x3f490fda) { // |x| ~<= pi/4 if (ix < 0x39800000) { // |x| < 2**-12 // raise inexact if x != 0 - if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); return 1.0; } return trig.__cosdf(x); @@ -90,7 +91,7 @@ pub fn cos(x: f64) callconv(.c) f64 { if (ix <= 0x3fe921fb) { if (ix < 0x3e46a09e) { // |x| < 2**-27 * sqrt(2) // raise inexact if x!=0 - if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); return 1.0; } return trig.__cos(x, 0); diff --git a/lib/compiler_rt/count0bits.zig b/lib/compiler_rt/count0bits.zig index 3696c89944..1208486464 100644 --- a/lib/compiler_rt/count0bits.zig +++ b/lib/compiler_rt/count0bits.zig @@ -1,17 +1,17 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const std = @import("std"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__clzsi2, .{ .name = "__clzsi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__clzdi2, .{ .name = "__clzdi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__clzti2, .{ .name = "__clzti2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ctzsi2, .{ .name = "__ctzsi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ctzdi2, .{ .name = "__ctzdi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ctzti2, .{ .name = "__ctzti2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ffssi2, .{ .name = "__ffssi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ffsdi2, .{ .name = "__ffsdi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ffsti2, .{ .name = "__ffsti2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__clzsi2, "__clzsi2"); + symbol(&__clzdi2, "__clzdi2"); + symbol(&__clzti2, "__clzti2"); + symbol(&__ctzsi2, "__ctzsi2"); + symbol(&__ctzdi2, "__ctzdi2"); + symbol(&__ctzti2, "__ctzti2"); + symbol(&__ffssi2, "__ffssi2"); + symbol(&__ffsdi2, "__ffsdi2"); + symbol(&__ffsti2, "__ffsti2"); } // clz - count leading zeroes diff --git a/lib/compiler_rt/divdc3.zig b/lib/compiler_rt/divdc3.zig index ce2797ee39..e26dd26d61 100644 --- a/lib/compiler_rt/divdc3.zig +++ b/lib/compiler_rt/divdc3.zig @@ -1,10 +1,10 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const divc3 = @import("./divc3.zig"); const Complex = @import("./mulc3.zig").Complex; comptime { if (@import("builtin").zig_backend != .stage2_c) { - @export(&__divdc3, .{ .name = "__divdc3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divdc3, "__divdc3"); } } diff --git a/lib/compiler_rt/divdf3.zig b/lib/compiler_rt/divdf3.zig index a94544165b..b8a9c1914e 100644 --- a/lib/compiler_rt/divdf3.zig +++ b/lib/compiler_rt/divdf3.zig @@ -3,18 +3,17 @@ //! https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divdf3.c const std = @import("std"); -const builtin = @import("builtin"); -const arch = builtin.cpu.arch; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; -const normalize = common.normalize; -const wideMultiply = common.wideMultiply; +const normalize = compiler_rt.normalize; +const wideMultiply = compiler_rt.wideMultiply; comptime { - if (common.want_aeabi) { - @export(&__aeabi_ddiv, .{ .name = "__aeabi_ddiv", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_ddiv, "__aeabi_ddiv"); } else { - @export(&__divdf3, .{ .name = "__divdf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divdf3, "__divdf3"); } } diff --git a/lib/compiler_rt/divhc3.zig b/lib/compiler_rt/divhc3.zig index 8243c545b1..c9668f4ca8 100644 --- a/lib/compiler_rt/divhc3.zig +++ b/lib/compiler_rt/divhc3.zig @@ -1,10 +1,11 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const divc3 = @import("./divc3.zig"); const Complex = @import("./mulc3.zig").Complex; comptime { if (@import("builtin").zig_backend != .stage2_c) { - @export(&__divhc3, .{ .name = "__divhc3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divhc3, "__divhc3"); } } diff --git a/lib/compiler_rt/divhf3.zig b/lib/compiler_rt/divhf3.zig index 84bfe37871..fc2710ff27 100644 --- a/lib/compiler_rt/divhf3.zig +++ b/lib/compiler_rt/divhf3.zig @@ -1,8 +1,8 @@ -const common = @import("common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const divsf3 = @import("./divsf3.zig"); comptime { - @export(&__divhf3, .{ .name = "__divhf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divhf3, "__divhf3"); } pub fn __divhf3(a: f16, b: f16) callconv(.c) f16 { diff --git a/lib/compiler_rt/divmodei4.zig b/lib/compiler_rt/divmodei4.zig index ab11452206..4fa168a675 100644 --- a/lib/compiler_rt/divmodei4.zig +++ b/lib/compiler_rt/divmodei4.zig @@ -1,15 +1,17 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const endian = builtin.cpu.arch.endian(); + +const std = @import("std"); + +const compiler_rt = @import("../compiler_rt.zig"); const udivmod = @import("udivmodei4.zig").divmod; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__divei4, .{ .name = "__divei4", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__modei4, .{ .name = "__modei4", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divei4, "__divei4"); + symbol(&__modei4, "__modei4"); } -const endian = builtin.cpu.arch.endian(); - inline fn limb(x: []u32, i: usize) *u32 { return if (endian == .little) &x[i] else &x[x.len - 1 - i]; } @@ -34,7 +36,7 @@ fn divmod(q: ?[]u32, r: ?[]u32, u: []u32, v: []u32) !void { } pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits)); const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size])); const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size])); @@ -43,7 +45,7 @@ pub fn __divei4(q_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) vo } pub fn __modei4(r_p: [*]u8, u_p: [*]u8, v_p: [*]u8, bits: usize) callconv(.c) void { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits)); const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size])); const u: []u32 = @ptrCast(@alignCast(u_p[0..byte_size])); diff --git a/lib/compiler_rt/divsc3.zig b/lib/compiler_rt/divsc3.zig index 504d8f7d67..9378bfab8c 100644 --- a/lib/compiler_rt/divsc3.zig +++ b/lib/compiler_rt/divsc3.zig @@ -1,10 +1,10 @@ -const common = @import("./common.zig"); const divc3 = @import("./divc3.zig"); const Complex = @import("./mulc3.zig").Complex; +const symbol = @import("../compiler_rt.zig").symbol; comptime { if (@import("builtin").zig_backend != .stage2_c) { - @export(&__divsc3, .{ .name = "__divsc3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divsc3, "__divsc3"); } } diff --git a/lib/compiler_rt/divsf3.zig b/lib/compiler_rt/divsf3.zig index dca1d49ebe..5406dc8ccf 100644 --- a/lib/compiler_rt/divsf3.zig +++ b/lib/compiler_rt/divsf3.zig @@ -3,17 +3,16 @@ //! https://github.com/llvm/llvm-project/commit/d674d96bc56c0f377879d01c9d8dfdaaa7859cdb/compiler-rt/lib/builtins/divsf3.c const std = @import("std"); -const builtin = @import("builtin"); -const arch = builtin.cpu.arch; -const common = @import("common.zig"); -const normalize = common.normalize; +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; +const normalize = compiler_rt.normalize; comptime { - if (common.want_aeabi) { - @export(&__aeabi_fdiv, .{ .name = "__aeabi_fdiv", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_fdiv, "__aeabi_fdiv"); } else { - @export(&__divsf3, .{ .name = "__divsf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divsf3, "__divsf3"); } } diff --git a/lib/compiler_rt/divtc3.zig b/lib/compiler_rt/divtc3.zig index 3bdf2a9033..b0e0f35f54 100644 --- a/lib/compiler_rt/divtc3.zig +++ b/lib/compiler_rt/divtc3.zig @@ -1,12 +1,13 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const divc3 = @import("./divc3.zig"); const Complex = @import("./mulc3.zig").Complex; +const symbol = @import("../compiler_rt.zig").symbol; comptime { if (@import("builtin").zig_backend != .stage2_c) { - if (common.want_ppc_abi) - @export(&__divtc3, .{ .name = "__divkc3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__divtc3, .{ .name = "__divtc3", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) + symbol(&__divtc3, "__divkc3"); + symbol(&__divtc3, "__divtc3"); } } diff --git a/lib/compiler_rt/divtf3.zig b/lib/compiler_rt/divtf3.zig index 6606d0de38..d5d76c3c8c 100644 --- a/lib/compiler_rt/divtf3.zig +++ b/lib/compiler_rt/divtf3.zig @@ -1,17 +1,18 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); -const normalize = common.normalize; -const wideMultiply = common.wideMultiply; +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; +const normalize = compiler_rt.normalize; +const wideMultiply = compiler_rt.wideMultiply; comptime { - if (common.want_ppc_abi) { - @export(&__divtf3, .{ .name = "__divkf3", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_div, .{ .name = "_Qp_div", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__divtf3, "__divkf3"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_div, "_Qp_div"); } - @export(&__divtf3, .{ .name = "__divtf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divtf3, "__divtf3"); } pub fn __divtf3(a: f128, b: f128) callconv(.c) f128 { @@ -221,10 +222,29 @@ inline fn div(a: f128, b: f128) f128 { // The rounded result is normal; return it. return @bitCast(absResult | quotientSign); } + // Result is denormal with exponent 0 + return @bitCast(absResult | quotientSign); + } else { + // For denormals with writtenExponent < 0, + // the implicit bit must be shifted into the mantissa (IEEE 754) + const shiftAmount = @as(u7, @intCast(1 - writtenExponent)); + + // Check for underflow + if (shiftAmount > significandBits) { + return @bitCast(quotientSign); + } + + // Round the quotient before pushing + const shouldRound = (residual << 1) > bSignificand; + const roundedQuotient = quotient +% @as(u113, @intFromBool(shouldRound)); + + // Move to the denormal range and apply the mask + const denormQuotient = roundedQuotient >> shiftAmount; + const absResult = denormQuotient & significandMask; + + // Add sign to denormal mantissa and return + return @bitCast(absResult | quotientSign); } - // Flush denormals to zero. In the future, it would be nice to add - // code to round them correctly. - return @bitCast(quotientSign); } else { const round = @intFromBool((residual << 1) >= bSignificand); // Clear the implicit bit diff --git a/lib/compiler_rt/divtf3_test.zig b/lib/compiler_rt/divtf3_test.zig index f8f2b0d188..4573d2ed85 100644 --- a/lib/compiler_rt/divtf3_test.zig +++ b/lib/compiler_rt/divtf3_test.zig @@ -46,4 +46,9 @@ test "divtf3" { try test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234, 0x1.edcba987d6bb3aa467754354321fp-4055, 0x50bf2e02f0798d36, 0x5e6fcb6b60044078); try test__divtf3(6.72420628622418701252535563464350521E-4932, 2.0, 0x0001000000000000, 0); try test__divtf3(1.0, 0x1.ffffffffffffffffffffffffffffp-1, 0x3FFF000000000000, 1); + + try test__divtf3(std.math.floatMin(f128), 2.0, 0x0000800000000000, 0x0000000000000000); + try test__divtf3(std.math.floatMin(f128), 4.0, 0x0000400000000000, 0x0000000000000000); + try test__divtf3(1.0, 0x1.0000000000000000000000000001p16382, 0x0000ffffffffffff, 0xfffffffffffffffe); + try test__divtf3(1.2, std.math.floatMax(f128), 0x00004ccccccccccc, 0xcccccccccccccccd); } diff --git a/lib/compiler_rt/divti3.zig b/lib/compiler_rt/divti3.zig deleted file mode 100644 index 9eb8dda187..0000000000 --- a/lib/compiler_rt/divti3.zig +++ /dev/null @@ -1,39 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const udivmod = @import("udivmod.zig").udivmod; -const arch = builtin.cpu.arch; -const common = @import("common.zig"); - -comptime { - if (common.want_windows_v2u64_abi) { - @export(&__divti3_windows_x86_64, .{ .name = "__divti3", .linkage = common.linkage, .visibility = common.visibility }); - } else { - @export(&__divti3, .{ .name = "__divti3", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -pub fn __divti3(a: i128, b: i128) callconv(.c) i128 { - return div(a, b); -} - -const v128 = @Vector(2, u64); - -fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.c) v128 { - return @bitCast(div(@bitCast(a), @bitCast(b))); -} - -inline fn div(a: i128, b: i128) i128 { - const s_a = a >> (128 - 1); - const s_b = b >> (128 - 1); - - const an = (a ^ s_a) -% s_a; - const bn = (b ^ s_b) -% s_b; - - const r = udivmod(u128, @bitCast(an), @bitCast(bn), null); - const s = s_a ^ s_b; - return (@as(i128, @bitCast(r)) ^ s) -% s; -} - -test { - _ = @import("divti3_test.zig"); -} diff --git a/lib/compiler_rt/divti3_test.zig b/lib/compiler_rt/divti3_test.zig index bcf45da3f2..34431d12af 100644 --- a/lib/compiler_rt/divti3_test.zig +++ b/lib/compiler_rt/divti3_test.zig @@ -1,4 +1,4 @@ -const __divti3 = @import("divti3.zig").__divti3; +const __divti3 = @import("udivmod.zig").__divti3; const testing = @import("std").testing; fn test__divti3(a: i128, b: i128, expected: i128) !void { diff --git a/lib/compiler_rt/divxc3.zig b/lib/compiler_rt/divxc3.zig index 6e5f7905dd..86c737a839 100644 --- a/lib/compiler_rt/divxc3.zig +++ b/lib/compiler_rt/divxc3.zig @@ -1,10 +1,10 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const divc3 = @import("./divc3.zig"); const Complex = @import("./mulc3.zig").Complex; comptime { if (@import("builtin").zig_backend != .stage2_c) { - @export(&__divxc3, .{ .name = "__divxc3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divxc3, "__divxc3"); } } diff --git a/lib/compiler_rt/divxf3.zig b/lib/compiler_rt/divxf3.zig index 069510a2b6..46210a500f 100644 --- a/lib/compiler_rt/divxf3.zig +++ b/lib/compiler_rt/divxf3.zig @@ -2,12 +2,13 @@ const std = @import("std"); const builtin = @import("builtin"); const arch = builtin.cpu.arch; -const common = @import("common.zig"); -const normalize = common.normalize; -const wideMultiply = common.wideMultiply; +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; +const normalize = compiler_rt.normalize; +const wideMultiply = compiler_rt.wideMultiply; comptime { - @export(&__divxf3, .{ .name = "__divxf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divxf3, "__divxf3"); } pub fn __divxf3(a: f80, b: f80) callconv(.c) f80 { diff --git a/lib/compiler_rt/emutls.zig b/lib/compiler_rt/emutls.zig index c52ce020ed..ee80d75d9f 100644 --- a/lib/compiler_rt/emutls.zig +++ b/lib/compiler_rt/emutls.zig @@ -5,7 +5,8 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const abort = std.process.abort; const assert = std.debug.assert; @@ -17,7 +18,7 @@ const gcc_word = usize; comptime { if (builtin.link_libc and (builtin.abi.isAndroid() or builtin.abi.isOpenHarmony() or builtin.os.tag == .openbsd)) { - @export(&__emutls_get_address, .{ .name = "__emutls_get_address", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__emutls_get_address, "__emutls_get_address"); } } @@ -147,7 +148,8 @@ const ObjectArray = struct { // It provides thread-safety for on-demand storage of Thread Objects. const current_thread_storage = struct { var key: std.c.pthread_key_t = undefined; - var init_once = std.once(current_thread_storage.init); + var init_mutex: std.c.pthread_mutex_t = std.c.PTHREAD_MUTEX_INITIALIZER; + var init_done: bool = false; /// Return a per thread ObjectArray with at least the expected index. pub fn getArray(index: usize) *ObjectArray { @@ -183,9 +185,13 @@ const current_thread_storage = struct { /// Initialize pthread_key_t. fn init() void { + if (@atomicLoad(bool, &init_done, .monotonic)) return; + _ = std.c.pthread_mutex_lock(&init_mutex); if (std.c.pthread_key_create(¤t_thread_storage.key, current_thread_storage.deinit) != .SUCCESS) { abort(); } + @atomicStore(bool, &init_done, true, .release); + _ = std.c.pthread_mutex_unlock(&init_mutex); } /// Invoked by pthread specific destructor. the passed argument is the ObjectArray pointer. @@ -283,7 +289,7 @@ const emutls_control = extern struct { /// Get the pointer on allocated storage for emutls variable. pub fn getPointer(self: *emutls_control) *anyopaque { // ensure current_thread_storage initialization is done - current_thread_storage.init_once.call(); + current_thread_storage.init(); const index = self.getIndex(); var array = current_thread_storage.getArray(index); diff --git a/lib/compiler_rt/exp.zig b/lib/compiler_rt/exp.zig index f25bf57092..c5a980ac72 100644 --- a/lib/compiler_rt/exp.zig +++ b/lib/compiler_rt/exp.zig @@ -4,25 +4,28 @@ // https://git.musl-libc.org/cgit/musl/tree/src/math/expf.c // https://git.musl-libc.org/cgit/musl/tree/src/math/exp.c -const std = @import("std"); const builtin = @import("builtin"); const arch = builtin.cpu.arch; + +const std = @import("std"); const math = std.math; const mem = std.mem; const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; -const common = @import("common.zig"); + +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__exph, .{ .name = "__exph", .linkage = common.linkage, .visibility = common.visibility }); - @export(&expf, .{ .name = "expf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&exp, .{ .name = "exp", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__expx, .{ .name = "__expx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&expq, .{ .name = "expf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__exph, "__exph"); + symbol(&expf, "expf"); + symbol(&exp, "exp"); + symbol(&__expx, "__expx"); + if (compiler_rt.want_ppc_abi) { + symbol(&expq, "expf128"); } - @export(&expq, .{ .name = "expq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&expl, .{ .name = "expl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&expq, "expq"); + symbol(&expl, "expl"); } pub fn __exph(a: f16) callconv(.c) f16 { @@ -58,7 +61,7 @@ pub fn expf(x_: f32) callconv(.c) f32 { return x * 0x1.0p127; } if (sign != 0) { - if (common.want_float_exceptions) mem.doNotOptimizeAway(-0x1.0p-149 / x); // overflow + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(-0x1.0p-149 / x); // overflow // x <= -103.972084 if (hx >= 0x42CFF1B5) { return 0; @@ -90,7 +93,7 @@ pub fn expf(x_: f32) callconv(.c) f32 { hi = x; lo = 0; } else { - if (common.want_float_exceptions) mem.doNotOptimizeAway(0x1.0p127 + x); // inexact + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(0x1.0p127 + x); // inexact return 1 + x; } @@ -134,11 +137,11 @@ pub fn exp(x_: f64) callconv(.c) f64 { } if (x > 709.782712893383973096) { // overflow if x != inf - return if (common.want_float_exceptions) x * 0x1p1023 else std.math.inf(f64); + return if (compiler_rt.want_float_exceptions) x * 0x1p1023 else std.math.inf(f64); } if (x < -708.39641853226410622) { // underflow if x != -inf - if (common.want_float_exceptions) mem.doNotOptimizeAway(-0x0.0000000000001p-1022 / x); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(-0x0.0000000000001p-1022 / x); if (x < -745.13321910194110842) { return 0; } @@ -171,7 +174,7 @@ pub fn exp(x_: f64) callconv(.c) f64 { lo = 0; } else { // inexact if x != 0 - if (common.want_float_exceptions) mem.doNotOptimizeAway(0x1.0p1023 + x); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(0x1.0p1023 + x); return 1 + x; } diff --git a/lib/compiler_rt/exp2.zig b/lib/compiler_rt/exp2.zig index f59e98620e..4e41db2f2d 100644 --- a/lib/compiler_rt/exp2.zig +++ b/lib/compiler_rt/exp2.zig @@ -11,18 +11,19 @@ const math = std.math; const mem = std.mem; const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__exp2h, .{ .name = "__exp2h", .linkage = common.linkage, .visibility = common.visibility }); - @export(&exp2f, .{ .name = "exp2f", .linkage = common.linkage, .visibility = common.visibility }); - @export(&exp2, .{ .name = "exp2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__exp2x, .{ .name = "__exp2x", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&exp2q, .{ .name = "exp2f128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__exp2h, "__exp2h"); + symbol(&exp2f, "exp2f"); + symbol(&exp2, "exp2"); + symbol(&__exp2x, "__exp2x"); + if (compiler_rt.want_ppc_abi) { + symbol(&exp2q, "exp2f128"); } - @export(&exp2q, .{ .name = "exp2q", .linkage = common.linkage, .visibility = common.visibility }); - @export(&exp2l, .{ .name = "exp2l", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&exp2q, "exp2q"); + symbol(&exp2l, "exp2l"); } pub fn __exp2h(x: f16) callconv(.c) f16 { @@ -54,7 +55,7 @@ pub fn exp2f(x: f32) callconv(.c) f32 { // x < -126 if (u >= 0x80000000) { if (u >= 0xC3160000 or u & 0x000FFFF != 0) { - if (common.want_float_exceptions) mem.doNotOptimizeAway(-0x1.0p-149 / x); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(-0x1.0p-149 / x); } // x <= -150 if (u >= 0xC3160000) { @@ -108,7 +109,7 @@ pub fn exp2(x: f64) callconv(.c) f64 { if (ix >= 0x408FF000) { // x >= 1024 or nan if (ix >= 0x40900000 and ux >> 63 == 0) { - return if (common.want_float_exceptions) x * 0x1p1023 else std.math.inf(f64); + return if (compiler_rt.want_float_exceptions) x * 0x1p1023 else std.math.inf(f64); } // -inf or -nan if (ix >= 0x7FF00000) { @@ -118,7 +119,7 @@ pub fn exp2(x: f64) callconv(.c) f64 { if (ux >> 63 != 0) { // underflow if (x <= -1075 or x - 0x1.0p52 + 0x1.0p52 != x) { - if (common.want_float_exceptions) mem.doNotOptimizeAway(@as(f32, @floatCast(-0x1.0p-149 / x))); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(@as(f32, @floatCast(-0x1.0p-149 / x))); } if (x <= -1075) { return 0; diff --git a/lib/compiler_rt/extenddftf2.zig b/lib/compiler_rt/extenddftf2.zig index 9ef552c2c5..4ccd402b24 100644 --- a/lib/compiler_rt/extenddftf2.zig +++ b/lib/compiler_rt/extenddftf2.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const extendf = @import("./extendf.zig").extendf; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_ppc_abi) { - @export(&__extenddftf2, .{ .name = "__extenddfkf2", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_dtoq, .{ .name = "_Qp_dtoq", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__extenddftf2, "__extenddfkf2"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_dtoq, "_Qp_dtoq"); } - @export(&__extenddftf2, .{ .name = "__extenddftf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__extenddftf2, "__extenddftf2"); } pub fn __extenddftf2(a: f64) callconv(.c) f128 { diff --git a/lib/compiler_rt/extenddfxf2.zig b/lib/compiler_rt/extenddfxf2.zig index 1d7bc998d7..d18195aea3 100644 --- a/lib/compiler_rt/extenddfxf2.zig +++ b/lib/compiler_rt/extenddfxf2.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const extend_f80 = @import("./extendf.zig").extend_f80; comptime { - @export(&__extenddfxf2, .{ .name = "__extenddfxf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__extenddfxf2, "__extenddfxf2"); } pub fn __extenddfxf2(a: f64) callconv(.c) f80 { diff --git a/lib/compiler_rt/extendf_test.zig b/lib/compiler_rt/extendf_test.zig index 20273507d1..f572495b66 100644 --- a/lib/compiler_rt/extendf_test.zig +++ b/lib/compiler_rt/extendf_test.zig @@ -1,12 +1,14 @@ +const builtin = @import("builtin"); + const std = @import("std"); const math = std.math; -const builtin = @import("builtin"); + const __extendhfsf2 = @import("extendhfsf2.zig").__extendhfsf2; const __extendhftf2 = @import("extendhftf2.zig").__extendhftf2; const __extendsftf2 = @import("extendsftf2.zig").__extendsftf2; const __extenddftf2 = @import("extenddftf2.zig").__extenddftf2; const __extenddfxf2 = @import("extenddfxf2.zig").__extenddfxf2; -const F16T = @import("./common.zig").F16T; +const F16T = @import("../compiler_rt.zig").F16T; fn test__extenddfxf2(a: f64, expected: u80) !void { const x = __extenddfxf2(a); diff --git a/lib/compiler_rt/extendhfdf2.zig b/lib/compiler_rt/extendhfdf2.zig index 3b3b65ec11..8cadc7139e 100644 --- a/lib/compiler_rt/extendhfdf2.zig +++ b/lib/compiler_rt/extendhfdf2.zig @@ -1,10 +1,11 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const extendf = @import("./extendf.zig").extendf; comptime { - @export(&__extendhfdf2, .{ .name = "__extendhfdf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__extendhfdf2, "__extendhfdf2"); } -pub fn __extendhfdf2(a: common.F16T(f64)) callconv(.c) f64 { +pub fn __extendhfdf2(a: compiler_rt.F16T(f64)) callconv(.c) f64 { return extendf(f64, f16, @as(u16, @bitCast(a))); } diff --git a/lib/compiler_rt/extendhfsf2.zig b/lib/compiler_rt/extendhfsf2.zig index f4f8be4305..b638192c47 100644 --- a/lib/compiler_rt/extendhfsf2.zig +++ b/lib/compiler_rt/extendhfsf2.zig @@ -1,20 +1,21 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const extendf = @import("./extendf.zig").extendf; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.gnu_f16_abi) { - @export(&__gnu_h2f_ieee, .{ .name = "__gnu_h2f_ieee", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_aeabi) { - @export(&__aeabi_h2f, .{ .name = "__aeabi_h2f", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.gnu_f16_abi) { + symbol(&__gnu_h2f_ieee, "__gnu_h2f_ieee"); + } else if (compiler_rt.want_aeabi) { + symbol(&__aeabi_h2f, "__aeabi_h2f"); } - @export(&__extendhfsf2, .{ .name = "__extendhfsf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__extendhfsf2, "__extendhfsf2"); } -pub fn __extendhfsf2(a: common.F16T(f32)) callconv(.c) f32 { +pub fn __extendhfsf2(a: compiler_rt.F16T(f32)) callconv(.c) f32 { return extendf(f32, f16, @as(u16, @bitCast(a))); } -fn __gnu_h2f_ieee(a: common.F16T(f32)) callconv(.c) f32 { +fn __gnu_h2f_ieee(a: compiler_rt.F16T(f32)) callconv(.c) f32 { return extendf(f32, f16, @as(u16, @bitCast(a))); } diff --git a/lib/compiler_rt/extendhftf2.zig b/lib/compiler_rt/extendhftf2.zig index a94b849a5a..29e7866b66 100644 --- a/lib/compiler_rt/extendhftf2.zig +++ b/lib/compiler_rt/extendhftf2.zig @@ -1,10 +1,11 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const extendf = @import("./extendf.zig").extendf; comptime { - @export(&__extendhftf2, .{ .name = "__extendhftf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__extendhftf2, "__extendhftf2"); } -pub fn __extendhftf2(a: common.F16T(f128)) callconv(.c) f128 { +pub fn __extendhftf2(a: compiler_rt.F16T(f128)) callconv(.c) f128 { return extendf(f128, f16, @as(u16, @bitCast(a))); } diff --git a/lib/compiler_rt/extendhfxf2.zig b/lib/compiler_rt/extendhfxf2.zig index 5e205b1f88..e76daf4f55 100644 --- a/lib/compiler_rt/extendhfxf2.zig +++ b/lib/compiler_rt/extendhfxf2.zig @@ -1,10 +1,11 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const extend_f80 = @import("./extendf.zig").extend_f80; comptime { - @export(&__extendhfxf2, .{ .name = "__extendhfxf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__extendhfxf2, "__extendhfxf2"); } -fn __extendhfxf2(a: common.F16T(f80)) callconv(.c) f80 { +fn __extendhfxf2(a: compiler_rt.F16T(f80)) callconv(.c) f80 { return extend_f80(f16, @as(u16, @bitCast(a))); } diff --git a/lib/compiler_rt/extendsfdf2.zig b/lib/compiler_rt/extendsfdf2.zig index 9cc0a43663..4f34b05242 100644 --- a/lib/compiler_rt/extendsfdf2.zig +++ b/lib/compiler_rt/extendsfdf2.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const extendf = @import("./extendf.zig").extendf; comptime { - if (common.want_aeabi) { - @export(&__aeabi_f2d, .{ .name = "__aeabi_f2d", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_f2d, "__aeabi_f2d"); } else { - @export(&__extendsfdf2, .{ .name = "__extendsfdf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__extendsfdf2, "__extendsfdf2"); } } diff --git a/lib/compiler_rt/extendsftf2.zig b/lib/compiler_rt/extendsftf2.zig index 3690a0733c..e260eec7fe 100644 --- a/lib/compiler_rt/extendsftf2.zig +++ b/lib/compiler_rt/extendsftf2.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const extendf = @import("./extendf.zig").extendf; comptime { - if (common.want_ppc_abi) { - @export(&__extendsftf2, .{ .name = "__extendsfkf2", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_stoq, .{ .name = "_Qp_stoq", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__extendsftf2, "__extendsfkf2"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_stoq, "_Qp_stoq"); } - @export(&__extendsftf2, .{ .name = "__extendsftf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__extendsftf2, "__extendsftf2"); } pub fn __extendsftf2(a: f32) callconv(.c) f128 { diff --git a/lib/compiler_rt/extendsfxf2.zig b/lib/compiler_rt/extendsfxf2.zig index 8665c445f7..9a6796bd66 100644 --- a/lib/compiler_rt/extendsfxf2.zig +++ b/lib/compiler_rt/extendsfxf2.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const extend_f80 = @import("./extendf.zig").extend_f80; comptime { - @export(&__extendsfxf2, .{ .name = "__extendsfxf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__extendsfxf2, "__extendsfxf2"); } fn __extendsfxf2(a: f32) callconv(.c) f80 { diff --git a/lib/compiler_rt/extendxftf2.zig b/lib/compiler_rt/extendxftf2.zig index cec1fa1f7c..1c39e1e84c 100644 --- a/lib/compiler_rt/extendxftf2.zig +++ b/lib/compiler_rt/extendxftf2.zig @@ -1,8 +1,9 @@ const std = @import("std"); -const common = @import("./common.zig"); + +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__extendxftf2, .{ .name = "__extendxftf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__extendxftf2, "__extendxftf2"); } fn __extendxftf2(a: f80) callconv(.c) f128 { diff --git a/lib/compiler_rt/fabs.zig b/lib/compiler_rt/fabs.zig index 9a10f4ce61..8fcf36262a 100644 --- a/lib/compiler_rt/fabs.zig +++ b/lib/compiler_rt/fabs.zig @@ -1,18 +1,19 @@ const std = @import("std"); const builtin = @import("builtin"); const arch = builtin.cpu.arch; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__fabsh, .{ .name = "__fabsh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fabsf, .{ .name = "fabsf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fabs, .{ .name = "fabs", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__fabsx, .{ .name = "__fabsx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&fabsq, .{ .name = "fabsf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fabsh, "__fabsh"); + symbol(&fabsf, "fabsf"); + symbol(&fabs, "fabs"); + symbol(&__fabsx, "__fabsx"); + if (compiler_rt.want_ppc_abi) { + symbol(&fabsq, "fabsf128"); } - @export(&fabsq, .{ .name = "fabsq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fabsl, .{ .name = "fabsl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&fabsq, "fabsq"); + symbol(&fabsl, "fabsl"); } pub fn __fabsh(a: f16) callconv(.c) f16 { diff --git a/lib/compiler_rt/fixdfdi.zig b/lib/compiler_rt/fixdfdi.zig index 97f3be044e..5a66cc124f 100644 --- a/lib/compiler_rt/fixdfdi.zig +++ b/lib/compiler_rt/fixdfdi.zig @@ -1,15 +1,16 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_aeabi) { - @export(&__aeabi_d2lz, .{ .name = "__aeabi_d2lz", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_d2lz, "__aeabi_d2lz"); } else { - if (common.want_windows_arm_abi) { - @export(&__fixdfdi, .{ .name = "__dtoi64", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_arm_abi) { + symbol(&__fixdfdi, "__dtoi64"); } - @export(&__fixdfdi, .{ .name = "__fixdfdi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixdfdi, "__fixdfdi"); } } diff --git a/lib/compiler_rt/fixdfei.zig b/lib/compiler_rt/fixdfei.zig index 3565cb45ba..170b4a1603 100644 --- a/lib/compiler_rt/fixdfei.zig +++ b/lib/compiler_rt/fixdfei.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; comptime { - @export(&__fixdfei, .{ .name = "__fixdfei", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixdfei, "__fixdfei"); } pub fn __fixdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void { diff --git a/lib/compiler_rt/fixdfsi.zig b/lib/compiler_rt/fixdfsi.zig index b1b26867b9..1d42337ea5 100644 --- a/lib/compiler_rt/fixdfsi.zig +++ b/lib/compiler_rt/fixdfsi.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const intFromFloat = @import("./int_from_float.zig").intFromFloat; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_aeabi) { - @export(&__aeabi_d2iz, .{ .name = "__aeabi_d2iz", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_d2iz, "__aeabi_d2iz"); } else { - @export(&__fixdfsi, .{ .name = "__fixdfsi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixdfsi, "__fixdfsi"); } } diff --git a/lib/compiler_rt/fixdfti.zig b/lib/compiler_rt/fixdfti.zig index 499811c551..4717fd7b59 100644 --- a/lib/compiler_rt/fixdfti.zig +++ b/lib/compiler_rt/fixdfti.zig @@ -1,12 +1,12 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const intFromFloat = @import("./int_from_float.zig").intFromFloat; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__fixdfti_windows_x86_64, .{ .name = "__fixdfti", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__fixdfti_windows_x86_64, "__fixdfti"); } else { - @export(&__fixdfti, .{ .name = "__fixdfti", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixdfti, "__fixdfti"); } } diff --git a/lib/compiler_rt/fixhfdi.zig b/lib/compiler_rt/fixhfdi.zig deleted file mode 100644 index 3bcb848972..0000000000 --- a/lib/compiler_rt/fixhfdi.zig +++ /dev/null @@ -1,10 +0,0 @@ -const common = @import("./common.zig"); -const intFromFloat = @import("./int_from_float.zig").intFromFloat; - -comptime { - @export(&__fixhfdi, .{ .name = "__fixhfdi", .linkage = common.linkage, .visibility = common.visibility }); -} - -fn __fixhfdi(a: f16) callconv(.c) i64 { - return intFromFloat(i64, a); -} diff --git a/lib/compiler_rt/fixhfei.zig b/lib/compiler_rt/fixhfei.zig index 1eef56073f..5b759c3fc6 100644 --- a/lib/compiler_rt/fixhfei.zig +++ b/lib/compiler_rt/fixhfei.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; comptime { - @export(&__fixhfei, .{ .name = "__fixhfei", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixhfei, "__fixhfei"); } pub fn __fixhfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void { diff --git a/lib/compiler_rt/fixhfsi.zig b/lib/compiler_rt/fixhfsi.zig deleted file mode 100644 index 658f13bb71..0000000000 --- a/lib/compiler_rt/fixhfsi.zig +++ /dev/null @@ -1,10 +0,0 @@ -const common = @import("./common.zig"); -const intFromFloat = @import("./int_from_float.zig").intFromFloat; - -comptime { - @export(&__fixhfsi, .{ .name = "__fixhfsi", .linkage = common.linkage, .visibility = common.visibility }); -} - -fn __fixhfsi(a: f16) callconv(.c) i32 { - return intFromFloat(i32, a); -} diff --git a/lib/compiler_rt/fixhfti.zig b/lib/compiler_rt/fixhfti.zig deleted file mode 100644 index 1c51ebc056..0000000000 --- a/lib/compiler_rt/fixhfti.zig +++ /dev/null @@ -1,21 +0,0 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); -const intFromFloat = @import("./int_from_float.zig").intFromFloat; - -comptime { - if (common.want_windows_v2u64_abi) { - @export(&__fixhfti_windows_x86_64, .{ .name = "__fixhfti", .linkage = common.linkage, .visibility = common.visibility }); - } else { - @export(&__fixhfti, .{ .name = "__fixhfti", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -pub fn __fixhfti(a: f16) callconv(.c) i128 { - return intFromFloat(i128, a); -} - -const v2u64 = @Vector(2, u64); - -fn __fixhfti_windows_x86_64(a: f16) callconv(.c) v2u64 { - return @bitCast(intFromFloat(i128, a)); -} diff --git a/lib/compiler_rt/fixsfdi.zig b/lib/compiler_rt/fixsfdi.zig index 894d5a0c13..0a3731877e 100644 --- a/lib/compiler_rt/fixsfdi.zig +++ b/lib/compiler_rt/fixsfdi.zig @@ -1,15 +1,16 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const intFromFloat = @import("./int_from_float.zig").intFromFloat; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_aeabi) { - @export(&__aeabi_f2lz, .{ .name = "__aeabi_f2lz", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_f2lz, "__aeabi_f2lz"); } else { - if (common.want_windows_arm_abi) { - @export(&__fixsfdi, .{ .name = "__stoi64", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_arm_abi) { + symbol(&__fixsfdi, "__stoi64"); } - @export(&__fixsfdi, .{ .name = "__fixsfdi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixsfdi, "__fixsfdi"); } } diff --git a/lib/compiler_rt/fixsfei.zig b/lib/compiler_rt/fixsfei.zig index efbccfa299..4324325405 100644 --- a/lib/compiler_rt/fixsfei.zig +++ b/lib/compiler_rt/fixsfei.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; comptime { - @export(&__fixsfei, .{ .name = "__fixsfei", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixsfei, "__fixsfei"); } pub fn __fixsfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void { diff --git a/lib/compiler_rt/fixsfsi.zig b/lib/compiler_rt/fixsfsi.zig index abb8564369..9c07c5824a 100644 --- a/lib/compiler_rt/fixsfsi.zig +++ b/lib/compiler_rt/fixsfsi.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_aeabi) { - @export(&__aeabi_f2iz, .{ .name = "__aeabi_f2iz", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_f2iz, "__aeabi_f2iz"); } else { - @export(&__fixsfsi, .{ .name = "__fixsfsi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixsfsi, "__fixsfsi"); } } diff --git a/lib/compiler_rt/fixsfti.zig b/lib/compiler_rt/fixsfti.zig index 82b1db70dc..0980012a45 100644 --- a/lib/compiler_rt/fixsfti.zig +++ b/lib/compiler_rt/fixsfti.zig @@ -1,12 +1,13 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__fixsfti_windows_x86_64, .{ .name = "__fixsfti", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__fixsfti_windows_x86_64, "__fixsfti"); } else { - @export(&__fixsfti, .{ .name = "__fixsfti", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixsfti, "__fixsfti"); } } diff --git a/lib/compiler_rt/fixtfdi.zig b/lib/compiler_rt/fixtfdi.zig index 5c41f56595..f3cb7bc1cf 100644 --- a/lib/compiler_rt/fixtfdi.zig +++ b/lib/compiler_rt/fixtfdi.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const intFromFloat = @import("./int_from_float.zig").intFromFloat; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_ppc_abi) { - @export(&__fixtfdi, .{ .name = "__fixkfdi", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_qtox, .{ .name = "_Qp_qtox", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__fixtfdi, "__fixkfdi"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_qtox, "_Qp_qtox"); } - @export(&__fixtfdi, .{ .name = "__fixtfdi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixtfdi, "__fixtfdi"); } pub fn __fixtfdi(a: f128) callconv(.c) i64 { diff --git a/lib/compiler_rt/fixtfei.zig b/lib/compiler_rt/fixtfei.zig index 980db4c614..6443a0cb3b 100644 --- a/lib/compiler_rt/fixtfei.zig +++ b/lib/compiler_rt/fixtfei.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; comptime { - @export(&__fixtfei, .{ .name = "__fixtfei", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixtfei, "__fixtfei"); } pub fn __fixtfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void { diff --git a/lib/compiler_rt/fixtfsi.zig b/lib/compiler_rt/fixtfsi.zig index 0d525cf8c4..10cddec0da 100644 --- a/lib/compiler_rt/fixtfsi.zig +++ b/lib/compiler_rt/fixtfsi.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_ppc_abi) { - @export(&__fixtfsi, .{ .name = "__fixkfsi", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_qtoi, .{ .name = "_Qp_qtoi", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__fixtfsi, "__fixkfsi"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_qtoi, "_Qp_qtoi"); } - @export(&__fixtfsi, .{ .name = "__fixtfsi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixtfsi, "__fixtfsi"); } pub fn __fixtfsi(a: f128) callconv(.c) i32 { diff --git a/lib/compiler_rt/fixtfti.zig b/lib/compiler_rt/fixtfti.zig index fe71a0f089..cb642d6166 100644 --- a/lib/compiler_rt/fixtfti.zig +++ b/lib/compiler_rt/fixtfti.zig @@ -1,14 +1,14 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const intFromFloat = @import("./int_from_float.zig").intFromFloat; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__fixtfti_windows_x86_64, .{ .name = "__fixtfti", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__fixtfti_windows_x86_64, "__fixtfti"); } else { - if (common.want_ppc_abi) - @export(&__fixtfti, .{ .name = "__fixkfti", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__fixtfti, .{ .name = "__fixtfti", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) + symbol(&__fixtfti, "__fixkfti"); + symbol(&__fixtfti, "__fixtfti"); } } diff --git a/lib/compiler_rt/fixunsdfdi.zig b/lib/compiler_rt/fixunsdfdi.zig index 211963bf3e..340bb8f6b1 100644 --- a/lib/compiler_rt/fixunsdfdi.zig +++ b/lib/compiler_rt/fixunsdfdi.zig @@ -1,15 +1,16 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_aeabi) { - @export(&__aeabi_d2ulz, .{ .name = "__aeabi_d2ulz", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_d2ulz, "__aeabi_d2ulz"); } else { - if (common.want_windows_arm_abi) { - @export(&__fixunsdfdi, .{ .name = "__dtou64", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_arm_abi) { + symbol(&__fixunsdfdi, "__dtou64"); } - @export(&__fixunsdfdi, .{ .name = "__fixunsdfdi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunsdfdi, "__fixunsdfdi"); } } diff --git a/lib/compiler_rt/fixunsdfei.zig b/lib/compiler_rt/fixunsdfei.zig index be5bbf0a8a..f564f7f7a3 100644 --- a/lib/compiler_rt/fixunsdfei.zig +++ b/lib/compiler_rt/fixunsdfei.zig @@ -1,10 +1,12 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); + +const std = @import("std"); + +const symbol = @import("../compiler_rt.zig").symbol; const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; comptime { - @export(&__fixunsdfei, .{ .name = "__fixunsdfei", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunsdfei, "__fixunsdfei"); } pub fn __fixunsdfei(r: [*]u8, bits: usize, a: f64) callconv(.c) void { diff --git a/lib/compiler_rt/fixunsdfsi.zig b/lib/compiler_rt/fixunsdfsi.zig index a8e9197361..e8b976d03d 100644 --- a/lib/compiler_rt/fixunsdfsi.zig +++ b/lib/compiler_rt/fixunsdfsi.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_aeabi) { - @export(&__aeabi_d2uiz, .{ .name = "__aeabi_d2uiz", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_d2uiz, "__aeabi_d2uiz"); } else { - @export(&__fixunsdfsi, .{ .name = "__fixunsdfsi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunsdfsi, "__fixunsdfsi"); } } diff --git a/lib/compiler_rt/fixunsdfti.zig b/lib/compiler_rt/fixunsdfti.zig index 28b79a0733..95d15ac313 100644 --- a/lib/compiler_rt/fixunsdfti.zig +++ b/lib/compiler_rt/fixunsdfti.zig @@ -1,12 +1,12 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__fixunsdfti_windows_x86_64, .{ .name = "__fixunsdfti", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__fixunsdfti_windows_x86_64, "__fixunsdfti"); } else { - @export(&__fixunsdfti, .{ .name = "__fixunsdfti", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunsdfti, "__fixunsdfti"); } } diff --git a/lib/compiler_rt/fixunshfdi.zig b/lib/compiler_rt/fixunshfdi.zig index a949ee9904..741e482506 100644 --- a/lib/compiler_rt/fixunshfdi.zig +++ b/lib/compiler_rt/fixunshfdi.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - @export(&__fixunshfdi, .{ .name = "__fixunshfdi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunshfdi, "__fixunshfdi"); } fn __fixunshfdi(a: f16) callconv(.c) u64 { diff --git a/lib/compiler_rt/fixunshfei.zig b/lib/compiler_rt/fixunshfei.zig index 4cb7ef2ba8..a61d94f395 100644 --- a/lib/compiler_rt/fixunshfei.zig +++ b/lib/compiler_rt/fixunshfei.zig @@ -1,10 +1,12 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); + +const std = @import("std"); + +const symbol = @import("../compiler_rt.zig").symbol; const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; comptime { - @export(&__fixunshfei, .{ .name = "__fixunshfei", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunshfei, "__fixunshfei"); } pub fn __fixunshfei(r: [*]u8, bits: usize, a: f16) callconv(.c) void { diff --git a/lib/compiler_rt/fixunshfsi.zig b/lib/compiler_rt/fixunshfsi.zig index fca40d1b0a..438767c7a8 100644 --- a/lib/compiler_rt/fixunshfsi.zig +++ b/lib/compiler_rt/fixunshfsi.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - @export(&__fixunshfsi, .{ .name = "__fixunshfsi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunshfsi, "__fixunshfsi"); } fn __fixunshfsi(a: f16) callconv(.c) u32 { diff --git a/lib/compiler_rt/fixunshfti.zig b/lib/compiler_rt/fixunshfti.zig index c61be597e7..a090027196 100644 --- a/lib/compiler_rt/fixunshfti.zig +++ b/lib/compiler_rt/fixunshfti.zig @@ -1,12 +1,12 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const intFromFloat = @import("./int_from_float.zig").intFromFloat; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__fixunshfti_windows_x86_64, .{ .name = "__fixunshfti", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__fixunshfti_windows_x86_64, "__fixunshfti"); } else { - @export(&__fixunshfti, .{ .name = "__fixunshfti", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunshfti, "__fixunshfti"); } } diff --git a/lib/compiler_rt/fixunssfdi.zig b/lib/compiler_rt/fixunssfdi.zig index f12ec1cd5a..ffc238a53f 100644 --- a/lib/compiler_rt/fixunssfdi.zig +++ b/lib/compiler_rt/fixunssfdi.zig @@ -1,15 +1,16 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_aeabi) { - @export(&__aeabi_f2ulz, .{ .name = "__aeabi_f2ulz", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_f2ulz, "__aeabi_f2ulz"); } else { - if (common.want_windows_arm_abi) { - @export(&__fixunssfdi, .{ .name = "__stou64", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_arm_abi) { + symbol(&__fixunssfdi, "__stou64"); } - @export(&__fixunssfdi, .{ .name = "__fixunssfdi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunssfdi, "__fixunssfdi"); } } diff --git a/lib/compiler_rt/fixunssfei.zig b/lib/compiler_rt/fixunssfei.zig index 0fb957ed1f..2fd123bd1b 100644 --- a/lib/compiler_rt/fixunssfei.zig +++ b/lib/compiler_rt/fixunssfei.zig @@ -1,10 +1,12 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); + +const std = @import("std"); + +const symbol = @import("../compiler_rt.zig").symbol; const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; comptime { - @export(&__fixunssfei, .{ .name = "__fixunssfei", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunssfei, "__fixunssfei"); } pub fn __fixunssfei(r: [*]u8, bits: usize, a: f32) callconv(.c) void { diff --git a/lib/compiler_rt/fixunssfsi.zig b/lib/compiler_rt/fixunssfsi.zig index 4def4b867f..f9c09b3f3d 100644 --- a/lib/compiler_rt/fixunssfsi.zig +++ b/lib/compiler_rt/fixunssfsi.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_aeabi) { - @export(&__aeabi_f2uiz, .{ .name = "__aeabi_f2uiz", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_f2uiz, "__aeabi_f2uiz"); } else { - @export(&__fixunssfsi, .{ .name = "__fixunssfsi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunssfsi, "__fixunssfsi"); } } diff --git a/lib/compiler_rt/fixunssfti.zig b/lib/compiler_rt/fixunssfti.zig index 693442417c..da46f43d5b 100644 --- a/lib/compiler_rt/fixunssfti.zig +++ b/lib/compiler_rt/fixunssfti.zig @@ -1,12 +1,13 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const intFromFloat = @import("./int_from_float.zig").intFromFloat; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__fixunssfti_windows_x86_64, .{ .name = "__fixunssfti", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__fixunssfti_windows_x86_64, "__fixunssfti"); } else { - @export(&__fixunssfti, .{ .name = "__fixunssfti", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunssfti, "__fixunssfti"); } } diff --git a/lib/compiler_rt/fixunstfdi.zig b/lib/compiler_rt/fixunstfdi.zig index f1e1822a31..809fe6eb80 100644 --- a/lib/compiler_rt/fixunstfdi.zig +++ b/lib/compiler_rt/fixunstfdi.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_ppc_abi) { - @export(&__fixunstfdi, .{ .name = "__fixunskfdi", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_qtoux, .{ .name = "_Qp_qtoux", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__fixunstfdi, "__fixunskfdi"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_qtoux, "_Qp_qtoux"); } - @export(&__fixunstfdi, .{ .name = "__fixunstfdi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunstfdi, "__fixunstfdi"); } pub fn __fixunstfdi(a: f128) callconv(.c) u64 { diff --git a/lib/compiler_rt/fixunstfei.zig b/lib/compiler_rt/fixunstfei.zig index 84ac5010c9..3d8986da90 100644 --- a/lib/compiler_rt/fixunstfei.zig +++ b/lib/compiler_rt/fixunstfei.zig @@ -1,10 +1,12 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); + +const std = @import("std"); + +const symbol = @import("../compiler_rt.zig").symbol; const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; comptime { - @export(&__fixunstfei, .{ .name = "__fixunstfei", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunstfei, "__fixunstfei"); } pub fn __fixunstfei(r: [*]u8, bits: usize, a: f128) callconv(.c) void { diff --git a/lib/compiler_rt/fixunstfsi.zig b/lib/compiler_rt/fixunstfsi.zig index d3a9bfbed8..e8ec0aea93 100644 --- a/lib/compiler_rt/fixunstfsi.zig +++ b/lib/compiler_rt/fixunstfsi.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_ppc_abi) { - @export(&__fixunstfsi, .{ .name = "__fixunskfsi", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_qtoui, .{ .name = "_Qp_qtoui", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__fixunstfsi, "__fixunskfsi"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_qtoui, "_Qp_qtoui"); } - @export(&__fixunstfsi, .{ .name = "__fixunstfsi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunstfsi, "__fixunstfsi"); } pub fn __fixunstfsi(a: f128) callconv(.c) u32 { diff --git a/lib/compiler_rt/fixunstfti.zig b/lib/compiler_rt/fixunstfti.zig index 92fcd569dc..81c2a16095 100644 --- a/lib/compiler_rt/fixunstfti.zig +++ b/lib/compiler_rt/fixunstfti.zig @@ -1,14 +1,15 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__fixunstfti_windows_x86_64, .{ .name = "__fixunstfti", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__fixunstfti_windows_x86_64, "__fixunstfti"); } else { - if (common.want_ppc_abi) - @export(&__fixunstfti, .{ .name = "__fixunskfti", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__fixunstfti, .{ .name = "__fixunstfti", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) + symbol(&__fixunstfti, "__fixunskfti"); + symbol(&__fixunstfti, "__fixunstfti"); } } diff --git a/lib/compiler_rt/fixunsxfdi.zig b/lib/compiler_rt/fixunsxfdi.zig index 4dffd0253e..8385961b6b 100644 --- a/lib/compiler_rt/fixunsxfdi.zig +++ b/lib/compiler_rt/fixunsxfdi.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); const intFromFloat = @import("./int_from_float.zig").intFromFloat; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__fixunsxfdi, .{ .name = "__fixunsxfdi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunsxfdi, "__fixunsxfdi"); } fn __fixunsxfdi(a: f80) callconv(.c) u64 { diff --git a/lib/compiler_rt/fixunsxfei.zig b/lib/compiler_rt/fixunsxfei.zig index dc795e74c6..d7902ddff5 100644 --- a/lib/compiler_rt/fixunsxfei.zig +++ b/lib/compiler_rt/fixunsxfei.zig @@ -1,10 +1,10 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; comptime { - @export(&__fixunsxfei, .{ .name = "__fixunsxfei", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunsxfei, "__fixunsxfei"); } pub fn __fixunsxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void { diff --git a/lib/compiler_rt/fixunsxfsi.zig b/lib/compiler_rt/fixunsxfsi.zig index 8f900076c7..7309fbf5a6 100644 --- a/lib/compiler_rt/fixunsxfsi.zig +++ b/lib/compiler_rt/fixunsxfsi.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - @export(&__fixunsxfsi, .{ .name = "__fixunsxfsi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunsxfsi, "__fixunsxfsi"); } fn __fixunsxfsi(a: f80) callconv(.c) u32 { diff --git a/lib/compiler_rt/fixunsxfti.zig b/lib/compiler_rt/fixunsxfti.zig index 39dde2ca12..24296dd416 100644 --- a/lib/compiler_rt/fixunsxfti.zig +++ b/lib/compiler_rt/fixunsxfti.zig @@ -1,12 +1,13 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__fixunsxfti_windows_x86_64, .{ .name = "__fixunsxfti", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__fixunsxfti_windows_x86_64, "__fixunsxfti"); } else { - @export(&__fixunsxfti, .{ .name = "__fixunsxfti", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixunsxfti, "__fixunsxfti"); } } diff --git a/lib/compiler_rt/fixxfdi.zig b/lib/compiler_rt/fixxfdi.zig index 155fead1bb..e9e4b7528b 100644 --- a/lib/compiler_rt/fixxfdi.zig +++ b/lib/compiler_rt/fixxfdi.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - @export(&__fixxfdi, .{ .name = "__fixxfdi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixxfdi, "__fixxfdi"); } fn __fixxfdi(a: f80) callconv(.c) i64 { diff --git a/lib/compiler_rt/fixxfei.zig b/lib/compiler_rt/fixxfei.zig index 75edfad035..82cd67648d 100644 --- a/lib/compiler_rt/fixxfei.zig +++ b/lib/compiler_rt/fixxfei.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const bigIntFromFloat = @import("int_from_float.zig").bigIntFromFloat; comptime { - @export(&__fixxfei, .{ .name = "__fixxfei", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixxfei, "__fixxfei"); } pub fn __fixxfei(r: [*]u8, bits: usize, a: f80) callconv(.c) void { diff --git a/lib/compiler_rt/fixxfsi.zig b/lib/compiler_rt/fixxfsi.zig index 8a645bdae1..363492168c 100644 --- a/lib/compiler_rt/fixxfsi.zig +++ b/lib/compiler_rt/fixxfsi.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const intFromFloat = @import("./int_from_float.zig").intFromFloat; comptime { - @export(&__fixxfsi, .{ .name = "__fixxfsi", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fixxfsi, "__fixxfsi"); } fn __fixxfsi(a: f80) callconv(.c) i32 { diff --git a/lib/compiler_rt/fixxfti.zig b/lib/compiler_rt/fixxfti.zig deleted file mode 100644 index 292b9688e7..0000000000 --- a/lib/compiler_rt/fixxfti.zig +++ /dev/null @@ -1,21 +0,0 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); -const intFromFloat = @import("./int_from_float.zig").intFromFloat; - -comptime { - if (common.want_windows_v2u64_abi) { - @export(&__fixxfti_windows_x86_64, .{ .name = "__fixxfti", .linkage = common.linkage, .visibility = common.visibility }); - } else { - @export(&__fixxfti, .{ .name = "__fixxfti", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -pub fn __fixxfti(a: f80) callconv(.c) i128 { - return intFromFloat(i128, a); -} - -const v2u64 = @Vector(2, u64); - -fn __fixxfti_windows_x86_64(a: f80) callconv(.c) v2u64 { - return @bitCast(intFromFloat(i128, a)); -} diff --git a/lib/compiler_rt/floatdidf.zig b/lib/compiler_rt/floatdidf.zig index f614521478..f8d5153d5b 100644 --- a/lib/compiler_rt/floatdidf.zig +++ b/lib/compiler_rt/floatdidf.zig @@ -1,15 +1,16 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_aeabi) { - @export(&__aeabi_l2d, .{ .name = "__aeabi_l2d", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_l2d, "__aeabi_l2d"); } else { - if (common.want_windows_arm_abi) { - @export(&__floatdidf, .{ .name = "__i64tod", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_arm_abi) { + symbol(&__floatdidf, "__i64tod"); } - @export(&__floatdidf, .{ .name = "__floatdidf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatdidf, "__floatdidf"); } } diff --git a/lib/compiler_rt/floatdihf.zig b/lib/compiler_rt/floatdihf.zig index fd534e5946..c6865dff6b 100644 --- a/lib/compiler_rt/floatdihf.zig +++ b/lib/compiler_rt/floatdihf.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - @export(&__floatdihf, .{ .name = "__floatdihf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatdihf, "__floatdihf"); } fn __floatdihf(a: i64) callconv(.c) f16 { diff --git a/lib/compiler_rt/floatdisf.zig b/lib/compiler_rt/floatdisf.zig index 1efd9c937f..3da1faba36 100644 --- a/lib/compiler_rt/floatdisf.zig +++ b/lib/compiler_rt/floatdisf.zig @@ -1,15 +1,15 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_aeabi) { - @export(&__aeabi_l2f, .{ .name = "__aeabi_l2f", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_l2f, "__aeabi_l2f"); } else { - if (common.want_windows_arm_abi) { - @export(&__floatdisf, .{ .name = "__i64tos", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_arm_abi) { + symbol(&__floatdisf, "__i64tos"); } - @export(&__floatdisf, .{ .name = "__floatdisf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatdisf, "__floatdisf"); } } diff --git a/lib/compiler_rt/floatditf.zig b/lib/compiler_rt/floatditf.zig index 864361b7b3..544c059f1b 100644 --- a/lib/compiler_rt/floatditf.zig +++ b/lib/compiler_rt/floatditf.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const floatFromInt = @import("./float_from_int.zig").floatFromInt; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_ppc_abi) { - @export(&__floatditf, .{ .name = "__floatdikf", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_xtoq, .{ .name = "_Qp_xtoq", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__floatditf, "__floatdikf"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_xtoq, "_Qp_xtoq"); } - @export(&__floatditf, .{ .name = "__floatditf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatditf, "__floatditf"); } pub fn __floatditf(a: i64) callconv(.c) f128 { diff --git a/lib/compiler_rt/floatdixf.zig b/lib/compiler_rt/floatdixf.zig index 8ac6f06fb5..6bd06245d5 100644 --- a/lib/compiler_rt/floatdixf.zig +++ b/lib/compiler_rt/floatdixf.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - @export(&__floatdixf, .{ .name = "__floatdixf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatdixf, "__floatdixf"); } fn __floatdixf(a: i64) callconv(.c) f80 { diff --git a/lib/compiler_rt/floateidf.zig b/lib/compiler_rt/floateidf.zig index 6434743939..ac3972c287 100644 --- a/lib/compiler_rt/floateidf.zig +++ b/lib/compiler_rt/floateidf.zig @@ -1,10 +1,12 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); + +const std = @import("std"); + const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__floateidf, .{ .name = "__floateidf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floateidf, "__floateidf"); } pub fn __floateidf(a: [*]const u8, bits: usize) callconv(.c) f64 { diff --git a/lib/compiler_rt/floateihf.zig b/lib/compiler_rt/floateihf.zig index 013e6d2d79..c1ec290fb1 100644 --- a/lib/compiler_rt/floateihf.zig +++ b/lib/compiler_rt/floateihf.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; comptime { - @export(&__floateihf, .{ .name = "__floateihf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floateihf, "__floateihf"); } pub fn __floateihf(a: [*]const u8, bits: usize) callconv(.c) f16 { diff --git a/lib/compiler_rt/floateisf.zig b/lib/compiler_rt/floateisf.zig index eb24b6aa43..dd5933b7df 100644 --- a/lib/compiler_rt/floateisf.zig +++ b/lib/compiler_rt/floateisf.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; comptime { - @export(&__floateisf, .{ .name = "__floateisf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floateisf, "__floateisf"); } pub fn __floateisf(a: [*]const u8, bits: usize) callconv(.c) f32 { diff --git a/lib/compiler_rt/floateitf.zig b/lib/compiler_rt/floateitf.zig index e5b50ab7a6..0df893bd18 100644 --- a/lib/compiler_rt/floateitf.zig +++ b/lib/compiler_rt/floateitf.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; comptime { - @export(&__floateitf, .{ .name = "__floateitf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floateitf, "__floateitf"); } pub fn __floateitf(a: [*]const u8, bits: usize) callconv(.c) f128 { diff --git a/lib/compiler_rt/floateixf.zig b/lib/compiler_rt/floateixf.zig index ffb8445fd3..dafefa4e8f 100644 --- a/lib/compiler_rt/floateixf.zig +++ b/lib/compiler_rt/floateixf.zig @@ -1,10 +1,12 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); + +const std = @import("std"); + +const symbol = @import("../compiler_rt.zig").symbol; const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; comptime { - @export(&__floateixf, .{ .name = "__floateixf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floateixf, "__floateixf"); } pub fn __floateixf(a: [*]const u8, bits: usize) callconv(.c) f80 { diff --git a/lib/compiler_rt/floatsidf.zig b/lib/compiler_rt/floatsidf.zig index 435c8db9a4..dc5a261a08 100644 --- a/lib/compiler_rt/floatsidf.zig +++ b/lib/compiler_rt/floatsidf.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_aeabi) { - @export(&__aeabi_i2d, .{ .name = "__aeabi_i2d", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_i2d, "__aeabi_i2d"); } else { - @export(&__floatsidf, .{ .name = "__floatsidf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatsidf, "__floatsidf"); } } diff --git a/lib/compiler_rt/floatsihf.zig b/lib/compiler_rt/floatsihf.zig index 5f2db12585..e1d588cfb0 100644 --- a/lib/compiler_rt/floatsihf.zig +++ b/lib/compiler_rt/floatsihf.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - @export(&__floatsihf, .{ .name = "__floatsihf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatsihf, "__floatsihf"); } fn __floatsihf(a: i32) callconv(.c) f16 { diff --git a/lib/compiler_rt/floatsisf.zig b/lib/compiler_rt/floatsisf.zig index 9c36387c66..0dac860ebf 100644 --- a/lib/compiler_rt/floatsisf.zig +++ b/lib/compiler_rt/floatsisf.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_aeabi) { - @export(&__aeabi_i2f, .{ .name = "__aeabi_i2f", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_i2f, "__aeabi_i2f"); } else { - @export(&__floatsisf, .{ .name = "__floatsisf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatsisf, "__floatsisf"); } } diff --git a/lib/compiler_rt/floatsitf.zig b/lib/compiler_rt/floatsitf.zig index 750633052d..b004d53989 100644 --- a/lib/compiler_rt/floatsitf.zig +++ b/lib/compiler_rt/floatsitf.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_ppc_abi) { - @export(&__floatsitf, .{ .name = "__floatsikf", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_itoq, .{ .name = "_Qp_itoq", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__floatsitf, "__floatsikf"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_itoq, "_Qp_itoq"); } - @export(&__floatsitf, .{ .name = "__floatsitf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatsitf, "__floatsitf"); } pub fn __floatsitf(a: i32) callconv(.c) f128 { diff --git a/lib/compiler_rt/floatsixf.zig b/lib/compiler_rt/floatsixf.zig index 59bf7ddb99..bd28eaf1fa 100644 --- a/lib/compiler_rt/floatsixf.zig +++ b/lib/compiler_rt/floatsixf.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const floatFromInt = @import("./float_from_int.zig").floatFromInt; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__floatsixf, .{ .name = "__floatsixf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatsixf, "__floatsixf"); } fn __floatsixf(a: i32) callconv(.c) f80 { diff --git a/lib/compiler_rt/floattidf.zig b/lib/compiler_rt/floattidf.zig index 2ac5726b51..5fd6b4c0f6 100644 --- a/lib/compiler_rt/floattidf.zig +++ b/lib/compiler_rt/floattidf.zig @@ -1,12 +1,12 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__floattidf_windows_x86_64, .{ .name = "__floattidf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__floattidf_windows_x86_64, "__floattidf"); } else { - @export(&__floattidf, .{ .name = "__floattidf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floattidf, "__floattidf"); } } diff --git a/lib/compiler_rt/floattihf.zig b/lib/compiler_rt/floattihf.zig index 9ad705870e..643849f48e 100644 --- a/lib/compiler_rt/floattihf.zig +++ b/lib/compiler_rt/floattihf.zig @@ -1,12 +1,13 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__floattihf_windows_x86_64, .{ .name = "__floattihf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__floattihf_windows_x86_64, "__floattihf"); } else { - @export(&__floattihf, .{ .name = "__floattihf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floattihf, "__floattihf"); } } diff --git a/lib/compiler_rt/floattisf.zig b/lib/compiler_rt/floattisf.zig index 953192f331..8926105d2d 100644 --- a/lib/compiler_rt/floattisf.zig +++ b/lib/compiler_rt/floattisf.zig @@ -1,12 +1,12 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const floatFromInt = @import("./float_from_int.zig").floatFromInt; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__floattisf_windows_x86_64, .{ .name = "__floattisf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__floattisf_windows_x86_64, "__floattisf"); } else { - @export(&__floattisf, .{ .name = "__floattisf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floattisf, "__floattisf"); } } diff --git a/lib/compiler_rt/floattitf.zig b/lib/compiler_rt/floattitf.zig index 3973aa4ab2..f8e6ca80e6 100644 --- a/lib/compiler_rt/floattitf.zig +++ b/lib/compiler_rt/floattitf.zig @@ -1,14 +1,14 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__floattitf_windows_x86_64, .{ .name = "__floattitf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__floattitf_windows_x86_64, "__floattitf"); } else { - if (common.want_ppc_abi) - @export(&__floattitf, .{ .name = "__floattikf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__floattitf, .{ .name = "__floattitf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) + symbol(&__floattitf, "__floattikf"); + symbol(&__floattitf, "__floattitf"); } } diff --git a/lib/compiler_rt/floattixf.zig b/lib/compiler_rt/floattixf.zig index ac1df5ba32..b69b8f9845 100644 --- a/lib/compiler_rt/floattixf.zig +++ b/lib/compiler_rt/floattixf.zig @@ -1,12 +1,13 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__floattixf_windows_x86_64, .{ .name = "__floattixf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__floattixf_windows_x86_64, "__floattixf"); } else { - @export(&__floattixf, .{ .name = "__floattixf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floattixf, "__floattixf"); } } diff --git a/lib/compiler_rt/floatundidf.zig b/lib/compiler_rt/floatundidf.zig index 7a9e4afe7a..8526753705 100644 --- a/lib/compiler_rt/floatundidf.zig +++ b/lib/compiler_rt/floatundidf.zig @@ -1,15 +1,15 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const floatFromInt = @import("./float_from_int.zig").floatFromInt; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_aeabi) { - @export(&__aeabi_ul2d, .{ .name = "__aeabi_ul2d", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_ul2d, "__aeabi_ul2d"); } else { - if (common.want_windows_arm_abi) { - @export(&__floatundidf, .{ .name = "__u64tod", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_arm_abi) { + symbol(&__floatundidf, "__u64tod"); } - @export(&__floatundidf, .{ .name = "__floatundidf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatundidf, "__floatundidf"); } } diff --git a/lib/compiler_rt/floatundihf.zig b/lib/compiler_rt/floatundihf.zig index e7a3f865f8..064d565d2d 100644 --- a/lib/compiler_rt/floatundihf.zig +++ b/lib/compiler_rt/floatundihf.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - @export(&__floatundihf, .{ .name = "__floatundihf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatundihf, "__floatundihf"); } fn __floatundihf(a: u64) callconv(.c) f16 { diff --git a/lib/compiler_rt/floatundisf.zig b/lib/compiler_rt/floatundisf.zig index 89e7fa1f4b..827a419fd5 100644 --- a/lib/compiler_rt/floatundisf.zig +++ b/lib/compiler_rt/floatundisf.zig @@ -1,15 +1,16 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_aeabi) { - @export(&__aeabi_ul2f, .{ .name = "__aeabi_ul2f", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_ul2f, "__aeabi_ul2f"); } else { - if (common.want_windows_arm_abi) { - @export(&__floatundisf, .{ .name = "__u64tos", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_arm_abi) { + symbol(&__floatundisf, "__u64tos"); } - @export(&__floatundisf, .{ .name = "__floatundisf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatundisf, "__floatundisf"); } } diff --git a/lib/compiler_rt/floatunditf.zig b/lib/compiler_rt/floatunditf.zig index d313ff3d12..257a5779bb 100644 --- a/lib/compiler_rt/floatunditf.zig +++ b/lib/compiler_rt/floatunditf.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_ppc_abi) { - @export(&__floatunditf, .{ .name = "__floatundikf", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_uxtoq, .{ .name = "_Qp_uxtoq", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__floatunditf, "__floatundikf"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_uxtoq, "_Qp_uxtoq"); } - @export(&__floatunditf, .{ .name = "__floatunditf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatunditf, "__floatunditf"); } pub fn __floatunditf(a: u64) callconv(.c) f128 { diff --git a/lib/compiler_rt/floatundixf.zig b/lib/compiler_rt/floatundixf.zig index b9691e9144..ce36d47a4e 100644 --- a/lib/compiler_rt/floatundixf.zig +++ b/lib/compiler_rt/floatundixf.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - @export(&__floatundixf, .{ .name = "__floatundixf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatundixf, "__floatundixf"); } fn __floatundixf(a: u64) callconv(.c) f80 { diff --git a/lib/compiler_rt/floatuneidf.zig b/lib/compiler_rt/floatuneidf.zig index bb8a6579ce..6e391b7cf1 100644 --- a/lib/compiler_rt/floatuneidf.zig +++ b/lib/compiler_rt/floatuneidf.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; comptime { - @export(&__floatuneidf, .{ .name = "__floatuneidf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatuneidf, "__floatuneidf"); } pub fn __floatuneidf(a: [*]const u8, bits: usize) callconv(.c) f64 { diff --git a/lib/compiler_rt/floatuneihf.zig b/lib/compiler_rt/floatuneihf.zig index 17b1e1d290..0df0cf155b 100644 --- a/lib/compiler_rt/floatuneihf.zig +++ b/lib/compiler_rt/floatuneihf.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; comptime { - @export(&__floatuneihf, .{ .name = "__floatuneihf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatuneihf, "__floatuneihf"); } pub fn __floatuneihf(a: [*]const u8, bits: usize) callconv(.c) f16 { diff --git a/lib/compiler_rt/floatuneisf.zig b/lib/compiler_rt/floatuneisf.zig index bb43b6ee65..e2dadd9ffd 100644 --- a/lib/compiler_rt/floatuneisf.zig +++ b/lib/compiler_rt/floatuneisf.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; comptime { - @export(&__floatuneisf, .{ .name = "__floatuneisf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatuneisf, "__floatuneisf"); } pub fn __floatuneisf(a: [*]const u8, bits: usize) callconv(.c) f32 { diff --git a/lib/compiler_rt/floatuneitf.zig b/lib/compiler_rt/floatuneitf.zig index d84678ce11..ddee65dfb1 100644 --- a/lib/compiler_rt/floatuneitf.zig +++ b/lib/compiler_rt/floatuneitf.zig @@ -1,10 +1,12 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); + +const std = @import("std"); + +const symbol = @import("../compiler_rt.zig").symbol; const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; comptime { - @export(&__floatuneitf, .{ .name = "__floatuneitf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatuneitf, "__floatuneitf"); } pub fn __floatuneitf(a: [*]const u8, bits: usize) callconv(.c) f128 { diff --git a/lib/compiler_rt/floatuneixf.zig b/lib/compiler_rt/floatuneixf.zig index ad0b8f24de..75dd565daf 100644 --- a/lib/compiler_rt/floatuneixf.zig +++ b/lib/compiler_rt/floatuneixf.zig @@ -1,10 +1,11 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromBigInt = @import("float_from_int.zig").floatFromBigInt; comptime { - @export(&__floatuneixf, .{ .name = "__floatuneixf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatuneixf, "__floatuneixf"); } pub fn __floatuneixf(a: [*]const u8, bits: usize) callconv(.c) f80 { diff --git a/lib/compiler_rt/floatunsidf.zig b/lib/compiler_rt/floatunsidf.zig index fc50a5ad37..94949c7bff 100644 --- a/lib/compiler_rt/floatunsidf.zig +++ b/lib/compiler_rt/floatunsidf.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_aeabi) { - @export(&__aeabi_ui2d, .{ .name = "__aeabi_ui2d", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_ui2d, "__aeabi_ui2d"); } else { - @export(&__floatunsidf, .{ .name = "__floatunsidf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatunsidf, "__floatunsidf"); } } diff --git a/lib/compiler_rt/floatunsihf.zig b/lib/compiler_rt/floatunsihf.zig index 123b76fcde..a2e42ca10f 100644 --- a/lib/compiler_rt/floatunsihf.zig +++ b/lib/compiler_rt/floatunsihf.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - @export(&__floatunsihf, .{ .name = "__floatunsihf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatunsihf, "__floatunsihf"); } pub fn __floatunsihf(a: u32) callconv(.c) f16 { diff --git a/lib/compiler_rt/floatunsisf.zig b/lib/compiler_rt/floatunsisf.zig index 4bcceba5c8..04da1aa5c0 100644 --- a/lib/compiler_rt/floatunsisf.zig +++ b/lib/compiler_rt/floatunsisf.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const floatFromInt = @import("./float_from_int.zig").floatFromInt; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_aeabi) { - @export(&__aeabi_ui2f, .{ .name = "__aeabi_ui2f", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_ui2f, "__aeabi_ui2f"); } else { - @export(&__floatunsisf, .{ .name = "__floatunsisf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatunsisf, "__floatunsisf"); } } diff --git a/lib/compiler_rt/floatunsitf.zig b/lib/compiler_rt/floatunsitf.zig index e491987003..6a5607c147 100644 --- a/lib/compiler_rt/floatunsitf.zig +++ b/lib/compiler_rt/floatunsitf.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const floatFromInt = @import("./float_from_int.zig").floatFromInt; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_ppc_abi) { - @export(&__floatunsitf, .{ .name = "__floatunsikf", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_uitoq, .{ .name = "_Qp_uitoq", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__floatunsitf, "__floatunsikf"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_uitoq, "_Qp_uitoq"); } - @export(&__floatunsitf, .{ .name = "__floatunsitf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatunsitf, "__floatunsitf"); } pub fn __floatunsitf(a: u32) callconv(.c) f128 { diff --git a/lib/compiler_rt/floatunsixf.zig b/lib/compiler_rt/floatunsixf.zig index 875d3476fa..906f0270f5 100644 --- a/lib/compiler_rt/floatunsixf.zig +++ b/lib/compiler_rt/floatunsixf.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - @export(&__floatunsixf, .{ .name = "__floatunsixf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatunsixf, "__floatunsixf"); } fn __floatunsixf(a: u32) callconv(.c) f80 { diff --git a/lib/compiler_rt/floatuntidf.zig b/lib/compiler_rt/floatuntidf.zig index 284e50dd36..7e08a66b97 100644 --- a/lib/compiler_rt/floatuntidf.zig +++ b/lib/compiler_rt/floatuntidf.zig @@ -1,12 +1,12 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const floatFromInt = @import("./float_from_int.zig").floatFromInt; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__floatuntidf_windows_x86_64, .{ .name = "__floatuntidf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__floatuntidf_windows_x86_64, "__floatuntidf"); } else { - @export(&__floatuntidf, .{ .name = "__floatuntidf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatuntidf, "__floatuntidf"); } } diff --git a/lib/compiler_rt/floatuntihf.zig b/lib/compiler_rt/floatuntihf.zig index 41da6f1bfb..5c50f39eaa 100644 --- a/lib/compiler_rt/floatuntihf.zig +++ b/lib/compiler_rt/floatuntihf.zig @@ -1,12 +1,12 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__floatuntihf_windows_x86_64, .{ .name = "__floatuntihf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__floatuntihf_windows_x86_64, "__floatuntihf"); } else { - @export(&__floatuntihf, .{ .name = "__floatuntihf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatuntihf, "__floatuntihf"); } } diff --git a/lib/compiler_rt/floatuntisf.zig b/lib/compiler_rt/floatuntisf.zig index f79d2e5fed..5a15f7c19d 100644 --- a/lib/compiler_rt/floatuntisf.zig +++ b/lib/compiler_rt/floatuntisf.zig @@ -1,12 +1,13 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__floatuntisf_windows_x86_64, .{ .name = "__floatuntisf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__floatuntisf_windows_x86_64, "__floatuntisf"); } else { - @export(&__floatuntisf, .{ .name = "__floatuntisf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatuntisf, "__floatuntisf"); } } diff --git a/lib/compiler_rt/floatuntitf.zig b/lib/compiler_rt/floatuntitf.zig index 77dd22ed59..6df02c5bef 100644 --- a/lib/compiler_rt/floatuntitf.zig +++ b/lib/compiler_rt/floatuntitf.zig @@ -1,14 +1,14 @@ -const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const floatFromInt = @import("./float_from_int.zig").floatFromInt; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__floatuntitf_windows_x86_64, .{ .name = "__floatuntitf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__floatuntitf_windows_x86_64, "__floatuntitf"); } else { - if (common.want_ppc_abi) - @export(&__floatuntitf, .{ .name = "__floatuntikf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__floatuntitf, .{ .name = "__floatuntitf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) + symbol(&__floatuntitf, "__floatuntikf"); + symbol(&__floatuntitf, "__floatuntitf"); } } diff --git a/lib/compiler_rt/floatuntixf.zig b/lib/compiler_rt/floatuntixf.zig index 12a561b573..27e668109f 100644 --- a/lib/compiler_rt/floatuntixf.zig +++ b/lib/compiler_rt/floatuntixf.zig @@ -1,12 +1,13 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const floatFromInt = @import("./float_from_int.zig").floatFromInt; comptime { - if (common.want_windows_v2u64_abi) { - @export(&__floatuntixf_windows_x86_64, .{ .name = "__floatuntixf", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__floatuntixf_windows_x86_64, "__floatuntixf"); } else { - @export(&__floatuntixf, .{ .name = "__floatuntixf", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floatuntixf, "__floatuntixf"); } } diff --git a/lib/compiler_rt/floor_ceil.zig b/lib/compiler_rt/floor_ceil.zig index e669cb812d..f81d2e0011 100644 --- a/lib/compiler_rt/floor_ceil.zig +++ b/lib/compiler_rt/floor_ceil.zig @@ -14,30 +14,31 @@ const math = std.math; const mem = std.mem; const expect = std.testing.expect; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { // floor - @export(&__floorh, .{ .name = "__floorh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&floorf, .{ .name = "floorf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&floor, .{ .name = "floor", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__floorx, .{ .name = "__floorx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&floorq, .{ .name = "floorf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__floorh, "__floorh"); + symbol(&floorf, "floorf"); + symbol(&floor, "floor"); + symbol(&__floorx, "__floorx"); + if (compiler_rt.want_ppc_abi) { + symbol(&floorq, "floorf128"); } - @export(&floorq, .{ .name = "floorq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&floorl, .{ .name = "floorl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&floorq, "floorq"); + symbol(&floorl, "floorl"); // ceil - @export(&__ceilh, .{ .name = "__ceilh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&ceilf, .{ .name = "ceilf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&ceil, .{ .name = "ceil", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ceilx, .{ .name = "__ceilx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&ceilq, .{ .name = "ceilf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__ceilh, "__ceilh"); + symbol(&ceilf, "ceilf"); + symbol(&ceil, "ceil"); + symbol(&__ceilx, "__ceilx"); + if (compiler_rt.want_ppc_abi) { + symbol(&ceilq, "ceilf128"); } - @export(&ceilq, .{ .name = "ceilq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&ceill, .{ .name = "ceill", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&ceilq, "ceilq"); + symbol(&ceill, "ceill"); } pub fn __floorh(x: f16) callconv(.c) f16 { @@ -105,11 +106,11 @@ inline fn impl(comptime T: type, comptime op: enum { floor, ceil }, x: T) T { if (e >= 0) { const m = (@as(U, 1) << @intCast(mantissa - e)) - 1; if (u & m == 0) return x; - if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120); if (u >> bits - 1 == @intFromBool(op == .floor)) u += m; return @bitCast(u & ~m); } else { - if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120); return switch (op) { .floor => if (u >> bits - 1 == 0) 0.0 else if (u << 1 != 0) -1.0 else x, .ceil => if (u >> bits - 1 != 0) -0.0 else if (u << 1 != 0) 1.0 else x, @@ -127,7 +128,7 @@ inline fn impl(comptime T: type, comptime op: enum { floor, ceil }, x: T) T { x - C + C - x; if (e <= bias - 1) { - if (common.want_float_exceptions) mem.doNotOptimizeAway(y); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(y); return switch (op) { .floor => if (positive) 0.0 else -1.0, .ceil => if (positive) 1.0 else -0.0, diff --git a/lib/compiler_rt/fma.zig b/lib/compiler_rt/fma.zig index cce9215f88..10926e9bde 100644 --- a/lib/compiler_rt/fma.zig +++ b/lib/compiler_rt/fma.zig @@ -8,18 +8,19 @@ const std = @import("std"); const math = std.math; const expect = std.testing.expect; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__fmah, .{ .name = "__fmah", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fmaf, .{ .name = "fmaf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fma, .{ .name = "fma", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__fmax, .{ .name = "__fmax", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&fmaq, .{ .name = "fmaf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fmah, "__fmah"); + symbol(&fmaf, "fmaf"); + symbol(&fma, "fma"); + symbol(&__fmax, "__fmax"); + if (compiler_rt.want_ppc_abi) { + symbol(&fmaq, "fmaf128"); } - @export(&fmaq, .{ .name = "fmaq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fmal, .{ .name = "fmal", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&fmaq, "fmaq"); + symbol(&fmal, "fmal"); } pub fn __fmah(x: f16, y: f16, z: f16) callconv(.c) f16 { diff --git a/lib/compiler_rt/fmax.zig b/lib/compiler_rt/fmax.zig index 19a7c3f6f7..606888d2d4 100644 --- a/lib/compiler_rt/fmax.zig +++ b/lib/compiler_rt/fmax.zig @@ -2,18 +2,19 @@ const std = @import("std"); const builtin = @import("builtin"); const math = std.math; const arch = builtin.cpu.arch; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__fmaxh, .{ .name = "__fmaxh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fmaxf, .{ .name = "fmaxf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fmax, .{ .name = "fmax", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__fmaxx, .{ .name = "__fmaxx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&fmaxq, .{ .name = "fmaxf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fmaxh, "__fmaxh"); + symbol(&fmaxf, "fmaxf"); + symbol(&fmax, "fmax"); + symbol(&__fmaxx, "__fmaxx"); + if (compiler_rt.want_ppc_abi) { + symbol(&fmaxq, "fmaxf128"); } - @export(&fmaxq, .{ .name = "fmaxq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fmaxl, .{ .name = "fmaxl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&fmaxq, "fmaxq"); + symbol(&fmaxl, "fmaxl"); } pub fn __fmaxh(x: f16, y: f16) callconv(.c) f16 { diff --git a/lib/compiler_rt/fmin.zig b/lib/compiler_rt/fmin.zig index aa54ba6e0b..bea1779476 100644 --- a/lib/compiler_rt/fmin.zig +++ b/lib/compiler_rt/fmin.zig @@ -2,18 +2,19 @@ const std = @import("std"); const builtin = @import("builtin"); const math = std.math; const arch = builtin.cpu.arch; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__fminh, .{ .name = "__fminh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fminf, .{ .name = "fminf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fmin, .{ .name = "fmin", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__fminx, .{ .name = "__fminx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&fminq, .{ .name = "fminf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fminh, "__fminh"); + symbol(&fminf, "fminf"); + symbol(&fmin, "fmin"); + symbol(&__fminx, "__fminx"); + if (compiler_rt.want_ppc_abi) { + symbol(&fminq, "fminf128"); } - @export(&fminq, .{ .name = "fminq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fminl, .{ .name = "fminl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&fminq, "fminq"); + symbol(&fminl, "fminl"); } pub fn __fminh(x: f16, y: f16) callconv(.c) f16 { diff --git a/lib/compiler_rt/fmod.zig b/lib/compiler_rt/fmod.zig index ae5abaae65..c2108abf33 100644 --- a/lib/compiler_rt/fmod.zig +++ b/lib/compiler_rt/fmod.zig @@ -3,19 +3,20 @@ const std = @import("std"); const math = std.math; const assert = std.debug.assert; const arch = builtin.cpu.arch; -const common = @import("common.zig"); -const normalize = common.normalize; +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; +const normalize = compiler_rt.normalize; comptime { - @export(&__fmodh, .{ .name = "__fmodh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fmodf, .{ .name = "fmodf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fmod, .{ .name = "fmod", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__fmodx, .{ .name = "__fmodx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&fmodq, .{ .name = "fmodf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__fmodh, "__fmodh"); + symbol(&fmodf, "fmodf"); + symbol(&fmod, "fmod"); + symbol(&__fmodx, "__fmodx"); + if (compiler_rt.want_ppc_abi) { + symbol(&fmodq, "fmodf128"); } - @export(&fmodq, .{ .name = "fmodq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&fmodl, .{ .name = "fmodl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&fmodq, "fmodq"); + symbol(&fmodl, "fmodl"); } pub fn __fmodh(x: f16, y: f16) callconv(.c) f16 { diff --git a/lib/compiler_rt/gedf2.zig b/lib/compiler_rt/gedf2.zig index aeb08b4a8b..a37fb27bd3 100644 --- a/lib/compiler_rt/gedf2.zig +++ b/lib/compiler_rt/gedf2.zig @@ -1,15 +1,16 @@ ///! The quoted behavior definitions are from ///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const comparef = @import("./comparef.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_aeabi) { - @export(&__aeabi_dcmpge, .{ .name = "__aeabi_dcmpge", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_dcmpgt, .{ .name = "__aeabi_dcmpgt", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_dcmpge, "__aeabi_dcmpge"); + symbol(&__aeabi_dcmpgt, "__aeabi_dcmpgt"); } else { - @export(&__gedf2, .{ .name = "__gedf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__gtdf2, .{ .name = "__gtdf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__gedf2, "__gedf2"); + symbol(&__gtdf2, "__gtdf2"); } } diff --git a/lib/compiler_rt/gehf2.zig b/lib/compiler_rt/gehf2.zig index b46d4a1a24..e4e15a449d 100644 --- a/lib/compiler_rt/gehf2.zig +++ b/lib/compiler_rt/gehf2.zig @@ -1,11 +1,11 @@ ///! The quoted behavior definitions are from ///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const comparef = @import("./comparef.zig"); comptime { - @export(&__gehf2, .{ .name = "__gehf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__gthf2, .{ .name = "__gthf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__gehf2, "__gehf2"); + symbol(&__gthf2, "__gthf2"); } /// "These functions return a value greater than or equal to zero if neither diff --git a/lib/compiler_rt/gesf2.zig b/lib/compiler_rt/gesf2.zig index d4b6a23c66..49454c4694 100644 --- a/lib/compiler_rt/gesf2.zig +++ b/lib/compiler_rt/gesf2.zig @@ -1,15 +1,16 @@ ///! The quoted behavior definitions are from ///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const comparef = @import("./comparef.zig"); comptime { - if (common.want_aeabi) { - @export(&__aeabi_fcmpge, .{ .name = "__aeabi_fcmpge", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_fcmpgt, .{ .name = "__aeabi_fcmpgt", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_fcmpge, "__aeabi_fcmpge"); + symbol(&__aeabi_fcmpgt, "__aeabi_fcmpgt"); } else { - @export(&__gesf2, .{ .name = "__gesf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__gtsf2, .{ .name = "__gtsf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__gesf2, "__gesf2"); + symbol(&__gtsf2, "__gtsf2"); } } diff --git a/lib/compiler_rt/getf2.zig b/lib/compiler_rt/getf2.zig index a6014b365e..4476ab636c 100644 --- a/lib/compiler_rt/getf2.zig +++ b/lib/compiler_rt/getf2.zig @@ -1,18 +1,19 @@ ///! The quoted behavior definitions are from ///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const comparef = @import("./comparef.zig"); comptime { - if (common.want_ppc_abi) { - @export(&__getf2, .{ .name = "__gekf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__gttf2, .{ .name = "__gtkf2", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { + if (compiler_rt.want_ppc_abi) { + symbol(&__getf2, "__gekf2"); + symbol(&__gttf2, "__gtkf2"); + } else if (compiler_rt.want_sparc_abi) { // These exports are handled in cmptf2.zig because gt and ge on sparc // are based on calling _Qp_cmp. } - @export(&__getf2, .{ .name = "__getf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__gttf2, .{ .name = "__gttf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__getf2, "__getf2"); + symbol(&__gttf2, "__gttf2"); } /// "These functions return a value greater than or equal to zero if neither diff --git a/lib/compiler_rt/gexf2.zig b/lib/compiler_rt/gexf2.zig index 365c298cc6..c6b3a1befd 100644 --- a/lib/compiler_rt/gexf2.zig +++ b/lib/compiler_rt/gexf2.zig @@ -1,9 +1,9 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const comparef = @import("./comparef.zig"); comptime { - @export(&__gexf2, .{ .name = "__gexf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__gtxf2, .{ .name = "__gtxf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__gexf2, "__gexf2"); + symbol(&__gtxf2, "__gtxf2"); } fn __gexf2(a: f80, b: f80) callconv(.c) i32 { diff --git a/lib/compiler_rt/hexagon.zig b/lib/compiler_rt/hexagon.zig index de7fd96491..2a4b8b75f7 100644 --- a/lib/compiler_rt/hexagon.zig +++ b/lib/compiler_rt/hexagon.zig @@ -1,5 +1,7 @@ const builtin = @import("builtin"); -const common = @import("./common.zig"); + +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; fn __hexagon_divsi3() callconv(.naked) noreturn { asm volatile ( @@ -1759,29 +1761,29 @@ fn __hexagon_sqrtdf2() align(32) callconv(.naked) noreturn { comptime { if (builtin.cpu.arch == .hexagon) { - @export(&__hexagon_adddf3, .{ .name = "__hexagon_adddf3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_adddf3, .{ .name = "__hexagon_fast_adddf3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_subdf3, .{ .name = "__hexagon_subdf3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_subdf3, .{ .name = "__hexagon_fast_subdf3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_divdf3, .{ .name = "__hexagon_divdf3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_divdf3, .{ .name = "__hexagon_fast_divdf3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_muldf3, .{ .name = "__hexagon_muldf3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_muldf3, .{ .name = "__hexagon_fast_muldf3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_sqrtdf2, .{ .name = "__hexagon_sqrtdf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_sqrtdf2, .{ .name = "__hexagon_fast2_sqrtdf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_sqrtdf2, .{ .name = "__hexagon_sqrt", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_divsf3, .{ .name = "__hexagon_divsf3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_divsf3, .{ .name = "__hexagon_fast_divsf3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_divsi3, .{ .name = "__hexagon_divsi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_umodsi3, .{ .name = "__hexagon_umodsi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_sqrtf, .{ .name = "__hexagon_sqrtf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_sqrtf, .{ .name = "__hexagon_fast2_sqrtf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_moddi3, .{ .name = "__hexagon_moddi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_divdi3, .{ .name = "__hexagon_divdi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_udivdi3, .{ .name = "__hexagon_udivdi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_umoddi3, .{ .name = "__hexagon_umoddi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_modsi3, .{ .name = "__hexagon_modsi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes, .{ .name = "__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__hexagon_udivsi3, .{ .name = "__hexagon_udivsi3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__hexagon_adddf3, "__hexagon_adddf3"); + symbol(&__hexagon_adddf3, "__hexagon_fast_adddf3"); + symbol(&__hexagon_subdf3, "__hexagon_subdf3"); + symbol(&__hexagon_subdf3, "__hexagon_fast_subdf3"); + symbol(&__hexagon_divdf3, "__hexagon_divdf3"); + symbol(&__hexagon_divdf3, "__hexagon_fast_divdf3"); + symbol(&__hexagon_muldf3, "__hexagon_muldf3"); + symbol(&__hexagon_muldf3, "__hexagon_fast_muldf3"); + symbol(&__hexagon_sqrtdf2, "__hexagon_sqrtdf2"); + symbol(&__hexagon_sqrtdf2, "__hexagon_fast2_sqrtdf2"); + symbol(&__hexagon_sqrtdf2, "__hexagon_sqrt"); + symbol(&__hexagon_divsf3, "__hexagon_divsf3"); + symbol(&__hexagon_divsf3, "__hexagon_fast_divsf3"); + symbol(&__hexagon_divsi3, "__hexagon_divsi3"); + symbol(&__hexagon_umodsi3, "__hexagon_umodsi3"); + symbol(&__hexagon_sqrtf, "__hexagon_sqrtf"); + symbol(&__hexagon_sqrtf, "__hexagon_fast2_sqrtf"); + symbol(&__hexagon_moddi3, "__hexagon_moddi3"); + symbol(&__hexagon_divdi3, "__hexagon_divdi3"); + symbol(&__hexagon_udivdi3, "__hexagon_udivdi3"); + symbol(&__hexagon_umoddi3, "__hexagon_umoddi3"); + symbol(&__hexagon_modsi3, "__hexagon_modsi3"); + symbol(&__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes, "__hexagon_memcpy_likely_aligned_min32bytes_mult8bytes"); + symbol(&__hexagon_udivsi3, "__hexagon_udivsi3"); } } diff --git a/lib/compiler_rt/int.zig b/lib/compiler_rt/int.zig index 3f38bad973..48c900207b 100644 --- a/lib/compiler_rt/int.zig +++ b/lib/compiler_rt/int.zig @@ -1,34 +1,37 @@ //! Builtin functions that operate on integer types const builtin = @import("builtin"); +const arch = builtin.cpu.arch; + const std = @import("std"); const testing = std.testing; const maxInt = std.math.maxInt; const minInt = std.math.minInt; -const arch = builtin.cpu.arch; -const common = @import("common.zig"); + +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const udivmod = @import("udivmod.zig").udivmod; -const __divti3 = @import("divti3.zig").__divti3; +const __divti3 = @import("udivmod.zig").__divti3; comptime { - @export(&__divmodti4, .{ .name = "__divmodti4", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__divmoddi4, .{ .name = "__divmoddi4", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_aeabi) { - @export(&__aeabi_idiv, .{ .name = "__aeabi_idiv", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_uidiv, .{ .name = "__aeabi_uidiv", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divmodti4, "__divmodti4"); + symbol(&__udivmoddi4, "__udivmoddi4"); + symbol(&__divmoddi4, "__divmoddi4"); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_idiv, "__aeabi_idiv"); + symbol(&__aeabi_uidiv, "__aeabi_uidiv"); } else { - @export(&__divsi3, .{ .name = "__divsi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__udivsi3, .{ .name = "__udivsi3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divsi3, "__divsi3"); + symbol(&__udivsi3, "__udivsi3"); } - @export(&__divdi3, .{ .name = "__divdi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__udivdi3, .{ .name = "__udivdi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__modsi3, .{ .name = "__modsi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__moddi3, .{ .name = "__moddi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__umodsi3, .{ .name = "__umodsi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__umoddi3, .{ .name = "__umoddi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__divmodsi4, .{ .name = "__divmodsi4", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__udivmodsi4, .{ .name = "__udivmodsi4", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__divdi3, "__divdi3"); + symbol(&__udivdi3, "__udivdi3"); + symbol(&__modsi3, "__modsi3"); + symbol(&__moddi3, "__moddi3"); + symbol(&__umodsi3, "__umodsi3"); + symbol(&__umoddi3, "__umoddi3"); + symbol(&__divmodsi4, "__divmodsi4"); + symbol(&__udivmodsi4, "__udivmodsi4"); } pub fn __divmodti4(a: i128, b: i128, rem: *i128) callconv(.c) i128 { diff --git a/lib/compiler_rt/int_from_float.zig b/lib/compiler_rt/int_from_float.zig index 1f1cdb215f..146456fd11 100644 --- a/lib/compiler_rt/int_from_float.zig +++ b/lib/compiler_rt/int_from_float.zig @@ -1,13 +1,58 @@ const std = @import("std"); -const Int = std.meta.Int; const math = std.math; -const Log2Int = math.Log2Int; +const Log2Int = std.math.Log2Int; + +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; + +comptime { + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__fixxfti_windows_x86_64, "__fixxfti"); + } else { + symbol(&__fixxfti, "__fixxfti"); + } + + symbol(&__fixhfsi, "__fixhfsi"); + symbol(&__fixhfdi, "__fixhfdi"); + + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__fixhfti_windows_x86_64, "__fixhfti"); + } else { + symbol(&__fixhfti, "__fixhfti"); + } +} + +const v2u64 = @Vector(2, u64); + +pub fn __fixhfti(a: f16) callconv(.c) i128 { + return intFromFloat(i128, a); +} + +fn __fixhfti_windows_x86_64(a: f16) callconv(.c) v2u64 { + return @bitCast(intFromFloat(i128, a)); +} + +fn __fixhfdi(a: f16) callconv(.c) i64 { + return intFromFloat(i64, a); +} + +fn __fixhfsi(a: f16) callconv(.c) i32 { + return intFromFloat(i32, a); +} + +pub fn __fixxfti(a: f80) callconv(.c) i128 { + return intFromFloat(i128, a); +} + +fn __fixxfti_windows_x86_64(a: f80) callconv(.c) v2u64 { + return @bitCast(intFromFloat(i128, a)); +} pub inline fn intFromFloat(comptime I: type, a: anytype) I { const F = @TypeOf(a); const float_bits = @typeInfo(F).float.bits; const int_bits = @typeInfo(I).int.bits; - const rep_t = Int(.unsigned, float_bits); + const rep_t = @Int(.unsigned, float_bits); const sig_bits = math.floatMantissaBits(F); const exp_bits = math.floatExponentBits(F); const fractional_bits = math.floatFractionalBits(F); diff --git a/lib/compiler_rt/log.zig b/lib/compiler_rt/log.zig index 3270b27916..0cd2a00ddb 100644 --- a/lib/compiler_rt/log.zig +++ b/lib/compiler_rt/log.zig @@ -5,23 +5,23 @@ //! https://git.musl-libc.org/cgit/musl/tree/src/math/log.c?h=1b76ff0767d01df72f692806ee5adee13c67ef88 const std = @import("std"); -const builtin = @import("builtin"); const math = std.math; const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; -const arch = builtin.cpu.arch; -const common = @import("common.zig"); + +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__logh, .{ .name = "__logh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&logf, .{ .name = "logf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&log, .{ .name = "log", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__logx, .{ .name = "__logx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&logq, .{ .name = "logf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__logh, "__logh"); + symbol(&logf, "logf"); + symbol(&log, "log"); + symbol(&__logx, "__logx"); + if (compiler_rt.want_ppc_abi) { + symbol(&logq, "logf128"); } - @export(&logq, .{ .name = "logq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&logl, .{ .name = "logl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&logq, "logq"); + symbol(&logl, "logl"); } pub fn __logh(a: f16) callconv(.c) f16 { @@ -45,11 +45,11 @@ pub fn logf(x_: f32) callconv(.c) f32 { if (ix < 0x00800000 or ix >> 31 != 0) { // log(+-0) = -inf if (ix << 1 == 0) { - return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); + return if (compiler_rt.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); } // log(-#) = nan if (ix >> 31 != 0) { - return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); + return if (compiler_rt.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); } // subnormal, scale x @@ -398,13 +398,13 @@ pub fn log(x: f64) callconv(.c) f64 { @branchHint(.unlikely); if (ix << 1 == 0) - return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); + return if (compiler_rt.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); if (ix == @as(i64, @bitCast(std.math.inf(f64)))) return x; if (top & 0x8000 != 0 or top & 0x7ff0 == 0x7ff0) - return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); + return if (compiler_rt.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); ix = @as(i64, @bitCast(x * 0x1p52)) - (52 << 52); } diff --git a/lib/compiler_rt/log10.zig b/lib/compiler_rt/log10.zig index d501cef461..ec4edac618 100644 --- a/lib/compiler_rt/log10.zig +++ b/lib/compiler_rt/log10.zig @@ -5,24 +5,24 @@ //! https://git.musl-libc.org/cgit/musl/tree/src/math/log10.c const std = @import("std"); -const builtin = @import("builtin"); const math = std.math; const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; const maxInt = std.math.maxInt; -const arch = builtin.cpu.arch; -const common = @import("common.zig"); + +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__log10h, .{ .name = "__log10h", .linkage = common.linkage, .visibility = common.visibility }); - @export(&log10f, .{ .name = "log10f", .linkage = common.linkage, .visibility = common.visibility }); - @export(&log10, .{ .name = "log10", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__log10x, .{ .name = "__log10x", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&log10q, .{ .name = "log10f128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__log10h, "__log10h"); + symbol(&log10f, "log10f"); + symbol(&log10, "log10"); + symbol(&__log10x, "__log10x"); + if (compiler_rt.want_ppc_abi) { + symbol(&log10q, "log10f128"); } - @export(&log10q, .{ .name = "log10q", .linkage = common.linkage, .visibility = common.visibility }); - @export(&log10l, .{ .name = "log10l", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&log10q, "log10q"); + symbol(&log10l, "log10l"); } pub fn __log10h(a: f16) callconv(.c) f16 { @@ -49,11 +49,11 @@ pub fn log10f(x_: f32) callconv(.c) f32 { if (ix < 0x00800000 or ix >> 31 != 0) { // log(+-0) = -inf if (ix << 1 == 0) { - return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); + return if (compiler_rt.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); } // log(-#) = nan if (ix >> 31 != 0) { - return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); + return if (compiler_rt.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); } k -= 25; @@ -111,11 +111,11 @@ pub fn log10(x_: f64) callconv(.c) f64 { if (hx < 0x00100000 or hx >> 31 != 0) { // log(+-0) = -inf if (ix << 1 == 0) { - return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); + return if (compiler_rt.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); } // log(-#) = nan if (hx >> 31 != 0) { - return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); + return if (compiler_rt.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); } // subnormal, scale x diff --git a/lib/compiler_rt/log2.zig b/lib/compiler_rt/log2.zig index 48ff6135d8..ad17df7f65 100644 --- a/lib/compiler_rt/log2.zig +++ b/lib/compiler_rt/log2.zig @@ -11,18 +11,19 @@ const expect = std.testing.expect; const expectEqual = std.testing.expectEqual; const maxInt = std.math.maxInt; const arch = builtin.cpu.arch; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__log2h, .{ .name = "__log2h", .linkage = common.linkage, .visibility = common.visibility }); - @export(&log2f, .{ .name = "log2f", .linkage = common.linkage, .visibility = common.visibility }); - @export(&log2, .{ .name = "log2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__log2x, .{ .name = "__log2x", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&log2q, .{ .name = "log2f128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__log2h, "__log2h"); + symbol(&log2f, "log2f"); + symbol(&log2, "log2"); + symbol(&__log2x, "__log2x"); + if (compiler_rt.want_ppc_abi) { + symbol(&log2q, "log2f128"); } - @export(&log2q, .{ .name = "log2q", .linkage = common.linkage, .visibility = common.visibility }); - @export(&log2l, .{ .name = "log2l", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&log2q, "log2q"); + symbol(&log2l, "log2l"); } pub fn __log2h(a: f16) callconv(.c) f16 { @@ -47,11 +48,11 @@ pub fn log2f(x_: f32) callconv(.c) f32 { if (ix < 0x00800000 or ix >> 31 != 0) { // log(+-0) = -inf if (ix << 1 == 0) { - return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); + return if (compiler_rt.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); } // log(-#) = nan if (ix >> 31 != 0) { - return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); + return if (compiler_rt.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); } k -= 25; @@ -105,11 +106,11 @@ pub fn log2(x_: f64) callconv(.c) f64 { if (hx < 0x00100000 or hx >> 31 != 0) { // log(+-0) = -inf if (ix << 1 == 0) { - return if (common.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); + return if (compiler_rt.want_float_exceptions) -1 / (x * x) else -std.math.inf(f64); } // log(-#) = nan if (hx >> 31 != 0) { - return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); + return if (compiler_rt.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); } // subnormal, scale x diff --git a/lib/compiler_rt/memcmp.zig b/lib/compiler_rt/memcmp.zig deleted file mode 100644 index f332d82eac..0000000000 --- a/lib/compiler_rt/memcmp.zig +++ /dev/null @@ -1,30 +0,0 @@ -const std = @import("std"); -const common = @import("./common.zig"); - -comptime { - @export(&memcmp, .{ .name = "memcmp", .linkage = common.linkage, .visibility = common.visibility }); -} - -pub fn memcmp(vl: [*]const u8, vr: [*]const u8, n: usize) callconv(.c) c_int { - var i: usize = 0; - while (i < n) : (i += 1) { - const compared = @as(c_int, vl[i]) -% @as(c_int, vr[i]); - if (compared != 0) return compared; - } - return 0; -} - -test "memcmp" { - const arr0 = &[_]u8{ 1, 1, 1 }; - const arr1 = &[_]u8{ 1, 1, 1 }; - const arr2 = &[_]u8{ 1, 0, 1 }; - const arr3 = &[_]u8{ 1, 2, 1 }; - const arr4 = &[_]u8{ 1, 0xff, 1 }; - - try std.testing.expect(memcmp(arr0, arr1, 3) == 0); - try std.testing.expect(memcmp(arr0, arr2, 3) > 0); - try std.testing.expect(memcmp(arr0, arr3, 3) < 0); - - try std.testing.expect(memcmp(arr0, arr4, 3) < 0); - try std.testing.expect(memcmp(arr4, arr0, 3) > 0); -} diff --git a/lib/compiler_rt/memcpy.zig b/lib/compiler_rt/memcpy.zig index 4dcd184d29..bb3c91eea8 100644 --- a/lib/compiler_rt/memcpy.zig +++ b/lib/compiler_rt/memcpy.zig @@ -1,14 +1,14 @@ const std = @import("std"); const assert = std.debug.assert; -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const builtin = @import("builtin"); comptime { if (builtin.object_format != .c) { const export_options: std.builtin.ExportOptions = .{ .name = "memcpy", - .linkage = common.linkage, - .visibility = common.visibility, + .linkage = compiler_rt.linkage, + .visibility = compiler_rt.visibility, }; if (builtin.mode == .ReleaseSmall or builtin.zig_backend == .stage2_aarch64) @@ -18,7 +18,7 @@ comptime { } } -const Element = common.PreferredLoadStoreElement; +const Element = compiler_rt.PreferredLoadStoreElement; comptime { assert(std.math.isPowerOfTwo(@sizeOf(Element))); diff --git a/lib/compiler_rt/memmove.zig b/lib/compiler_rt/memmove.zig index c57ba9c3cc..ad501e758a 100644 --- a/lib/compiler_rt/memmove.zig +++ b/lib/compiler_rt/memmove.zig @@ -1,17 +1,17 @@ const std = @import("std"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const builtin = @import("builtin"); const assert = std.debug.assert; const memcpy = @import("memcpy.zig"); -const Element = common.PreferredLoadStoreElement; +const Element = compiler_rt.PreferredLoadStoreElement; comptime { if (builtin.object_format != .c) { const export_options: std.builtin.ExportOptions = .{ .name = "memmove", - .linkage = common.linkage, - .visibility = common.visibility, + .linkage = compiler_rt.linkage, + .visibility = compiler_rt.visibility, }; if (builtin.mode == .ReleaseSmall or builtin.zig_backend == .stage2_aarch64) @@ -39,7 +39,7 @@ fn memmoveSmall(opt_dest: ?[*]u8, opt_src: ?[*]const u8, len: usize) callconv(.c } fn memmoveFast(dest: ?[*]u8, src: ?[*]u8, len: usize) callconv(.c) ?[*]u8 { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); const small_limit = @max(2 * @sizeOf(Element), @sizeOf(Element)); if (copySmallLength(small_limit, dest.?, src.?, len)) return dest; @@ -79,7 +79,7 @@ inline fn copyLessThan16( src: [*]const u8, len: usize, ) void { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); if (len < 4) { if (len == 0) return; const b = len / 2; @@ -100,7 +100,7 @@ inline fn copy16ToSmallLimit( src: [*]const u8, len: usize, ) bool { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); inline for (2..(std.math.log2(small_limit) + 1) / 2 + 1) |p| { const limit = 1 << (2 * p); if (len < limit) { @@ -119,7 +119,7 @@ inline fn copyRange4( src: [*]const u8, len: usize, ) void { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); comptime assert(std.math.isPowerOfTwo(copy_len)); assert(len >= copy_len); assert(len < 4 * copy_len); @@ -147,7 +147,7 @@ inline fn copyForwards( src: [*]const u8, len: usize, ) void { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); assert(len >= 2 * @sizeOf(Element)); const head = src[0..@sizeOf(Element)].*; @@ -181,7 +181,7 @@ inline fn copyBlocks( src: anytype, max_bytes: usize, ) void { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); const T = @typeInfo(@TypeOf(dest)).pointer.child; comptime assert(T == @typeInfo(@TypeOf(src)).pointer.child); diff --git a/lib/compiler_rt/memset.zig b/lib/compiler_rt/memset.zig deleted file mode 100644 index 6b51037b57..0000000000 --- a/lib/compiler_rt/memset.zig +++ /dev/null @@ -1,33 +0,0 @@ -const std = @import("std"); -const common = @import("./common.zig"); -const builtin = @import("builtin"); - -comptime { - if (builtin.object_format != .c) { - @export(&memset, .{ .name = "memset", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__memset, .{ .name = "__memset", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -pub fn memset(dest: ?[*]u8, c: u8, len: usize) callconv(.c) ?[*]u8 { - @setRuntimeSafety(false); - - if (len != 0) { - var d = dest.?; - var n = len; - while (true) { - d[0] = c; - n -= 1; - if (n == 0) break; - d += 1; - } - } - - return dest; -} - -pub fn __memset(dest: ?[*]u8, c: u8, n: usize, dest_n: usize) callconv(.c) ?[*]u8 { - if (dest_n < n) - @panic("buffer overflow"); - return memset(dest, c, n); -} diff --git a/lib/compiler_rt/modti3.zig b/lib/compiler_rt/modti3.zig deleted file mode 100644 index 74e431a061..0000000000 --- a/lib/compiler_rt/modti3.zig +++ /dev/null @@ -1,42 +0,0 @@ -//! Ported from: -//! -//! https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/modti3.c - -const std = @import("std"); -const builtin = @import("builtin"); -const udivmod = @import("udivmod.zig").udivmod; -const common = @import("common.zig"); - -comptime { - if (common.want_windows_v2u64_abi) { - @export(&__modti3_windows_x86_64, .{ .name = "__modti3", .linkage = common.linkage, .visibility = common.visibility }); - } else { - @export(&__modti3, .{ .name = "__modti3", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -pub fn __modti3(a: i128, b: i128) callconv(.c) i128 { - return mod(a, b); -} - -const v2u64 = @Vector(2, u64); - -fn __modti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.c) v2u64 { - return @bitCast(mod(@as(i128, @bitCast(a)), @as(i128, @bitCast(b)))); -} - -inline fn mod(a: i128, b: i128) i128 { - const s_a = a >> (128 - 1); // s = a < 0 ? -1 : 0 - const s_b = b >> (128 - 1); // s = b < 0 ? -1 : 0 - - const an = (a ^ s_a) -% s_a; // negate if s == -1 - const bn = (b ^ s_b) -% s_b; // negate if s == -1 - - var r: u128 = undefined; - _ = udivmod(u128, @as(u128, @bitCast(an)), @as(u128, @bitCast(bn)), &r); - return (@as(i128, @bitCast(r)) ^ s_a) -% s_a; // negate if s == -1 -} - -test { - _ = @import("modti3_test.zig"); -} diff --git a/lib/compiler_rt/modti3_test.zig b/lib/compiler_rt/modti3_test.zig index 800547b48b..6959e09dcc 100644 --- a/lib/compiler_rt/modti3_test.zig +++ b/lib/compiler_rt/modti3_test.zig @@ -1,4 +1,4 @@ -const __modti3 = @import("modti3.zig").__modti3; +const __modti3 = @import("udivmod.zig").__modti3; const testing = @import("std").testing; fn test__modti3(a: i128, b: i128, expected: i128) !void { diff --git a/lib/compiler_rt/mulXi3.zig b/lib/compiler_rt/mulXi3.zig index 198d51c888..41df7283ea 100644 --- a/lib/compiler_rt/mulXi3.zig +++ b/lib/compiler_rt/mulXi3.zig @@ -1,20 +1,21 @@ const builtin = @import("builtin"); const std = @import("std"); const testing = std.testing; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const native_endian = builtin.cpu.arch.endian(); comptime { - @export(&__mulsi3, .{ .name = "__mulsi3", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_aeabi) { - @export(&__aeabi_lmul, .{ .name = "__aeabi_lmul", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__mulsi3, "__mulsi3"); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_lmul, "__aeabi_lmul"); } else { - @export(&__muldi3, .{ .name = "__muldi3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__muldi3, "__muldi3"); } - if (common.want_windows_v2u64_abi) { - @export(&__multi3_windows_x86_64, .{ .name = "__multi3", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__multi3_windows_x86_64, "__multi3"); } else { - @export(&__multi3, .{ .name = "__multi3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__multi3, "__multi3"); } } @@ -41,7 +42,7 @@ fn __aeabi_lmul(a: i64, b: i64) callconv(.{ .arm_aapcs = .{} }) i64 { } inline fn mulX(comptime T: type, a: T, b: T) T { - const word_t = common.HalveInt(T, false); + const word_t = compiler_rt.HalveInt(T, false); const x = word_t{ .all = a }; const y = word_t{ .all = b }; var r = switch (T) { @@ -64,7 +65,7 @@ fn DoubleInt(comptime T: type) type { fn muldXi(comptime T: type, a: T, b: T) DoubleInt(T) { const DT = DoubleInt(T); - const word_t = common.HalveInt(DT, false); + const word_t = compiler_rt.HalveInt(DT, false); const bits_in_word_2 = @sizeOf(T) * 8 / 2; const lower_mask = (~@as(T, 0)) >> bits_in_word_2; diff --git a/lib/compiler_rt/muldc3.zig b/lib/compiler_rt/muldc3.zig index 9670c13128..d5facaa2b6 100644 --- a/lib/compiler_rt/muldc3.zig +++ b/lib/compiler_rt/muldc3.zig @@ -1,9 +1,9 @@ -const common = @import("./common.zig"); const mulc3 = @import("./mulc3.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { if (@import("builtin").zig_backend != .stage2_c) { - @export(&__muldc3, .{ .name = "__muldc3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__muldc3, "__muldc3"); } } diff --git a/lib/compiler_rt/muldf3.zig b/lib/compiler_rt/muldf3.zig index cf67df0913..b8809e76da 100644 --- a/lib/compiler_rt/muldf3.zig +++ b/lib/compiler_rt/muldf3.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const mulf3 = @import("./mulf3.zig").mulf3; comptime { - if (common.want_aeabi) { - @export(&__aeabi_dmul, .{ .name = "__aeabi_dmul", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_dmul, "__aeabi_dmul"); } else { - @export(&__muldf3, .{ .name = "__muldf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__muldf3, "__muldf3"); } } diff --git a/lib/compiler_rt/mulf3.zig b/lib/compiler_rt/mulf3.zig index 34d39fb9b7..d85b0bf8d5 100644 --- a/lib/compiler_rt/mulf3.zig +++ b/lib/compiler_rt/mulf3.zig @@ -1,12 +1,12 @@ const std = @import("std"); const math = std.math; const builtin = @import("builtin"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); /// Ported from: /// https://github.com/llvm/llvm-project/blob/2ffb1b0413efa9a24eb3c49e710e36f92e2cb50b/compiler-rt/lib/builtins/fp_mul_impl.inc pub inline fn mulf3(comptime T: type, a: T, b: T) T { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); const typeWidth = @typeInfo(T).float.bits; const significandBits = math.floatMantissaBits(T); const fractionalBits = math.floatFractionalBits(T); @@ -97,7 +97,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { var productHi: ZSignificand = undefined; var productLo: ZSignificand = undefined; const left_align_shift = ZSignificandBits - fractionalBits - 1; - common.wideMultiply(ZSignificand, aSignificand, bSignificand << left_align_shift, &productHi, &productLo); + compiler_rt.wideMultiply(ZSignificand, aSignificand, bSignificand << left_align_shift, &productHi, &productLo); var productExponent: i32 = @as(i32, @intCast(aExponent + bExponent)) - exponentBias + scale; @@ -163,7 +163,7 @@ pub inline fn mulf3(comptime T: type, a: T, b: T) T { /// /// This is analogous to an shr version of `@shlWithOverflow` fn wideShrWithTruncation(comptime Z: type, hi: *Z, lo: *Z, count: u32) bool { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); const typeWidth = @typeInfo(Z).int.bits; var inexact = false; if (count < typeWidth) { diff --git a/lib/compiler_rt/mulhc3.zig b/lib/compiler_rt/mulhc3.zig index 09bca03a05..4e0d3f8753 100644 --- a/lib/compiler_rt/mulhc3.zig +++ b/lib/compiler_rt/mulhc3.zig @@ -1,9 +1,10 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const mulc3 = @import("./mulc3.zig"); comptime { if (@import("builtin").zig_backend != .stage2_c) { - @export(&__mulhc3, .{ .name = "__mulhc3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__mulhc3, "__mulhc3"); } } diff --git a/lib/compiler_rt/mulhf3.zig b/lib/compiler_rt/mulhf3.zig index 22f7a95627..46ce7a6b99 100644 --- a/lib/compiler_rt/mulhf3.zig +++ b/lib/compiler_rt/mulhf3.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const mulf3 = @import("./mulf3.zig").mulf3; comptime { - @export(&__mulhf3, .{ .name = "__mulhf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__mulhf3, "__mulhf3"); } pub fn __mulhf3(a: f16, b: f16) callconv(.c) f16 { diff --git a/lib/compiler_rt/mulo.zig b/lib/compiler_rt/mulo.zig index b85623eb7e..979a5452a5 100644 --- a/lib/compiler_rt/mulo.zig +++ b/lib/compiler_rt/mulo.zig @@ -1,12 +1,13 @@ const std = @import("std"); const builtin = @import("builtin"); const math = std.math; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__mulosi4, .{ .name = "__mulosi4", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__mulodi4, .{ .name = "__mulodi4", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__muloti4, .{ .name = "__muloti4", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__mulosi4, "__mulosi4"); + symbol(&__mulodi4, "__mulodi4"); + symbol(&__muloti4, "__muloti4"); } // mulo - multiplication overflow diff --git a/lib/compiler_rt/mulsc3.zig b/lib/compiler_rt/mulsc3.zig index 49c1e31aec..e735e65ead 100644 --- a/lib/compiler_rt/mulsc3.zig +++ b/lib/compiler_rt/mulsc3.zig @@ -1,9 +1,9 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const mulc3 = @import("./mulc3.zig"); comptime { if (@import("builtin").zig_backend != .stage2_c) { - @export(&__mulsc3, .{ .name = "__mulsc3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__mulsc3, "__mulsc3"); } } diff --git a/lib/compiler_rt/mulsf3.zig b/lib/compiler_rt/mulsf3.zig index a603652262..81f9eafae2 100644 --- a/lib/compiler_rt/mulsf3.zig +++ b/lib/compiler_rt/mulsf3.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const mulf3 = @import("./mulf3.zig").mulf3; comptime { - if (common.want_aeabi) { - @export(&__aeabi_fmul, .{ .name = "__aeabi_fmul", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_fmul, "__aeabi_fmul"); } else { - @export(&__mulsf3, .{ .name = "__mulsf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__mulsf3, "__mulsf3"); } } diff --git a/lib/compiler_rt/multc3.zig b/lib/compiler_rt/multc3.zig index 1ed373660f..4914735b10 100644 --- a/lib/compiler_rt/multc3.zig +++ b/lib/compiler_rt/multc3.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const mulc3 = @import("./mulc3.zig"); comptime { if (@import("builtin").zig_backend != .stage2_c) { - if (common.want_ppc_abi) - @export(&__multc3, .{ .name = "__mulkc3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__multc3, .{ .name = "__multc3", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) + symbol(&__multc3, "__mulkc3"); + symbol(&__multc3, "__multc3"); } } diff --git a/lib/compiler_rt/multf3.zig b/lib/compiler_rt/multf3.zig index 6ef9cc2c25..3befe34da0 100644 --- a/lib/compiler_rt/multf3.zig +++ b/lib/compiler_rt/multf3.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const mulf3 = @import("./mulf3.zig").mulf3; comptime { - if (common.want_ppc_abi) { - @export(&__multf3, .{ .name = "__mulkf3", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_mul, .{ .name = "_Qp_mul", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__multf3, "__mulkf3"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_mul, "_Qp_mul"); } - @export(&__multf3, .{ .name = "__multf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__multf3, "__multf3"); } pub fn __multf3(a: f128, b: f128) callconv(.c) f128 { diff --git a/lib/compiler_rt/mulvsi3.zig b/lib/compiler_rt/mulvsi3.zig index e773ea0d9a..0935ea497a 100644 --- a/lib/compiler_rt/mulvsi3.zig +++ b/lib/compiler_rt/mulvsi3.zig @@ -1,9 +1,10 @@ -const mulv = @import("mulo.zig"); -const common = @import("./common.zig"); const testing = @import("std").testing; +const mulv = @import("mulo.zig"); +const symbol = @import("../compiler_rt.zig").symbol; + comptime { - @export(&__mulvsi3, .{ .name = "__mulvsi3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__mulvsi3, "__mulvsi3"); } pub fn __mulvsi3(a: i32, b: i32) callconv(.c) i32 { diff --git a/lib/compiler_rt/mulxc3.zig b/lib/compiler_rt/mulxc3.zig index cbf9c64083..ac0e189f63 100644 --- a/lib/compiler_rt/mulxc3.zig +++ b/lib/compiler_rt/mulxc3.zig @@ -1,9 +1,10 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const mulc3 = @import("./mulc3.zig"); comptime { if (@import("builtin").zig_backend != .stage2_c) { - @export(&__mulxc3, .{ .name = "__mulxc3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__mulxc3, "__mulxc3"); } } diff --git a/lib/compiler_rt/mulxf3.zig b/lib/compiler_rt/mulxf3.zig index 1d9f465ebd..dcf783a4a6 100644 --- a/lib/compiler_rt/mulxf3.zig +++ b/lib/compiler_rt/mulxf3.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const mulf3 = @import("./mulf3.zig").mulf3; comptime { - @export(&__mulxf3, .{ .name = "__mulxf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__mulxf3, "__mulxf3"); } pub fn __mulxf3(a: f80, b: f80) callconv(.c) f80 { diff --git a/lib/compiler_rt/negXi2.zig b/lib/compiler_rt/negXi2.zig deleted file mode 100644 index 7a57e988c6..0000000000 --- a/lib/compiler_rt/negXi2.zig +++ /dev/null @@ -1,39 +0,0 @@ -//! neg - negate (the number) -//! - negXi2 for unoptimized little and big endian -//! sfffffff = 2^31-1 -//! two's complement inverting bits and add 1 would result in -INT_MIN == 0 -//! => -INT_MIN = -2^31 forbidden -//! * size optimized builds -//! * machines that dont support carry operations - -const std = @import("std"); -const builtin = @import("builtin"); -const common = @import("common.zig"); - -comptime { - @export(&__negsi2, .{ .name = "__negsi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__negdi2, .{ .name = "__negdi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__negti2, .{ .name = "__negti2", .linkage = common.linkage, .visibility = common.visibility }); -} - -pub fn __negsi2(a: i32) callconv(.c) i32 { - return negXi2(i32, a); -} - -pub fn __negdi2(a: i64) callconv(.c) i64 { - return negXi2(i64, a); -} - -pub fn __negti2(a: i128) callconv(.c) i128 { - return negXi2(i128, a); -} - -inline fn negXi2(comptime T: type, a: T) T { - return -a; -} - -test { - _ = @import("negsi2_test.zig"); - _ = @import("negdi2_test.zig"); - _ = @import("negti2_test.zig"); -} diff --git a/lib/compiler_rt/negdf2.zig b/lib/compiler_rt/negdf2.zig deleted file mode 100644 index b0ac26e6c0..0000000000 --- a/lib/compiler_rt/negdf2.zig +++ /dev/null @@ -1,17 +0,0 @@ -const common = @import("./common.zig"); - -comptime { - if (common.want_aeabi) { - @export(&__aeabi_dneg, .{ .name = "__aeabi_dneg", .linkage = common.linkage, .visibility = common.visibility }); - } else { - @export(&__negdf2, .{ .name = "__negdf2", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -fn __negdf2(a: f64) callconv(.c) f64 { - return common.fneg(a); -} - -fn __aeabi_dneg(a: f64) callconv(.{ .arm_aapcs = .{} }) f64 { - return common.fneg(a); -} diff --git a/lib/compiler_rt/negdi2_test.zig b/lib/compiler_rt/negdi2_test.zig index a4bb0217ad..2a3a966193 100644 --- a/lib/compiler_rt/negdi2_test.zig +++ b/lib/compiler_rt/negdi2_test.zig @@ -1,8 +1,10 @@ -const neg = @import("negXi2.zig"); -const testing = @import("std").testing; +const std = @import("std"); +const testing = std.testing; + +const compiler_rt = @import("../compiler_rt.zig"); fn test__negdi2(a: i64, expected: i64) !void { - const result = neg.__negdi2(a); + const result = compiler_rt.__negdi2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/neghf2.zig b/lib/compiler_rt/neghf2.zig deleted file mode 100644 index 59c7e155b7..0000000000 --- a/lib/compiler_rt/neghf2.zig +++ /dev/null @@ -1,9 +0,0 @@ -const common = @import("./common.zig"); - -comptime { - @export(&__neghf2, .{ .name = "__neghf2", .linkage = common.linkage, .visibility = common.visibility }); -} - -fn __neghf2(a: f16) callconv(.c) f16 { - return common.fneg(a); -} diff --git a/lib/compiler_rt/negsf2.zig b/lib/compiler_rt/negsf2.zig deleted file mode 100644 index 065dc3acd1..0000000000 --- a/lib/compiler_rt/negsf2.zig +++ /dev/null @@ -1,17 +0,0 @@ -const common = @import("./common.zig"); - -comptime { - if (common.want_aeabi) { - @export(&__aeabi_fneg, .{ .name = "__aeabi_fneg", .linkage = common.linkage, .visibility = common.visibility }); - } else { - @export(&__negsf2, .{ .name = "__negsf2", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -fn __negsf2(a: f32) callconv(.c) f32 { - return common.fneg(a); -} - -fn __aeabi_fneg(a: f32) callconv(.{ .arm_aapcs = .{} }) f32 { - return common.fneg(a); -} diff --git a/lib/compiler_rt/negsi2_test.zig b/lib/compiler_rt/negsi2_test.zig index 2584de2136..0eecd6a728 100644 --- a/lib/compiler_rt/negsi2_test.zig +++ b/lib/compiler_rt/negsi2_test.zig @@ -1,11 +1,12 @@ const std = @import("std"); -const neg = @import("negXi2.zig"); const testing = std.testing; +const compiler_rt = @import("../compiler_rt.zig"); + const print = std.debug.print; fn test__negsi2(a: i32, expected: i32) !void { - const result = neg.__negsi2(a); + const result = compiler_rt.__negsi2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/negtf2.zig b/lib/compiler_rt/negtf2.zig deleted file mode 100644 index ecb5cc2c90..0000000000 --- a/lib/compiler_rt/negtf2.zig +++ /dev/null @@ -1,11 +0,0 @@ -const common = @import("./common.zig"); - -comptime { - if (common.want_ppc_abi) - @export(&__negtf2, .{ .name = "__negkf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__negtf2, .{ .name = "__negtf2", .linkage = common.linkage, .visibility = common.visibility }); -} - -fn __negtf2(a: f128) callconv(.c) f128 { - return common.fneg(a); -} diff --git a/lib/compiler_rt/negti2_test.zig b/lib/compiler_rt/negti2_test.zig index d58f9c8f27..ea9e917312 100644 --- a/lib/compiler_rt/negti2_test.zig +++ b/lib/compiler_rt/negti2_test.zig @@ -1,8 +1,10 @@ -const neg = @import("negXi2.zig"); -const testing = @import("std").testing; +const std = @import("std"); +const testing = std.testing; + +const compiler_rt = @import("../compiler_rt.zig"); fn test__negti2(a: i128, expected: i128) !void { - const result = neg.__negti2(a); + const result = compiler_rt.__negti2(a); try testing.expectEqual(expected, result); } diff --git a/lib/compiler_rt/negv.zig b/lib/compiler_rt/negv.zig index 98934b78f4..7c67a51c34 100644 --- a/lib/compiler_rt/negv.zig +++ b/lib/compiler_rt/negv.zig @@ -3,12 +3,13 @@ //! - negvXi4_generic for unoptimized version const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__negvsi2, .{ .name = "__negvsi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__negvdi2, .{ .name = "__negvdi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__negvti2, .{ .name = "__negvti2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__negvsi2, "__negvsi2"); + symbol(&__negvdi2, "__negvdi2"); + symbol(&__negvti2, "__negvti2"); } pub fn __negvsi2(a: i32) callconv(.c) i32 { diff --git a/lib/compiler_rt/negxf2.zig b/lib/compiler_rt/negxf2.zig deleted file mode 100644 index ea16c8fef2..0000000000 --- a/lib/compiler_rt/negxf2.zig +++ /dev/null @@ -1,9 +0,0 @@ -const common = @import("./common.zig"); - -comptime { - @export(&__negxf2, .{ .name = "__negxf2", .linkage = common.linkage, .visibility = common.visibility }); -} - -fn __negxf2(a: f80) callconv(.c) f80 { - return common.fneg(a); -} diff --git a/lib/compiler_rt/os_version_check.zig b/lib/compiler_rt/os_version_check.zig index a2dc7f221e..e575fef9ce 100644 --- a/lib/compiler_rt/os_version_check.zig +++ b/lib/compiler_rt/os_version_check.zig @@ -1,15 +1,16 @@ const std = @import("std"); const testing = std.testing; const builtin = @import("builtin"); -const common = @import("common.zig"); -const panic = @import("common.zig").panic; +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; +const panic = @import("../compiler_rt.zig").panic; const have_availability_version_check = builtin.os.tag.isDarwin() and builtin.os.version_range.semver.min.order(.{ .major = 10, .minor = 15, .patch = 0 }).compare(.gte); comptime { if (have_availability_version_check) { - @export(&__isPlatformVersionAtLeast, .{ .name = "__isPlatformVersionAtLeast", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__isPlatformVersionAtLeast, "__isPlatformVersionAtLeast"); } } diff --git a/lib/compiler_rt/parity.zig b/lib/compiler_rt/parity.zig index 71d50f327b..e388169904 100644 --- a/lib/compiler_rt/parity.zig +++ b/lib/compiler_rt/parity.zig @@ -1,14 +1,11 @@ //! parity - if number of bits set is even => 0, else => 1 //! - pariytXi2_generic for big and little endian - -const std = @import("std"); -const builtin = @import("builtin"); -const common = @import("common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__paritysi2, .{ .name = "__paritysi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__paritydi2, .{ .name = "__paritydi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__parityti2, .{ .name = "__parityti2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__paritysi2, "__paritysi2"); + symbol(&__paritydi2, "__paritydi2"); + symbol(&__parityti2, "__parityti2"); } pub fn __paritysi2(a: i32) callconv(.c) i32 { @@ -24,7 +21,7 @@ pub fn __parityti2(a: i128) callconv(.c) i32 { } inline fn parityXi2(comptime T: type, a: T) i32 { - var x: std.meta.Int(.unsigned, @typeInfo(T).int.bits) = @bitCast(a); + var x: @Int(.unsigned, @typeInfo(T).int.bits) = @bitCast(a); // Bit Twiddling Hacks: Compute parity in parallel comptime var shift: u8 = @bitSizeOf(T) / 2; inline while (shift > 2) { diff --git a/lib/compiler_rt/popcount.zig b/lib/compiler_rt/popcount.zig index 12ecda16cc..b1ef500ea1 100644 --- a/lib/compiler_rt/popcount.zig +++ b/lib/compiler_rt/popcount.zig @@ -6,14 +6,12 @@ //! TAOCP: Combinational Algorithms, Bitwise Tricks And Techniques, //! subsubsection "Working with the rightmost bits" and "Sideways addition". -const builtin = @import("builtin"); -const std = @import("std"); -const common = @import("common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__popcountsi2, .{ .name = "__popcountsi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__popcountdi2, .{ .name = "__popcountdi2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__popcountti2, .{ .name = "__popcountti2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__popcountsi2, "__popcountsi2"); + symbol(&__popcountdi2, "__popcountdi2"); + symbol(&__popcountti2, "__popcountti2"); } pub fn __popcountsi2(a: i32) callconv(.c) i32 { diff --git a/lib/compiler_rt/powiXf2.zig b/lib/compiler_rt/powiXf2.zig index b603998d55..b2a1e3e698 100644 --- a/lib/compiler_rt/powiXf2.zig +++ b/lib/compiler_rt/powiXf2.zig @@ -3,18 +3,17 @@ //! Multiplication order (left-to-right or right-to-left) does not matter for //! error propagation and this method is optimized for performance, not accuracy. -const builtin = @import("builtin"); -const common = @import("common.zig"); -const std = @import("std"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__powihf2, .{ .name = "__powihf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__powisf2, .{ .name = "__powisf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__powidf2, .{ .name = "__powidf2", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) - @export(&__powitf2, .{ .name = "__powikf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__powitf2, .{ .name = "__powitf2", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__powixf2, .{ .name = "__powixf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__powihf2, "__powihf2"); + symbol(&__powisf2, "__powisf2"); + symbol(&__powidf2, "__powidf2"); + if (compiler_rt.want_ppc_abi) + symbol(&__powitf2, "__powikf2"); + symbol(&__powitf2, "__powitf2"); + symbol(&__powixf2, "__powixf2"); } inline fn powiXf2(comptime FT: type, a: FT, b: i32) FT { diff --git a/lib/compiler_rt/round.zig b/lib/compiler_rt/round.zig index b643bfd89f..8087fd6e15 100644 --- a/lib/compiler_rt/round.zig +++ b/lib/compiler_rt/round.zig @@ -10,18 +10,19 @@ const math = std.math; const mem = std.mem; const expect = std.testing.expect; const arch = builtin.cpu.arch; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__roundh, .{ .name = "__roundh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&roundf, .{ .name = "roundf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&round, .{ .name = "round", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__roundx, .{ .name = "__roundx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&roundq, .{ .name = "roundf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__roundh, "__roundh"); + symbol(&roundf, "roundf"); + symbol(&round, "round"); + symbol(&__roundx, "__roundx"); + if (compiler_rt.want_ppc_abi) { + symbol(&roundq, "roundf128"); } - @export(&roundq, .{ .name = "roundq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&roundl, .{ .name = "roundl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&roundq, "roundq"); + symbol(&roundl, "roundl"); } pub fn __roundh(x: f16) callconv(.c) f16 { @@ -44,7 +45,7 @@ pub fn roundf(x_: f32) callconv(.c) f32 { x = -x; } if (e < 0x7F - 1) { - if (common.want_float_exceptions) mem.doNotOptimizeAway(x + f32_toint); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + f32_toint); return 0 * @as(f32, @bitCast(u)); } @@ -79,7 +80,7 @@ pub fn round(x_: f64) callconv(.c) f64 { x = -x; } if (e < 0x3ff - 1) { - if (common.want_float_exceptions) mem.doNotOptimizeAway(x + f64_toint); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + f64_toint); return 0 * @as(f64, @bitCast(u)); } @@ -119,7 +120,7 @@ pub fn roundq(x_: f128) callconv(.c) f128 { x = -x; } if (e < 0x3FFF - 1) { - if (common.want_float_exceptions) mem.doNotOptimizeAway(x + f128_toint); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + f128_toint); return 0 * @as(f128, @bitCast(u)); } diff --git a/lib/compiler_rt/shift.zig b/lib/compiler_rt/shift.zig index 9c75bd3475..425ca2c69c 100644 --- a/lib/compiler_rt/shift.zig +++ b/lib/compiler_rt/shift.zig @@ -1,33 +1,34 @@ const std = @import("std"); const builtin = @import("builtin"); const Log2Int = std.math.Log2Int; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { // symbol compatibility with libgcc - @export(&__ashlsi3, .{ .name = "__ashlsi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ashrsi3, .{ .name = "__ashrsi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__lshrsi3, .{ .name = "__lshrsi3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__ashlsi3, "__ashlsi3"); + symbol(&__ashrsi3, "__ashrsi3"); + symbol(&__lshrsi3, "__lshrsi3"); - @export(&__ashlti3, .{ .name = "__ashlti3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ashrti3, .{ .name = "__ashrti3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__lshrti3, .{ .name = "__lshrti3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__ashlti3, "__ashlti3"); + symbol(&__ashrti3, "__ashrti3"); + symbol(&__lshrti3, "__lshrti3"); - if (common.want_aeabi) { - @export(&__aeabi_llsl, .{ .name = "__aeabi_llsl", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_lasr, .{ .name = "__aeabi_lasr", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__aeabi_llsr, .{ .name = "__aeabi_llsr", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_llsl, "__aeabi_llsl"); + symbol(&__aeabi_lasr, "__aeabi_lasr"); + symbol(&__aeabi_llsr, "__aeabi_llsr"); } else { - @export(&__ashldi3, .{ .name = "__ashldi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__ashrdi3, .{ .name = "__ashrdi3", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__lshrdi3, .{ .name = "__lshrdi3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__ashldi3, "__ashldi3"); + symbol(&__ashrdi3, "__ashrdi3"); + symbol(&__lshrdi3, "__lshrdi3"); } } // Arithmetic shift left: shift in 0 from right to left // Precondition: 0 <= b < bits_in_dword inline fn ashlXi3(comptime T: type, a: T, b: i32) T { - const word_t = common.HalveInt(T, false); + const word_t = compiler_rt.HalveInt(T, false); const input = word_t{ .all = a }; var output: word_t = undefined; @@ -49,7 +50,7 @@ inline fn ashlXi3(comptime T: type, a: T, b: i32) T { // Arithmetic shift right: shift in 1 from left to right // Precondition: 0 <= b < T.bit_count inline fn ashrXi3(comptime T: type, a: T, b: i32) T { - const word_t = common.HalveInt(T, true); + const word_t = compiler_rt.HalveInt(T, true); const input = word_t{ .all = a }; var output: word_t = undefined; @@ -72,7 +73,7 @@ inline fn ashrXi3(comptime T: type, a: T, b: i32) T { // Logical shift right: shift in 0 from left to right // Precondition: 0 <= b < T.bit_count inline fn lshrXi3(comptime T: type, a: T, b: i32) T { - const word_t = common.HalveInt(T, false); + const word_t = compiler_rt.HalveInt(T, false); const input = word_t{ .all = a }; var output: word_t = undefined; diff --git a/lib/compiler_rt/sin.zig b/lib/compiler_rt/sin.zig index d25c1cd23a..ef3709bc18 100644 --- a/lib/compiler_rt/sin.zig +++ b/lib/compiler_rt/sin.zig @@ -5,27 +5,26 @@ //! https://git.musl-libc.org/cgit/musl/tree/src/math/sin.c const std = @import("std"); -const builtin = @import("builtin"); -const arch = builtin.cpu.arch; const math = std.math; const mem = std.mem; const expect = std.testing.expect; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const trig = @import("trig.zig"); const rem_pio2 = @import("rem_pio2.zig").rem_pio2; const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f; comptime { - @export(&__sinh, .{ .name = "__sinh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&sinf, .{ .name = "sinf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&sin, .{ .name = "sin", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__sinx, .{ .name = "__sinx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&sinq, .{ .name = "sinf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__sinh, "__sinh"); + symbol(&sinf, "sinf"); + symbol(&sin, "sin"); + symbol(&__sinx, "__sinx"); + if (compiler_rt.want_ppc_abi) { + symbol(&sinq, "sinf128"); } - @export(&sinq, .{ .name = "sinq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&sinl, .{ .name = "sinl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&sinq, "sinq"); + symbol(&sinl, "sinl"); } pub fn __sinh(x: f16) callconv(.c) f16 { @@ -47,7 +46,7 @@ pub fn sinf(x: f32) callconv(.c) f32 { if (ix <= 0x3f490fda) { // |x| ~<= pi/4 if (ix < 0x39800000) { // |x| < 2**-12 // raise inexact if x!=0 and underflow if subnormal - if (common.want_float_exceptions) { + if (compiler_rt.want_float_exceptions) { if (ix < 0x00800000) { mem.doNotOptimizeAway(x / 0x1p120); } else { @@ -102,7 +101,7 @@ pub fn sin(x: f64) callconv(.c) f64 { if (ix <= 0x3fe921fb) { if (ix < 0x3e500000) { // |x| < 2**-26 // raise inexact if x != 0 and underflow if subnormal - if (common.want_float_exceptions) { + if (compiler_rt.want_float_exceptions) { if (ix < 0x00100000) { mem.doNotOptimizeAway(x / 0x1p120); } else { diff --git a/lib/compiler_rt/sincos.zig b/lib/compiler_rt/sincos.zig index 46fec8ff64..6aeb1105e5 100644 --- a/lib/compiler_rt/sincos.zig +++ b/lib/compiler_rt/sincos.zig @@ -6,18 +6,19 @@ const mem = std.mem; const trig = @import("trig.zig"); const rem_pio2 = @import("rem_pio2.zig").rem_pio2; const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__sincosh, .{ .name = "__sincosh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&sincosf, .{ .name = "sincosf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&sincos, .{ .name = "sincos", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__sincosx, .{ .name = "__sincosx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&sincosq, .{ .name = "sincosf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__sincosh, "__sincosh"); + symbol(&sincosf, "sincosf"); + symbol(&sincos, "sincos"); + symbol(&__sincosx, "__sincosx"); + if (compiler_rt.want_ppc_abi) { + symbol(&sincosq, "sincosf128"); } - @export(&sincosq, .{ .name = "sincosq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&sincosl, .{ .name = "sincosl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&sincosq, "sincosq"); + symbol(&sincosl, "sincosl"); } pub fn __sincosh(x: f16, r_sin: *f16, r_cos: *f16) callconv(.c) void { @@ -44,7 +45,7 @@ pub fn sincosf(x: f32, r_sin: *f32, r_cos: *f32) callconv(.c) void { // |x| < 2**-12 if (ix < 0x39800000) { // raise inexact if x!=0 and underflow if subnormal - if (common.want_float_exceptions) { + if (compiler_rt.want_float_exceptions) { if (ix < 0x00100000) { mem.doNotOptimizeAway(x / 0x1p120); } else { @@ -138,7 +139,7 @@ pub fn sincos(x: f64, r_sin: *f64, r_cos: *f64) callconv(.c) void { // if |x| < 2**-27 * sqrt(2) if (ix < 0x3e46a09e) { // raise inexact if x != 0 and underflow if subnormal - if (common.want_float_exceptions) { + if (compiler_rt.want_float_exceptions) { if (ix < 0x00100000) { mem.doNotOptimizeAway(x / 0x1p120); } else { @@ -242,7 +243,7 @@ inline fn sincos_generic(comptime F: type, x: F, r_sin: *F, r_cos: *F) void { if (se < 0x3fff - math.floatFractionalBits(F) - 1) { // raise underflow if subnormal if (se == 0) { - if (common.want_float_exceptions) mem.doNotOptimizeAway(x * 0x1p-120); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x * 0x1p-120); } r_sin.* = x; // raise inexact if x!=0 diff --git a/lib/compiler_rt/sqrt.zig b/lib/compiler_rt/sqrt.zig index 870b1ee560..e765414fb0 100644 --- a/lib/compiler_rt/sqrt.zig +++ b/lib/compiler_rt/sqrt.zig @@ -9,20 +9,21 @@ const std = @import("std"); const builtin = @import("builtin"); const arch = builtin.cpu.arch; const math = std.math; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__sqrth, .{ .name = "__sqrth", .linkage = common.linkage, .visibility = common.visibility }); - @export(&sqrtf, .{ .name = "sqrtf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&sqrt, .{ .name = "sqrt", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__sqrtx, .{ .name = "__sqrtx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&sqrtq, .{ .name = "sqrtf128", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_sqrt, .{ .name = "_Qp_sqrt", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__sqrth, "__sqrth"); + symbol(&sqrtf, "sqrtf"); + symbol(&sqrt, "sqrt"); + symbol(&__sqrtx, "__sqrtx"); + if (compiler_rt.want_ppc_abi) { + symbol(&sqrtq, "sqrtf128"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_sqrt, "_Qp_sqrt"); } - @export(&sqrtq, .{ .name = "sqrtq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&sqrtl, .{ .name = "sqrtl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&sqrtq, "sqrtq"); + symbol(&sqrtl, "sqrtl"); } pub fn __sqrth(x: f16) callconv(.c) f16 { @@ -103,7 +104,7 @@ pub fn sqrtf(x: f32) callconv(.c) f32 { return x; if (ix > @as(u32, @bitCast(std.math.inf(f32)))) - return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f32); + return if (compiler_rt.want_float_exceptions) (x - x) / 0.0 else math.nan(f32); ix = @as(u32, @bitCast(@as(i32, @bitCast(x * 0x1p23)) - (23 << 23))); } @@ -154,7 +155,7 @@ pub fn sqrt(x: f64) callconv(.c) f64 { // x < 0x1p-1022 or inf or nan. if (ix & 0x7FFF_FFFF_FFFF_FFFF == 0) return x; if (ix == 0x7FF0_0000_0000_0000) return x; - if (ix > 0x7FF0_0000_0000_0000) return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); + if (ix > 0x7FF0_0000_0000_0000) return if (compiler_rt.want_float_exceptions) (x - x) / 0.0 else math.nan(f64); // x is subnormal, normalize it. ix = @bitCast(x * 0x1p52); top = (ix >> 52) -% 52; @@ -291,7 +292,7 @@ pub fn __sqrtx(x: f80) callconv(.c) f80 { // x < 0x1p-16382 or inf or nan. if (ix & 0x7FFF_FFFF_FFFF_FFFF_FFFF == 0) return x; if (ix == 0x7FFF_8000_0000_0000_0000) return x; - if (ix > 0x7FFF_8000_0000_0000_0000) return if (common.want_float_exceptions) (x - x) / 0.0 else math.nan(f80); + if (ix > 0x7FFF_8000_0000_0000_0000) return if (compiler_rt.want_float_exceptions) (x - x) / 0.0 else math.nan(f80); // x is subnormal, normalize it. ix = @bitCast(x * 0x1p63); top = (ix >> 64) -% 63; diff --git a/lib/compiler_rt/ssp.zig b/lib/compiler_rt/ssp.zig index 0a138735ba..403652ea1b 100644 --- a/lib/compiler_rt/ssp.zig +++ b/lib/compiler_rt/ssp.zig @@ -13,7 +13,8 @@ //! - __vsprintf_chk const std = @import("std"); -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const builtin = @import("builtin"); extern fn memset(dest: ?[*]u8, c: u8, n: usize) callconv(.c) ?[*]u8; @@ -21,16 +22,16 @@ extern fn memcpy(noalias dest: ?[*]u8, noalias src: ?[*]const u8, n: usize) call extern fn memmove(dest: ?[*]u8, src: ?[*]const u8, n: usize) callconv(.c) ?[*]u8; comptime { - @export(&__stack_chk_fail, .{ .name = if (builtin.os.tag == .openbsd) "__stack_smash_handler" else "__stack_chk_fail", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__chk_fail, .{ .name = "__chk_fail", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__stack_chk_guard, .{ .name = "__stack_chk_guard", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__strcpy_chk, .{ .name = "__strcpy_chk", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__strncpy_chk, .{ .name = "__strncpy_chk", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__strcat_chk, .{ .name = "__strcat_chk", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__strncat_chk, .{ .name = "__strncat_chk", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__memcpy_chk, .{ .name = "__memcpy_chk", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__memmove_chk, .{ .name = "__memmove_chk", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__memset_chk, .{ .name = "__memset_chk", .linkage = common.linkage, .visibility = common.visibility }); + @export(&__stack_chk_fail, .{ .name = if (builtin.os.tag == .openbsd) "__stack_smash_handler" else "__stack_chk_fail", .linkage = compiler_rt.linkage, .visibility = compiler_rt.visibility }); + symbol(&__chk_fail, "__chk_fail"); + symbol(&__stack_chk_guard, "__stack_chk_guard"); + symbol(&__strcpy_chk, "__strcpy_chk"); + symbol(&__strncpy_chk, "__strncpy_chk"); + symbol(&__strcat_chk, "__strcat_chk"); + symbol(&__strncat_chk, "__strncat_chk"); + symbol(&__memcpy_chk, "__memcpy_chk"); + symbol(&__memmove_chk, "__memmove_chk"); + symbol(&__memset_chk, "__memset_chk"); } fn __stack_chk_fail() callconv(.c) noreturn { diff --git a/lib/compiler_rt/stack_probe.zig b/lib/compiler_rt/stack_probe.zig index 83e08be015..5d63c9a422 100644 --- a/lib/compiler_rt/stack_probe.zig +++ b/lib/compiler_rt/stack_probe.zig @@ -1,6 +1,7 @@ const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const os_tag = builtin.os.tag; const arch = builtin.cpu.arch; const abi = builtin.abi; @@ -9,16 +10,16 @@ comptime { if (builtin.os.tag == .windows) { // Default stack-probe functions emitted by LLVM if (builtin.target.isMinGW()) { - @export(&_chkstk, .{ .name = "_alloca", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__chkstk, .{ .name = "__chkstk", .linkage = common.linkage, .visibility = common.visibility }); - @export(&___chkstk, .{ .name = "__alloca", .linkage = common.linkage, .visibility = common.visibility }); - @export(&___chkstk, .{ .name = "___chkstk", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__chkstk_ms, .{ .name = "__chkstk_ms", .linkage = common.linkage, .visibility = common.visibility }); - @export(&___chkstk_ms, .{ .name = "___chkstk_ms", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&_chkstk, "_alloca"); + symbol(&__chkstk, "__chkstk"); + symbol(&___chkstk, "__alloca"); + symbol(&___chkstk, "___chkstk"); + symbol(&__chkstk_ms, "__chkstk_ms"); + symbol(&___chkstk_ms, "___chkstk_ms"); } else if (!builtin.link_libc) { // This symbols are otherwise exported by MSVCRT.lib - @export(&_chkstk, .{ .name = "_chkstk", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__chkstk, .{ .name = "__chkstk", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&_chkstk, "_chkstk"); + symbol(&__chkstk, "__chkstk"); } } @@ -26,7 +27,7 @@ comptime { .x86, .x86_64, => { - @export(&zig_probe_stack, .{ .name = "__zig_probe_stack", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&zig_probe_stack, "__zig_probe_stack"); }, else => {}, } diff --git a/lib/compiler_rt/strlen.zig b/lib/compiler_rt/strlen.zig deleted file mode 100644 index 01d4e760dc..0000000000 --- a/lib/compiler_rt/strlen.zig +++ /dev/null @@ -1,10 +0,0 @@ -const std = @import("std"); -const common = @import("common.zig"); - -comptime { - @export(&strlen, .{ .name = "strlen", .linkage = common.linkage, .visibility = common.visibility }); -} - -fn strlen(s: [*:0]const c_char) callconv(.c) usize { - return std.mem.len(s); -} diff --git a/lib/compiler_rt/subdf3.zig b/lib/compiler_rt/subdf3.zig index b1d7850902..4d00a7f03a 100644 --- a/lib/compiler_rt/subdf3.zig +++ b/lib/compiler_rt/subdf3.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const addf3 = @import("./addf3.zig").addf3; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_aeabi) { - @export(&__aeabi_dsub, .{ .name = "__aeabi_dsub", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_dsub, "__aeabi_dsub"); } else { - @export(&__subdf3, .{ .name = "__subdf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__subdf3, "__subdf3"); } } diff --git a/lib/compiler_rt/subhf3.zig b/lib/compiler_rt/subhf3.zig index e019005ae4..258401d295 100644 --- a/lib/compiler_rt/subhf3.zig +++ b/lib/compiler_rt/subhf3.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const addf3 = @import("./addf3.zig").addf3; comptime { - @export(&__subhf3, .{ .name = "__subhf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__subhf3, "__subhf3"); } fn __subhf3(a: f16, b: f16) callconv(.c) f16 { diff --git a/lib/compiler_rt/subsf3.zig b/lib/compiler_rt/subsf3.zig index 9a1cb559b2..94d4722016 100644 --- a/lib/compiler_rt/subsf3.zig +++ b/lib/compiler_rt/subsf3.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const addf3 = @import("./addf3.zig").addf3; comptime { - if (common.want_aeabi) { - @export(&__aeabi_fsub, .{ .name = "__aeabi_fsub", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_fsub, "__aeabi_fsub"); } else { - @export(&__subsf3, .{ .name = "__subsf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__subsf3, "__subsf3"); } } diff --git a/lib/compiler_rt/subtf3.zig b/lib/compiler_rt/subtf3.zig index b187eaf579..617e0e7016 100644 --- a/lib/compiler_rt/subtf3.zig +++ b/lib/compiler_rt/subtf3.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const addf3 = @import("./addf3.zig").addf3; comptime { - if (common.want_ppc_abi) { - @export(&__subtf3, .{ .name = "__subkf3", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_sub, .{ .name = "_Qp_sub", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__subtf3, "__subkf3"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_sub, "_Qp_sub"); } - @export(&__subtf3, .{ .name = "__subtf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__subtf3, "__subtf3"); } pub fn __subtf3(a: f128, b: f128) callconv(.c) f128 { diff --git a/lib/compiler_rt/subvdi3.zig b/lib/compiler_rt/subvdi3.zig index 17c893c911..62bb1b4068 100644 --- a/lib/compiler_rt/subvdi3.zig +++ b/lib/compiler_rt/subvdi3.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const testing = @import("std").testing; comptime { - @export(&__subvdi3, .{ .name = "__subvdi3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__subvdi3, "__subvdi3"); } pub fn __subvdi3(a: i64, b: i64) callconv(.c) i64 { diff --git a/lib/compiler_rt/subvsi3.zig b/lib/compiler_rt/subvsi3.zig index 68f551071c..0744585770 100644 --- a/lib/compiler_rt/subvsi3.zig +++ b/lib/compiler_rt/subvsi3.zig @@ -1,8 +1,9 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const testing = @import("std").testing; comptime { - @export(&__subvsi3, .{ .name = "__subvsi3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__subvsi3, "__subvsi3"); } pub fn __subvsi3(a: i32, b: i32) callconv(.c) i32 { diff --git a/lib/compiler_rt/subxf3.zig b/lib/compiler_rt/subxf3.zig index d119f0bd98..1c2dcd6542 100644 --- a/lib/compiler_rt/subxf3.zig +++ b/lib/compiler_rt/subxf3.zig @@ -1,8 +1,8 @@ const std = @import("std"); -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__subxf3, .{ .name = "__subxf3", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__subxf3, "__subxf3"); } fn __subxf3(a: f80, b: f80) callconv(.c) f80 { diff --git a/lib/compiler_rt/tan.zig b/lib/compiler_rt/tan.zig index a78d7afb67..822ffd4dec 100644 --- a/lib/compiler_rt/tan.zig +++ b/lib/compiler_rt/tan.zig @@ -16,18 +16,19 @@ const rem_pio2 = @import("rem_pio2.zig").rem_pio2; const rem_pio2f = @import("rem_pio2f.zig").rem_pio2f; const arch = builtin.cpu.arch; -const common = @import("common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__tanh, .{ .name = "__tanh", .linkage = common.linkage, .visibility = common.visibility }); - @export(&tanf, .{ .name = "tanf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&tan, .{ .name = "tan", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__tanx, .{ .name = "__tanx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&tanq, .{ .name = "tanf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__tanh, "__tanh"); + symbol(&tanf, "tanf"); + symbol(&tan, "tan"); + symbol(&__tanx, "__tanx"); + if (compiler_rt.want_ppc_abi) { + symbol(&tanq, "tanf128"); } - @export(&tanq, .{ .name = "tanq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&tanl, .{ .name = "tanl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&tanq, "tanq"); + symbol(&tanl, "tanl"); } pub fn __tanh(x: f16) callconv(.c) f16 { @@ -49,7 +50,7 @@ pub fn tanf(x: f32) callconv(.c) f32 { if (ix <= 0x3f490fda) { // |x| ~<= pi/4 if (ix < 0x39800000) { // |x| < 2**-12 // raise inexact if x!=0 and underflow if subnormal - if (common.want_float_exceptions) { + if (compiler_rt.want_float_exceptions) { if (ix < 0x00800000) { mem.doNotOptimizeAway(x / 0x1p120); } else { @@ -93,7 +94,7 @@ pub fn tan(x: f64) callconv(.c) f64 { if (ix <= 0x3fe921fb) { if (ix < 0x3e400000) { // |x| < 2**-27 // raise inexact if x!=0 and underflow if subnormal - if (common.want_float_exceptions) { + if (compiler_rt.want_float_exceptions) { if (ix < 0x00100000) { mem.doNotOptimizeAway(x / 0x1p120); } else { diff --git a/lib/compiler_rt/trunc.zig b/lib/compiler_rt/trunc.zig index 55468c752f..b784630703 100644 --- a/lib/compiler_rt/trunc.zig +++ b/lib/compiler_rt/trunc.zig @@ -5,23 +5,23 @@ //! https://git.musl-libc.org/cgit/musl/tree/src/math/trunc.c const std = @import("std"); -const builtin = @import("builtin"); -const arch = builtin.cpu.arch; const math = std.math; const mem = std.mem; const expect = std.testing.expect; -const common = @import("common.zig"); + +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; comptime { - @export(&__trunch, .{ .name = "__trunch", .linkage = common.linkage, .visibility = common.visibility }); - @export(&truncf, .{ .name = "truncf", .linkage = common.linkage, .visibility = common.visibility }); - @export(&trunc, .{ .name = "trunc", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__truncx, .{ .name = "__truncx", .linkage = common.linkage, .visibility = common.visibility }); - if (common.want_ppc_abi) { - @export(&truncq, .{ .name = "truncf128", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__trunch, "__trunch"); + symbol(&truncf, "truncf"); + symbol(&trunc, "trunc"); + symbol(&__truncx, "__truncx"); + if (compiler_rt.want_ppc_abi) { + symbol(&truncq, "truncf128"); } - @export(&truncq, .{ .name = "truncq", .linkage = common.linkage, .visibility = common.visibility }); - @export(&truncl, .{ .name = "truncl", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&truncq, "truncq"); + symbol(&truncl, "truncl"); } pub fn __trunch(x: f16) callconv(.c) f16 { @@ -45,7 +45,7 @@ pub fn truncf(x: f32) callconv(.c) f32 { if (u & m == 0) { return x; } else { - if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); return @bitCast(u & ~m); } } @@ -66,7 +66,7 @@ pub fn trunc(x: f64) callconv(.c) f64 { if (u & m == 0) { return x; } else { - if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); return @bitCast(u & ~m); } } @@ -92,7 +92,7 @@ pub fn truncq(x: f128) callconv(.c) f128 { if (u & m == 0) { return x; } else { - if (common.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); + if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1p120); return @bitCast(u & ~m); } } diff --git a/lib/compiler_rt/truncdfhf2.zig b/lib/compiler_rt/truncdfhf2.zig index 4db14f0211..e01e187763 100644 --- a/lib/compiler_rt/truncdfhf2.zig +++ b/lib/compiler_rt/truncdfhf2.zig @@ -1,14 +1,15 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const truncf = @import("./truncf.zig").truncf; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_aeabi) { - @export(&__aeabi_d2h, .{ .name = "__aeabi_d2h", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_d2h, "__aeabi_d2h"); } - @export(&__truncdfhf2, .{ .name = "__truncdfhf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__truncdfhf2, "__truncdfhf2"); } -pub fn __truncdfhf2(a: f64) callconv(.c) common.F16T(f64) { +pub fn __truncdfhf2(a: f64) callconv(.c) compiler_rt.F16T(f64) { return @bitCast(truncf(f16, f64, a)); } diff --git a/lib/compiler_rt/truncdfsf2.zig b/lib/compiler_rt/truncdfsf2.zig index 8d6ed5c320..f1bada1844 100644 --- a/lib/compiler_rt/truncdfsf2.zig +++ b/lib/compiler_rt/truncdfsf2.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const truncf = @import("./truncf.zig").truncf; comptime { - if (common.want_aeabi) { - @export(&__aeabi_d2f, .{ .name = "__aeabi_d2f", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_d2f, "__aeabi_d2f"); } else { - @export(&__truncdfsf2, .{ .name = "__truncdfsf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__truncdfsf2, "__truncdfsf2"); } } diff --git a/lib/compiler_rt/truncsfhf2.zig b/lib/compiler_rt/truncsfhf2.zig index acd5631da8..e0b2b1e4bf 100644 --- a/lib/compiler_rt/truncsfhf2.zig +++ b/lib/compiler_rt/truncsfhf2.zig @@ -1,20 +1,21 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const truncf = @import("./truncf.zig").truncf; comptime { - if (common.gnu_f16_abi) { - @export(&__gnu_f2h_ieee, .{ .name = "__gnu_f2h_ieee", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_aeabi) { - @export(&__aeabi_f2h, .{ .name = "__aeabi_f2h", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.gnu_f16_abi) { + symbol(&__gnu_f2h_ieee, "__gnu_f2h_ieee"); + } else if (compiler_rt.want_aeabi) { + symbol(&__aeabi_f2h, "__aeabi_f2h"); } - @export(&__truncsfhf2, .{ .name = "__truncsfhf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__truncsfhf2, "__truncsfhf2"); } -pub fn __truncsfhf2(a: f32) callconv(.c) common.F16T(f32) { +pub fn __truncsfhf2(a: f32) callconv(.c) compiler_rt.F16T(f32) { return @bitCast(truncf(f16, f32, a)); } -fn __gnu_f2h_ieee(a: f32) callconv(.c) common.F16T(f32) { +fn __gnu_f2h_ieee(a: f32) callconv(.c) compiler_rt.F16T(f32) { return @bitCast(truncf(f16, f32, a)); } diff --git a/lib/compiler_rt/trunctfdf2.zig b/lib/compiler_rt/trunctfdf2.zig index 4f569dae67..5396e87151 100644 --- a/lib/compiler_rt/trunctfdf2.zig +++ b/lib/compiler_rt/trunctfdf2.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const truncf = @import("./truncf.zig").truncf; comptime { - if (common.want_ppc_abi) { - @export(&__trunctfdf2, .{ .name = "__trunckfdf2", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_qtod, .{ .name = "_Qp_qtod", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__trunctfdf2, "__trunckfdf2"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_qtod, "_Qp_qtod"); } - @export(&__trunctfdf2, .{ .name = "__trunctfdf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__trunctfdf2, "__trunctfdf2"); } pub fn __trunctfdf2(a: f128) callconv(.c) f64 { diff --git a/lib/compiler_rt/trunctfhf2.zig b/lib/compiler_rt/trunctfhf2.zig index f5adc918c2..46c6e34ec9 100644 --- a/lib/compiler_rt/trunctfhf2.zig +++ b/lib/compiler_rt/trunctfhf2.zig @@ -1,10 +1,11 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const truncf = @import("./truncf.zig").truncf; comptime { - @export(&__trunctfhf2, .{ .name = "__trunctfhf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__trunctfhf2, "__trunctfhf2"); } -pub fn __trunctfhf2(a: f128) callconv(.c) common.F16T(f128) { +pub fn __trunctfhf2(a: f128) callconv(.c) compiler_rt.F16T(f128) { return @bitCast(truncf(f16, f128, a)); } diff --git a/lib/compiler_rt/trunctfsf2.zig b/lib/compiler_rt/trunctfsf2.zig index 17e7570c9f..94dbff6ef9 100644 --- a/lib/compiler_rt/trunctfsf2.zig +++ b/lib/compiler_rt/trunctfsf2.zig @@ -1,13 +1,14 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const truncf = @import("./truncf.zig").truncf; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_ppc_abi) { - @export(&__trunctfsf2, .{ .name = "__trunckfsf2", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - @export(&_Qp_qtos, .{ .name = "_Qp_qtos", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_ppc_abi) { + symbol(&__trunctfsf2, "__trunckfsf2"); + } else if (compiler_rt.want_sparc_abi) { + symbol(&_Qp_qtos, "_Qp_qtos"); } - @export(&__trunctfsf2, .{ .name = "__trunctfsf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__trunctfsf2, "__trunctfsf2"); } pub fn __trunctfsf2(a: f128) callconv(.c) f32 { diff --git a/lib/compiler_rt/trunctfxf2.zig b/lib/compiler_rt/trunctfxf2.zig index df0db2393a..dfb9ef8040 100644 --- a/lib/compiler_rt/trunctfxf2.zig +++ b/lib/compiler_rt/trunctfxf2.zig @@ -1,9 +1,10 @@ const math = @import("std").math; -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; const trunc_f80 = @import("./truncf.zig").trunc_f80; comptime { - @export(&__trunctfxf2, .{ .name = "__trunctfxf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__trunctfxf2, "__trunctfxf2"); } pub fn __trunctfxf2(a: f128) callconv(.c) f80 { diff --git a/lib/compiler_rt/truncxfdf2.zig b/lib/compiler_rt/truncxfdf2.zig index 1d7e66c278..6140d94181 100644 --- a/lib/compiler_rt/truncxfdf2.zig +++ b/lib/compiler_rt/truncxfdf2.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const trunc_f80 = @import("./truncf.zig").trunc_f80; comptime { - @export(&__truncxfdf2, .{ .name = "__truncxfdf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__truncxfdf2, "__truncxfdf2"); } fn __truncxfdf2(a: f80) callconv(.c) f64 { diff --git a/lib/compiler_rt/truncxfhf2.zig b/lib/compiler_rt/truncxfhf2.zig index b2dd9c7468..4c3e951bfe 100644 --- a/lib/compiler_rt/truncxfhf2.zig +++ b/lib/compiler_rt/truncxfhf2.zig @@ -1,10 +1,11 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; const trunc_f80 = @import("./truncf.zig").trunc_f80; comptime { - @export(&__truncxfhf2, .{ .name = "__truncxfhf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__truncxfhf2, "__truncxfhf2"); } -fn __truncxfhf2(a: f80) callconv(.c) common.F16T(f80) { +fn __truncxfhf2(a: f80) callconv(.c) compiler_rt.F16T(f80) { return @bitCast(trunc_f80(f16, a)); } diff --git a/lib/compiler_rt/truncxfsf2.zig b/lib/compiler_rt/truncxfsf2.zig index 9d36f7aa29..8aaf7e6906 100644 --- a/lib/compiler_rt/truncxfsf2.zig +++ b/lib/compiler_rt/truncxfsf2.zig @@ -1,8 +1,8 @@ -const common = @import("./common.zig"); const trunc_f80 = @import("./truncf.zig").trunc_f80; +const symbol = @import("../compiler_rt.zig").symbol; comptime { - @export(&__truncxfsf2, .{ .name = "__truncxfsf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__truncxfsf2, "__truncxfsf2"); } fn __truncxfsf2(a: f80) callconv(.c) f32 { diff --git a/lib/compiler_rt/udivmod.zig b/lib/compiler_rt/udivmod.zig index bf6aaadeae..fdb338c21a 100644 --- a/lib/compiler_rt/udivmod.zig +++ b/lib/compiler_rt/udivmod.zig @@ -1,8 +1,98 @@ -const std = @import("std"); const builtin = @import("builtin"); + +const std = @import("std"); const Log2Int = std.math.Log2Int; -const common = @import("common.zig"); -const HalveInt = common.HalveInt; + +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = compiler_rt.symbol; +const HalveInt = compiler_rt.HalveInt; + +comptime { + if (compiler_rt.want_windows_v2u64_abi) { + symbol(&__umodti3_windows_x86_64, "__umodti3"); + symbol(&__modti3_windows_x86_64, "__modti3"); + symbol(&__udivti3_windows_x86_64, "__udivti3"); + symbol(&__divti3_windows_x86_64, "__divti3"); + symbol(&__udivmodti4_windows_x86_64, "__udivmodti4"); + } else { + symbol(&__umodti3, "__umodti3"); + symbol(&__modti3, "__modti3"); + symbol(&__udivti3, "__udivti3"); + symbol(&__divti3, "__divti3"); + symbol(&__udivmodti4, "__udivmodti4"); + } +} + +const v128 = @Vector(2, u64); +const v2u64 = @Vector(2, u64); + +pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.c) u128 { + return udivmod(u128, a, b, maybe_rem); +} + +fn __udivmodti4_windows_x86_64(a: v2u64, b: v2u64, maybe_rem: ?*u128) callconv(.c) v2u64 { + return @bitCast(udivmod(u128, @bitCast(a), @bitCast(b), maybe_rem)); +} + +pub fn __divti3(a: i128, b: i128) callconv(.c) i128 { + return div(a, b); +} + +fn __divti3_windows_x86_64(a: v128, b: v128) callconv(.c) v128 { + return @bitCast(div(@bitCast(a), @bitCast(b))); +} + +inline fn div(a: i128, b: i128) i128 { + const s_a = a >> (128 - 1); + const s_b = b >> (128 - 1); + + const an = (a ^ s_a) -% s_a; + const bn = (b ^ s_b) -% s_b; + + const r = udivmod(u128, @bitCast(an), @bitCast(bn), null); + const s = s_a ^ s_b; + return (@as(i128, @bitCast(r)) ^ s) -% s; +} + +pub fn __udivti3(a: u128, b: u128) callconv(.c) u128 { + return udivmod(u128, a, b, null); +} + +fn __udivti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.c) v2u64 { + return @bitCast(udivmod(u128, @bitCast(a), @bitCast(b), null)); +} + +pub fn __modti3(a: i128, b: i128) callconv(.c) i128 { + return mod(a, b); +} + +fn __modti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.c) v2u64 { + return @bitCast(mod(@as(i128, @bitCast(a)), @as(i128, @bitCast(b)))); +} + +inline fn mod(a: i128, b: i128) i128 { + const s_a = a >> (128 - 1); // s = a < 0 ? -1 : 0 + const s_b = b >> (128 - 1); // s = b < 0 ? -1 : 0 + + const an = (a ^ s_a) -% s_a; // negate if s == -1 + const bn = (b ^ s_b) -% s_b; // negate if s == -1 + + var r: u128 = undefined; + _ = udivmod(u128, @as(u128, @bitCast(an)), @as(u128, @bitCast(bn)), &r); + return (@as(i128, @bitCast(r)) ^ s_a) -% s_a; // negate if s == -1 +} + +pub fn __umodti3(a: u128, b: u128) callconv(.c) u128 { + var r: u128 = undefined; + _ = udivmod(u128, a, b, &r); + return r; +} + +fn __umodti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.c) v2u64 { + var r: u128 = undefined; + _ = udivmod(u128, @bitCast(a), @bitCast(b), &r); + return @bitCast(r); +} const lo = switch (builtin.cpu.arch.endian()) { .big => 1, @@ -14,7 +104,7 @@ const hi = 1 - lo; // Returns U / v_ and sets r = U % v_. fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T { const HalfT = HalveInt(T, false).HalfT; - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); var v = v_; const b = @as(T, 1) << (@bitSizeOf(T) / 2); @@ -70,7 +160,7 @@ fn divwide_generic(comptime T: type, _u1: T, _u0: T, v_: T, r: *T) T { } fn divwide(comptime T: type, _u1: T, _u0: T, v: T, r: *T) T { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); if (T == u64 and builtin.target.cpu.arch == .x86_64 and builtin.target.os.tag != .windows) { var rem: T = undefined; const quo = asm ( @@ -90,9 +180,9 @@ fn divwide(comptime T: type, _u1: T, _u0: T, v: T, r: *T) T { // Returns a_ / b_ and sets maybe_rem = a_ % b. pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); const HalfT = HalveInt(T, false).HalfT; - const SignedT = std.meta.Int(.signed, @bitSizeOf(T)); + const half_bits = @bitSizeOf(HalfT); if (b_ > a_) { if (maybe_rem) |rem| { @@ -124,26 +214,91 @@ pub fn udivmod(comptime T: type, a_: T, b_: T, maybe_rem: ?*T) T { return @bitCast(q); } - // 0 <= shift <= 63 - const shift: Log2Int(T) = @clz(b[hi]) - @clz(a[hi]); - var af: T = @bitCast(a); - var bf = @as(T, @bitCast(b)) << shift; - q = @bitCast(@as(T, 0)); + // Large-divisor case: b[hi] != 0, so the quotient fits in one HalfT word. + // + // Trial quotient via divwide (Knuth Vol 2, Section 4.3.1): + // Normalize the divisor so its high half has the MSB set, then use divwide + // on the top bits to get a trial quotient that is at most 1 too large. + // This replaces the O(shift) bit-by-bit loop with O(1) operations. + const s: Log2Int(HalfT) = @intCast(@clz(b[hi])); - for (0..shift + 1) |_| { - q[lo] <<= 1; - // Branchless version of: - // if (af >= bf) { - // af -= bf; - // q[lo] |= 1; - // } - const s = @as(SignedT, @bitCast(bf -% af -% 1)) >> (@bitSizeOf(T) - 1); - q[lo] |= @intCast(s & 1); - af -= bf & @as(T, @bitCast(s)); - bf >>= 1; + if (s == 0) { + // b[hi] already has its MSB set, so b >= 2^(T_bits - 1). Since a >= b + // (we passed the b_ > a_ check), a >= 2^(T_bits - 1) too, meaning + // a[hi] also has its MSB set. Therefore a / b < 2, and the quotient + // is exactly 1. + q = @bitCast(@as(T, 0)); + q[lo] = 1; + if (maybe_rem) |rem| { + rem.* = a_ - b_; + } + return @bitCast(q); } + + // Normalize b: shift left by s so bn_hi has its MSB set. + const sr: Log2Int(HalfT) = @intCast(half_bits - @as( + std.math.IntFittingRange(0, half_bits), + @intCast(s), + )); + const bn_hi: HalfT = (b[hi] << s) | (b[lo] >> sr); + + // Trial numerator: the top (half_bits + s) bits of (a << s), as [a2:a1]. + // a2 < bn_hi is guaranteed since a2 < 2^s and bn_hi >= 2^(half_bits - 1). + const a2: HalfT = a[hi] >> sr; + const a1: HalfT = (a[hi] << s) | (a[lo] >> sr); + + // Trial quotient via divwide: q_hat = floor([a2:a1] / bn_hi). + // By Knuth's theorem (normalized divisor), q <= q_hat <= q + 1. + var r_tmp: HalfT = undefined; + var q_hat: HalfT = divwide(HalfT, a2, a1, bn_hi, &r_tmp); + + // Verify: q_hat * b must not exceed a. + // Compute the product using HalfT * HalfT -> T widening multiplications, + // which are native single-instruction ops when HalfT fits in a register + // (e.g. u64 * u64 -> u128 via mulq on x86_64, mul on aarch64). + // product = q_hat * [b[hi]:b[lo]] = [p_top : p_mid : p_lo] (3 half-words) + const prod_lo: T = @as(T, q_hat) * @as(T, b[lo]); + const prod_hi: T = @as(T, q_hat) * @as(T, b[hi]); + + const prod_lo_parts: [2]HalfT = @bitCast(prod_lo); + const prod_hi_parts: [2]HalfT = @bitCast(prod_hi); + + const mid_add = @addWithOverflow(prod_hi_parts[lo], prod_lo_parts[hi]); + var p_mid: HalfT = mid_add[0]; + const p_top: HalfT = prod_hi_parts[hi] +% @as(HalfT, mid_add[1]); + var p_lo: HalfT = prod_lo_parts[lo]; + + // If product > a, decrement q_hat (at most once, guaranteed by Knuth). + if (p_top > 0 or p_mid > a[hi] or (p_mid == a[hi] and p_lo > a[lo])) { + q_hat -= 1; + // Subtract b from the product for correct remainder computation. + // After correction, (q_hat * b) fits in T bits, so borrows into + // p_top cancel it to zero -- we only need [p_mid:p_lo]. + const sub_lo = @subWithOverflow(p_lo, b[lo]); + p_lo = sub_lo[0]; + const sub_mid = @subWithOverflow(p_mid, b[hi]); + const sub_mid2 = @subWithOverflow(sub_mid[0], @as(HalfT, sub_lo[1])); + p_mid = sub_mid2[0]; + } + + q = @bitCast(@as(T, 0)); + q[lo] = q_hat; + if (maybe_rem) |rem| { - rem.* = @bitCast(af); + // remainder = a - q_hat * b = [a[hi]:a[lo]] - [p_mid:p_lo] + // This subtraction is non-negative since q_hat <= true quotient. + const rem_lo = @subWithOverflow(a[lo], p_lo); + r[lo] = rem_lo[0]; + const rem_hi = @subWithOverflow(a[hi], p_mid); + const rem_hi2 = @subWithOverflow(rem_hi[0], @as(HalfT, rem_lo[1])); + r[hi] = rem_hi2[0]; + rem.* = @bitCast(r); } return @bitCast(q); } + +test { + _ = @import("modti3_test.zig"); + _ = @import("divti3_test.zig"); + _ = @import("udivmodti4_test.zig"); +} diff --git a/lib/compiler_rt/udivmodei4.zig b/lib/compiler_rt/udivmodei4.zig index 0923f3f222..f037639c72 100644 --- a/lib/compiler_rt/udivmodei4.zig +++ b/lib/compiler_rt/udivmodei4.zig @@ -1,18 +1,20 @@ -const std = @import("std"); const builtin = @import("builtin"); -const common = @import("common.zig"); +const endian = builtin.cpu.arch.endian(); + +const std = @import("std"); const shr = std.math.shr; const shl = std.math.shl; +const compiler_rt = @import("../compiler_rt.zig"); +const symbol = @import("../compiler_rt.zig").symbol; + const max_limbs = std.math.divCeil(usize, 65535, 32) catch unreachable; // max supported type is u65535 comptime { - @export(&__udivei4, .{ .name = "__udivei4", .linkage = common.linkage, .visibility = common.visibility }); - @export(&__umodei4, .{ .name = "__umodei4", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__udivei4, "__udivei4"); + symbol(&__umodei4, "__umodei4"); } -const endian = builtin.cpu.arch.endian(); - /// Get the value of a limb. inline fn limb(x: []const u32, i: usize) u32 { return if (endian == .little) x[i] else x[x.len - 1 - i]; @@ -113,7 +115,7 @@ pub fn divmod(q: ?[]u32, r: ?[]u32, u: []const u32, v: []const u32) !void { } pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits)); const q: []u32 = @ptrCast(@alignCast(q_p[0..byte_size])); const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size])); @@ -122,7 +124,7 @@ pub fn __udivei4(q_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) ca } pub fn __umodei4(r_p: [*]u8, u_p: [*]const u8, v_p: [*]const u8, bits: usize) callconv(.c) void { - @setRuntimeSafety(common.test_safety); + @setRuntimeSafety(compiler_rt.test_safety); const byte_size = std.zig.target.intByteSize(&builtin.target, @intCast(bits)); const r: []u32 = @ptrCast(@alignCast(r_p[0..byte_size])); const u: []const u32 = @ptrCast(@alignCast(u_p[0..byte_size])); diff --git a/lib/compiler_rt/udivmodti4.zig b/lib/compiler_rt/udivmodti4.zig deleted file mode 100644 index a1b89bb962..0000000000 --- a/lib/compiler_rt/udivmodti4.zig +++ /dev/null @@ -1,26 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const udivmod = @import("udivmod.zig").udivmod; -const common = @import("common.zig"); - -comptime { - if (common.want_windows_v2u64_abi) { - @export(&__udivmodti4_windows_x86_64, .{ .name = "__udivmodti4", .linkage = common.linkage, .visibility = common.visibility }); - } else { - @export(&__udivmodti4, .{ .name = "__udivmodti4", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -pub fn __udivmodti4(a: u128, b: u128, maybe_rem: ?*u128) callconv(.c) u128 { - return udivmod(u128, a, b, maybe_rem); -} - -const v2u64 = @Vector(2, u64); - -fn __udivmodti4_windows_x86_64(a: v2u64, b: v2u64, maybe_rem: ?*u128) callconv(.c) v2u64 { - return @bitCast(udivmod(u128, @bitCast(a), @bitCast(b), maybe_rem)); -} - -test { - _ = @import("udivmodti4_test.zig"); -} diff --git a/lib/compiler_rt/udivmodti4_test.zig b/lib/compiler_rt/udivmodti4_test.zig index 5e172c29f8..fc457990e6 100644 --- a/lib/compiler_rt/udivmodti4_test.zig +++ b/lib/compiler_rt/udivmodti4_test.zig @@ -1,6 +1,6 @@ // Disable formatting to avoid unnecessary source repository bloat. // zig fmt: off -const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4; +const __udivmodti4 = @import("udivmod.zig").__udivmodti4; const testing = @import("std").testing; fn test__udivmodti4(a: u128, b: u128, expected_q: u128, expected_r: u128) !void { diff --git a/lib/compiler_rt/udivti3.zig b/lib/compiler_rt/udivti3.zig deleted file mode 100644 index a579d81e47..0000000000 --- a/lib/compiler_rt/udivti3.zig +++ /dev/null @@ -1,22 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const udivmod = @import("udivmod.zig").udivmod; -const common = @import("common.zig"); - -comptime { - if (common.want_windows_v2u64_abi) { - @export(&__udivti3_windows_x86_64, .{ .name = "__udivti3", .linkage = common.linkage, .visibility = common.visibility }); - } else { - @export(&__udivti3, .{ .name = "__udivti3", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -pub fn __udivti3(a: u128, b: u128) callconv(.c) u128 { - return udivmod(u128, a, b, null); -} - -const v2u64 = @Vector(2, u64); - -fn __udivti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.c) v2u64 { - return @bitCast(udivmod(u128, @bitCast(a), @bitCast(b), null)); -} diff --git a/lib/compiler_rt/umodti3.zig b/lib/compiler_rt/umodti3.zig deleted file mode 100644 index 63cfcc2c25..0000000000 --- a/lib/compiler_rt/umodti3.zig +++ /dev/null @@ -1,26 +0,0 @@ -const std = @import("std"); -const builtin = @import("builtin"); -const udivmod = @import("udivmod.zig").udivmod; -const common = @import("common.zig"); - -comptime { - if (common.want_windows_v2u64_abi) { - @export(&__umodti3_windows_x86_64, .{ .name = "__umodti3", .linkage = common.linkage, .visibility = common.visibility }); - } else { - @export(&__umodti3, .{ .name = "__umodti3", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -pub fn __umodti3(a: u128, b: u128) callconv(.c) u128 { - var r: u128 = undefined; - _ = udivmod(u128, a, b, &r); - return r; -} - -const v2u64 = @Vector(2, u64); - -fn __umodti3_windows_x86_64(a: v2u64, b: v2u64) callconv(.c) v2u64 { - var r: u128 = undefined; - _ = udivmod(u128, @bitCast(a), @bitCast(b), &r); - return @bitCast(r); -} diff --git a/lib/compiler_rt/unorddf2.zig b/lib/compiler_rt/unorddf2.zig index 5b17343a51..90da745199 100644 --- a/lib/compiler_rt/unorddf2.zig +++ b/lib/compiler_rt/unorddf2.zig @@ -1,11 +1,12 @@ -const common = @import("./common.zig"); +const compiler_rt = @import("../compiler_rt.zig"); const comparef = @import("./comparef.zig"); +const symbol = @import("../compiler_rt.zig").symbol; comptime { - if (common.want_aeabi) { - @export(&__aeabi_dcmpun, .{ .name = "__aeabi_dcmpun", .linkage = common.linkage, .visibility = common.visibility }); + if (compiler_rt.want_aeabi) { + symbol(&__aeabi_dcmpun, "__aeabi_dcmpun"); } else { - @export(&__unorddf2, .{ .name = "__unorddf2", .linkage = common.linkage, .visibility = common.visibility }); + symbol(&__unorddf2, "__unorddf2"); } } diff --git a/lib/compiler_rt/unordhf2.zig b/lib/compiler_rt/unordhf2.zig deleted file mode 100644 index 4fcffd1a1d..0000000000 --- a/lib/compiler_rt/unordhf2.zig +++ /dev/null @@ -1,10 +0,0 @@ -const common = @import("./common.zig"); -const comparef = @import("./comparef.zig"); - -comptime { - @export(&__unordhf2, .{ .name = "__unordhf2", .linkage = common.linkage, .visibility = common.visibility }); -} - -pub fn __unordhf2(a: f16, b: f16) callconv(.c) i32 { - return comparef.unordcmp(f16, a, b); -} diff --git a/lib/compiler_rt/unordsf2.zig b/lib/compiler_rt/unordsf2.zig deleted file mode 100644 index 56bfb94028..0000000000 --- a/lib/compiler_rt/unordsf2.zig +++ /dev/null @@ -1,18 +0,0 @@ -const common = @import("./common.zig"); -const comparef = @import("./comparef.zig"); - -comptime { - if (common.want_aeabi) { - @export(&__aeabi_fcmpun, .{ .name = "__aeabi_fcmpun", .linkage = common.linkage, .visibility = common.visibility }); - } else { - @export(&__unordsf2, .{ .name = "__unordsf2", .linkage = common.linkage, .visibility = common.visibility }); - } -} - -pub fn __unordsf2(a: f32, b: f32) callconv(.c) i32 { - return comparef.unordcmp(f32, a, b); -} - -fn __aeabi_fcmpun(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 { - return comparef.unordcmp(f32, a, b); -} diff --git a/lib/compiler_rt/unordtf2.zig b/lib/compiler_rt/unordtf2.zig deleted file mode 100644 index 22e90acaae..0000000000 --- a/lib/compiler_rt/unordtf2.zig +++ /dev/null @@ -1,16 +0,0 @@ -const common = @import("./common.zig"); -const comparef = @import("./comparef.zig"); - -comptime { - if (common.want_ppc_abi) { - @export(&__unordtf2, .{ .name = "__unordkf2", .linkage = common.linkage, .visibility = common.visibility }); - } else if (common.want_sparc_abi) { - // These exports are handled in cmptf2.zig because unordered comparisons - // are based on calling _Qp_cmp. - } - @export(&__unordtf2, .{ .name = "__unordtf2", .linkage = common.linkage, .visibility = common.visibility }); -} - -fn __unordtf2(a: f128, b: f128) callconv(.c) i32 { - return comparef.unordcmp(f128, a, b); -} diff --git a/lib/compiler_rt/unordxf2.zig b/lib/compiler_rt/unordxf2.zig deleted file mode 100644 index 2ebf5f413c..0000000000 --- a/lib/compiler_rt/unordxf2.zig +++ /dev/null @@ -1,10 +0,0 @@ -const common = @import("./common.zig"); -const comparef = @import("./comparef.zig"); - -comptime { - @export(&__unordxf2, .{ .name = "__unordxf2", .linkage = common.linkage, .visibility = common.visibility }); -} - -pub fn __unordxf2(a: f80, b: f80) callconv(.c) i32 { - return comparef.unordcmp(f80, a, b); -} diff --git a/lib/docs/index.html b/lib/docs/index.html index e60a3f960a..75c0daf797 100644 --- a/lib/docs/index.html +++ b/lib/docs/index.html @@ -40,6 +40,15 @@ code a { color: #000000; } + .source-code { + display: grid; + grid-template-columns: auto 1fr; + align-items: start; + } + .source-line-numbers pre { + text-align: right; + color: #666; + } #listFields > div, #listParams > div { margin-bottom: 1em; } @@ -429,7 +438,14 @@