Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Runtime.Intrinsics;
- using System.Runtime.Intrinsics.X86;
- namespace Intrinsics
- {
- [StructLayout(LayoutKind.Sequential)]
- public struct SrVector
- {
- public readonly float X;
- public readonly float Y;
- public readonly float Z;
- private Vector128<float> _m128;
- public SrVector(float x, float y, float z)
- {
- X = x;
- Y = y;
- Z = z;
- _m128 = Vector128.Create(X, Y, Z, 0f);
- }
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static float Dot(SrVector a, SrVector b) => Sse41.DotProduct(a._m128, b._m128, 0x7F).ToScalar();
- }
- class Program
- {
- static void Main(string[] args)
- {
- // Do something with the results to ensure the compiler does not optimize the computations away in Release build.
- float sum = 0;
- Vector3 v4a = new Vector3(1f, 0f, 3.2f);
- Vector3 v4b = new Vector3(2f, 2f, 0f);
- var vdot = Vector3.Dot(v4a, v4b);
- sum += vdot;
- SrVector sra = new SrVector(1f, 0f, 3.2f);
- SrVector srb = new SrVector(2f, 2f, 0f);
- var srdot = SrVector.Dot(sra, srb);
- sum += srdot;
- Console.WriteLine(sum);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement