@@ -50,6 +50,12 @@ namespace JIT.HardwareIntrinsics.Arm
5050
5151 // Validates passing an instance member of a struct works
5252 test.RunStructFldScenario();
53+
54+ // Validates executing the test inside conditional, with op3 as falseValue
55+ test.ConditionalSelect_FalseOp();
56+
57+ // Validates executing the test inside conditional, with op3 as zero
58+ test.ConditionalSelect_ZeroOp();
5359 }
5460 else
5561 {
@@ -139,18 +145,25 @@ namespace JIT.HardwareIntrinsics.Arm
139145 private static readonly int Op1ElementCount = Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>() / sizeof({Op1BaseType});
140146 private static readonly int RetElementCount = Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>() / sizeof({RetBaseType});
141147
148+ private static {RetBaseType}[] _maskData = new {RetBaseType}[RetElementCount];
142149 private static {Op1BaseType}[] _data1 = new {Op1BaseType}[Op1ElementCount];
143150
151+ private {RetVectorType}<{RetBaseType}> _mask;
144152 private {Op1VectorType}<{Op1BaseType}> _fld1;
153+ private {RetVectorType}<{RetBaseType}> _falseFld;
145154
146155 private DataTable _dataTable;
147156
148157 public {TemplateName}UnaryOpTest__{TestName}()
149158 {
150159 Succeeded = true;
151160
161+ for (var i = 0; i < RetElementCount; i++) { _maskData[i] = ({RetBaseType})(TestLibrary.Generator.Get{RetBaseType}() % 2); }
162+ Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetVectorType}<{RetBaseType}>, byte>(ref _mask), ref Unsafe.As<{RetBaseType}, byte>(ref _maskData[0]), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>());
163+
152164 for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; }
153165 Unsafe.CopyBlockUnaligned(ref Unsafe.As<{Op1VectorType}<{Op1BaseType}>, byte>(ref _fld1), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<{Op1VectorType}<{Op1BaseType}>>());
166+ Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetVectorType}<{RetBaseType}>, byte>(ref _falseFld), ref Unsafe.As<{Op1BaseType}, byte>(ref _data1[0]), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>());
154167
155168 for (var i = 0; i < Op1ElementCount; i++) { _data1[i] = {NextValueOp1}; }
156169 _dataTable = new DataTable(_data1, new {RetBaseType}[RetElementCount], LargestVectorSize);
@@ -239,6 +252,66 @@ namespace JIT.HardwareIntrinsics.Arm
239252 test.RunStructFldScenario(this);
240253 }
241254
255+ public void ConditionalSelect_FalseOp()
256+ {
257+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_mask - operation in trueValue");
258+ ConditionalSelectScenario_TrueValue(_mask, _fld1, _falseFld);
259+
260+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_zero - operation in trueValue");
261+ ConditionalSelectScenario_TrueValue({RetVectorType}<{RetBaseType}>.Zero, _fld1, _falseFld);
262+
263+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_all - operation in trueValue");
264+ ConditionalSelectScenario_TrueValue({RetVectorType}<{RetBaseType}>.AllBitsSet, _fld1, _falseFld);
265+
266+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_mask - operation in falseValue");
267+ ConditionalSelectScenario_FalseValue(_mask, _fld1, _falseFld);
268+
269+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_zero - operation in falseValue");
270+ ConditionalSelectScenario_FalseValue({RetVectorType}<{RetBaseType}>.Zero, _fld1, _falseFld);
271+
272+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_FalseOp_all - operation in falseValue");
273+ ConditionalSelectScenario_FalseValue({RetVectorType}<{RetBaseType}>.AllBitsSet, _fld1, _falseFld);
274+ }
275+
276+ public void ConditionalSelect_ZeroOp()
277+ {
278+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_mask - operation in trueValue");
279+ ConditionalSelectScenario_TrueValue(_mask, _fld1, {RetVectorType}<{RetBaseType}>.Zero);
280+
281+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_zero - operation in trueValue");
282+ ConditionalSelectScenario_TrueValue({RetVectorType}<{RetBaseType}>.Zero, _fld1, {RetVectorType}<{RetBaseType}>.Zero);
283+
284+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_all - operation in trueValue");
285+ ConditionalSelectScenario_TrueValue({RetVectorType}<{RetBaseType}>.AllBitsSet, _fld1, {RetVectorType}<{RetBaseType}>.Zero);
286+
287+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_mask - operation in falseValue");
288+ ConditionalSelectScenario_FalseValue(_mask, _fld1, {RetVectorType}<{RetBaseType}>.Zero);
289+
290+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_zero - operation in falseValue");
291+ ConditionalSelectScenario_FalseValue({RetVectorType}<{RetBaseType}>.Zero, _fld1, {RetVectorType}<{RetBaseType}>.Zero);
292+
293+ TestLibrary.TestFramework.BeginScenario("ConditionalSelect_ZeroOp_all - operation in falseValue");
294+ ConditionalSelectScenario_FalseValue({RetVectorType}<{RetBaseType}>.AllBitsSet, _fld1, {RetVectorType}<{RetBaseType}>.Zero);
295+ }
296+
297+ [method: MethodImpl(MethodImplOptions.AggressiveInlining)]
298+ private void ConditionalSelectScenario_TrueValue({RetVectorType}<{RetBaseType}> mask, {Op1VectorType}<{Op1BaseType}> op1, {RetVectorType}<{RetBaseType}> falseOp)
299+ {
300+ var result = Sve.ConditionalSelect(mask, {Isa}.{Method}(op1), falseOp);
301+
302+ Unsafe.Write(_dataTable.outArrayPtr, result);
303+ ValidateConditionalSelectResult_TrueValue(mask, op1, falseOp, _dataTable.outArrayPtr);
304+ }
305+
306+ [method: MethodImpl(MethodImplOptions.AggressiveInlining)]
307+ private void ConditionalSelectScenario_FalseValue({RetVectorType}<{RetBaseType}> mask, {Op1VectorType}<{Op1BaseType}> op1, {RetVectorType}<{RetBaseType}> trueOp)
308+ {
309+ var result = Sve.ConditionalSelect(mask, trueOp, {Isa}.{Method}(op1));
310+
311+ Unsafe.Write(_dataTable.outArrayPtr, result);
312+ ValidateConditionalSelectResult_FalseValue(mask, op1, trueOp, _dataTable.outArrayPtr);
313+ }
314+
242315 public void RunUnsupportedScenario()
243316 {
244317 TestLibrary.TestFramework.BeginScenario(nameof(RunUnsupportedScenario));
@@ -260,6 +333,62 @@ namespace JIT.HardwareIntrinsics.Arm
260333 }
261334 }
262335
336+ private void ValidateConditionalSelectResult_TrueValue({RetVectorType}<{RetBaseType}> maskOp, {Op1VectorType}<{Op1BaseType}> leftOp, {RetVectorType}<{RetBaseType}> falseOp, void* output, [CallerMemberName] string method = "")
337+ {
338+ {RetBaseType}[] mask = new {RetBaseType}[RetElementCount];
339+ {Op1BaseType}[] firstOp = new {Op1BaseType}[Op1ElementCount];
340+ {RetBaseType}[] falseVal = new {RetBaseType}[RetElementCount];
341+ {RetBaseType}[] result = new {RetBaseType}[RetElementCount];
342+
343+ Unsafe.WriteUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref mask[0]), maskOp);
344+ Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref firstOp[0]), leftOp);
345+ Unsafe.WriteUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref falseVal[0]), falseOp);
346+ Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref result[0]), ref Unsafe.AsRef<byte>(output), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>());
347+
348+ bool succeeded = true;
349+ {TemplateValidationLogicForCndSel}
350+
351+ if (!succeeded)
352+ {
353+ TestLibrary.TestFramework.LogInformation($"{nameof(Sve)}.{nameof({Isa}.{Method})}<{RetBaseType}>({RetVectorType}<{RetBaseType}>, {RetVectorType}<{RetBaseType}>): {method} failed:");
354+ TestLibrary.TestFramework.LogInformation($" mask: ({string.Join(", ", mask)})");
355+ TestLibrary.TestFramework.LogInformation($" firstOp: ({string.Join(", ", firstOp)})");
356+ TestLibrary.TestFramework.LogInformation($" falseOp: ({string.Join(", ", falseVal)})");
357+ TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
358+ TestLibrary.TestFramework.LogInformation(string.Empty);
359+
360+ Succeeded = false;
361+ }
362+ }
363+
364+ private void ValidateConditionalSelectResult_FalseValue({RetVectorType}<{RetBaseType}> maskOp, {Op1VectorType}<{Op1BaseType}> leftOp, {RetVectorType}<{RetBaseType}> trueOp, void* output, [CallerMemberName] string method = "")
365+ {
366+ {RetBaseType}[] mask = new {RetBaseType}[RetElementCount];
367+ {Op1BaseType}[] firstOp = new {Op1BaseType}[Op1ElementCount];
368+ {RetBaseType}[] trueVal = new {RetBaseType}[RetElementCount];
369+ {RetBaseType}[] result = new {RetBaseType}[RetElementCount];
370+
371+ Unsafe.WriteUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref mask[0]), maskOp);
372+ Unsafe.WriteUnaligned(ref Unsafe.As<{Op1BaseType}, byte>(ref firstOp[0]), leftOp);
373+ Unsafe.WriteUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref trueVal[0]), trueOp);
374+ Unsafe.CopyBlockUnaligned(ref Unsafe.As<{RetBaseType}, byte>(ref result[0]), ref Unsafe.AsRef<byte>(output), (uint)Unsafe.SizeOf<{RetVectorType}<{RetBaseType}>>());
375+
376+ bool succeeded = true;
377+ {TemplateValidationLogicForCndSel_FalseValue}
378+
379+ if (!succeeded)
380+ {
381+ TestLibrary.TestFramework.LogInformation($"{nameof(Sve)}.{nameof({Isa}.{Method})}<{RetBaseType}>({RetVectorType}<{RetBaseType}>, {RetVectorType}<{RetBaseType}>): {method} failed:");
382+ TestLibrary.TestFramework.LogInformation($" mask: ({string.Join(", ", mask)})");
383+ TestLibrary.TestFramework.LogInformation($"firstOp: ({string.Join(", ", firstOp)})");
384+ TestLibrary.TestFramework.LogInformation($" trueOp: ({string.Join(", ", trueVal)})");
385+ TestLibrary.TestFramework.LogInformation($" result: ({string.Join(", ", result)})");
386+ TestLibrary.TestFramework.LogInformation(string.Empty);
387+
388+ Succeeded = false;
389+ }
390+ }
391+
263392 private void ValidateResult({Op1VectorType}<{Op1BaseType}> op1, void* result, [CallerMemberName] string method = "")
264393 {
265394 {Op1BaseType}[] inArray1 = new {Op1BaseType}[Op1ElementCount];
0 commit comments