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
Use the u64 backend by default on x86_64 #126
Comments
build.rs gets always compiled for the host platform but has to create programs for the target platform. If the two platforms are different (in a cross compilation scenario), the platform build.rs gets built for is different from the platform it has to build stuff for. So don't use |
|
It seems like the "optimal" thing to do would be something like the following:
However, because we load the entire crate into the |
Each backend can now be selected by an individual feature: - `u32_backend` for `backend::u32`; - `u64_backend` for `backend::u64`; - `avx2_backend` for `backend::avx2`; The `u64_backend` is selected by default, since most people use X64 and we have no way to select based on target (see discussion in #126). However, these changes mean that it is possible to select the backend explicitly, and if we had the ability to select target-default features, we could do so easily.
Each backend can now be selected by an individual feature: - `u32_backend` for `backend::u32`; - `u64_backend` for `backend::u64`; - `avx2_backend` for `backend::avx2`; The `u64_backend` is selected by default, since most people use X64 and we have no way to select based on target (see discussion in #126). However, these changes mean that it is possible to select the backend explicitly, and if we had the ability to select target-default features, we could do so easily.
Each backend can now be selected by an individual feature: - `u32_backend` for `backend::u32`; - `u64_backend` for `backend::u64`; - `avx2_backend` for `backend::avx2`; The `u64_backend` is selected by default, since most people use X64 and we have no way to select based on target (see discussion in #126). However, these changes mean that it is possible to select the backend explicitly, and if we had the ability to select target-default features, we could do so easily.
|
The current status is that the Ideally we would auto-select the backend, but for the reasons described above we can't currently do this. |
(Branching off of this comment since I think this may be off-topic there)
curve25519-dalekhas two field arithmetic implementations, au32implementation (usingu64s for products) and au64implementation (usingu128s for products). Theu64backend is selected by theradix_51feature, which is selected by thenightlyfeature. Now thatu128s are stabilizing (tracking issue),u128s aren't nightly-only. We should:#![feature(i128_type)]lines;radix_51fromnightly;radix_51the default feature onx86_64.The last point seems tricky / impossible, since target-specific or target-default features are currently an open issue in Cargo.
Features are selected before any code is built, so it's not possible to use architecture-dependent
#[cfg]s to choose a feature.One hack (mentioned in the Cargo issue and in the
u128tracking issue) is to use a#[cfg]s in a build script to emit feature selections for the main crate. But this doesn't work for us, because we use the build script to generate constants, so by the time we're inbuild.rswe need to already know which backend to use.Another approach is to select the backend not by a feature but directly by architecture, or to always use
u128s, as in zkcrypto/pairing#80 .However, the problem is that just because
u128s are supported by a target's backend (1) or even lowered to instructions that do a64 x 64 -> 128bit multiplication (2) doesn't mean it's better to use them. For (1), if a 64-bit multiplication is going to be emulated by 32-bit multiplications anyways, it would be better just to use them directly, and as an example of (2),aarch64has instructions for computing high and low parts of a 128-bit product, but they're not necessarily fast. (This is considering only speed and not safety, like whether emulated multiplications are constant-time).The text was updated successfully, but these errors were encountered: