diff --git a/avm-transpiler/src/transpile.rs b/avm-transpiler/src/transpile.rs index c0cb28c9f0d..a5087582327 100644 --- a/avm-transpiler/src/transpile.rs +++ b/avm-transpiler/src/transpile.rs @@ -179,6 +179,39 @@ pub fn brillig_to_avm( ], }); } + BrilligOpcode::Not { destination, source, bit_size } => { + assert!( + is_integral_bit_size(*bit_size), + "Not bit size should be integral: {:?}", + brillig_instr + ); + let bits_needed = + [source.0, destination.0].iter().map(bits_needed_for).max().unwrap(); + assert!( + bits_needed == 8 || bits_needed == 16, + "Not only support 8 or 16 bit encodings, got: {}", + bits_needed + ); + + avm_instrs.push(AvmInstruction { + opcode: if bits_needed == 8 { AvmOpcode::NOT_8 } else { AvmOpcode::NOT_16 }, + indirect: Some(ALL_DIRECT), + operands: vec![ + make_operand(bits_needed, &source.0), + make_operand(bits_needed, &destination.0), + ], + tag: Some(tag_from_bit_size(BitSize::Integer(*bit_size))), + }); + if let IntegerBitSize::U1 = bit_size { + // We need to cast the result back to u1 + handle_cast( + &mut avm_instrs, + destination, + destination, + BitSize::Integer(IntegerBitSize::U1), + ); + } + } BrilligOpcode::CalldataCopy { destination_address, size_address, offset_address } => { avm_instrs.push(AvmInstruction { opcode: AvmOpcode::CALLDATACOPY, @@ -493,8 +526,6 @@ fn handle_cast( AvmOperand::U32 { value: /*limbs=*/ 1}, ], }, - // Then we cast back to u8 (which is what we use for u1). - generate_cast_instruction(dest_offset, false, dest_offset, false, AvmTypeTag::UINT8), ]); } else { let tag = tag_from_bit_size(bit_size); @@ -1282,7 +1313,8 @@ pub fn map_brillig_pcs_to_avm_pcs(brillig_bytecode: &[BrilligOpcode 3, + BrilligOpcode::Cast { bit_size: BitSize::Integer(IntegerBitSize::U1), .. } => 2, + BrilligOpcode::Not { bit_size: IntegerBitSize::U1, .. } => 3, _ => 1, }; // next Brillig pc will map to an AVM pc offset by the diff --git a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp index a9975e3f57b..d4bdab6ebb0 100644 --- a/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp +++ b/barretenberg/cpp/src/barretenberg/dsl/acir_format/serde/acir.hpp @@ -594,6 +594,16 @@ struct BrilligOpcode { static BinaryIntOp bincodeDeserialize(std::vector); }; + struct Not { + Program::MemoryAddress destination; + Program::MemoryAddress source; + Program::IntegerBitSize bit_size; + + friend bool operator==(const Not&, const Not&); + std::vector bincodeSerialize() const; + static Not bincodeDeserialize(std::vector); + }; + struct Cast { Program::MemoryAddress destination; Program::MemoryAddress source; @@ -751,6 +761,7 @@ struct BrilligOpcode { std::variant BrilligOpcode::Not::bincodeSerialize() const +{ + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); +} + +inline BrilligOpcode::Not BrilligOpcode::Not::bincodeDeserialize(std::vector input) +{ + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw_or_abort("Some input bytes were not read"); + } + return value; +} + +} // end of namespace Program + +template <> +template +void serde::Serializable::serialize(const Program::BrilligOpcode::Not& obj, + Serializer& serializer) +{ + serde::Serializable::serialize(obj.destination, serializer); + serde::Serializable::serialize(obj.source, serializer); + serde::Serializable::serialize(obj.bit_size, serializer); +} + +template <> +template +Program::BrilligOpcode::Not serde::Deserializable::deserialize(Deserializer& deserializer) +{ + Program::BrilligOpcode::Not obj; + obj.destination = serde::Deserializable::deserialize(deserializer); + obj.source = serde::Deserializable::deserialize(deserializer); + obj.bit_size = serde::Deserializable::deserialize(deserializer); + return obj; +} + +namespace Program { + inline bool operator==(const BrilligOpcode::Cast& lhs, const BrilligOpcode::Cast& rhs) { if (!(lhs.destination == rhs.destination)) { diff --git a/noir/noir-repo/acvm-repo/acir/codegen/acir.cpp b/noir/noir-repo/acvm-repo/acir/codegen/acir.cpp index ef5baf076a0..a789a0f0c47 100644 --- a/noir/noir-repo/acvm-repo/acir/codegen/acir.cpp +++ b/noir/noir-repo/acvm-repo/acir/codegen/acir.cpp @@ -572,6 +572,16 @@ namespace Program { static BinaryIntOp bincodeDeserialize(std::vector); }; + struct Not { + Program::MemoryAddress destination; + Program::MemoryAddress source; + Program::IntegerBitSize bit_size; + + friend bool operator==(const Not&, const Not&); + std::vector bincodeSerialize() const; + static Not bincodeDeserialize(std::vector); + }; + struct Cast { Program::MemoryAddress destination; Program::MemoryAddress source; @@ -727,7 +737,7 @@ namespace Program { static Stop bincodeDeserialize(std::vector); }; - std::variant value; + std::variant value; friend bool operator==(const BrilligOpcode&, const BrilligOpcode&); std::vector bincodeSerialize() const; @@ -5110,6 +5120,50 @@ Program::BrilligOpcode::BinaryIntOp serde::Deserializable BrilligOpcode::Not::bincodeSerialize() const { + auto serializer = serde::BincodeSerializer(); + serde::Serializable::serialize(*this, serializer); + return std::move(serializer).bytes(); + } + + inline BrilligOpcode::Not BrilligOpcode::Not::bincodeDeserialize(std::vector input) { + auto deserializer = serde::BincodeDeserializer(input); + auto value = serde::Deserializable::deserialize(deserializer); + if (deserializer.get_buffer_offset() < input.size()) { + throw serde::deserialization_error("Some input bytes were not read"); + } + return value; + } + +} // end of namespace Program + +template <> +template +void serde::Serializable::serialize(const Program::BrilligOpcode::Not &obj, Serializer &serializer) { + serde::Serializable::serialize(obj.destination, serializer); + serde::Serializable::serialize(obj.source, serializer); + serde::Serializable::serialize(obj.bit_size, serializer); +} + +template <> +template +Program::BrilligOpcode::Not serde::Deserializable::deserialize(Deserializer &deserializer) { + Program::BrilligOpcode::Not obj; + obj.destination = serde::Deserializable::deserialize(deserializer); + obj.source = serde::Deserializable::deserialize(deserializer); + obj.bit_size = serde::Deserializable::deserialize(deserializer); + return obj; +} + namespace Program { inline bool operator==(const BrilligOpcode::Cast &lhs, const BrilligOpcode::Cast &rhs) { diff --git a/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs b/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs index 6dd99f2c289..2b6ea83fafa 100644 --- a/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs +++ b/noir/noir-repo/acvm-repo/acir/tests/test_program_serialization.rs @@ -214,12 +214,12 @@ fn simple_brillig_foreign_call() { let bytes = Program::serialize_program(&program); let expected_serialization: Vec = vec![ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 81, 49, 10, 128, 48, 12, 108, 196, 138, 224, 230, - 75, 226, 15, 252, 140, 131, 139, 131, 136, 239, 111, 161, 9, 28, 165, 205, 210, 28, 132, - 36, 119, 16, 114, 9, 133, 130, 53, 7, 73, 29, 37, 107, 143, 80, 238, 148, 204, 99, 56, 200, - 111, 22, 227, 190, 83, 93, 16, 146, 193, 112, 22, 225, 34, 168, 205, 142, 174, 241, 218, - 206, 179, 121, 49, 188, 109, 57, 84, 191, 159, 255, 122, 63, 235, 199, 189, 190, 197, 237, - 13, 45, 1, 20, 245, 146, 30, 92, 2, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 81, 73, 10, 192, 48, 8, 140, 165, 91, 160, 183, + 126, 196, 254, 160, 159, 233, 161, 151, 30, 74, 200, 251, 19, 136, 130, 132, 196, 75, 28, + 16, 199, 17, 212, 65, 112, 5, 123, 14, 32, 190, 80, 230, 90, 130, 181, 155, 50, 142, 225, + 2, 187, 89, 40, 239, 157, 106, 2, 82, 116, 138, 51, 118, 239, 171, 222, 108, 232, 218, 139, + 125, 198, 179, 113, 83, 188, 29, 57, 86, 226, 239, 23, 159, 63, 104, 63, 238, 213, 45, 237, + 108, 244, 18, 195, 174, 252, 193, 92, 2, 0, 0, ]; assert_eq!(bytes, expected_serialization) @@ -338,17 +338,17 @@ fn complex_brillig_foreign_call() { let bytes = Program::serialize_program(&program); let expected_serialization: Vec = vec![ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 85, 81, 14, 194, 48, 8, 133, 118, 206, 26, 255, 60, - 129, 137, 30, 160, 211, 11, 120, 23, 227, 159, 70, 63, 61, 190, 146, 209, 140, 177, 46, - 251, 24, 77, 182, 151, 44, 116, 45, 16, 120, 64, 139, 208, 34, 252, 63, 228, 245, 134, 165, - 99, 73, 251, 30, 250, 72, 186, 55, 150, 113, 30, 26, 180, 243, 21, 75, 197, 232, 86, 16, - 163, 47, 16, 35, 136, 250, 47, 176, 222, 150, 117, 49, 229, 207, 103, 230, 167, 130, 118, - 190, 106, 254, 223, 178, 12, 154, 104, 50, 114, 48, 28, 188, 30, 82, 247, 236, 180, 23, 62, - 171, 236, 178, 185, 202, 27, 194, 216, 119, 36, 54, 142, 35, 185, 149, 203, 233, 18, 131, - 34, 220, 48, 167, 38, 176, 191, 18, 181, 168, 5, 63, 178, 179, 8, 123, 232, 186, 234, 254, - 126, 125, 158, 143, 175, 87, 148, 74, 51, 194, 73, 172, 207, 234, 28, 149, 157, 182, 149, - 144, 15, 70, 78, 23, 51, 122, 83, 190, 15, 208, 181, 70, 122, 152, 126, 56, 83, 244, 10, - 181, 6, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 85, 81, 14, 194, 48, 8, 133, 118, 186, 53, 241, + 207, 11, 152, 232, 1, 58, 189, 128, 119, 49, 254, 105, 244, 211, 227, 59, 50, 154, 49, 214, + 100, 31, 163, 201, 246, 146, 133, 174, 5, 10, 15, 72, 17, 122, 52, 221, 135, 188, 222, 177, + 116, 44, 105, 223, 195, 24, 73, 247, 206, 50, 46, 67, 139, 118, 190, 98, 169, 24, 221, 6, + 98, 244, 5, 98, 4, 81, 255, 21, 214, 219, 178, 46, 166, 252, 249, 204, 252, 84, 208, 207, + 215, 158, 255, 107, 150, 141, 38, 154, 140, 28, 76, 7, 111, 132, 212, 61, 65, 201, 116, 86, + 217, 101, 115, 11, 226, 62, 99, 223, 145, 88, 56, 205, 228, 102, 127, 239, 53, 6, 69, 184, + 97, 78, 109, 96, 127, 37, 106, 81, 11, 126, 100, 103, 17, 14, 48, 116, 213, 227, 243, 254, + 190, 158, 63, 175, 40, 149, 102, 132, 179, 88, 95, 212, 57, 42, 59, 109, 43, 33, 31, 140, + 156, 46, 102, 244, 230, 124, 31, 97, 104, 141, 244, 48, 253, 1, 180, 46, 168, 159, 181, 6, + 0, 0, ]; assert_eq!(bytes, expected_serialization) diff --git a/noir/noir-repo/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts b/noir/noir-repo/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts index ba26e3d139a..60e4c8d5829 100644 --- a/noir/noir-repo/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts +++ b/noir/noir-repo/acvm-repo/acvm_js/test/shared/complex_foreign_call.ts @@ -2,14 +2,14 @@ import { WitnessMap } from '@noir-lang/acvm_js'; // See `complex_brillig_foreign_call` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 85, 81, 14, 194, 48, 8, 133, 118, 206, 26, 255, 60, 129, 137, 30, 160, 211, - 11, 120, 23, 227, 159, 70, 63, 61, 190, 146, 209, 140, 177, 46, 251, 24, 77, 182, 151, 44, 116, 45, 16, 120, 64, 139, - 208, 34, 252, 63, 228, 245, 134, 165, 99, 73, 251, 30, 250, 72, 186, 55, 150, 113, 30, 26, 180, 243, 21, 75, 197, 232, - 86, 16, 163, 47, 16, 35, 136, 250, 47, 176, 222, 150, 117, 49, 229, 207, 103, 230, 167, 130, 118, 190, 106, 254, 223, - 178, 12, 154, 104, 50, 114, 48, 28, 188, 30, 82, 247, 236, 180, 23, 62, 171, 236, 178, 185, 202, 27, 194, 216, 119, - 36, 54, 142, 35, 185, 149, 203, 233, 18, 131, 34, 220, 48, 167, 38, 176, 191, 18, 181, 168, 5, 63, 178, 179, 8, 123, - 232, 186, 234, 254, 126, 125, 158, 143, 175, 87, 148, 74, 51, 194, 73, 172, 207, 234, 28, 149, 157, 182, 149, 144, 15, - 70, 78, 23, 51, 122, 83, 190, 15, 208, 181, 70, 122, 152, 126, 56, 83, 244, 10, 181, 6, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 213, 85, 81, 14, 194, 48, 8, 133, 118, 186, 53, 241, 207, 11, 152, 232, 1, 58, 189, + 128, 119, 49, 254, 105, 244, 211, 227, 59, 50, 154, 49, 214, 100, 31, 163, 201, 246, 146, 133, 174, 5, 10, 15, 72, 17, + 122, 52, 221, 135, 188, 222, 177, 116, 44, 105, 223, 195, 24, 73, 247, 206, 50, 46, 67, 139, 118, 190, 98, 169, 24, + 221, 6, 98, 244, 5, 98, 4, 81, 255, 21, 214, 219, 178, 46, 166, 252, 249, 204, 252, 84, 208, 207, 215, 158, 255, 107, + 150, 141, 38, 154, 140, 28, 76, 7, 111, 132, 212, 61, 65, 201, 116, 86, 217, 101, 115, 11, 226, 62, 99, 223, 145, 88, + 56, 205, 228, 102, 127, 239, 53, 6, 69, 184, 97, 78, 109, 96, 127, 37, 106, 81, 11, 126, 100, 103, 17, 14, 48, 116, + 213, 227, 243, 254, 190, 158, 63, 175, 40, 149, 102, 132, 179, 88, 95, 212, 57, 42, 59, 109, 43, 33, 31, 140, 156, 46, + 102, 244, 230, 124, 31, 97, 104, 141, 244, 48, 253, 1, 180, 46, 168, 159, 181, 6, 0, 0, ]); export const initialWitnessMap: WitnessMap = new Map([ [1, '0x0000000000000000000000000000000000000000000000000000000000000001'], diff --git a/noir/noir-repo/acvm-repo/acvm_js/test/shared/foreign_call.ts b/noir/noir-repo/acvm-repo/acvm_js/test/shared/foreign_call.ts index 498a914cff4..9bf57535c87 100644 --- a/noir/noir-repo/acvm-repo/acvm_js/test/shared/foreign_call.ts +++ b/noir/noir-repo/acvm-repo/acvm_js/test/shared/foreign_call.ts @@ -2,11 +2,11 @@ import { WitnessMap } from '@noir-lang/acvm_js'; // See `simple_brillig_foreign_call` integration test in `acir/tests/test_program_serialization.rs`. export const bytecode = Uint8Array.from([ - 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 81, 49, 10, 128, 48, 12, 108, 196, 138, 224, 230, 75, 226, 15, 252, 140, 131, - 139, 131, 136, 239, 111, 161, 9, 28, 165, 205, 210, 28, 132, 36, 119, 16, 114, 9, 133, 130, 53, 7, 73, 29, 37, 107, - 143, 80, 238, 148, 204, 99, 56, 200, 111, 22, 227, 190, 83, 93, 16, 146, 193, 112, 22, 225, 34, 168, 205, 142, 174, - 241, 218, 206, 179, 121, 49, 188, 109, 57, 84, 191, 159, 255, 122, 63, 235, 199, 189, 190, 197, 237, 13, 45, 1, 20, - 245, 146, 30, 92, 2, 0, 0, + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 173, 81, 73, 10, 192, 48, 8, 140, 165, 91, 160, 183, 126, 196, 254, 160, 159, 233, + 161, 151, 30, 74, 200, 251, 19, 136, 130, 132, 196, 75, 28, 16, 199, 17, 212, 65, 112, 5, 123, 14, 32, 190, 80, 230, + 90, 130, 181, 155, 50, 142, 225, 2, 187, 89, 40, 239, 157, 106, 2, 82, 116, 138, 51, 118, 239, 171, 222, 108, 232, + 218, 139, 125, 198, 179, 113, 83, 188, 29, 57, 86, 226, 239, 23, 159, 63, 104, 63, 238, 213, 45, 237, 108, 244, 18, + 195, 174, 252, 193, 92, 2, 0, 0, ]); export const initialWitnessMap: WitnessMap = new Map([ [1, '0x0000000000000000000000000000000000000000000000000000000000000005'], diff --git a/noir/noir-repo/acvm-repo/brillig/src/opcodes.rs b/noir/noir-repo/acvm-repo/brillig/src/opcodes.rs index ac469cebf87..45df2aca2d8 100644 --- a/noir/noir-repo/acvm-repo/brillig/src/opcodes.rs +++ b/noir/noir-repo/acvm-repo/brillig/src/opcodes.rs @@ -188,6 +188,11 @@ pub enum BrilligOpcode { lhs: MemoryAddress, rhs: MemoryAddress, }, + Not { + destination: MemoryAddress, + source: MemoryAddress, + bit_size: IntegerBitSize, + }, Cast { destination: MemoryAddress, source: MemoryAddress, diff --git a/noir/noir-repo/acvm-repo/brillig_vm/src/lib.rs b/noir/noir-repo/acvm-repo/brillig_vm/src/lib.rs index 04519279d52..07d0ea02ad4 100644 --- a/noir/noir-repo/acvm-repo/brillig_vm/src/lib.rs +++ b/noir/noir-repo/acvm-repo/brillig_vm/src/lib.rs @@ -213,6 +213,13 @@ impl<'a, F: AcirField, B: BlackBoxFunctionSolver> VM<'a, F, B> { self.increment_program_counter() } } + Opcode::Not { destination, source, bit_size } => { + if let Err(error) = self.process_not(*source, *destination, *bit_size) { + self.fail(error) + } else { + self.increment_program_counter() + } + } Opcode::Cast { destination: destination_address, source: source_address, bit_size } => { let source_value = self.memory.read(*source_address); let casted_value = self.cast(*bit_size, source_value); @@ -709,6 +716,36 @@ impl<'a, F: AcirField, B: BlackBoxFunctionSolver> VM<'a, F, B> { Ok(()) } + fn process_not( + &mut self, + source: MemoryAddress, + destination: MemoryAddress, + op_bit_size: IntegerBitSize, + ) -> Result<(), String> { + let (value, bit_size) = self + .memory + .read(source) + .extract_integer() + .ok_or("Not opcode source is not an integer")?; + + if bit_size != op_bit_size { + return Err(format!( + "Not opcode source bit size {} does not match expected bit size {}", + bit_size, op_bit_size + )); + } + + let negated_value = if let IntegerBitSize::U128 = bit_size { + !value + } else { + let bit_size: u32 = bit_size.into(); + let mask = (1_u128 << bit_size as u128) - 1; + (!value) & mask + }; + self.memory.write(destination, MemoryValue::new_integer(negated_value, bit_size)); + Ok(()) + } + /// Casts a value to a different bit size. fn cast(&self, target_bit_size: BitSize, source_value: MemoryValue) -> MemoryValue { match (source_value, target_bit_size) { @@ -952,6 +989,62 @@ mod tests { assert_eq!(casted_value.to_field(), (2_u128.pow(8) - 1).into()); } + #[test] + fn not_opcode() { + let calldata: Vec = vec![(1_usize).into()]; + + let opcodes = &[ + Opcode::Const { + destination: MemoryAddress(0), + bit_size: BitSize::Integer(IntegerBitSize::U32), + value: FieldElement::from(1u64), + }, + Opcode::Const { + destination: MemoryAddress(1), + bit_size: BitSize::Integer(IntegerBitSize::U32), + value: FieldElement::from(0u64), + }, + Opcode::CalldataCopy { + destination_address: MemoryAddress(0), + size_address: MemoryAddress(0), + offset_address: MemoryAddress(1), + }, + Opcode::Cast { + destination: MemoryAddress::from(1), + source: MemoryAddress::from(0), + bit_size: BitSize::Integer(IntegerBitSize::U128), + }, + Opcode::Not { + destination: MemoryAddress::from(1), + source: MemoryAddress::from(1), + bit_size: IntegerBitSize::U128, + }, + Opcode::Stop { return_data_offset: 1, return_data_size: 1 }, + ]; + let mut vm = VM::new(calldata, opcodes, vec![], &StubbedBlackBoxSolver); + + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::InProgress); + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::InProgress); + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::InProgress); + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::InProgress); + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::InProgress); + let status = vm.process_opcode(); + assert_eq!(status, VMStatus::Finished { return_data_offset: 1, return_data_size: 1 }); + + let VM { memory, .. } = vm; + + let (negated_value, _) = memory + .read(MemoryAddress::from(1)) + .extract_integer() + .expect("Expected integer as the output of Not"); + assert_eq!(negated_value, !1_u128); + } + #[test] fn mov_opcode() { let calldata: Vec = vec![(1u128).into(), (2u128).into(), (3u128).into()]; diff --git a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/instructions.rs b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/instructions.rs index faeade7fcf1..f196552b768 100644 --- a/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/instructions.rs +++ b/noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/instructions.rs @@ -48,12 +48,12 @@ impl BrilligContext< result: SingleAddrVariable, ) { self.debug_show.not_instruction(input.address, input.bit_size, result.address); - // Compile !x as ((-1) - x) - let u_max = F::from(2_u128).pow(&F::from(input.bit_size as u128)) - F::one(); - let max = self.make_constant(u_max, input.bit_size); - - self.binary(max, input, result, BrilligBinaryOp::Sub); - self.deallocate_single_addr(max); + assert_eq!(input.bit_size, result.bit_size, "Not operands should have the same bit size"); + self.push_opcode(BrilligOpcode::Not { + destination: result.address, + source: input.address, + bit_size: input.bit_size.try_into().unwrap(), + }); } /// Utility method to perform a binary instruction with a memory address @@ -418,12 +418,6 @@ impl BrilligContext< var } - fn make_constant(&mut self, constant: F, bit_size: u32) -> SingleAddrVariable { - let var = SingleAddrVariable::new(self.allocate_register(), bit_size); - self.constant(var.address, var.bit_size, constant, false); - var - } - /// Returns a register which holds the value of an usize constant pub(crate) fn make_usize_constant_instruction(&mut self, constant: F) -> SingleAddrVariable { let register = self.allocate_register(); diff --git a/noir/noir-repo/tooling/profiler/src/opcode_formatter.rs b/noir/noir-repo/tooling/profiler/src/opcode_formatter.rs index 56c00bb856b..fa72793e406 100644 --- a/noir/noir-repo/tooling/profiler/src/opcode_formatter.rs +++ b/noir/noir-repo/tooling/profiler/src/opcode_formatter.rs @@ -123,6 +123,7 @@ fn format_brillig_opcode_kind(opcode: &BrilligOpcode) -> String { BrilligOpcode::BinaryIntOp { op, bit_size, .. } => { format!("{bit_size}::{}", format_binary_int(op)) } + BrilligOpcode::Not { .. } => "not".to_string(), BrilligOpcode::BlackBox(func) => format!("blackbox::{}", format_blackbox_op(func)), BrilligOpcode::Call { .. } => "call".to_string(), BrilligOpcode::CalldataCopy { .. } => "calldata_copy".to_string(),