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 CompareLessThanOrEqualOrderedScalarBoolean()
24 var test = new BooleanComparisonOpTest__CompareLessThanOrEqualOrderedScalarBoolean();
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 works
68 test.RunLclFldScenario();
70 // Validates passing an instance member works
71 test.RunFldScenario();
75 // Validates we throw on unsupported hardware
76 test.RunUnsupportedScenario();
81 throw new Exception("One or more scenarios did not complete as expected.");
86 public sealed unsafe class BooleanComparisonOpTest__CompareLessThanOrEqualOrderedScalarBoolean
88 private const int VectorSize = 16;
90 private const int Op1ElementCount = VectorSize / sizeof(Single);
91 private const int Op2ElementCount = VectorSize / sizeof(Single);
93 private static Single[] _data1 = new Single[Op1ElementCount];
94 private static Single[] _data2 = new Single[Op2ElementCount];
96 private static Vector128<Single> _clsVar1;
97 private static Vector128<Single> _clsVar2;
99 private Vector128<Single> _fld1;
100 private Vector128<Single> _fld2;
102 private BooleanComparisonOpTest__DataTable<Single, Single> _dataTable;
104 static BooleanComparisonOpTest__CompareLessThanOrEqualOrderedScalarBoolean()
106 var random = new Random();
108 for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); }
109 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _clsVar1), ref Unsafe.As<Single, byte>(ref _data1[0]), VectorSize);
110 for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = (float)(random.NextDouble()); }
111 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _clsVar2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize);
114 public BooleanComparisonOpTest__CompareLessThanOrEqualOrderedScalarBoolean()
118 var random = new Random();
120 for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); }
121 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld1), ref Unsafe.As<Single, byte>(ref _data1[0]), VectorSize);
122 for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = (float)(random.NextDouble()); }
123 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector128<Single>, byte>(ref _fld2), ref Unsafe.As<Single, byte>(ref _data2[0]), VectorSize);
125 for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = (float)(random.NextDouble()); }
126 for (var i = 0; i < Op2ElementCount; i++) { _data2[i] = (float)(random.NextDouble()); }
127 _dataTable = new BooleanComparisonOpTest__DataTable<Single, Single>(_data1, _data2, VectorSize);
130 public bool IsSupported => Sse.IsSupported;
132 public bool Succeeded { get; set; }
134 public void RunBasicScenario_UnsafeRead()
136 var result = Sse.CompareLessThanOrEqualOrderedScalar(
137 Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr),
138 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr)
141 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result);
144 public void RunBasicScenario_Load()
146 var result = Sse.CompareLessThanOrEqualOrderedScalar(
147 Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)),
148 Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr))
151 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result);
154 public void RunBasicScenario_LoadAligned()
156 var result = Sse.CompareLessThanOrEqualOrderedScalar(
157 Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)),
158 Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr))
161 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, result);
164 public void RunReflectionScenario_UnsafeRead()
166 var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) })
167 .Invoke(null, new object[] {
168 Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr),
169 Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr)
172 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
175 public void RunReflectionScenario_Load()
177 var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) })
178 .Invoke(null, new object[] {
179 Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr)),
180 Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr))
183 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
186 public void RunReflectionScenario_LoadAligned()
188 var result = typeof(Sse).GetMethod(nameof(Sse.CompareLessThanOrEqualOrderedScalar), new Type[] { typeof(Vector128<Single>), typeof(Vector128<Single>) })
189 .Invoke(null, new object[] {
190 Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr)),
191 Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr))
194 ValidateResult(_dataTable.inArray1Ptr, _dataTable.inArray2Ptr, (bool)(result));
197 public void RunClsVarScenario()
199 var result = Sse.CompareLessThanOrEqualOrderedScalar(
204 ValidateResult(_clsVar1, _clsVar2, result);
207 public void RunLclVarScenario_UnsafeRead()
209 var left = Unsafe.Read<Vector128<Single>>(_dataTable.inArray1Ptr);
210 var right = Unsafe.Read<Vector128<Single>>(_dataTable.inArray2Ptr);
211 var result = Sse.CompareLessThanOrEqualOrderedScalar(left, right);
213 ValidateResult(left, right, result);
216 public void RunLclVarScenario_Load()
218 var left = Sse.LoadVector128((Single*)(_dataTable.inArray1Ptr));
219 var right = Sse.LoadVector128((Single*)(_dataTable.inArray2Ptr));
220 var result = Sse.CompareLessThanOrEqualOrderedScalar(left, right);
222 ValidateResult(left, right, result);
225 public void RunLclVarScenario_LoadAligned()
227 var left = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray1Ptr));
228 var right = Sse.LoadAlignedVector128((Single*)(_dataTable.inArray2Ptr));
229 var result = Sse.CompareLessThanOrEqualOrderedScalar(left, right);
231 ValidateResult(left, right, result);
234 public void RunLclFldScenario()
236 var test = new BooleanComparisonOpTest__CompareLessThanOrEqualOrderedScalarBoolean();
237 var result = Sse.CompareLessThanOrEqualOrderedScalar(test._fld1, test._fld2);
239 ValidateResult(test._fld1, test._fld2, result);
242 public void RunFldScenario()
244 var result = Sse.CompareLessThanOrEqualOrderedScalar(_fld1, _fld2);
246 ValidateResult(_fld1, _fld2, result);
249 public void RunUnsupportedScenario()
255 RunBasicScenario_UnsafeRead();
257 catch (PlatformNotSupportedException)
263 private void ValidateResult(Vector128<Single> left, Vector128<Single> right, bool result, [CallerMemberName] string method = "")
265 Single[] inArray1 = new Single[Op1ElementCount];
266 Single[] inArray2 = new Single[Op2ElementCount];
268 Unsafe.Write(Unsafe.AsPointer(ref inArray1[0]), left);
269 Unsafe.Write(Unsafe.AsPointer(ref inArray2[0]), right);
271 ValidateResult(inArray1, inArray2, result, method);
274 private void ValidateResult(void* left, void* right, bool result, [CallerMemberName] string method = "")
276 Single[] inArray1 = new Single[Op1ElementCount];
277 Single[] inArray2 = new Single[Op2ElementCount];
279 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray1[0]), ref Unsafe.AsRef<byte>(left), VectorSize);
280 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Single, byte>(ref inArray2[0]), ref Unsafe.AsRef<byte>(right), VectorSize);
282 ValidateResult(inArray1, inArray2, result, method);
285 private void ValidateResult(Single[] left, Single[] right, bool result, [CallerMemberName] string method = "")
287 if ((left[0] <= right[0]) != result)
291 Console.WriteLine($"{nameof(Sse)}.{nameof(Sse.CompareLessThanOrEqualOrderedScalar)}<Boolean>(Vector128<Single>, Vector128<Single>): {method} failed:");
292 Console.WriteLine($" left: ({string.Join(", ", left)})");
293 Console.WriteLine($" right: ({string.Join(", ", right)})");
294 Console.WriteLine($" result: ({string.Join(", ", result)})");