Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions compiler/noirc_evaluator/src/ssa/interpreter/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ impl Interpreter<'_> {
Intrinsic::ToBits(endian) => {
check_argument_count(args, 1, intrinsic)?;
let field = self.lookup_field(args[0], "call to to_bits")?;
self.to_radix(endian, args[0], field, 2, results[0])
let element_type = NumericType::bool();
self.to_radix(endian, element_type, args[0], field, 2, results[0])
}
Intrinsic::ToRadix(endian) => {
check_argument_count(args, 2, intrinsic)?;
let field = self.lookup_field(args[0], "call to to_bits")?;
let radix = self.lookup_u32(args[1], "call to to_bits")?;
self.to_radix(endian, args[0], field, radix, results[0])
let field = self.lookup_field(args[0], "call to to_radix")?;
let radix = self.lookup_u32(args[1], "call to to_radix")?;
let element_type = NumericType::Unsigned { bit_size: 8 };
self.to_radix(endian, element_type, args[0], field, radix, results[0])
}
Intrinsic::BlackBox(black_box_func) => match black_box_func {
acvm::acir::BlackBoxFunc::AES128Encrypt => {
Expand Down Expand Up @@ -425,6 +427,7 @@ impl Interpreter<'_> {
fn to_radix(
&self,
endian: Endian,
element_type: NumericType,
field_id: ValueId,
field: FieldElement,
radix: u32,
Expand All @@ -444,9 +447,8 @@ impl Interpreter<'_> {
return Err(InterpreterError::ToRadixFailed { field_id, field, radix });
};

let elements =
try_vecmap(limbs, |limb| Value::from_constant(limb, NumericType::unsigned(8)))?;
Ok(vec![Value::array(elements, vec![Type::unsigned(8)])])
let elements = try_vecmap(limbs, |limb| Value::from_constant(limb, element_type))?;
Ok(vec![Value::array(elements, vec![Type::Numeric(element_type)])])
}

/// (length, slice, elem...) -> (length, slice)
Expand Down
38 changes: 38 additions & 0 deletions compiler/noirc_evaluator/src/ssa/interpreter/tests/intrinstics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::ssa::interpreter::{
tests::expect_value,
value::{NumericValue, Value},
};

#[test]
fn to_le_bits() {
let value = expect_value(
"
acir(inline) fn main f0 {
b0():
v0 = add Field 0, Field 0
v1 = call to_le_bits(v0) -> [u1; 2]
v2 = array_get v1, index u32 0 -> u1
v3 = not v2
return v3
}
",
);
assert_eq!(value, Value::Numeric(NumericValue::U1(true)));
}

#[test]
fn to_le_radix() {
let value = expect_value(
"
acir(inline) fn main f0 {
b0():
v0 = add Field 0, Field 0
v1 = call to_le_radix(v0, u32 2) -> [u8; 32]
v2 = array_get v1, index u32 0 -> u8
v3 = not v2
return v3
}
",
);
assert_eq!(value, Value::Numeric(NumericValue::U8(255)));
}
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/src/ssa/interpreter/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

mod black_box;
mod instructions;
mod intrinstics;

Check warning on line 16 in compiler/noirc_evaluator/src/ssa/interpreter/tests/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (intrinstics)
Comment thread
asterite marked this conversation as resolved.
Outdated

#[track_caller]
fn executes_with_no_errors(src: &str) {
Expand Down
Loading