✅ How to make the compile treat a specific struct as a vector?
As I understand it, the compile has special handling for vector types, which allows them to have better performance than regular structs. Is there a way to get the compile to recognize a struct as a vector to get the same performance benefits?
Or have I misunderstood what it is doing and it doesn't have special handling?
10 Replies
what do you mean when you say vector? if you're referring to vectors in terms of SIMD then that is a specific hardware intrinsic used to optimize doing the same operation on multiple numbers at the same time
it can't be generally applied to any data structure to make it faster
I read (now I can't remember where, but was creditable) that the System.Numerics Vector2, Vector3, etc. were treated differently in some cases to be more performant.
For context, I am working on a mathematics library, containing things like double based vector2/3/4, and potentially alternatives for the System.Numerics types.
This seems to be relevant to what I might be talking about https://stackoverflow.com/questions/56388664/what-does-the-intrinsic-attribute-in-c-sharp-do
Stack Overflow
What does the [Intrinsic] attribute in C# do?
A quick Google search for "instrinsic attribute c#" only returns articles about other attributes, such as [Serializable]. Apparently these are called "intrinsic attributes".
However, there is als...
i don't think you can use that in your own code
Yeah, that is what it seems, but I think that may be what was being referred to when the person said that the System.Numerics vectors had different handling
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
yes, that suggests that the JIT/runtime has specific special optimizations for only those types/methods
Thanks I will try there
if your vector type has the same layout as the builtin one, you could reinterpret a span of your vectors as that of the built-in vectors if you really had to
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View