1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
7 using System.Runtime.CompilerServices;
8 using System.Runtime.InteropServices;
9 using System.Runtime.Intrinsics.X86;
10 using System.Runtime.Intrinsics;
12 namespace IntelHardwareIntrinsicTest
19 static unsafe int Main(string[] args)
21 int testResult = Pass;
25 using (TestTable<double> doubleTable = new TestTable<double>(new double[2] { 1, -5 }, new double[2]))
27 var vf = Sse2.LoadVector128((double*)(doubleTable.inArrayPtr));
28 Unsafe.Write(doubleTable.outArrayPtr, vf);
30 if (!doubleTable.CheckResult((x, y) => BitConverter.DoubleToInt64Bits(x) == BitConverter.DoubleToInt64Bits(y)))
32 Console.WriteLine("Sse2 LoadVector128 failed on double:");
33 foreach (var item in doubleTable.outArray)
35 Console.Write(item + ", ");
42 using (TestTable<int> intTable = new TestTable<int>(new int[4] { 1, -5, 100, 0 }, new int[4]))
44 var vf = Sse2.LoadVector128((int*)(intTable.inArrayPtr));
45 Unsafe.Write(intTable.outArrayPtr, vf);
47 if (!intTable.CheckResult((x, y) => x == y))
49 Console.WriteLine("Sse2 LoadVector128 failed on int:");
50 foreach (var item in intTable.outArray)
52 Console.Write(item + ", ");
59 using (TestTable<long> longTable = new TestTable<long>(new long[2] { 1, -5 }, new long[2]))
61 var vf = Sse2.LoadVector128((long*)(longTable.inArrayPtr));
62 Unsafe.Write(longTable.outArrayPtr, vf);
64 if (!longTable.CheckResult((x, y) => x == y))
66 Console.WriteLine("Sse2 LoadVector128 failed on long:");
67 foreach (var item in longTable.outArray)
69 Console.Write(item + ", ");
76 using (TestTable<uint> uintTable = new TestTable<uint>(new uint[4] { 1, 5, 100, 0 }, new uint[4]))
78 var vf = Sse2.LoadVector128((uint*)(uintTable.inArrayPtr));
79 Unsafe.Write(uintTable.outArrayPtr, vf);
81 if (!uintTable.CheckResult((x, y) => x == y))
83 Console.WriteLine("Sse2 LoadVector128 failed on uint:");
84 foreach (var item in uintTable.outArray)
86 Console.Write(item + ", ");
93 using (TestTable<ulong> ulongTable = new TestTable<ulong>(new ulong[2] { 1, 5 }, new ulong[2]))
95 var vf = Sse2.LoadVector128((ulong*)(ulongTable.inArrayPtr));
96 Unsafe.Write(ulongTable.outArrayPtr, vf);
98 if (!ulongTable.CheckResult((x, y) => x == y))
100 Console.WriteLine("Sse2 LoadVector128 failed on ulong:");
101 foreach (var item in ulongTable.outArray)
103 Console.Write(item + ", ");
110 using (TestTable<short> shortTable = new TestTable<short>(new short[8] { 1, -5, 100, 0, 1, -5, 100, 0 }, new short[8]))
112 var vf = Sse2.LoadVector128((short*)(shortTable.inArrayPtr));
113 Unsafe.Write(shortTable.outArrayPtr, vf);
115 if (!shortTable.CheckResult((x, y) => x == y))
117 Console.WriteLine("Sse2 LoadVector128 failed on short:");
118 foreach (var item in shortTable.outArray)
120 Console.Write(item + ", ");
127 using (TestTable<ushort> ushortTable = new TestTable<ushort>(new ushort[8] { 1, 5, 100, 0, 1, 5, 100, 0 }, new ushort[8]))
129 var vf = Sse2.LoadVector128((ushort*)(ushortTable.inArrayPtr));
130 Unsafe.Write(ushortTable.outArrayPtr, vf);
132 if (!ushortTable.CheckResult((x, y) => x == y))
134 Console.WriteLine("Sse2 LoadVector128 failed on ushort:");
135 foreach (var item in ushortTable.outArray)
137 Console.Write(item + ", ");
144 using (TestTable<sbyte> sbyteTable = new TestTable<sbyte>(new sbyte[16] { 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0, 1, -5, 100, 0 }, new sbyte[16]))
146 var vf = Sse2.LoadVector128((sbyte*)(sbyteTable.inArrayPtr));
147 Unsafe.Write(sbyteTable.outArrayPtr, vf);
149 if (!sbyteTable.CheckResult((x, y) => x == y))
151 Console.WriteLine("Sse2 LoadVector128 failed on sbyte:");
152 foreach (var item in sbyteTable.outArray)
154 Console.Write(item + ", ");
161 using (TestTable<byte> byteTable = new TestTable<byte>(new byte[16] { 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0, 1, 5, 100, 0 }, new byte[16]))
163 var vf = Sse2.LoadVector128((byte*)(byteTable.inArrayPtr));
164 Unsafe.Write(byteTable.outArrayPtr, vf);
166 if (!byteTable.CheckResult((x, y) => x == y))
168 Console.WriteLine("Sse2 LoadVector128 failed on byte:");
169 foreach (var item in byteTable.outArray)
171 Console.Write(item + ", ");
182 public unsafe struct TestTable<T> : IDisposable where T : struct
187 public void* inArrayPtr => inHandle.AddrOfPinnedObject().ToPointer();
188 public void* outArrayPtr => outHandle.AddrOfPinnedObject().ToPointer();
192 public TestTable(T[] a, T[] b)
197 inHandle = GCHandle.Alloc(inArray, GCHandleType.Pinned);
198 outHandle = GCHandle.Alloc(outArray, GCHandleType.Pinned);
200 public bool CheckResult(Func<T, T, bool> check)
202 for (int i = 0; i < inArray.Length; i++)
204 if (!check(inArray[i], outArray[i]))
212 public void Dispose()