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.
Add conversions for boolean <=> bigint type as needed
- Loading branch information
Showing
5 changed files
with
205 additions
and
14 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,22 @@ | ||
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 --enable-var-scope %s | ||
|
||
function binop_comp(a, b) { | ||
return a > b; | ||
} | ||
|
||
template A(x) { | ||
signal input in; | ||
signal output out; | ||
|
||
out <-- binop_comp(in, x); | ||
} | ||
|
||
component main = A(5); | ||
|
||
//CHECK-LABEL: define i256 @binop_comp_{{[0-9]+}} | ||
//CHECK-SAME: (i256* %0) | ||
//CHECK: %call.fr_gt = call i1 @fr_gt(i256 %{{[0-9]+}}, i256 %{{[0-9]+}}) | ||
//CHECK: %[[RET:[0-9]+]] = zext i1 %call.fr_gt to i256 | ||
//CHECK: ret i256 %[[RET]] |
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,31 @@ | ||
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 --enable-var-scope %s | ||
|
||
function binop_bool(a, b) { | ||
return a || b; | ||
} | ||
|
||
template A(x) { | ||
signal input in; | ||
signal output out; | ||
|
||
var temp; | ||
if (binop_bool(in, x)) { | ||
temp = 1; | ||
} else { | ||
temp = 0; | ||
} | ||
out <-- temp; | ||
|
||
//Essentially equivalent code: | ||
// out <-- binop_bool(in, x); | ||
} | ||
|
||
component main = A(555); | ||
|
||
//CHECK-LABEL: define i256 @binop_bool_{{[0-9]+}} | ||
//CHECK-SAME: (i256* %0) | ||
//CHECK: %call.fr_logic_or = call i1 @fr_logic_or(i1 %{{[0-9]+}}, i1 %{{[0-9]+}}) | ||
//CHECK: %[[RET:[0-9]+]] = zext i1 %call.fr_logic_or to i256 | ||
//CHECK: ret i256 %[[RET]] |
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,24 @@ | ||
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 --enable-var-scope %s | ||
|
||
template A(x) { | ||
signal input in; | ||
signal output out; | ||
|
||
var z = 0; | ||
if (in || x) { | ||
z = 1; | ||
} | ||
out <-- z; | ||
} | ||
|
||
component main = A(99); | ||
|
||
//CHECK-LABEL: define void @A_{{[0-9]+}}_run | ||
//CHECK-SAME: ([0 x i256]* %0) | ||
//CHECK: branch{{[0-9]+}}: | ||
//CHECK: %[[VAL_PTR:[0-9]+]] = getelementptr [0 x i256], [0 x i256]* %0, i32 0, i32 1 | ||
//CHECK: %[[VAL:[0-9]+]] = load i256, i256* %[[VAL_PTR]] | ||
//CHECK: %[[BOOL:[0-9]+]] = icmp ne i256 %[[VAL]], 0 | ||
//CHECK: %call.fr_logic_or = call i1 @fr_logic_or(i1 %[[BOOL]], i1 true) |
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,27 @@ | ||
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 --enable-var-scope %s | ||
|
||
function binop_bool_array(a, b) { | ||
var arr[10]; | ||
for (var i = 0; i < 10; i++) { | ||
arr[i] = a[i] || b[i]; | ||
} | ||
return arr; | ||
} | ||
|
||
template A() { | ||
signal input in1[10]; | ||
signal input in2[10]; | ||
signal output out[10]; | ||
|
||
out <-- binop_bool_array(in1, in2); | ||
} | ||
|
||
component main = A(); | ||
|
||
//CHECK-LABEL: define void @binop_bool_array_{{[0-9]+}} | ||
//CHECK-SAME: (i256* %0) | ||
//CHECK: %call.fr_logic_or = call i1 @fr_logic_or(i1 %{{[0-9]+}}, i1 %{{[0-9]+}}) | ||
//CHECK: %[[VAL:[0-9]+]] = zext i1 %call.fr_logic_or to i256 | ||
//CHECK: store i256 %[[VAL]], i256* %{{[0-9]+}} |
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