RustCrypto / RustCrypto/utils

cpufeatures: `cfg_select!`-like macro

Open
#1,529 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
674
Forks
170
Avg merge
1d 12h
Merged PRs (30d)
10

Description

More than once I wrote a piece of code that has the following shape:

cpufeatures::new!(has_avx512f_vaes, "avx512f", "vaes");
if has_avx512f_vaes::get() {
    return /* .. */;
}

cpufeatures::new!(has_avx2_vaes, "avx2", "vaes");
if has_avx2_vaes::get() {
    return /* .. */;
}

cpufeatures::new!(has_aes_sse41, "aes", "sse4.1");
if has_aes_sse41::get() {
    return /* .. */;
}

// Fallback

It'd be great to have something that can replace multiple individual atomic reads with a single one in such cases.

The shape of cfg_select! seems perfect for this.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the cpufeatures::new! entry point and compare the requested behavior with Rust's cfg_select! macro semantics. Trace how generated feature checks are read, then define and test an ordered selection interface that avoids repeated atomic reads and preserves the fallback; done when the requested feature combinations select the correct branch.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.