Skip to content

Crate for choosing between 32-bit and 64-bit arithmetic backends #824

Open
@tarcieri

Description

@tarcieri

We have several crates that naively choose between a 32-bit or 64-bit implementation based on cfg(target_pointer_width).

However, in many cases, like ARMv7 and wasm32, LLVM can generate better code from the 64-bit implementation, even though the CPU is natively 32-bits.

Whatever heuristics are used, it's nice to be able to override the decision. Past experiences show crate features are a poor fit for this selection, however cfg attributes seem like a reasonable fit, as they leave the decision up to the toplevel [bin] crate.

The selection often needs to be cross-cutting across many crates. For example, the crypto-bigint and the https://github.com/rustcrypto/elliptic-curves crates built on top of it need to choose the same backend size.

To make that all work, I would propose having some utility crate for making this selection. An approach being used by curve25519-dalek is to have the selection made inside of a build script which sets defaults for cfg attributes if they aren't already set explicitly, which makes the actual cfg gating in the source code quite simple.

I think we could probably shoehorn such functionality into cpufeatures and use optional cfg attributes like cpufeatures_bits="32" or cpufeatures_bits="64" to make the selection. Or failing that, it could be put in a separate crate which is only intended to be used via build-dependencies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions