| 394 | } |
| 395 | |
| 396 | fn add_with_overflow_helper(first: u64, second: u64, st: ScalarType) -> Result<(u64, u64)> { |
| 397 | let bits = st.size_in_bits(); |
| 398 | let c = simple_context(|g| { |
| 399 | let i1 = g.input(array_type(vec![bits], BIT))?; |
| 400 | let i2 = g.input(array_type(vec![bits], BIT))?; |
| 401 | g.custom_op( |
| 402 | CustomOperation::new(BinaryAdd { overflow_bit: true }), |
| 403 | vec![i1, i2], |
| 404 | ) |
| 405 | })?; |
| 406 | let mapped_c = run_instantiation_pass(c)?; |
| 407 | let input0 = Value::from_scalar(first, st)?; |
| 408 | let input1 = Value::from_scalar(second, st)?; |
| 409 | let results = random_evaluate( |
| 410 | mapped_c.get_context().get_main_graph()?, |
| 411 | vec![input0, input1], |
| 412 | )? |
| 413 | .to_vector()?; |
| 414 | Ok((results[0].to_u64(st)?, results[1].to_u64(BIT)?)) |
| 415 | } |
| 416 | |
| 417 | #[test] |
| 418 | fn test_add_with_overflow_bit() -> Result<()> { |