forked from iden3/circom
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VAN-1446] use vector values in interpreter to properly handle vector…
… returns (#142) * update tests to keep original intent in light of better optimization * also a random test fix
- Loading branch information
1 parent
a24620d
commit ccaa1c1
Showing
14 changed files
with
878 additions
and
405 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
pragma circom 2.0.3; | ||
// REQUIRES: circom | ||
// RUN: rm -rf %t && mkdir %t && %circom --llvm -o %t %s | sed -n 's/.*Written successfully:.* \(.*\)/\1/p' | xargs cat | FileCheck %s --enable-var-scope | ||
|
||
function long_gt(a, b) { | ||
for (var i = 1; i >= 0; i--) { | ||
if (a[i] > b[i]) { | ||
return 1; | ||
} | ||
if (a[i] < b[i]) { | ||
return 2; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
function long_scalar_mult() { | ||
return [[99, 88, 77], [66, 55, 44]]; | ||
} | ||
|
||
template Test() { | ||
var norm[2][3] = long_scalar_mult(); | ||
var out[1] = [long_gt(norm[0], norm[1])]; | ||
} | ||
|
||
component main = Test(); | ||
|
||
// NOTE: With the constant arrays propagated through return and call, | ||
// the long_gt() function is totally optimized away to the value '1'. | ||
|
||
//CHECK-LABEL: define{{.*}} void @Test_{{[0-9]+}}_run([0 x i256]* %0){{.*}} { | ||
//CHECK-NEXT: prelude: | ||
//CHECK-NEXT: %lvars = alloca [7 x i256], align 8 | ||
//CHECK-NEXT: %subcmps = alloca [0 x { [0 x i256]*, i32 }], align 8 | ||
//CHECK-NEXT: br label %call1 | ||
//CHECK-EMPTY: | ||
//CHECK-NEXT: call1: | ||
//CHECK-NEXT: %[[ARENA:[0-9a-zA-Z_\.]+]] = alloca [12 x i256], align 8 | ||
//CHECK-NEXT: %[[T01:[0-9a-zA-Z_\.]+]] = bitcast [12 x i256]* %[[ARENA]] to i256* | ||
//CHECK-NEXT: %[[T99:[0-9a-zA-Z_\.]+]] = call i256* @long_scalar_mult_{{[0-9a-zA-Z_\.]+}}(i256* %[[T01]]) | ||
//CHECK-NEXT: %[[T02:[0-9a-zA-Z_\.]+]] = getelementptr [7 x i256], [7 x i256]* %lvars, i32 0, i32 0 | ||
//CHECK-NEXT: %[[CPY_SRC_0:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T99]], i32 0 | ||
//CHECK-NEXT: %[[CPY_DST_0:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T02]], i32 0 | ||
//CHECK-NEXT: %[[CPY_VAL_0:[0-9a-zA-Z_\.]+]] = load i256, i256* %[[CPY_SRC_0]], align 4 | ||
//CHECK-NEXT: store i256 %[[CPY_VAL_0]], i256* %[[CPY_DST_0]], align 4 | ||
//CHECK-NEXT: %[[CPY_SRC_1:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T99]], i32 1 | ||
//CHECK-NEXT: %[[CPY_DST_1:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T02]], i32 1 | ||
//CHECK-NEXT: %[[CPY_VAL_1:[0-9a-zA-Z_\.]+]] = load i256, i256* %[[CPY_SRC_1]], align 4 | ||
//CHECK-NEXT: store i256 %[[CPY_VAL_1]], i256* %[[CPY_DST_1]], align 4 | ||
//CHECK-NEXT: %[[CPY_SRC_2:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T99]], i32 2 | ||
//CHECK-NEXT: %[[CPY_DST_2:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T02]], i32 2 | ||
//CHECK-NEXT: %[[CPY_VAL_2:[0-9a-zA-Z_\.]+]] = load i256, i256* %[[CPY_SRC_2]], align 4 | ||
//CHECK-NEXT: store i256 %[[CPY_VAL_2]], i256* %[[CPY_DST_2]], align 4 | ||
//CHECK-NEXT: %[[CPY_SRC_3:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T99]], i32 3 | ||
//CHECK-NEXT: %[[CPY_DST_3:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T02]], i32 3 | ||
//CHECK-NEXT: %[[CPY_VAL_3:[0-9a-zA-Z_\.]+]] = load i256, i256* %[[CPY_SRC_3]], align 4 | ||
//CHECK-NEXT: store i256 %[[CPY_VAL_3]], i256* %[[CPY_DST_3]], align 4 | ||
//CHECK-NEXT: %[[CPY_SRC_4:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T99]], i32 4 | ||
//CHECK-NEXT: %[[CPY_DST_4:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T02]], i32 4 | ||
//CHECK-NEXT: %[[CPY_VAL_4:[0-9a-zA-Z_\.]+]] = load i256, i256* %[[CPY_SRC_4]], align 4 | ||
//CHECK-NEXT: store i256 %[[CPY_VAL_4]], i256* %[[CPY_DST_4]], align 4 | ||
//CHECK-NEXT: %[[CPY_SRC_5:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T99]], i32 5 | ||
//CHECK-NEXT: %[[CPY_DST_5:[0-9a-zA-Z_\.]+]] = getelementptr i256, i256* %[[T02]], i32 5 | ||
//CHECK-NEXT: %[[CPY_VAL_5:[0-9a-zA-Z_\.]+]] = load i256, i256* %[[CPY_SRC_5]], align 4 | ||
//CHECK-NEXT: store i256 %[[CPY_VAL_5]], i256* %[[CPY_DST_5]], align 4 | ||
//CHECK-NEXT: br label %store2 | ||
//CHECK-EMPTY: | ||
//CHECK-NEXT: store2: | ||
//CHECK-NEXT: %[[T03:[0-9a-zA-Z_\.]+]] = getelementptr [7 x i256], [7 x i256]* %lvars, i32 0, i32 6 | ||
//CHECK-NEXT: store i256 1, i256* %[[T03]], align 4 | ||
//CHECK-NEXT: br label %prologue | ||
//CHECK-EMPTY: | ||
//CHECK-NEXT: prologue: | ||
//CHECK-NEXT: ret void | ||
//CHECK-NEXT: } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
pragma circom 2.0.0; | ||
// REQUIRES: circom | ||
// RUN: rm -rf %t && mkdir %t && %circom --llvm -o %t %s | sed -n 's/.*Written successfully:.* \(.*\)/\1/p' | xargs cat | FileCheck %s --enable-var-scope | ||
|
||
// The circom compiler only gives a warning for this: | ||
// warning[T3001]: Typing warning: Mismatched dimensions, assigning to an array an expression of smaller length, the remaining positions are assigned to 0. | ||
|
||
function smaller() { | ||
return [99, 98, 97, 96, 95]; | ||
} | ||
|
||
template ImplicitExtension() { | ||
signal output out[10]; | ||
var temp[10] = smaller(); | ||
out[0] <-- temp[0]; | ||
out[4] <-- temp[4]; | ||
out[5] <-- temp[5]; | ||
out[9] <-- temp[9]; | ||
} | ||
|
||
component main = ImplicitExtension(); | ||
|
||
//CHECK-LABEL: define{{.*}} void @ImplicitExtension_{{[0-9]+}}_run([0 x i256]* %0){{.*}} { | ||
//CHECK: store2: | ||
//CHECK-NEXT: %[[T03:[0-9a-zA-Z_\.]+]] = getelementptr [0 x i256], [0 x i256]* %0, i32 0, i32 0 | ||
//CHECK-NEXT: store i256 99, i256* %[[T03]], align 4 | ||
//CHECK: store3: | ||
//CHECK-NEXT: %[[T04:[0-9a-zA-Z_\.]+]] = getelementptr [0 x i256], [0 x i256]* %0, i32 0, i32 4 | ||
//CHECK-NEXT: store i256 95, i256* %[[T04]], align 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pragma circom 2.0.0; | ||
// REQUIRES: circom | ||
// RUN: rm -rf %t && mkdir %t && %circom --llvm -o %t %s | sed -n 's/.*Written successfully:.* \(.*\)/\1/p' | xargs cat | FileCheck %s --enable-var-scope | ||
|
||
// The circom compiler only gives a warning for this: | ||
// warning[T3001]: Typing warning: Mismatched dimensions, assigning to an array an expression of smaller length, the remaining positions are assigned to 0. | ||
|
||
template ImplicitExtension() { | ||
signal output out[10]; | ||
var temp[10] = [99, 98, 97, 96, 95]; | ||
out[0] <-- temp[0]; | ||
out[4] <-- temp[4]; | ||
out[5] <-- temp[5]; | ||
out[9] <-- temp[9]; | ||
} | ||
|
||
component main = ImplicitExtension(); | ||
|
||
//CHECK-LABEL: define{{.*}} void @ImplicitExtension_{{[0-9]+}}_run([0 x i256]* %0){{.*}} { | ||
//CHECK: store6: | ||
//CHECK-NEXT: %[[T06:[0-9a-zA-Z_\.]+]] = getelementptr [0 x i256], [0 x i256]* %0, i32 0, i32 0 | ||
//CHECK-NEXT: store i256 99, i256* %[[T06]], align 4 | ||
//CHECK: store7: | ||
//CHECK-NEXT: %[[T07:[0-9a-zA-Z_\.]+]] = getelementptr [0 x i256], [0 x i256]* %0, i32 0, i32 4 | ||
//CHECK-NEXT: store i256 95, i256* %[[T07]], align 4 |
Oops, something went wrong.