// @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 modulus_index;
uint encoded_index;
uint status_index;
uint count;
uint words;
};
[[vk::push_constant]] PushConstants push;
[[vk::binding(0, 0)]] RWByteAddressBuffer storage_buffers[];
[kernel_name("setup_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 modulus_extent, encoded_extent;
storage_buffers[push.modulus_index].GetDimensions(modulus_extent);
storage_buffers[push.encoded_index].GetDimensions(encoded_extent);
if (push.count > modulus_extent / row_bytes || push.count > encoded_extent / prepared_bytes) return;
uint modulus[128], mu[130], k;
bigint_zero(modulus);
for (uint i = 0u; i < push.words; ++i)
modulus[i] = storage_buffers[push.modulus_index].Load(row * row_bytes + i * 4u);
bool valid = bigint_barrett_reciprocal(modulus, push.words, mu, k);
for (uint i = 0u; i < push.words; ++i)
storage_buffers[push.encoded_index].Store(row * prepared_bytes + i * 4u, modulus[i]);
for (uint i = 0u; i < push.words + 2u; ++i)
storage_buffers[push.encoded_index].Store(row * prepared_bytes + (i + push.words) * 4u, mu[i]);
storage_buffers[push.encoded_index].Store(row * prepared_bytes + (push.words * 2u + 2u) * 4u, k);
storage_buffers[push.status_index].Store(row * 4u, uint(valid));
}