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 ShiftRightLogical128BitLaneUInt641()
24 var test = new SimpleUnaryOpTest__ShiftRightLogical128BitLaneUInt641();
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 SimpleUnaryOpTest__ShiftRightLogical128BitLaneUInt641
88 private const int VectorSize = 32;
90 private const int Op1ElementCount = VectorSize / sizeof(UInt64);
91 private const int RetElementCount = VectorSize / sizeof(UInt64);
93 private static UInt64[] _data = new UInt64[Op1ElementCount];
95 private static Vector256<UInt64> _clsVar;
97 private Vector256<UInt64> _fld;
99 private SimpleUnaryOpTest__DataTable<UInt64, UInt64> _dataTable;
101 static SimpleUnaryOpTest__ShiftRightLogical128BitLaneUInt641()
103 var random = new Random();
105 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = (ulong)8; }
106 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref _clsVar), ref Unsafe.As<UInt64, byte>(ref _data[0]), VectorSize);
109 public SimpleUnaryOpTest__ShiftRightLogical128BitLaneUInt641()
113 var random = new Random();
115 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = (ulong)8; }
116 Unsafe.CopyBlockUnaligned(ref Unsafe.As<Vector256<UInt64>, byte>(ref _fld), ref Unsafe.As<UInt64, byte>(ref _data[0]), VectorSize);
118 for (var i = 0; i < Op1ElementCount; i++) { _data[i] = (ulong)8; }
119 _dataTable = new SimpleUnaryOpTest__DataTable<UInt64, UInt64>(_data, new UInt64[RetElementCount], VectorSize);
122 public bool IsSupported => Avx2.IsSupported;
124 public bool Succeeded { get; set; }
126 public void RunBasicScenario_UnsafeRead()
128 var result = Avx2.ShiftRightLogical128BitLane(
129 Unsafe.Read<Vector256<UInt64>>(_dataTable.inArrayPtr),
133 Unsafe.Write(_dataTable.outArrayPtr, result);
134 ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
137 public void RunBasicScenario_Load()
139 var result = Avx2.ShiftRightLogical128BitLane(
140 Avx.LoadVector256((UInt64*)(_dataTable.inArrayPtr)),
144 Unsafe.Write(_dataTable.outArrayPtr, result);
145 ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
148 public void RunBasicScenario_LoadAligned()
150 var result = Avx2.ShiftRightLogical128BitLane(
151 Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArrayPtr)),
155 Unsafe.Write(_dataTable.outArrayPtr, result);
156 ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
159 public void RunReflectionScenario_UnsafeRead()
161 var result = typeof(Avx2).GetMethod(nameof(Avx2.ShiftRightLogical128BitLane), new Type[] { typeof(Vector256<UInt64>), typeof(byte) })
162 .Invoke(null, new object[] {
163 Unsafe.Read<Vector256<UInt64>>(_dataTable.inArrayPtr),
167 Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt64>)(result));
168 ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
171 public void RunReflectionScenario_Load()
173 var result = typeof(Avx2).GetMethod(nameof(Avx2.ShiftRightLogical128BitLane), new Type[] { typeof(Vector256<UInt64>), typeof(byte) })
174 .Invoke(null, new object[] {
175 Avx.LoadVector256((UInt64*)(_dataTable.inArrayPtr)),
179 Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt64>)(result));
180 ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
183 public void RunReflectionScenario_LoadAligned()
185 var result = typeof(Avx2).GetMethod(nameof(Avx2.ShiftRightLogical128BitLane), new Type[] { typeof(Vector256<UInt64>), typeof(byte) })
186 .Invoke(null, new object[] {
187 Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArrayPtr)),
191 Unsafe.Write(_dataTable.outArrayPtr, (Vector256<UInt64>)(result));
192 ValidateResult(_dataTable.inArrayPtr, _dataTable.outArrayPtr);
195 public void RunClsVarScenario()
197 var result = Avx2.ShiftRightLogical128BitLane(
202 Unsafe.Write(_dataTable.outArrayPtr, result);
203 ValidateResult(_clsVar, _dataTable.outArrayPtr);
206 public void RunLclVarScenario_UnsafeRead()
208 var firstOp = Unsafe.Read<Vector256<UInt64>>(_dataTable.inArrayPtr);
209 var result = Avx2.ShiftRightLogical128BitLane(firstOp, 1);
211 Unsafe.Write(_dataTable.outArrayPtr, result);
212 ValidateResult(firstOp, _dataTable.outArrayPtr);
215 public void RunLclVarScenario_Load()
217 var firstOp = Avx.LoadVector256((UInt64*)(_dataTable.inArrayPtr));
218 var result = Avx2.ShiftRightLogical128BitLane(firstOp, 1);
220 Unsafe.Write(_dataTable.outArrayPtr, result);
221 ValidateResult(firstOp, _dataTable.outArrayPtr);
224 public void RunLclVarScenario_LoadAligned()
226 var firstOp = Avx.LoadAlignedVector256((UInt64*)(_dataTable.inArrayPtr));
227 var result = Avx2.ShiftRightLogical128BitLane(firstOp, 1);
229 Unsafe.Write(_dataTable.outArrayPtr, result);
230 ValidateResult(firstOp, _dataTable.outArrayPtr);
233 public void RunLclFldScenario()
235 var test = new SimpleUnaryOpTest__ShiftRightLogical128BitLaneUInt641();
236 var result = Avx2.ShiftRightLogical128BitLane(test._fld, 1);
238 Unsafe.Write(_dataTable.outArrayPtr, result);
239 ValidateResult(test._fld, _dataTable.outArrayPtr);
242 public void RunFldScenario()
244 var result = Avx2.ShiftRightLogical128BitLane(_fld, 1);
246 Unsafe.Write(_dataTable.outArrayPtr, result);
247 ValidateResult(_fld, _dataTable.outArrayPtr);
250 public void RunUnsupportedScenario()
256 RunBasicScenario_UnsafeRead();
258 catch (PlatformNotSupportedException)
264 private void ValidateResult(Vector256<UInt64> firstOp, void* result, [CallerMemberName] string method = "")
266 UInt64[] inArray = new UInt64[Op1ElementCount];
267 UInt64[] outArray = new UInt64[RetElementCount];
269 Unsafe.Write(Unsafe.AsPointer(ref inArray[0]), firstOp);
270 Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize);
272 ValidateResult(inArray, outArray, method);
275 private void ValidateResult(void* firstOp, void* result, [CallerMemberName] string method = "")
277 UInt64[] inArray = new UInt64[Op1ElementCount];
278 UInt64[] outArray = new UInt64[RetElementCount];
280 Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref inArray[0]), ref Unsafe.AsRef<byte>(firstOp), VectorSize);
281 Unsafe.CopyBlockUnaligned(ref Unsafe.As<UInt64, byte>(ref outArray[0]), ref Unsafe.AsRef<byte>(result), VectorSize);
283 ValidateResult(inArray, outArray, method);
286 private void ValidateResult(UInt64[] firstOp, UInt64[] result, [CallerMemberName] string method = "")
288 if (result[0] != 576460752303423488UL)
294 for (var i = 1; i < RetElementCount; i++)
296 if ((i == 2 ? result[i] != 576460752303423488UL : result[i] != 0))
306 Console.WriteLine($"{nameof(Avx2)}.{nameof(Avx2.ShiftRightLogical128BitLane)}<UInt64>(Vector256<UInt64><9>): {method} failed:");
307 Console.WriteLine($" firstOp: ({string.Join(", ", firstOp)})");
308 Console.WriteLine($" result: ({string.Join(", ", result)})");