Skip to documentation
SLOP

tiny.accy.kernel.library.random.block

Reference tiny.accy kernel library random block

Defined in kernel.library.random.

API (24)

Actions

Public operations.

Values and defaults

Public values and defaults.

No direct callersNo direct callskernel.library.randomblock
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Source: lib/accy/src/kernel/library/random/block/philox.zig:15

zig
pub fn philoxBlock(rounds: u32, counter: [4]u32, key: [2]u32) [4]u32 {    var state = counter;    var bumped = key;    var round: u32 = 0;    while (round < rounds) : (round += 1) {        if (round > 0) {            bumped[0] +%= philox_w0;            bumped[1] +%= philox_w1;        }        const product0 = @as(u64, philox_m0) * @as(u64, state[0]);        const product1 = @as(u64, philox_m1) * @as(u64, state[2]);        const hi0: u32 = @truncate(product0 >> 32);        const lo0: u32 = @truncate(product0);        const hi1: u32 = @truncate(product1 >> 32);        const lo1: u32 = @truncate(product1);        state = .{ hi1 ^ state[1] ^ bumped[0], lo1, hi0 ^ state[3] ^ bumped[1], lo0 };    }    return state;}
Called byCallsNo direct callskernel.library.randomfeistelPermuteReferencekernel.library.randomphiloxFoldBitsReferencekernel.library.randomphiloxFoldUniformReferencetest sourcelib.accy.src.kernel.library.random.testtest: random philox entry writes Rand...test sourcelib.accy.src.kernel.library.random.testtest: random philox key counter unifo...+4 morekernel.library.randomphiloxBlock
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/accy/src/kernel/library/random/block/philox.zig:35

zig
pub fn philoxWords(    k: anytype,    rounds: u32,    counter: kernel.Value,    counter_fold: kernel.Value,    seed_lo: kernel.Value,    seed_hi: kernel.Value,) ![philox_lanes]kernel.Value {    const zero = try k.constantInt(.i32, 0);    const m0 = try wordConstant(k, philox_m0);    const m1 = try wordConstant(k, philox_m1);    const w0 = try wordConstant(k, philox_w0);    const w1 = try wordConstant(k, philox_w1);    var state = [philox_lanes]kernel.Value{ counter, counter_fold, zero, zero };    var key = [2]kernel.Value{ seed_lo, seed_hi };    var round: u32 = 0;    while (round < rounds) : (round += 1) {        if (round > 0) {            key[0] = try k.add(key[0], w0);            key[1] = try k.add(key[1], w1);        }        const hi0 = try k.umulhi(m0, state[0]);        const lo0 = try k.mul(m0, state[0]);        const hi1 = try k.umulhi(m1, state[2]);        const lo1 = try k.mul(m1, state[2]);        state = .{            try k.xor(try k.xor(hi1, state[1]), key[0]),            lo1,            try k.xor(try k.xor(hi0, state[3]), key[1]),            lo0,        };    }    return state;}
Called byCallsprivate sourcelib.accy.src.kernel.library.random.feistel.ru...feistelPermuteValueprivate sourcelib.accy.src.kernel.library.random.fold.philo...philox fold runtime body applyprivate sourcelib.accy.src.kernel.library.random.key.runtimephiloxKeyCounterUniformBodyprivate sourcelib.accy.src.kernel.library.random.key.runtimephiloxKeySplitBodyprivate sourcelib.accy.src.kernel.library.random.key.runtimephiloxKeyUniformBody+2 morekernel.library.random.blockwordConstantkernel.library.random.blockphiloxWords
Static calls · unresolved targets: 1 · external targets: 4.

Source: lib/accy/src/kernel/library/random/block/philox.zig:7

zig
pub const philox_default_rounds: u32 = 10;

Source: lib/accy/src/kernel/library/random/block/philox.zig:6

zig
pub const philox_lanes: u64 = 4;

Source: lib/accy/src/kernel/library/random/block/philox.zig:8

zig
pub const philox_max_rounds: u32 = 16;

Source: lib/accy/src/kernel/library/random/block/squares.zig:28

zig
pub fn rotateWide32(k: anytype, value: kernel.Value) !kernel.Value {    const half = try k.constantInt(.i64, 32);    const low = try k.ushr(value, half);    const high = try k.shl(value, half);    return k.or_(low, high);}
Called byCallsNo direct callskernel.library.random.blocksquaresWordkernel.library.random.blockrotateWide32
Static calls · unresolved targets: 0 · external targets: 4.

Source: lib/accy/src/kernel/library/random/block/squares.zig:9

