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

Safe intrinsics in core::arch #494

Closed
veluca93 opened this issue Nov 23, 2024 · 1 comment
Closed

Safe intrinsics in core::arch #494

veluca93 opened this issue Nov 23, 2024 · 1 comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api

Comments

@veluca93
Copy link

Proposal

Problem statement

With target features 1.1 now ready to be stabilized, it is soon going to be possible to write i.e. intrinsics-using SIMD code with minimal use of unsafe (specifically, only at the initial entry point of feature-using code.

However, most intrinsics in core::arch are currently unsafe (excluding wasm32 intrinsics), requiring user code to introduce some amount of unsafe at the lowest level of the call hierarchy too.

Motivating examples or use cases

For example, the DCT code in jpeg-decoder (here) could reduce usage of unsafe to effectively just a couple of lines, making the code significantly easier to audit.

This is common to multiple SIMD-using crates.

Solution sketch

Arch-specific intrinsics (such as AVX/AVX2 SIMD intrinsics) in core::arch that do not operate on pointers, and do not affect global state (such as FP rounding modes) could be made safe once target_features 1.1 is stabilized.

Alternatives

An alternative would be for people to write/use a crate that wraps relevant core::arch intrinsics in safe wrappers.

@veluca93 veluca93 added api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api labels Nov 23, 2024
@Amanieu
Copy link
Member

Amanieu commented Nov 26, 2024

We discussed this in the libs-api meeting and we're happy to accept. This is technically a breaking change since (in theory) someone could take a function pointer to an intrinsic function. However since this is very unlikely we are happy to consider this after a crater run.

@Amanieu Amanieu closed this as completed Nov 26, 2024
@Amanieu Amanieu added the ACP-accepted API Change Proposal is accepted (seconded with no objections) label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ACP-accepted API Change Proposal is accepted (seconded with no objections) api-change-proposal A proposal to add or alter unstable APIs in the standard libraries T-libs-api
Projects
None yet
Development

No branches or pull requests

2 participants