Skip to content

Commit

Permalink
test: add semantic tests for Felt intrinsics (add, sub, mul, div, neg,
Browse files Browse the repository at this point in the history
eq)
  • Loading branch information
greenhat committed Apr 19, 2024
1 parent 9397872 commit 2ac171f
Show file tree
Hide file tree
Showing 34 changed files with 7,219 additions and 27 deletions.
30 changes: 29 additions & 1 deletion sdk/prelude/src/intrinsics/felt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::ops::{Add, Div, Mul, Neg, Sub};
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};

#[link(wasm_import_module = "miden:prelude/intrinsics_felt")]
extern "C" {
Expand Down Expand Up @@ -171,6 +171,13 @@ impl Add for Felt {
}
}

impl AddAssign for Felt {
#[inline(always)]
fn add_assign(&mut self, other: Self) {
*self = *self + other;
}
}

impl Sub for Felt {
type Output = Self;

Expand All @@ -180,6 +187,13 @@ impl Sub for Felt {
}
}

impl SubAssign for Felt {
#[inline(always)]
fn sub_assign(&mut self, other: Self) {
*self = *self - other;
}
}

impl Mul for Felt {
type Output = Self;

Expand All @@ -189,6 +203,13 @@ impl Mul for Felt {
}
}

impl MulAssign for Felt {
#[inline(always)]
fn mul_assign(&mut self, other: Self) {
*self = *self * other;
}
}

impl Div for Felt {
type Output = Self;

Expand All @@ -198,6 +219,13 @@ impl Div for Felt {
}
}

impl DivAssign for Felt {
#[inline(always)]
fn div_assign(&mut self, other: Self) {
*self = *self / other;
}
}

impl Neg for Felt {
type Output = Self;

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ cargo-util = "0.2"
filetime = "0.2.23"
glob = "0.3.1"
walkdir = "2.5.0"
proptest.workspace = true

[dev-dependencies]
miden-core.workspace = true
proptest.workspace = true
concat-idents = "1.1"
21 changes: 21 additions & 0 deletions tests/integration/expected/add_felt.hir
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(component
;; Modules
(module #add_felt
;; Constants
(const (id 0) 0x00100000)

;; Global Variables
(global (export #__stack_pointer) (id 0) (type i32) (const 0))

;; Functions
(func (export #entrypoint) (param felt) (param felt) (result felt)
(block 0 (param v0 felt) (param v1 felt)
(let (v3 felt) (add.unchecked v0 v1))
(br (block 1 v3)))

(block 1 (param v2 felt)
(ret v2))
)
)

)
Loading

0 comments on commit 2ac171f

Please sign in to comment.