zig
pub fn squaresBlock(counter: u64, key: u64) u32 {    var x = counter *% key;    const y = x;    const z = y +% key;    x = x *% x +% y;    x = std.math.rotr(u64, x, 32);    x = x *% x +% z;    x = std.math.rotr(u64, x, 32);    x = x *% x +% y;    x = std.math.rotr(u64, x, 32);    return @truncate((x *% x +% z) >> 32);}
Called byCallsNo direct callskernel.library.randomsquaresFoldBitsReferencekernel.library.randomsquaresFoldUniformReferencetest sourcelib.accy.src.kernel.library.random.testtest: random reference streams keep e...test sourcelib.accy.src.kernel.library.random.testtest: random squares reference matche...test sourcelib.accy.src.kernel.library.random.testtest: random squares runtime family e...kernel.library.randomsquaresBlock
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/accy/src/kernel/library/random/block/squares.zig:55

zig
pub fn squaresKeyValue(k: anytype, key_lo: kernel.Value, key_hi: kernel.Value) !kernel.Value {    const lo = try zeroExtendWord(k, key_lo);    const hi = try zeroExtendWord(k, key_hi);    const half = try k.constantInt(.i64, 32);    return k.or_(try k.shl(hi, half), lo);}
Called byCallsprivate sourcelib.accy.src.kernel.library.random.fold.squar...squares fold runtime body activeprivate sourcelib.accy.src.kernel.library.random.squares.ru...squares runtime body activekernel.library.random.blockzeroExtendWordkernel.library.random.blocksquaresKeyValue
Static calls · unresolved targets: 0 · external targets: 3.

Source: lib/accy/src/kernel/library/random/block/squares.zig:35

zig
pub fn squaresWord(    k: anytype,    counter: kernel.Value,    key: kernel.Value,) !kernel.Value {    var x = try k.mul(counter, key);    const y = x;    const z = try k.add(y, key);    x = try k.add(try k.mul(x, x), y);    x = try rotateWide32(k, x);    x = try k.add(try k.mul(x, x), z);    x = try rotateWide32(k, x);    x = try k.add(try k.mul(x, x), y);    x = try rotateWide32(k, x);    const final = try k.add(try k.mul(x, x), z);    const half = try k.constantInt(.i64, 32);    const high = try k.ushr(final, half);    return k.cast(high, .i32);}
Called byCallsprivate sourcelib.accy.src.kernel.library.random.fold.squar...squares fold runtime body applyprivate sourcelib.accy.src.kernel.library.random.squares.ru...squares runtime body activekernel.library.random.blockrotateWide32kernel.library.random.blocksquaresWord
Static calls · unresolved targets: 1 · external targets: 4.

Source: lib/accy/src/kernel/library/random/block/squares.zig:7

zig
pub const squares_default_key: u64 = 0x123456789abcdef0;

Source: lib/accy/src/kernel/library/random/block/squares.zig:6

zig
pub const squares_lanes: u64 = 1;

Source: lib/accy/src/kernel/library/random/block/squares.zig:22

zig
pub fn zeroExtendWord(k: anytype, word: kernel.Value) !kernel.Value {    const wide = try k.cast(word, .i64);    const mask = try k.constantInt(.i64, 0xFFFFFFFF);    return k.and_(wide, mask);}
Called byCallsNo direct callskernel.library.random.blocksquaresKeyValueprivate sourcelib.accy.src.kernel.library.random.fold.squar...squares fold runtime body activeprivate sourcelib.accy.src.kernel.library.random.fold.squar...squares fold runtime body applyprivate sourcelib.accy.src.kernel.library.random.squares.ru...squares runtime body activekernel.library.random.blockzeroExtendWord
Static calls · unresolved targets: 0 · external targets: 3.

Source: lib/accy/src/kernel/library/random/block/threefry.zig:33

zig
pub fn rotateLeftWord(k: anytype, value: kernel.Value, amount: u5) !kernel.Value {    const left = try k.shl(value, try k.constantInt(.i32, amount));    const right = try k.ushr(value, try k.constantInt(.i32, 32 - @as(i64, amount)));    return k.or_(left, right);}
Called byCallsNo direct callskernel.library.random.blockthreefryWordskernel.library.random.blockrotateLeftWord
Static calls · unresolved targets: 0 · external targets: 4.

Source: lib/accy/src/kernel/library/random/block/threefry.zig:14

