Pack polynomial with coefficients in (-2^(D-1), 2^(D-1)] (T0) into bytes. Packs 13 bits per coefficient: 8 coefficients into 13 bytes. Assumes coefficients are not normalized, but in (q-2^(D-1), q+2^(D-1)].
fn polyPackT0(p: Poly, buf: []u8) void
fn polyPackT0(p: Poly, buf: []u8) void {
const bound = 1 << (D - 1);
var j: usize = 0;
var i: usize = 0;
while (i < buf.len) : (i += 13) {
const p0 = Q + bound - p.cs[j];
const p1 = Q + bound - p.cs[j + 1];
const p2 = Q + bound - p.cs[j + 2];
const p3 = Q + bound - p.cs[j + 3];
const p4 = Q + bound - p.cs[j + 4];
const p5 = Q + bound - p.cs[j + 5];
const p6 = Q + bound - p.cs[j + 6];
const p7 = Q + bound - p.cs[j + 7];
buf[i] = @truncate(p0 >> 0);
buf[i + 1] = @truncate((p0 >> 8) | (p1 << 5));
buf[i + 2] = @truncate(p1 >> 3);
buf[i + 3] = @truncate((p1 >> 11) | (p2 << 2));
buf[i + 4] = @truncate((p2 >> 6) | (p3 << 7));
buf[i + 5] = @truncate(p3 >> 1);
buf[i + 6] = @truncate((p3 >> 9) | (p4 << 4));
buf[i + 7] = @truncate(p4 >> 4);
buf[i + 8] = @truncate((p4 >> 12) | (p5 << 1));
buf[i + 9] = @truncate((p5 >> 7) | (p6 << 6));
buf[i + 10] = @truncate(p6 >> 2);
buf[i + 11] = @truncate((p6 >> 10) | (p7 << 3));
buf[i + 12] = @truncate(p7 >> 5);
j += 8;
}
}