C
C#15mo ago
Digot

❔ System.Numerics.Vector<double> limited to 2 components with NativeAOT instead of 4

Hi! Im using the mentioned Vector struct for double Vectors and have seen that using NativeAOT it only allows for 2 components instead of 4 (without NativeAOT). Why is that?
11 Replies
reflectronic
reflectronic15mo ago
the size of Vector<T> needs to be known when the code is compiled, and Native AOT does not enable support for 256-bit vectors by default many CPUs, even ones released as late as 2020, do not have support for 256-bit vectors. enabling 256-bit vectors would make your Native AOT program not work on those processors
Digot
DigotOP15mo ago
Oh ok, thanks for the explanation! Is there alternative?
reflectronic
reflectronic15mo ago
for Native AOT, you either deal with it the way it is, or you make it so people with Atoms or Celerons cannot use your program
Digot
DigotOP15mo ago
If I want something with "similar" performance I would just go for a fixed double buffer[4] I guess?
reflectronic
reflectronic15mo ago
what are you actually going to do with the values in the buffer
Digot
DigotOP15mo ago
I'll have four of them to represent a 4x4 double Matrix. So I'll do calculations with the values and recreate some matrices few times a frame
reflectronic
reflectronic15mo ago
if you were mostly doing individual accesses to the elements, you will get much better performance with a struct that has 16 double fields compared to Vector<double> you do not want to use the indexer on Vector<T> very much
Digot
DigotOP15mo ago
Yeah individual access is happening a lot Would a 16 double field struct be better than
private unsafe fixed double row1[4];
private unsafe fixed double row2[4];
private unsafe fixed double row3[4];
private unsafe fixed double row4[4];
private unsafe fixed double row1[4];
private unsafe fixed double row2[4];
private unsafe fixed double row3[4];
private unsafe fixed double row4[4];
reflectronic
reflectronic15mo ago
the fixed buffer approach will be slower it introduces all manner of security checks wherever you use them i guess if you need an indexer, the 16 fields are sort of unpleasant
Digot
DigotOP15mo ago
I guess it would be fine to do it once, just so I understand it...why would it faster with 16 double fields? Which security checks are there on the fixed buffer?
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server