-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support assembly generation on the CPU that has no adx #3
base: master
Are you sure you want to change the base?
Conversation
|
|
src/montgomerybuilder.js
Outdated
c.op("sub","rsp", "" + n64 * 8); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this blank.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank is needed to change number to a string is how ops expects it otherwise it does different logic with numbers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I mean the blank line!
build_defs.bzl
Outdated
if no_adx != None: | ||
if no_adx == True: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it the same condition with below?
if no_adx != None: | |
if no_adx == True: | |
if no_adx: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, changing
.gitignore
Outdated
|
||
.idea | ||
.clwb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take this change out of this commit into a different commit, something like chore: update .gitignore
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing
build_defs.bzl
Outdated
@@ -9,7 +9,8 @@ def generate_prime_field( | |||
element_h_out = None, | |||
generic_c_out = None, | |||
raw_generic_c_out = None, | |||
arm64_s_out = None): | |||
arm64_s_out = None, | |||
no_adx = None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no_adx = None): | |
no_adx = False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing
src/buildzqfield.js
Outdated
@@ -62,7 +63,7 @@ async function buildField(q, name, hpp_out, element_hpp_out) { | |||
if (runningAsScript) { | |||
const fs = require("fs"); | |||
var argv = require("yargs") | |||
.usage("Usage: $0 -q [primeNum] -n [name] -oc [out .c file] -oh [out .h file] -oa [out .asm file]") | |||
.usage("Usage: $0 -q [primeNum] -n [name] -no_adx [no_adx] -oc [out .c file] -oh [out .h file] -oa [out .asm file]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add --
instead of -
.
.usage("Usage: $0 -q [primeNum] -n [name] -no_adx [no_adx] -oc [out .c file] -oh [out .h file] -oa [out .asm file]") | |
.usage("Usage: $0 -q [primeNum] -n [name] --no_adx [no_adx] -oc [out .c file] -oh [out .h file] -oa [out .asm file]") |
Please just test with this.
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
modified: src/buildzqfield.js
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
@ src/buildzqfield.js:92 @ if (runningAsScript) {
.alias("n", "name")
.argv;
+ console.log(argv);
const q = bigInt(argv.q);
const asmFileName = (argv.oa) ? argv.oa : argv.name.toLowerCase() + ".asm";
This shows me this output
node src/buildzqfield.js -q 7 -n fq -noadx --oc a.c
{
_: [],
q: 7,
prime: 7,
n: [ 'fq', true ],
name: [ 'fq', true ],
o: true,
a: true,
d: true,
x: true,
oc: 'a.c',
'$0': 'src/buildzqfield.js'
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, existing flags -oc
, -oh
and -oa
also should be fixed to --oc
, --oh
and --oa
. So I hope you add a separate commit for this change as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing
src/montgomerybuilder.js
Outdated
|
||
function buildFromMontgomery_no_adx(fn, q) { | ||
return templateMontgomery_no_adx(fn, q, function(c, params, i, r0, r1, r2) { | ||
const {t, n64, canOptimizeConsensys} = params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const {t, n64, canOptimizeConsensys} = params; | |
const {n64} = params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing
src/montgomerybuilder.js
Outdated
|
||
function buildSquare_no_adx(fn, q) { | ||
return templateMontgomery_no_adx(fn, q, function(c, params, i, r0, r1, r2) { | ||
const {t, n64, canOptimizeConsensys} = params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const {t, n64, canOptimizeConsensys} = params; | |
const {n64} = params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing
src/montgomerybuilder.js
Outdated
|
||
function buildMul_no_adx(fn, q) { | ||
return templateMontgomery_no_adx(fn, q, function(c, params, i, r0, r1, r2) { | ||
const {t, n64, canOptimizeConsensys} = params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const {t, n64, canOptimizeConsensys} = params; | |
const {n64} = params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing
src/montgomerybuilder.js
Outdated
c.code.push("jnz " + fn + "_mulM_sq") // q is lower | ||
} | ||
|
||
c.code.push("; If equal substract q") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c.code.push("; If equal substract q") | |
c.code.push("; If equal subtract q") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed bad spelling (safe replace) across other code as well
correct change was to explicitly address tachyon compatibility , changing rawMMul1 is outside of this scope |
src/montgomerybuilder.js
Outdated
@@ -311,6 +313,154 @@ function buildFromMontgomery(fn, q) { | |||
}); | |||
} | |||
|
|||
// no adx assembler | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about removing the empty line here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed // no adx assembler a leftover , blanks condensed
c.op("xor","r8","r8"); | ||
c.op("xor","r9","r9"); | ||
c.op("xor","r10","r10"); | ||
// Main loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Main loop | |
// Main loop |
How about adding an empty line here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@zkbitcoin I also think that you could squash the first 4 commmits into one! Could you do that for me? |
I can reverse fork, save project redo fork , do proper commit (all into 1) if you dont mind losing history here . sure can |
src/montgomerybuilder.js
Outdated
for (let i=0; i < n64 * 2; i++) { | ||
setR(i); | ||
round(c, params, i, r0, r1, r2); | ||
for (let j = i - 1; j >= 0; j--) { // All ms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does All ms
mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all modulus (kept in q array) are being processed in this loop, comment does not add anything extra code in mul q explains it, will remove it
src/montgomerybuilder.js
Outdated
c.op("sub","rsp", "" + n64 * 8); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I mean the blank line!
src/buildzqfield.js
Outdated
@@ -92,7 +92,7 @@ if (runningAsScript) { | |||
const q = bigInt(argv.q); | |||
|
|||
const asmFileName = (argv.oa) ? argv.oa : argv.name.toLowerCase() + ".asm"; | |||
const no_adx = (argv.no_adx) ? argv.no_adx : false; | |||
const no_adx = (argv.no_adx) ? argv.no_adx : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see. then isn't undefined
value is more proper for this purpose?
add non adx version of Montgomery modular multiplication/squaring and to fix stack allcoation and de-allocation correct flag no_adx condition fix no_adx flag propagation add adx detection support via /proc/cpuinfo perform detection only if flag was not explicitely specified
done |
Description
This PR addresses the issue where unsupported ADX CPU instruction sets cause invalid operation exceptions during unit tests (see #412).
A new flag,
--no_adx
, is introduced to handle logic branching for CPUs that do not support ADX and for CPUs that do not follow the assembly functions.The following functions have been modified:
rawMMul (Montgomery multiplication)
rawMSquare (Montgomery Square)
rawToMontgomery (from number to Montomery form conversion)
rawFromMontgomery (from Montomery form to number conversion)
rawMMul1
uses adx but this is out of scope because Tachyon doesn't depend on it.