tiny.simd.ShuffledIota
Defined in thread.pool.
API (5)
Actions
Public operations.
Fields and members
Public fields and members.
Source
Source: lib/simd/src/thread/pool.zig:141
zig
pub const ShuffledIota = struct { coprime: u32 = 1, pub fn init(coprime: u32) ShuffledIota { return .{ .coprime = coprime }; } pub fn next( self: ShuffledIota, current: u32, size: u32, ) u32 { std.debug.assert(size != 0); std.debug.assert(current < size); return @intCast( (@as(u64, current) + self.coprime) % @as(u64, size), ); } pub fn coprimeNonzero(a_value: u32, b_value: u32) bool { std.debug.assert(a_value != 0); std.debug.assert(b_value != 0); var a = a_value; var b = b_value; const trailing_a = @ctz(a); const trailing_b = @ctz(b); if (@min(trailing_a, trailing_b) != 0) return false; a >>= @intCast(trailing_a); b >>= @intCast(trailing_b); while (true) { const previous_a = a; a = @max(previous_a, b); b = @min(previous_a, b); if (b == 1) return true; a -= b; if (a == 0) return false; a >>= @intCast(@ctz(a)); } } pub fn findAnotherCoprime(size: u32, start: u32) u32 { std.debug.assert(size != 0); if (size <= 2) return 1; const increment: u32 = if (size & 1 == 0) 2 else 1; var candidate = start | 1; var attempts: u64 = 0; const max_attempts = @as(u64, size) * 16; while (attempts < max_attempts) : (attempts += 1) { if (coprimeNonzero(candidate, size)) return candidate; candidate +%= increment; if (candidate == 0) candidate = 1; } unreachable; }};Source: lib/simd/src/root.zig:132
zig
pub const ShuffledIota = thread.ShuffledIota;Also reachable as
Audit
| Definitions | 5 |
|---|---|
| Public names | 15 |
| Members | 1 |
| Version | 26.7.0 |
| Revision | daab053ee433 |