Skip to content

Is it possible to write zero cost wrappers around doubles, for dimensional annotation purposes? #74475

Closed Answered by tannergooding
soerenwolfers asked this question in General
Discussion options

You must be logged in to vote

Zero-cost wrappers in general are a complex topic and there is no definitive answer because it is often dependent on the ABI (application binary interface) that exists for the underlying C runtime.

In general, struct S { T x; } and T are not equivalent at the ABI level and while they often do get passed around the same, there are many cases that they may not and that can lead to deficiencies.

It used to be that structs with single-float fields could not be "promoted" (an optimization) due to such ABI differences, but I resolved that in the .NET 8 timeframe: dotnet/runtime#84627. -- This impacted all single-field floating-point wrapper structs, regardless of whether inlining happened or not.

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@soerenwolfers
Comment options

@CyrusNajmabadi
Comment options

@tannergooding
Comment options

Answer selected by soerenwolfers
@soerenwolfers
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants