oarust 0.9.0

GPU-first semantic computing engine written in Rust
// @generated by tool/gen/fn/generate.py; DO NOT EDIT.
// schema=cryptography_bigint.json schema_version=1 generator_version=64
// schema_sha256=636171eea6d8620d516a7d64ef1143ab03485ef3095474ad2e2c60e9fe0fe9e6
// Prepared public Barrett data is an immutable typed snapshot (see Rust API).
import attributes;
import bigint_words;
import bigint_barrett;
struct PushConstants {
	uint left_index;
	uint encoded_index;
	uint output_index;
	uint status_index;
	uint count;
	uint words;
	uint prepared_count;
};
[[vk::push_constant]] PushConstants push;
[[vk::binding(0, 0)]] RWByteAddressBuffer storage_buffers[];
[kernel_name("reduce_barrett")]
[domain("cryptography")]
[variant("generic")]
[dtype("u32")]
[status("experimental")]
[shader("compute")]
[numthreads(32, 1, 1)]
void main(uint3 tid : SV_DispatchThreadID) {
	uint row = tid.x;
	if (row >= push.count || push.words == 0u || push.words > 128u) return;
	uint row_bytes = push.words * 4u;
	uint prepared_bytes = (push.words * 2u + 3u) * 4u;
	uint status_extent; storage_buffers[push.status_index].GetDimensions(status_extent);
	if (push.count > status_extent / 4u) return;
	uint left_extent, encoded_extent, output_extent;
	storage_buffers[push.left_index].GetDimensions(left_extent);
	storage_buffers[push.encoded_index].GetDimensions(encoded_extent);
	storage_buffers[push.output_index].GetDimensions(output_extent);
	if (push.count > left_extent / (row_bytes * 2u) || push.count > output_extent / row_bytes
		|| (push.prepared_count != 1u && push.prepared_count != push.count)
		|| push.prepared_count > encoded_extent / prepared_bytes) return;
	uint base = (push.prepared_count == 1u ? 0u : row) * prepared_bytes;
	uint modulus[128], mu[130], input[256], result[128];
	bigint_zero(modulus); bigint_zero(result);
	for (uint i = 0u; i < 130u; ++i) mu[i] = 0u;
	for (uint i = 0u; i < 256u; ++i) input[i] = 0u;
	for (uint i = 0u; i < push.words; ++i)
		modulus[i] = storage_buffers[push.encoded_index].Load(base + i * 4u);
	for (uint i = 0u; i < push.words + 2u; ++i)
		mu[i] = storage_buffers[push.encoded_index].Load(base + (i + push.words) * 4u);
	uint k = storage_buffers[push.encoded_index].Load(base + (push.words * 2u + 2u) * 4u);
	uint overflow = 0u;
	for (uint i = 0u; i < push.words * 2u; ++i) {
		input[i] = storage_buffers[push.left_index].Load(row * row_bytes * 2u + i * 4u);
		if (i >= k * 2u) overflow |= input[i];
	}
	uint status = k == 0u ? 0u : (k > push.words || overflow != 0u ? 2u : 1u);
	if (status == 1u) bigint_barrett_reduce(input, modulus, mu, k, result);
	for (uint i = 0u; i < push.words; ++i)
		storage_buffers[push.output_index].Store(row * row_bytes + i * 4u, result[i]);
	storage_buffers[push.status_index].Store(row * 4u, status);
}