Skip to main content

handle_u128_div

Function handle_u128_div 

Source
pub fn handle_u128_div(
    process: &ProcessorState<'_>,
) -> Result<Vec<AdviceMutation>, EventError>
Expand description

U128_DIV system event handler.

Pushes the result of u128 division (both the quotient and the remainder) onto the advice stack.

Inputs: Operand stack: [event_id, b0, b1, b2, b3, a0, a1, a2, a3, …] Advice stack: […]

Outputs: Advice stack: [r0, r1, r2, r3, q0, q1, q2, q3, …]

Where (b0..b3) and (a0..a3) are the 32-bit limbs of the divisor and dividend respectively, with b0/a0 being the least significant limb.

After two padw adv_loadw in MASM: First: loads [r0, r1, r2, r3] onto operand stack Second: loads [q0, q1, q2, q3] onto operand stack

§Errors

Returns an error if the divisor is ZERO or any limb is not a valid u32.