mirror of
https://github.com/powdr-labs/powdr.git
synced 2026-04-20 03:03:25 -04:00
41 lines
1.2 KiB
NASM
41 lines
1.2 KiB
NASM
use std::utils::unchanged_until;
|
|
use std::convert::int;
|
|
|
|
machine Shift(latch, operation_id) {
|
|
// lower bound degree is 262144
|
|
|
|
operation shl<0> A, B -> C;
|
|
|
|
operation shr<1> A, B -> C;
|
|
|
|
col witness operation_id;
|
|
|
|
col fixed latch(i) { if (i % 4) == 3 { 1 } else { 0 } };
|
|
col fixed FACTOR_ROW(i) { (i + 1) % 4 };
|
|
col fixed FACTOR(i) { 1 << (((i + 1) % 4) * 8) };
|
|
|
|
col fixed P_A(i) { i % 256 };
|
|
col fixed P_B(i) { (i / 256) % 32 };
|
|
col fixed P_ROW(i) { (i / (256 * 32)) % 4 };
|
|
col fixed P_operation(i) { (i / (256 * 32 * 4)) % 2 };
|
|
col fixed P_C(i) {
|
|
match P_operation(i) {
|
|
0 => (int(P_A(i)) << (int(P_B(i)) + (int(P_ROW(i)) * 8))),
|
|
1 => (int(P_A(i)) << (int(P_ROW(i)) * 8)) >> int(P_B(i)),
|
|
} & 0xffffffff
|
|
};
|
|
|
|
col witness A_byte;
|
|
col witness C_part;
|
|
|
|
col witness A;
|
|
col witness B;
|
|
col witness C;
|
|
|
|
A' = A * (1 - latch) + A_byte * FACTOR;
|
|
unchanged_until(B, latch);
|
|
C' = C * (1 - latch) + C_part;
|
|
|
|
// TODO this way, we cannot prove anything that shifts by more than 31 bits.
|
|
{operation_id', A_byte, B', FACTOR_ROW, C_part} in {P_operation, P_A, P_B, P_ROW, P_C};
|
|
} |