zig
pub fn threefryBlock(rounds: u32, counter: [2]u32, key: [2]u32) [2]u32 {    const subkeys = [3]u32{ key[0], key[1], threefry_parity ^ key[0] ^ key[1] };    var x0 = counter[0] +% subkeys[0];    var x1 = counter[1] +% subkeys[1];    var round: u32 = 0;    while (round < rounds) : (round += 1) {        x0 +%= x1;        x1 = std.math.rotl(u32, x1, threefry_rotations[round % 8]);        x1 ^= x0;        if (round % 4 == 3) {            const injection = round / 4 + 1;            x0 +%= subkeys[injection % 3];            x1 +%= subkeys[(injection + 1) % 3];            x1 +%= injection;        }    }    return .{ x0, x1 };}
Called byCallsNo direct callskernel.library.randomthreefryFoldBitsReferencekernel.library.randomthreefryFoldUniformReferencetest sourcelib.accy.src.kernel.library.random.testtest: random reference streams keep e...test sourcelib.accy.src.kernel.library.random.testtest: random threefry entry matches r...test sourcelib.accy.src.kernel.library.random.testtest: random threefry reference match...test sourcelib.accy.src.kernel.library.random.testtest: random threefry runtime family ...kernel.library.randomthreefryBlock
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/accy/src/kernel/library/random/block/threefry.zig:39

zig
pub fn threefryWords(    k: anytype,    rounds: u32,    counter: kernel.Value,    counter_fold: kernel.Value,    seed_lo: kernel.Value,    seed_hi: kernel.Value,) ![threefry_lanes]kernel.Value {    const parity = try wordConstant(k, threefry_parity);    const subkeys = [3]kernel.Value{        seed_lo,        seed_hi,        try k.xor(try k.xor(parity, seed_lo), seed_hi),    };    var x0 = try k.add(counter, subkeys[0]);    var x1 = try k.add(counter_fold, subkeys[1]);    var round: u32 = 0;    while (round < rounds) : (round += 1) {        x0 = try k.add(x0, x1);        x1 = try rotateLeftWord(k, x1, threefry_rotations[round % 8]);        x1 = try k.xor(x1, x0);        if (round % 4 == 3) {            const injection = round / 4 + 1;            x0 = try k.add(x0, subkeys[injection % 3]);            x1 = try k.add(x1, subkeys[(injection + 1) % 3]);            x1 = try k.add(x1, try k.constantInt(.i32, injection));        }    }    return .{ x0, x1 };}
Called byCallsprivate sourcelib.accy.src.kernel.library.random.fold.three...threefry fold runtime body applyprivate sourcelib.accy.src.kernel.library.random.threefry.r...threefryRuntimeBodyprivate sourcelib.accy.src.kernel.library.random.threefry.s...threefry body eachkernel.library.random.blockrotateLeftWordkernel.library.random.blockwordConstantkernel.library.random.blockthreefryWords
Static calls · unresolved targets: 1 · external targets: 2.

Source: lib/accy/src/kernel/library/random/block/threefry.zig:8

zig
pub const threefry_default_rounds: u32 = 20;

Source: lib/accy/src/kernel/library/random/block/threefry.zig:7

zig
pub const threefry_lanes: u64 = 2;

Source: lib/accy/src/kernel/library/random/block/threefry.zig:9

zig
pub const threefry_max_rounds: u32 = 32;

Source: lib/accy/src/kernel/library/random/block/word.zig:21

zig
pub fn ceilDiv(numerator: u64, denominator: u64) u64 {    return numerator / denominator + @intFromBool(numerator % denominator != 0);}

Source: lib/accy/src/kernel/library/random/block/word.zig:29

zig
pub fn outputWord(k: anytype, comptime dtype: DType, word: kernel.Value) !kernel.Value {    return switch (dtype) {        .i32 => word,        .f32 => blk: {            const shifted = try k.ushr(word, try k.constantInt(.i32, uniform_mantissa_shift));            const filled = try k.or_(shifted, try wordConstant(k, uniform_one_bits));            const unit = try k.bitcast(filled, .f32);            break :blk try k.sub(unit, try k.constantFloat(.f32, 1.0));        },        else => @compileError("random kernels support dtype .i32 or .f32"),    };}
Called byCallsprivate sourcelib.accy.src.kernel.library.random.fold.commonfoldCombineprivate sourcelib.accy.src.kernel.library.random.key.runtimephiloxKeyCounterUniformBodyprivate sourcelib.accy.src.kernel.library.random.key.runtimephiloxKeyUniformBodyprivate sourcelib.accy.src.kernel.library.random.philox.run...philoxRuntimeBodyprivate sourcelib.accy.src.kernel.library.random.philox.staticphilox body each+3 morekernel.library.random.blockwordConstantkernel.library.random.blockoutputWord
Static calls · unresolved targets: 0 · external targets: 6.

Source: lib/accy/src/kernel/library/random/block/word.zig:14

zig
pub fn randomDTypeSupported(dtype: DType) bool {    return switch (dtype) {        .f32, .i32 => true,        else => false,    };}
Called byCallsNo direct callskernel.library.randomphiloxKeyCounterUniformInstanceFromSp...kernel.library.randomphiloxKeyUniformInstanceFromSpecializ...kernel.library.randomphiloxInstanceFromSpecializationkernel.library.randomsquaresInstanceFromSpecializationkernel.library.randomthreefryInstanceFromSpecializationkernel.library.randomrandomDTypeSupported
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/accy/src/kernel/library/random/block/word.zig:46

zig
pub fn storeGuarded(    k: anytype,    args: anytype,    out: kernel.Value,    element: kernel.Value,    count: kernel.Value,) !void {    const active = try k.compare(.lt, element, count);    try k.guardDo(active, .{ .args = args, .out = out, .element = element }, store_guarded_active);}
Called byCallsNo direct callsprivate sourcelib.accy.src.kernel.library.random.key.runtimephiloxKeyCounterUniformBodyprivate sourcelib.accy.src.kernel.library.random.key.runtimephiloxKeyUniformBodyprivate sourcelib.accy.src.kernel.library.random.philox.run...philoxRuntimeBodyprivate sourcelib.accy.src.kernel.library.random.philox.staticphilox body eachprivate sourcelib.accy.src.kernel.library.random.threefry.r...threefryRuntimeBodyprivate sourcelib.accy.src.kernel.library.random.threefry.s...threefry body eachkernel.library.random.blockstoreGuarded
Static calls · unresolved targets: 0 · external targets: 2.

Source: lib/accy/src/kernel/library/random/block/word.zig:9

zig
pub fn uniformFromBits(bits: u32) f32 {    const filled = (bits >> uniform_mantissa_shift) | uniform_one_bits;    return @as(f32, @bitCast(filled)) - 1.0;}
Called byCallsNo direct callskernel.library.randomphiloxFoldUniformReferencekernel.library.randomsquaresFoldUniformReferencekernel.library.randomthreefryFoldUniformReferencetest sourcelib.accy.src.kernel.library.random.testtest: random philox entry writes Rand...test sourcelib.accy.src.kernel.library.random.testtest: random philox key counter unifo...+3 morekernel.library.randomuniformFromBits
Static calls · unresolved targets: 0 · external targets: 0.

Source: lib/accy/src/kernel/library/random/block/word.zig:25

zig
pub fn wordConstant(k: anytype, word: u32) !kernel.Value {    return k.constantInt(.i32, @as(i32, @bitCast(word)));}
Called byCallsNo direct callskernel.library.random.blockphiloxWordskernel.library.random.blockthreefryWordskernel.library.random.blockoutputWordprivate sourcelib.accy.src.kernel.library.random.feistel.ru...feistelPermuteValuekernel.library.random.blockwordConstant
Static calls · unresolved targets: 0 · external targets: 1.

Source: lib/accy/src/kernel/library/random/block/root.zig

zig
const common = @import("word.zig");const philox = @import("philox.zig");const squares = @import("squares.zig");const threefry = @import("threefry.zig");pub const philox_lanes = philox.philox_lanes;pub const philox_default_rounds = philox.philox_default_rounds;pub const philox_max_rounds = philox.philox_max_rounds;pub const philoxBlock = philox.philoxBlock;pub const philoxWords = philox.philoxWords;pub const threefry_lanes = threefry.threefry_lanes;pub const threefry_default_rounds = threefry.threefry_default_rounds;pub const threefry_max_rounds = threefry.threefry_max_rounds;pub const threefryBlock = threefry.threefryBlock;pub const rotateLeftWord = threefry.rotateLeftWord;pub const threefryWords = threefry.threefryWords;pub const squares_lanes = squares.squares_lanes;pub const squares_default_key = squares.squares_default_key;pub const squaresBlock = squares.squaresBlock;pub const zeroExtendWord = squares.zeroExtendWord;pub const rotateWide32 = squares.rotateWide32;pub const squaresWord = squares.squaresWord;pub const squaresKeyValue = squares.squaresKeyValue;pub const uniformFromBits = common.uniformFromBits;pub const randomDTypeSupported = common.randomDTypeSupported;pub const ceilDiv = common.ceilDiv;pub const wordConstant = common.wordConstant;pub const outputWord = common.outputWord;pub const storeGuarded = common.storeGuarded;

Source: lib/accy/src/kernel/library/random/root.zig:2

zig
pub const block = @import("block/root.zig");

Complete caller list for kernel.library.random.philoxBlock

9 direct callers.

Complete caller list for kernel.library.random.block.philoxWords

7 direct callers.

Complete caller list for kernel.library.random.block.outputWord

8 direct callers.

Complete caller list for kernel.library.random.uniformFromBits

8 direct callers.

Audit

Definitions25
Public names38
Members0
Version26.7.0
Revisiondaab053ee433