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.
5 /******************************************************************************
6 * This file is auto-generated from a template file by the GenerateTests.csx *
7 * script in tests\src\JIT\HardwareIntrinsics\X86\Shared. In order to make *
8 * changes, please update the corresponding template and run according to the *
9 * directions listed in the file. *
10 ******************************************************************************/
13 using System.Runtime.CompilerServices;
14 using System.Runtime.InteropServices;
15 using System.Runtime.Intrinsics;
16 using System.Runtime.Intrinsics.X86;
18 namespace JIT.HardwareIntrinsics.X86
20 public static partial class Program
22 private static void CompareLessThanUnorderedScalarBoolean()
24 var test = new BooleanComparisonOpTest__CompareLessThanUnorderedScalarBoolean();
28 // Validates basic functionality works, using Unsafe.Read
29 test.RunBasicScenario_UnsafeRead();
33 // Validates basic functionality works, using Load
34 test.RunBasicScenario_Load();
36 // Validates basic functionality works, using LoadAligned
37 test.RunBasicScenario_LoadAligned();
40 // Validates calling via reflection works, using Unsafe.Read
41 test.RunReflectionScenario_UnsafeRead();
45 // Validates calling via reflection works, using Load
46 test.RunReflectionScenario_Load();
48 // Validates calling via reflection works, using LoadAligned
49 test.RunReflectionScenario_LoadAligned();
52 // Validates passing a static member works
53 test.RunClsVarScenario();
55 // Validates passing a local works, using Unsafe.Read
56 test.RunLclVarScenario_UnsafeRead();
60 // Validates passing a local works, using Load
61 test.RunLclVarScenario_Load();
63 // Validates passing a local works, using LoadAligned
64 test.RunLclVarScenario_LoadAligned();
67 // Validates passing the field of a local class works
68 test.RunClassLclFldScenario();
70 // Validates passing an instance member of a class works
71 test.RunClassFldScenario();
73 // Validates passing the field of a local struct works
74 test.RunStructLclFldScenario();
76 // Validates passing an instance member of a struct works
77 test.RunStructFldScenario();
81 // Validates we throw on unsupported hardware
82 test.RunUnsupportedScenario();
87 throw new Exception("One or more scenarios did not complete as expected.");
92 public sealed unsafe class BooleanComparisonOpTest__CompareLessThanUnorderedScalarBoolean
94 private struct TestStruct
96 public Vector128<Single> _fld1;
97 public Vector128<Single> _fld2;
99 public static TestStruct Create()
101 var testStruct = new TestStruct();
102 var random = new Random();
104 for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
105 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref testStruct._fld1), ref Unsafe.As<Single, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector128<Single>>());
106 for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSingle(); }
107 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref testStruct._fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Single>>());
112 public void RunStructFldScenario(BooleanComparisonOpTest__CompareLessThanUnorderedScalarBoolean testClass)
114 var result = Sse.CompareLessThanUnorderedScalar(_fld1, _fld2);
115 testClass.ValidateResult(_fld1, _fld2, result);
119 private static readonly int LargestVectorSize = 16;
121 private static readonly int Op1ElementCount = Unsafe.SizeOf<Vector128<Single>>() / sizeof(Single);
122 private static readonly int Op2ElementCount = Unsafe.SizeOf<Vector128<Single>>() / sizeof(Single);
124 private static Single[] _data1 = new Single[Op1ElementCount];
125 private static Single[] _data2 = new Single[Op2ElementCount];
127 private static Vector128<Single> _clsVar1;
128 private static Vector128<Single> _clsVar2;
130 private Vector128<Single> _fld1;
131 private Vector128<Single> _fld2;
133 private BooleanComparisonOpTest__DataTable<Single, Single> _dataTable;
135 static BooleanComparisonOpTest__CompareLessThanUnorderedScalarBoolean()
137 var random = new Random();
139 for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
140 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _clsVar1), ref Unsafe.As<Single, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector128<Single>>());
141 for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSingle(); }
142 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _clsVar2), ref Unsafe.As<Single, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Single>>());
145 public BooleanComparisonOpTest__CompareLessThanUnorderedScalarBoolean()
149 var random = new Random();
151 for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
152 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld1), ref Unsafe.As<Single, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<Vector128<Single>>());
153 for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSingle(); }
154 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), (uint)Unsafe.SizeOf<Vector128<Single>>());
156 for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = TestLibrary.Generator.GetSingle(); }
157 for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = TestLibrary.Generator.GetSingle(); }
158 _dataTable = new BooleanComparisonOpTest__DataTable<Single, Single>(_data1, _data2, LargestVectorSize);
161 public bool IsSupported => Sse.IsSupported;
163 public bool Succeeded { get; set; }
165 public void RunBasicScenario_UnsafeRead()
167 var result = Sse.CompareLessThanUnorderedScalar(
168 Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr),
169 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr)
172 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result);
175 public void RunBasicScenario_Load()
177 var result = Sse.CompareLessThanUnorderedScalar(
178 Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)),
179 Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr))
182 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result);
185 public void RunBasicScenario_LoadAligned()
187 var result = Sse.CompareLessThanUnorderedScalar(
188 Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)),
189 Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr))
192 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result);
195 public void RunReflectionScenario_UnsafeRead()
197 var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) })
198 .Invoke(null, new object[] {
199 Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr),
200 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr)
203 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
206 public void RunReflectionScenario_Load()
208 var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) })
209 .Invoke(null, new object[] {
210 Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)),
211 Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr))
214 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
217 public void RunReflectionScenario_LoadAligned()
219 var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanUnorderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) })
220 .Invoke(null, new object[] {
221 Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)),
222 Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr))
225 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
228 public void RunClsVarScenario()
230 var result = Sse.CompareLessThanUnorderedScalar(
235 ValidateResult(_clsVar1, _clsVar2, result);
238 public void RunLclVarScenario_UnsafeRead()
240 var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr);
241 var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr);
242 var result = Sse.CompareLessThanUnorderedScalar(left, right);
244 ValidateResult(left, right, result);
247 public void RunLclVarScenario_Load()
249 var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr));
250 var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr));
251 var result = Sse.CompareLessThanUnorderedScalar(left, right);
253 ValidateResult(left, right, result);
256 public void RunLclVarScenario_LoadAligned()
258 var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr));
259 var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr));
260 var result = Sse.CompareLessThanUnorderedScalar(left, right);
262 ValidateResult(left, right, result);
265 public void RunClassLclFldScenario()
267 var test = new BooleanComparisonOpTest__CompareLessThanUnorderedScalarBoolean();
268 var result = Sse.CompareLessThanUnorderedScalar(test._fld1, test._fld2);
270 ValidateResult(test._fld1, test._fld2, result);
273 public void RunClassFldScenario()
275 var result = Sse.CompareLessThanUnorderedScalar(_fld1, _fld2);
277 ValidateResult(_fld1, _fld2, result);
280 public void RunStructLclFldScenario()
282 var test = TestStruct.Create();
283 var result = Sse.CompareLessThanUnorderedScalar(test._fld1, test._fld2);
284 ValidateResult(test._fld1, test._fld2, result);
287 public void RunStructFldScenario()
289 var test = TestStruct.Create();
290 test.RunStructFldScenario(this);
293 public void RunUnsupportedScenario()
299 RunBasicScenario_UnsafeRead();
301 catch (PlatformNotSupportedException)
307 private void ValidateResult(Vector128<Single> left, Vector128<Single> right, bool result, [CallerMemberName] string method = "")
309 Single[] inArray1 = new Single[Op1ElementCount];
310 Single[] inArray2 = new Single[Op2ElementCount];
312 Unsafe.WriteUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), left);
313 Unsafe.WriteUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), right);
315 ValidateResult(inArray1, inArray2, result, method);
318 private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "")
320 Single[] inArray1 = new Single[Op1ElementCount];
321 Single[] inArray2 = new Single[Op2ElementCount];
323 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), (uint)Unsafe.SizeOf<Vector128<Single>>());
324 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), (uint)Unsafe.SizeOf<Vector128<Single>>());
326 ValidateResult(inArray1, inArray2, result, method);
329 private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "")
331 if ((left[0] < right[0]) != result)
335 Console.WriteLine($"{nameof(Sse)}.{nameof(Sse.CompareLessThanUnorderedScalar)}<Boolean>(Vector128<Single>, Vector128<Single>): {method} failed:");
336 Console.WriteLine($" left: ({string.Join(", ", left)})");
337 Console.WriteLine($" right: ({string.Join(", ", right)})");
338 Console.WriteLine($" result: ({string.Join(", ", result)})");