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

Possibility of non-u128 implementation of BigInteger #578

Open
weikengchen opened this issue Jan 13, 2023 · 5 comments
Open

Possibility of non-u128 implementation of BigInteger #578

weikengchen opened this issue Jan 13, 2023 · 5 comments

Comments

@weikengchen
Copy link
Member

In ZPrize submission for the WASM tracks, people have been using different ways to improve the WASM efficiency. There is a common thesis: people use other languages, such as C or JS, to implement 30-bit limbs.

One possible reason: is it a side effect of using u128 if the target is WASM?
Note: uint128 even in x86-64 always is complied into a few instructions over uint64.

We need more experiments to see if the use of u128 as the intermediate is the issue.

@weikengchen
Copy link
Member Author

And it seems that, even if two backends support u64 natively, whether or not they have "carry" would make things different.

@Pratyush
Copy link
Member

Pratyush commented Feb 5, 2023

We can implement a new arithmetic backend for our prime field elements which should make different backend possible.

@piotr-roslaniec
Copy link

piotr-roslaniec commented Sep 30, 2024

Hello. I found that using u128 leads to generating a __multi3 WASM function that causes a large performance penalty. Please see a reproduction here: https://github.com/piotr-roslaniec/wasm32-u32-u128

Edit: I just realized that there is a possible mitigation awaiting to be released:

#[cfg(target_family = "wasm")]
{
let a_lo = a as u32 as u64;
let a_hi = a >> 32;
let b_lo = b as u32 as u64;
let b_hi = b >> 32;
let lolo = (a_lo * b_lo) as u128;
let lohi = ((a_lo * b_hi) as u128) << 32;
let hilo = ((a_hi * b_lo) as u128) << 32;
let hihi = ((a_hi * b_hi) as u128) << 64;
(lolo | hihi) + (lohi + hilo)

@Pratyush
Copy link
Member

Yes, we need to make a release with the new code!

@TalDerei
Copy link

TalDerei commented Oct 30, 2024

Yes, we need to make a release with the new code!

this is great! what's the status of upstreaming these changes?

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

4 participants