Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

processLeafBatch

Process a batch of leaves in a single thread using SIMD

kangarootwelve.processLeafBatch
fn processLeafBatch(comptime Variant: type, ctx: LeafBatchContext) void

File

lib/std/crypto/kangarootwelve.zig:617

Code

fn processLeafBatch(comptime Variant: type, ctx: LeafBatchContext) void {
    const cv_size = Variant.cv_size;
    const leaf_buffer = ctx.scratch_buffer[0 .. 8 * chunk_size];

    var cvs_offset: usize = 0;
    var j: usize = ctx.batch_start;
    const batch_end = @min(ctx.batch_start + ctx.batch_count * chunk_size, ctx.total_len);

    // Process leaves using SIMD (8x, 4x, 2x) based on optimal vector length
    inline for ([_]usize{ 8, 4, 2 }) |batch_size| {
        while (optimal_vector_len >= batch_size and j + batch_size * chunk_size <= batch_end) {
            processNLeaves(Variant, batch_size, ctx.view, j, leaf_buffer, @alignCast(ctx.output_cvs[cvs_offset..]));
            cvs_offset += batch_size * cv_size;
            j += batch_size * chunk_size;
        }
    }

    // Process remaining single leaves
    while (j < batch_end) {
        const chunk_len = @min(chunk_size, batch_end - j);
        if (ctx.view.tryGetSlice(j, j + chunk_len)) |leaf_data| {
            const cv_slice = MultiSliceView.init(leaf_data, &[_]u8{}, &[_]u8{});
            Variant.turboShakeToBuffer(&cv_slice, 0x0B, ctx.output_cvs[cvs_offset..][0..cv_size]);
        } else {
            ctx.view.copyRange(j, j + chunk_len, leaf_buffer[0..chunk_len]);
            const cv_slice = MultiSliceView.init(leaf_buffer[0..chunk_len], &[_]u8{}, &[_]u8{});
            Variant.turboShakeToBuffer(&cv_slice, 0x0B, ctx.output_cvs[cvs_offset..][0..cv_size]);
        }
        cvs_offset += cv_size;
        j += chunk_len;
    }

    assert(cvs_offset == ctx.output_cvs.len);
}