// @generated by tool/gen/fn/generate.py; DO NOT EDIT.
// schema=cryptography_bigint.json schema_version=1 generator_version=64
// schema_sha256=636171eea6d8620d516a7d64ef1143ab03485ef3095474ad2e2c60e9fe0fe9e6
// No OA C++ BigInt donor exists. Arithmetic helpers are independently tested.
// One invocation owns every output limb/status of a complete batch row.
// This public-data baseline has no secret-placement or constant-time contract.
import attributes;
import bigint_words;
import bigint_division;
import wide_u32;
struct PushConstants {
uint left_index;
uint right_index;
uint quotient_index;
uint remainder_index;
uint status_index;
uint count;
uint words;
uint input_words;
uint right_count;
};
[[vk::push_constant]] PushConstants push;
[[vk::binding(0, 0)]] RWByteAddressBuffer storage_buffers[];
[kernel_name("div_rem_wide")]
[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.input_words == 0u || push.input_words > 256u || push.words == 0u || push.words > 128u || push.input_words != push.words * 2u) return;
uint left_extent; storage_buffers[push.left_index].GetDimensions(left_extent);
if (push.count > left_extent / (push.input_words * 4u)) return;
uint right_extent; storage_buffers[push.right_index].GetDimensions(right_extent);
if ((push.right_count != 1u && push.right_count != push.count) || push.right_count > right_extent / (push.words * 4u)) return;
uint quotient_extent; uint quotient_row_bytes = push.input_words * 4u;
storage_buffers[push.quotient_index].GetDimensions(quotient_extent);
if (push.count > quotient_extent / quotient_row_bytes) return;
uint remainder_extent; uint remainder_row_bytes = push.words * 4u;
storage_buffers[push.remainder_index].GetDimensions(remainder_extent);
if (push.count > remainder_extent / remainder_row_bytes) return;
uint status_extent; uint status_row_bytes = 1u * 4u;
storage_buffers[push.status_index].GetDimensions(status_extent);
if (push.count > status_extent / status_row_bytes) return;
uint a[256], b[128], quotient[256], remainder[128];
for (uint i = 0u; i < 256u; ++i) a[i] = 0u;
bigint_zero(b);
for (uint i = 0u; i < push.input_words; ++i)
a[i] = storage_buffers[push.left_index].Load(row * push.input_words * 4u + i * 4u);
uint right_base = (push.right_count == 1u ? 0u : row) * push.words * 4u;
for (uint i = 0u; i < push.words; ++i)
b[i] = storage_buffers[push.right_index].Load(right_base + i * 4u);
uint status = uint(bigint_divide_mixed(a, b, push.input_words, push.words, quotient, remainder));
uint quotient_words = push.input_words;
uint overflow = 0u;
for (uint i = quotient_words; i < push.input_words; ++i) overflow |= quotient[i];
if (status != 0u && overflow != 0u) status = 2u;
for (uint i = 0u; i < quotient_words; ++i)
storage_buffers[push.quotient_index].Store(row * quotient_row_bytes + i * 4u, status == 1u ? quotient[i] : 0u);
for (uint i = 0u; i < push.words; ++i)
storage_buffers[push.remainder_index].Store(row * remainder_row_bytes + i * 4u, status == 1u ? remainder[i] : 0u);
storage_buffers[push.status_index].Store(row * 4u, status);
}