From 55eea3b045c86c78eb8d9cc862122d260352a631 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 14 Oct 2021 21:17:30 -0700 Subject: stage2: implement `@minimum` and `@maximum`, including vectors * std.os: take advantage of `@minimum`. It's probably time to deprecate `std.min` and `std.max`. * New AIR instructions: min and max * Introduce SIMD vector support to stage2 * Add `@Type` support for vectors * Sema: add `checkSimdBinOp` which can be re-used for other arithmatic operators that want to support vectors. * Implement coercion from vectors to arrays. - In backends this is handled with bitcast for vector to array, however maybe we want to reduce the amount of branching by introducing an explicit AIR instruction for it in the future. * LLVM backend: implement lowering vector types * Sema: Implement `slice.ptr` at comptime * Value: improve `numberMin` and `numberMax` to support floats in addition to integers, and make them behave properly in the presence of NaN. --- lib/std/os.zig | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'lib/std/os.zig') diff --git a/lib/std/os.zig b/lib/std/os.zig index eda246d2a3..7bbc13d2ea 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -1,18 +1,18 @@ -// This file contains thin wrappers around OS-specific APIs, with these -// specific goals in mind: -// * Convert "errno"-style error codes into Zig errors. -// * When null-terminated byte buffers are required, provide APIs which accept -// slices as well as APIs which accept null-terminated byte buffers. Same goes -// for UTF-16LE encoding. -// * Where operating systems share APIs, e.g. POSIX, these thin wrappers provide -// cross platform abstracting. -// * When there exists a corresponding libc function and linking libc, the libc -// implementation is used. Exceptions are made for known buggy areas of libc. -// On Linux libc can be side-stepped by using `std.os.linux` directly. -// * For Windows, this file represents the API that libc would provide for -// Windows. For thin wrappers around Windows-specific APIs, see `std.os.windows`. -// Note: The Zig standard library does not support POSIX thread cancellation, and -// in general EINTR is handled by trying again. +//! This file contains thin wrappers around OS-specific APIs, with these +//! specific goals in mind: +//! * Convert "errno"-style error codes into Zig errors. +//! * When null-terminated byte buffers are required, provide APIs which accept +//! slices as well as APIs which accept null-terminated byte buffers. Same goes +//! for UTF-16LE encoding. +//! * Where operating systems share APIs, e.g. POSIX, these thin wrappers provide +//! cross platform abstracting. +//! * When there exists a corresponding libc function and linking libc, the libc +//! implementation is used. Exceptions are made for known buggy areas of libc. +//! On Linux libc can be side-stepped by using `std.os.linux` directly. +//! * For Windows, this file represents the API that libc would provide for +//! Windows. For thin wrappers around Windows-specific APIs, see `std.os.windows`. +//! Note: The Zig standard library does not support POSIX thread cancellation, and +//! in general EINTR is handled by trying again. const root = @import("root"); const std = @import("std.zig"); @@ -492,7 +492,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize { .macos, .ios, .watchos, .tvos => math.maxInt(i32), else => math.maxInt(isize), }; - const adjusted_len = math.min(max_count, buf.len); + const adjusted_len = @minimum(max_count, buf.len); while (true) { const rc = system.read(fd, buf.ptr, adjusted_len); @@ -621,7 +621,7 @@ pub fn pread(fd: fd_t, buf: []u8, offset: u64) PReadError!usize { .macos, .ios, .watchos, .tvos => math.maxInt(i32), else => math.maxInt(isize), }; - const adjusted_len = math.min(max_count, buf.len); + const adjusted_len = @minimum(max_count, buf.len); const pread_sym = if (builtin.os.tag == .linux and builtin.link_libc) system.pread64 @@ -873,7 +873,7 @@ pub fn write(fd: fd_t, bytes: []const u8) WriteError!usize { .macos, .ios, .watchos, .tvos => math.maxInt(i32), else => math.maxInt(isize), }; - const adjusted_len = math.min(max_count, bytes.len); + const adjusted_len = @minimum(max_count, bytes.len); while (true) { const rc = system.write(fd, bytes.ptr, adjusted_len); @@ -1029,7 +1029,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize { .macos, .ios, .watchos, .tvos => math.maxInt(i32), else => math.maxInt(isize), }; - const adjusted_len = math.min(max_count, bytes.len); + const adjusted_len = @minimum(max_count, bytes.len); const pwrite_sym = if (builtin.os.tag == .linux and builtin.link_libc) system.pwrite64 @@ -5439,7 +5439,7 @@ pub fn sendfile( } // Here we match BSD behavior, making a zero count value send as many bytes as possible. - const adjusted_count = if (in_len == 0) max_count else math.min(in_len, @as(size_t, max_count)); + const adjusted_count = if (in_len == 0) max_count else @minimum(in_len, @as(size_t, max_count)); const sendfile_sym = if (builtin.link_libc) system.sendfile64 @@ -5522,7 +5522,7 @@ pub fn sendfile( hdtr = &hdtr_data; } - const adjusted_count = math.min(in_len, max_count); + const adjusted_count = @minimum(in_len, max_count); while (true) { var sbytes: off_t = undefined; @@ -5601,7 +5601,7 @@ pub fn sendfile( hdtr = &hdtr_data; } - const adjusted_count = math.min(in_len, @as(u63, max_count)); + const adjusted_count = @minimum(in_len, @as(u63, max_count)); while (true) { var sbytes: off_t = adjusted_count; @@ -5655,7 +5655,7 @@ pub fn sendfile( rw: { var buf: [8 * 4096]u8 = undefined; // Here we match BSD behavior, making a zero count value send as many bytes as possible. - const adjusted_count = if (in_len == 0) buf.len else math.min(buf.len, in_len); + const adjusted_count = if (in_len == 0) buf.len else @minimum(buf.len, in_len); const amt_read = try pread(in_fd, buf[0..adjusted_count], in_offset); if (amt_read == 0) { if (in_len == 0) { @@ -5756,7 +5756,7 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len } var buf: [8 * 4096]u8 = undefined; - const adjusted_count = math.min(buf.len, len); + const adjusted_count = @minimum(buf.len, len); const amt_read = try pread(fd_in, buf[0..adjusted_count], off_in); // TODO without @as the line below fails to compile for wasm32-wasi: // error: integer value 0 cannot be coerced to type 'os.PWriteError!usize' @@ -5919,7 +5919,7 @@ pub fn dn_expand( const end = msg.ptr + msg.len; if (p == end or exp_dn.len == 0) return error.InvalidDnsPacket; var dest = exp_dn.ptr; - const dend = dest + std.math.min(exp_dn.len, 254); + const dend = dest + @minimum(exp_dn.len, 254); // detect reference loop using an iteration counter var i: usize = 0; while (i < msg.len) : (i += 2) { -- cgit v1.2.3