Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion include/NeuraDialect/NeuraOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def Neura_FAddOp : Op<NeuraDialect, "fadd"> {
let arguments = (ins AnyType:$lhs, AnyType:$rhs, Optional<AnyType>:$predicate);
let results = (outs AnyType:$result);
// let assemblyFormat = "$lhs `,` $rhs `,` $predicate attr-dict `:` type($result)";
//let traits = [SameOperandsAndResultElementType];
// let traits = [SameOperandsAndResultElementType];
}

// Defines a floating-point substraction operation.
Expand Down
13 changes: 0 additions & 13 deletions test/neura/interpreter/add.mlir

This file was deleted.

60 changes: 60 additions & 0 deletions test/neura/interpreter/basic_operation/add.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// RUN: neura-interpreter %s | FileCheck %s

// ===----------------------------------------------------------------------===//
// Test 1: Add two float constants
// ===----------------------------------------------------------------------===//
func.func @test_add_f32() -> f32 {
%a = arith.constant 10.0 : f32
%b = arith.constant 32.0 : f32
%res = "neura.add"(%a, %b) : (f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 42.000000
return %res : f32
}

// ===----------------------------------------------------------------------===//
// Test 2: Add a negative and positive float
// ===----------------------------------------------------------------------===//
func.func @test_add_negative() -> f32 {
%a = arith.constant -5.0 : f32
%b = arith.constant 3.0 : f32
%res = "neura.add"(%a, %b) : (f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: -2.000000
return %res : f32
}

// ===----------------------------------------------------------------------===//
// Test 3: Add two fractional values
// ===----------------------------------------------------------------------===//
func.func @test_add_fraction() -> f32 {
%a = arith.constant 2.5 : f32
%b = arith.constant 1.25 : f32
%res = "neura.add"(%a, %b) : (f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 4.000000
return %res : f32
}

// ===----------------------------------------------------------------------===//
// Test 4: Add zero and a number
// ===----------------------------------------------------------------------===//
func.func @test_add_zero() -> f32 {
%a = arith.constant 0.0 : f32
%b = arith.constant 7.0 : f32
%res = "neura.add"(%a, %b) : (f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 7.000000
return %res : f32
}

// RUN: neura-interpreter %s | FileCheck %s

// ===----------------------------------------------------------------------===//
// Test 5: Add with operation predicate 0
// ===----------------------------------------------------------------------===//
func.func @test_add_predicate_zero() -> f32 {
%a = arith.constant 10.0 : f32
%b = arith.constant 32.0 : f32
%pred = arith.constant 0 : i1
%pred_f32 = "neura.cast"(%pred) {cast_type = "bool2f"} : (i1) -> f32
%res = "neura.add"(%a, %b, %pred_f32) : (f32, f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 0.000000
return %res : f32
}
21 changes: 21 additions & 0 deletions test/neura/interpreter/basic_operation/br.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// RUN: neura-interpreter %s | FileCheck %s

func.func @test_br_with_args() -> i32 {
%0 = "neura.constant"() {value = 42 : i32} : () -> i32
"neura.br"(%0) [^bb1] {operandSegmentSizes = array<i32: 1>} : (i32) -> ()

^bb1(%a: i32):
// CHECK: [neura-interpreter] → Output: 42.000000
return %a : i32
}

func.func @test_br_with_multi_args() {
%0 = "neura.constant"() {value = 42 : i32} : () -> i32
%1 = "neura.constant"() {value = 1.0 : f32} : () -> f32
"neura.br"(%0, %1) [^bb1] {operandSegmentSizes = array<i32: 2>} : (i32, f32) -> ()

^bb1(%a: i32, %b: f32):
"neura.add"(%a, %a) : (i32, i32) -> i32
// CHECK-NEXT: [neura-interpreter] → Output: (void)
return
}
59 changes: 59 additions & 0 deletions test/neura/interpreter/basic_operation/cast.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// RUN: neura-interpreter %s | FileCheck %s

// int -> float
func.func @test_cast_i2f() -> f32 {
%a = arith.constant 42 : i32
%res = "neura.cast"(%a) { cast_type = "i2f" } : (i32) -> f32
// CHECK: [neura-interpreter] → Output: 42.000000
return %res : f32
}

// float -> int
func.func @test_cast_f2i() -> i32 {
%a = arith.constant 3.14 : f32
%res = "neura.cast"(%a) { cast_type = "f2i" } : (f32) -> i32
// CHECK: [neura-interpreter] → Output: 3.000000
return %res : i32
}

// bool -> int
func.func @test_cast_bool2i() -> i32 {
%b = arith.constant 1 : i1
%res = "neura.cast"(%b) { cast_type = "bool2i" } : (i1) -> i32
// CHECK: [neura-interpreter] → Output: 1.000000
return %res : i32
}

// bool -> float
func.func @test_cast_bool2f() -> f32 {
%b = arith.constant 0 : i1
%res = "neura.cast"(%b) { cast_type = "bool2f" } : (i1) -> f32
// CHECK: [neura-interpreter] → Output: 0.000000
return %res : f32
}

// int -> bool
func.func @test_cast_i2bool() -> i1 {
%a = arith.constant 100 : i32
%res = "neura.cast"(%a) { cast_type = "i2bool" } : (i32) -> i1
// CHECK: [neura-interpreter] → Output: 1.000000
return %res : i1
}

// f2i with true predicate
func.func @test_cast_predicated() -> i32 {
%val = arith.constant 5.5 : f32
%pred = arith.constant 1 : i1
%res = "neura.cast"(%val, %pred) { cast_type = "f2i" } : (f32, i1) -> i32
// CHECK: [neura-interpreter] → Output: 6.000000
return %res : i32
}

// f2i with false predicate
func.func @test_cast_predicate_false() -> i32 {
%val = arith.constant 5.5 : f32
%pred = arith.constant 0 : i1
%res = "neura.cast"(%val, %pred) { cast_type = "f2i" } : (f32, i1) -> i32
// CHECK: [neura-interpreter] → Output: 0.000000
return %res : i32
}
51 changes: 51 additions & 0 deletions test/neura/interpreter/basic_operation/cond_br.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// RUN: neura-interpreter %s | FileCheck %s

func.func @test_cond_br_true() {
%cond = arith.constant 1 : i1
"neura.cond_br"(%cond) [^bb1, ^bb2] {operandSegmentSizes = array<i32: 1, 0, 0, 0>} : (i1) -> ()
// CHECK: [neura-interpreter] → Output: (void)
^bb1:
return
^bb2:
return
}

func.func @test_cond_br_false() {
%cond = arith.constant 0 : i1
"neura.cond_br"(%cond) [^bb1, ^bb2] {operandSegmentSizes = array<i32: 1, 0, 0, 0>} : (i1) -> ()
// CHECK: [neura-interpreter] → Output: (void)
^bb1:
return
^bb2:
return
}

func.func @test_cond_br_with_valid_predicate() {
%cond = arith.constant 1 : i1
%pred = arith.constant 1 : i32
"neura.cond_br"(%cond, %pred) [^bb1, ^bb2] {operandSegmentSizes = array<i32: 1, 1, 0, 0>} : (i1, i32) -> ()
// CHECK: [neura-interpreter] → Output: (void)
^bb1:
return
^bb2:
return
}

func.func @test_nested_cond_br() {
%cond1 = arith.constant 1 : i1
"neura.cond_br"(%cond1) [^bb1, ^bb2] {operandSegmentSizes = array<i32: 1, 0, 0, 0>} : (i1) -> ()

^bb1:
%cond2 = arith.constant 0 : i1
"neura.cond_br"(%cond2) [^bb3, ^bb4] {operandSegmentSizes = array<i32: 1, 0, 0, 0>} : (i1) -> ()
// CHECK: [neura-interpreter] → Output: (void)

^bb2:
return

^bb3:
return

^bb4:
return
}
34 changes: 34 additions & 0 deletions test/neura/interpreter/basic_operation/ctrl_mov.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// RUN: neura-interpreter %s | FileCheck %s

func.func @test_ctrl_mov_basic() {
%a = "neura.reserve"() : () -> (i32)
%const = arith.constant 42 : i32

"neura.ctrl_mov"(%const, %a) : (i32, i32) -> ()

// CHECK: [neura-interpreter] → Output: (void)

return
}

func.func @test_ctrl_mov_chained() {
%a = "neura.reserve"() : () -> (i32)
%b = "neura.reserve"() : () -> (i32)
%const = arith.constant 10 : i32

"neura.ctrl_mov"(%const, %a) : (i32, i32) -> ()

"neura.ctrl_mov"(%a, %b) : (i32, i32) -> ()
// CHECK: [neura-interpreter] → Output: (void)

return
}

func.func @test_ctrl_mov_vector() {
%vec_reserve = "neura.reserve"() : () -> (vector<4xf32>)
%vec_const = "neura.constant"() {value = dense<[1.0, 2.0, 3.0, 4.0]> : vector<4xf32>} : () -> vector<4xf32>

"neura.ctrl_mov"(%vec_const, %vec_reserve) : (vector<4xf32>, vector<4xf32>) -> ()
// CHECK: [neura-interpreter] → Output: (void)
return
}
72 changes: 72 additions & 0 deletions test/neura/interpreter/basic_operation/fadd.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// RUN: neura-interpreter %s | FileCheck %s

// ===----------------------------------------------------------------------===//
// Test 1: Valid neura.fadd with positive constants
// ===----------------------------------------------------------------------===//
func.func @test_fadd_positive() -> f32 {
%a = arith.constant 5.5 : f32
%b = arith.constant 3.25 : f32
%res = "neura.fadd"(%a, %b) : (f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 8.750000
return %res : f32
}

// ===----------------------------------------------------------------------===//
// Test 2: Valid neura.fadd with negative constants
// ===----------------------------------------------------------------------===//
func.func @test_fadd_negative() -> f32 {
%a = arith.constant -10.25 : f32
%b = arith.constant -5.75 : f32
%res = "neura.fadd"(%a, %b) : (f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: -16.000000
return %res : f32
}

// ===----------------------------------------------------------------------===//
// Test 3: Valid neura.fadd with mixed signs
// ===----------------------------------------------------------------------===//
func.func @test_fadd_mixed_signs() -> f32 {
%a = arith.constant -7.5 : f32
%b = arith.constant 12.25 : f32
%res = "neura.fadd"(%a, %b) : (f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 4.750000
return %res : f32
}

// ===----------------------------------------------------------------------===//
// Test 4: Valid neura.fadd with zero
// ===----------------------------------------------------------------------===//
func.func @test_fadd_zero() -> f32 {
%a = arith.constant 0.0 : f32
%b = arith.constant 25.5 : f32
%res = "neura.fadd"(%a, %b) : (f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 25.500000
return %res : f32
}

// ===----------------------------------------------------------------------===//
// Test 4: Predicate handling in neura.fadd
// ===----------------------------------------------------------------------===//
func.func @test_fadd_invalid_predicate() -> f32 {
%a = arith.constant 0.0 : f32
%b = arith.constant 25.5 : f32
%pred = arith.constant 0 : i1
%pred_f32 = "neura.cast"(%pred) {cast_type = "bool2f"} : (i1) -> f32
%res = "neura.fadd"(%a, %b, %pred_f32) : (f32, f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 0.000000
return %res : f32
}

// ===----------------------------------------------------------------------===//
// Test 5: Nested predicate handling in neura.fadd
// ===----------------------------------------------------------------------===//
func.func @test_nested_fadd_invalid_predicate() -> f32 {
%a = arith.constant 0.0 : f32
%b = arith.constant 25.5 : f32
%pred = arith.constant 0 : i1
%pred_f32 = "neura.cast"(%pred) {cast_type = "bool2f"} : (i1) -> f32
%tmp = "neura.fadd"(%a, %b, %pred_f32) : (f32, f32, f32) -> f32
%res = "neura.fadd"(%tmp, %b, %pred_f32) : (f32, f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 0.000000
return %res : f32
}
65 changes: 65 additions & 0 deletions test/neura/interpreter/basic_operation/fadd_fadd.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// RUN: neura-interpreter %s | FileCheck %s

// Test basic fused fadd operation: (2.5 + 1.5) + 3.0 = 7.0
func.func @test_fadd_fadd_basic() -> f32 {
%a = arith.constant 2.5 : f32
%b = arith.constant 1.5 : f32
%c = arith.constant 3.0 : f32
%res = "neura.fadd_fadd"(%a, %b, %c) : (f32, f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 7.000000
return %res : f32
}

// Test with negative numbers: (5.0 + (-2.0)) + (-1.0) = 2.0
func.func @test_fadd_fadd_negative() -> f32 {
%a = arith.constant 5.0 : f32
%b = arith.constant -2.0 : f32
%c = arith.constant -1.0 : f32
%res = "neura.fadd_fadd"(%a, %b, %c) : (f32, f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 2.000000
return %res : f32
}

// Test with zero: (0.0 + 4.0) + 6.0 = 10.0
func.func @test_fadd_fadd_zero() -> f32 {
%a = arith.constant 0.0 : f32
%b = arith.constant 4.0 : f32
%c = arith.constant 6.0 : f32
%res = "neura.fadd_fadd"(%a, %b, %c) : (f32, f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 10.000000
return %res : f32
}

// Test with valid predicate: (3.0 + 1.0) + 2.0 = 6.0
func.func @test_fadd_fadd_with_valid_predicate() -> f32 {
%a = arith.constant 3.0 : f32
%b = arith.constant 1.0 : f32
%c = arith.constant 2.0 : f32
%pred = arith.constant 1 : i1
%pred_f32 = "neura.cast"(%pred) {cast_type = "bool2f"} : (i1) -> f32
%res = "neura.fadd_fadd"(%a, %b, %c, %pred_f32) : (f32, f32, f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 6.000000
return %res : f32
}

// Test with false predicate (should return 0)
func.func @test_fadd_fadd_with_invalid_predicate() -> f32 {
%a = arith.constant 10.0 : f32
%b = arith.constant 20.0 : f32
%c = arith.constant 30.0 : f32
%pred = arith.constant 0 : i1
%pred_f32 = "neura.cast"(%pred) {cast_type = "bool2f"} : (i1) -> f32
%res = "neura.fadd_fadd"(%a, %b, %c, %pred_f32) : (f32, f32, f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 0.000000
return %res : f32
}

// Test with invalid input predicate
func.func @test_fadd_fadd_with_invalid_input_predicate() -> f32 {
%a = "neura.constant"() {value = 5.0 : f32, predicate = false} : () -> f32
%b = arith.constant 3.0 : f32
%c = arith.constant 2.0 : f32
%res = "neura.fadd_fadd"(%a, %b, %c) : (f32, f32, f32) -> f32
// CHECK: [neura-interpreter] → Output: 0.000000
return %res : f32
}
Loading