Skip to content

Commit ef899e6

Browse files
committed
Wasm generation finished
1 parent 8f63d18 commit ef899e6

27 files changed

+2794
-551
lines changed

cli.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const version = require("./package").version;
3030

3131
const argv = require("yargs")
3232
.version(version)
33-
.usage("circom [input source circuit file] -o [output definition circuit file] -c [output c file]")
33+
.usage("circom [input source circuit file] -r [output r1cs file] -c [output c file] -w [output wasm file] -t [output wat file] -s [output sym file]")
3434
.alias("o", "output")
3535
.alias("c", "csource")
3636
.alias("w", "wasm")
@@ -50,6 +50,10 @@ const argv = require("yargs")
5050
type: "boolean",
5151
description: "Do not optimize constraints"
5252
})
53+
.option("sanityCheck", {
54+
type: "boolean",
55+
description: "Add sanity check code"
56+
})
5357
.epilogue(`Copyright (C) 2018 0kims association
5458
This program comes with ABSOLUTELY NO WARRANTY;
5559
This is free software, and you are welcome to redistribute it
@@ -79,6 +83,7 @@ const symName = typeof(argv.sym) === "string" ? argv.sym : fileName + ".sym";
7983
const options = {};
8084
options.reduceConstraints = !argv.fast;
8185
options.verbose = argv.verbose || false;
86+
options.sanityCheck = argv.sanitycheck;
8287
if (argv.csource) {
8388
options.cSourceWriteStream = fs.createWriteStream(cSourceName);
8489
}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports.compiler = require("./src/compiler.js");
22
module.exports.c_tester = require("./ports/c/tester.js");
33
module.exports.wasm_tester = require("./ports/wasm/tester.js");
4+
module.exports.tester = module.exports.wasm_tester;

ports/c/buildasm/add.asm.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ add_l1ms2m:
116116

117117
;;;;;;;;
118118
add_s1l2:
119-
bt rcx, 62 ; check if montgomery first
119+
bt rcx, 62 ; check if montgomery second
120120
jc add_s1l2m
121121
add_s1l2n:
122122
<%= global.setTypeDest("0x80"); %>
123123
<%= addS1L2(); %>
124124

125125
add_s1l2m:
126-
bt rax, 62 ; check if montgomery second
126+
bt rax, 62 ; check if montgomery first
127127
jc add_s1ml2m
128128
add_s1nl2m:
129129
<%= global.setTypeDest("0xC0"); %>

ports/c/buildasm/binops.asm.ejs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
<% function binOpSubQIfBigger() { %>
2+
<% const subQ = global.tmpLabel() %>
3+
<% const done = global.tmpLabel() %>
4+
5+
; Compare with q
6+
<% for (let i=0; i<n64; i++) { %>
7+
mov rax, [rdi + <%= (n64-i)*8 %>]
8+
cmp rax, [q + <%= (n64-i-1)*8 %>]
9+
jc <%=done%> ; q is bigget so done.
10+
jnz <%=subQ%> ; q is lower
11+
<% } %>
12+
; If equal substract q
13+
<%=subQ%>:
14+
<% for (let i=0; i<n64; i++) { %>
15+
mov rax, [q + <%=i*8%>]
16+
<%= i==0 ? "sub" : "sbb" %> [rdi + <%=i*8 + 8 %>], rax
17+
<% } %>
18+
<%=done%>:
19+
<% } %>
20+
21+
122
<% function binOpS1S2(op) { %>
223
cmp r8d, 0
324
<% const s1s2_solveNeg = global.tmpLabel() %>
@@ -35,6 +56,7 @@
3556
<% } %>
3657
mov [rdi + <%= (i*8)+8 %> ], rax
3758
<% } %>
59+
<% binOpSubQIfBigger() %>
3860
ret
3961
4062
<%=s1l2_solveNeg%>:
@@ -59,6 +81,7 @@
5981
<% } %>
6082
mov [rdi + <%= (i*8)+8 %> ], rax;
6183
<% } %>
84+
<% binOpSubQIfBigger() %>
6285
ret
6386
6487
<%=l1s2_solveNeg%>:
@@ -77,12 +100,11 @@
77100
<% } %>
78101
mov [rdi + <%= (i*8)+8 %> ], rax
79102
<% } %>
103+
<% binOpSubQIfBigger() %>
80104
ret
81105
<% } %>
82106

83107

84-
85-
86108
<% function binOp(op) { %>
87109
;;;;;;;;;;;;;;;;;;;;;;
88110
; b<%= op %>
@@ -212,6 +234,7 @@ bnot_l1n:
212234
<% } %>
213235
mov [rdi + <%= i*8 + 8 %>], rax
214236
<% } %>
237+
<% binOpSubQIfBigger() %>
215238
ret
216239

217240

0 commit comments

Comments
 (0)