tiny.simd.VectorXoshiro
Defined in random.
Source
Source: lib/simd/src/random.zig:107
zig
pub fn VectorXoshiro(comptime D: type) type { requireU64(D); return struct { state: [4]D.Vector, const Self = @This(); const DF: type = D.rebind(f64); pub fn init(seed: u64) Self { return initThread(seed, 0); } pub fn initThread(seed: u64, thread_number: u64) Self { var scalar = Xoshiro.init(seed); var stream: u64 = 0; while (stream < thread_number) : (stream += 1) scalar.longJump(); var state: [4]D.Vector = @splat(@splat(0)); inline for (0..D.lane_count) |lane| { const scalar_state = scalar.getState(); inline for (0..4) |index| state[index][lane] = scalar_state[index]; scalar.jump(); } return .{ .state = state }; } pub fn next(self: *Self) D.Vector { return update(&self.state); } pub fn fill(self: *Self, output: []u64) void { var index: usize = 0; while (index + D.lane_count <= output.len) : (index += D.lane_count) { const value: [D.lane_count]u64 = self.next(); @memcpy(output[index .. index + D.lane_count], &value); } if (index != output.len) { const value: [D.lane_count]u64 = self.next(); @memcpy(output[index..], value[0 .. output.len - index]); } } pub fn uniform(self: *Self) DF.Vector { return toUniform(self.next()); } pub fn fillUniform(self: *Self, output: []f64) void { var index: usize = 0; while (index + D.lane_count <= output.len) : (index += D.lane_count) { const value: [D.lane_count]f64 = self.uniform(); @memcpy(output[index .. index + D.lane_count], &value); } if (index != output.len) { const value: [D.lane_count]f64 = self.uniform(); @memcpy(output[index..], value[0 .. output.len - index]); } } pub fn getState(self: Self) [4]D.Vector { return self.state; } pub fn setState(self: *Self, state: [4]D.Vector) void { self.state = state; } pub fn stateSize() usize { return 4 * D.lane_count; } fn update(state: *[4]D.Vector) D.Vector { const result = rotate.rotateRightSame(D, state[0] +% state[3], 41) +% state[0]; const temporary = shift.shiftLeft(D, 17, state[1]); state[2] ^= state[0]; state[3] ^= state[1]; state[1] ^= state[2]; state[0] ^= state[3]; state[2] ^= temporary; state[3] = rotate.rotateRightSame(D, state[3], 19); return result; } fn toUniform(value: D.Vector) DF.Vector { const bits = shift.shiftRight(D, 11, value); var result: DF.Vector = undefined; inline for (0..D.lane_count) |index| { result[index] = @as(f64, @floatFromInt(bits[index])) * uniform_scale; } return result; } };}Source: lib/simd/src/root.zig:508
zig
pub const VectorXoshiro = random.VectorXoshiro;Complete call list
9 direct calls.
tiny.simd.Xoshiro.getState[method] atlib/simd/src/random.zig:73tiny.simd.Xoshiro.init[function] atlib/simd/src/random.zig:42tiny.simd.Xoshiro.initThread[function] atlib/simd/src/random.zig:49tiny.simd.Xoshiro.jump[method] atlib/simd/src/random.zig:85tiny.simd.Xoshiro.longJump[method] atlib/simd/src/random.zig:89lib.simd.src.random.requireU64[function] — private source atlib/simd/src/random.zig:349in nearest public ownertiny.simd.randomtiny.simd.rotate.rotateRightSame[function] atlib/simd/src/rotate.zig:32tiny.simd.shift.shiftLeft[function] atlib/simd/src/shift.zig:3tiny.simd.shift.shiftRight[function] atlib/simd/src/shift.zig:14
Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |