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.
Generalize mapped offset computation, add tests (#42)
- Loading branch information
Showing
5 changed files
with
172 additions
and
22 deletions.
There are no files selected for viewing
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,50 @@ | ||
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 | ||
|
||
template ArrayOp(q) { | ||
signal input inp[15]; | ||
signal output outp[15]; | ||
|
||
for (var i = 0; i < 15; i++) { | ||
outp[i] <== inp[i] + q; | ||
} | ||
} | ||
|
||
//CHECK-LABEL: define void @ArrayOp_{{[0-9]+}}_build | ||
//CHECK-SAME: ({ [0 x i256]*, i32 }* %{{.*}}) | ||
//CHECK: alloca [30 x i256] | ||
//CHECK: %[[DIM_REG:.*]] = getelementptr { [0 x i256]*, i32 }, { [0 x i256]*, i32 }* %0, i32 0, i32 1 | ||
//CHECK: store i32 15, i32* %{{.*}}[[DIM_REG]] | ||
|
||
template Wrapper() { | ||
signal input inp[15]; | ||
signal output outp; | ||
|
||
component m[4]; | ||
|
||
for (var q = 0; q < 4; q++) { | ||
// This test exhibits the behavior because the array of different subcomponents | ||
// (differentiated by the template parameter changing) | ||
m[q] = ArrayOp(q); | ||
for (var i = 0; i < 15; i++) { | ||
m[q].inp[i] <== inp[i]; | ||
} | ||
} | ||
|
||
outp <== m[2].outp[3]; | ||
} | ||
|
||
component main = Wrapper(); | ||
|
||
//CHECK-LABEL: define void @Wrapper_{{[0-9]+}}_run | ||
//CHECK-SAME: ([0 x i256]* %{{.*}}) | ||
//CHECK: %lvars = alloca [2 x i256] | ||
//COM: offset = (1 * (3 * 7)) + (2 * (7)) + (3) + 1 (since 0 is output) = 21 + 14 + 3 + 1 = 39 | ||
//CHECK: store{{.*}}:{{.*}}; preds = %unrolled_loop{{.*}} | ||
//CHECK: %[[SUB_PTR:.*]] = getelementptr [4 x { [0 x i256]*, i32 }], [4 x { [0 x i256]*, i32 }]* %subcmps, i32 0, i32 2, i32 0 | ||
//CHECK: %[[SUBCMP:.*]] = load [0 x i256]*, [0 x i256]** %[[SUB_PTR]] | ||
//CHECK: %[[VAL_PTR:.*]] = getelementptr [0 x i256], [0 x i256]* %[[SUBCMP]], i32 0, i32 3 | ||
//CHECK: %[[VAL:.*]] = load i256, i256* %[[VAL_PTR]] | ||
//CHECK: %[[OUTP_PTR:.*]] = getelementptr [0 x i256], [0 x i256]* %0, i32 0, i32 0 | ||
//CHECK: store i256 %[[VAL]], i256* %[[OUTP_PTR]] |
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,53 @@ | ||
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 | ||
|
||
template MatrixOp(q) { | ||
signal input inp[5][3]; | ||
signal output outp[5][3]; | ||
|
||
for (var i = 0; i < 5; i++) { | ||
for (var j = 0; j < 3; j++) { | ||
outp[i][j] <== inp[i][j] + q; | ||
} | ||
} | ||
} | ||
|
||
//CHECK-LABEL: define void @MatrixOp_{{[0-9]+}}_build | ||
//CHECK-SAME: ({ [0 x i256]*, i32 }* %{{.*}}) | ||
//CHECK: alloca [16 x i256] | ||
//CHECK: %[[DIM_REG:.*]] = getelementptr { [0 x i256]*, i32 }, { [0 x i256]*, i32 }* %0, i32 0, i32 1 | ||
//CHECK: store i32 15, i32* %{{.*}}[[DIM_REG]] | ||
|
||
template Wrapper() { | ||
signal input inp[5][3]; | ||
signal output outp; | ||
|
||
component m[4]; | ||
|
||
for (var q = 0; q < 4; q++) { | ||
// This test exhibits the behavior because the array of different subcomponents | ||
// (differentiated by the template parameter changing) | ||
m[q] = MatrixOp(q); | ||
for (var i = 0; i < 5; i++) { | ||
for (var j = 0; j < 3; j++) { | ||
m[q].inp[i][j] <== inp[i][j]; | ||
} | ||
} | ||
} | ||
|
||
outp <== m[2].outp[1][2]; | ||
} | ||
|
||
component main = Wrapper(); | ||
|
||
//CHECK-LABEL: define void @Wrapper_{{[0-9]+}}_run | ||
//CHECK-SAME: ([0 x i256]* %{{.*}}) | ||
//CHECK: %lvars = alloca [3 x i256] | ||
//CHECK: store{{.*}}:{{.*}}; preds = %unrolled_loop{{.*}} | ||
//CHECK: %[[SUB_PTR:.*]] = getelementptr [4 x { [0 x i256]*, i32 }], [4 x { [0 x i256]*, i32 }]* %subcmps, i32 0, i32 2, i32 0 | ||
//CHECK: %[[SUBCMP:.*]] = load [0 x i256]*, [0 x i256]** %[[SUB_PTR]] | ||
//CHECK: %[[VAL_PTR:.*]] = getelementptr [0 x i256], [0 x i256]* %[[SUBCMP]], i32 0, i32 5 | ||
//CHECK: %[[VAL:.*]] = load i256, i256* %[[VAL_PTR]] | ||
//CHECK: %[[OUTP_PTR:.*]] = getelementptr [0 x i256], [0 x i256]* %0, i32 0, i32 0 | ||
//CHECK: store i256 %[[VAL]], i256* %[[OUTP_PTR]] |
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