Merge branch 'LemonBoy-stdlib-32b'

master
Andrew Kelley 2019-05-04 15:19:14 -04:00
commit 6a34da963b
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
5 changed files with 18 additions and 14 deletions

View File

@ -142,7 +142,7 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32]
assert(in.len >= out.len);
assert(counter +% (in.len >> 6) >= counter);
var cursor: u64 = 0;
var cursor: usize = 0;
var k: [8]u32 = undefined;
var c: [4]u32 = undefined;
@ -161,7 +161,8 @@ pub fn chaCha20With64BitNonce(out: []u8, in: []const u8, counter: u64, key: [32]
c[3] = mem.readIntSliceLittle(u32, nonce[4..8]);
const block_size = (1 << 6);
const big_block = (block_size << 32);
// The full block size is greater than the address space on a 32bit machine
const big_block = if (@sizeOf(usize) > 4) (block_size << 32) else maxInt(usize);
// first partial big block
if (((@intCast(u64, maxInt(u32) - @truncate(u32, counter)) + 1) << 6) < in.len) {

View File

@ -603,7 +603,7 @@ test "ArenaAllocator" {
try testAllocatorAlignedShrink(&arena_allocator.allocator);
}
var test_fixed_buffer_allocator_memory: [40000 * @sizeOf(usize)]u8 = undefined;
var test_fixed_buffer_allocator_memory: [40000 * @sizeOf(u64)]u8 = undefined;
test "FixedBufferAllocator" {
var fixed_buffer_allocator = FixedBufferAllocator.init(test_fixed_buffer_allocator_memory[0..]);

View File

@ -1101,8 +1101,8 @@ pub fn sigaction(sig: u6, noalias act: *const Sigaction, noalias oact: ?*Sigacti
const NSIG = 65;
const sigset_t = [128 / @sizeOf(usize)]usize;
const all_mask = []usize{maxInt(usize)};
const app_mask = []usize{0xfffffffc7fffffff};
const all_mask = []u32{0xffffffff, 0xffffffff};
const app_mask = []u32{0xfffffffc, 0x7fffffff};
const k_sigaction = extern struct {
handler: extern fn (i32) void,

View File

@ -3,6 +3,7 @@ const builtin = @import("builtin");
const Os = builtin.Os;
const debug = std.debug;
const testing = std.testing;
const math = std.math;
const windows = std.os.windows;
const linux = std.os.linux;
@ -12,33 +13,34 @@ const posix = std.os.posix;
pub const epoch = @import("epoch.zig");
/// Sleep for the specified duration
/// Spurious wakeups are possible and no precision of timing is guaranteed.
pub fn sleep(nanoseconds: u64) void {
switch (builtin.os) {
Os.linux, Os.macosx, Os.ios, Os.freebsd, Os.netbsd => {
const s = nanoseconds / ns_per_s;
const ns = nanoseconds % ns_per_s;
posixSleep(@intCast(u63, s), @intCast(u63, ns));
posixSleep(s, ns);
},
Os.windows => {
const ns_per_ms = ns_per_s / ms_per_s;
const milliseconds = nanoseconds / ns_per_ms;
windows.Sleep(@intCast(windows.DWORD, milliseconds));
const ms_that_will_fit = std.math.cast(windows.DWORD, milliseconds) catch std.math.maxInt(windows.DWORD);
windows.Sleep(ms_that_will_fit);
},
else => @compileError("Unsupported OS"),
}
}
pub fn posixSleep(seconds: u63, nanoseconds: u63) void {
/// Spurious wakeups are possible and no precision of timing is guaranteed.
pub fn posixSleep(seconds: u64, nanoseconds: u64) void {
var req = posix.timespec{
.tv_sec = seconds,
.tv_nsec = nanoseconds,
.tv_sec = std.math.cast(isize, seconds) catch std.math.maxInt(isize),
.tv_nsec = std.math.cast(isize, nanoseconds) catch std.math.maxInt(isize),
};
var rem: posix.timespec = undefined;
while (true) {
const ret_val = posix.nanosleep(&req, &rem);
const err = posix.getErrno(ret_val);
if (err == 0) return;
switch (err) {
posix.EFAULT => unreachable,
posix.EINVAL => {
@ -50,6 +52,7 @@ pub fn posixSleep(seconds: u63, nanoseconds: u63) void {
req = rem;
continue;
},
// This prong handles success as well as unexpected errors.
else => return,
}
}

View File

@ -768,10 +768,10 @@ pub const Isaac64 = struct {
const x = self.m[base + m1];
self.a = mix +% self.m[base + m2];
const y = self.a +% self.b +% self.m[(x >> 3) % self.m.len];
const y = self.a +% self.b +% self.m[@intCast(usize, (x >> 3) % self.m.len)];
self.m[base + m1] = y;
self.b = x +% self.m[(y >> 11) % self.m.len];
self.b = x +% self.m[@intCast(usize, (y >> 11) % self.m.len)];
self.r[self.r.len - 1 - base - m1] = self.b;
}