Skip to content
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

Improve ll_u256_mont-riscv64.S to support wider width(384) #4

Open
XuJiandong opened this issue May 26, 2021 · 4 comments
Open

Improve ll_u256_mont-riscv64.S to support wider width(384) #4

XuJiandong opened this issue May 26, 2021 · 4 comments

Comments

@XuJiandong
Copy link

XuJiandong commented May 26, 2021

Hi @piggypiggy ,
We're trying to improve ll_u256_mont_mul (risc-v version) to support wider width(e.g.384 bits) .
Is there any reference C implementation (or something like that) of this assembly implementation?
So we can modify it much easier. Thanks.

@XuJiandong XuJiandong changed the title Improve ll_u256_mont-riscv64.S to suport wider witdth(384) Improve ll_u256_mont-riscv64.S to support wider width(384) May 26, 2021
@piggypiggy
Copy link
Owner

I didn't write or find 384 bit's c implementation, there is only pesudo code: paper page 7. There are c implementations for arbitrary size of integer: here and blst, armv8 384 bit implementation: blst armv8, they might be good references.

I found it quiet hard to modify ll_u256_mont-riscv64 to ll_u384_mont-riscv64 since you need to reconsider the register assignment, it brings lots of changes.

My advice: follow the pesudo code to write your own riscv code, if you find some piece of ll_u256_mont-riscv64.S useful, then copy it.

@XuJiandong
Copy link
Author

Thanks @piggypiggy .
Does blst version share the same algorithm as the implementation of ll_u256_mont-riscv64.S? l_u256_mont-riscv64.S is really difficult to understand.

@piggypiggy
Copy link
Owner

piggypiggy commented May 27, 2021

blst's c mul_mont_n implementation is the same as ll_mont_mul.c, ll_u256_mont_mul-riscv64,aarch64,x64 and blst's mul_mont_256-armv8,x86_64. But they are slightly diffrent from the pesudo code, instead they compute and plus A*B[i] then reduce it, repeat n times. You can verify that they are equivalent.

blst's 384 bit sqr_mont and fp256's mont_sqr asm code follow the pesudo code exactly. They compute A*B at first, then reduce n times.

@XuJiandong
Copy link
Author

Follow up: we've ported some part of blst's assembly code into RISC-V. It's used in our Smart contracts.
https://github.com/nervosnetwork/ckb-miscellaneous-scripts/tree/master/blst
We need specialists like you. If you're interested in our projects, please contact me via [email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants