|
| 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 | + |
| 4 | +using System; |
| 5 | +using System.Numerics; |
| 6 | +using System.Runtime.CompilerServices; |
| 7 | +using System.Runtime.Intrinsics; |
| 8 | +using System.Runtime.Intrinsics.Arm; |
| 9 | +using Xunit; |
| 10 | + |
| 11 | +namespace JIT.HardwareIntrinsics.Arm._Sve2 |
| 12 | +{ |
| 13 | + public static partial class Program |
| 14 | + { |
| 15 | + [Fact] |
| 16 | + public static unsafe void CreateWhileReadAfterWriteMaskByte_SameAddress() |
| 17 | + { |
| 18 | + if (!Sve2.IsSupported) |
| 19 | + { |
| 20 | + return; |
| 21 | + } |
| 22 | + |
| 23 | + // When pointers are idential, all elements of returned mask are "1" |
| 24 | + byte* ptr = stackalloc byte[Vector<byte>.Count]; |
| 25 | + Vector<byte> mask = Sve2.CreateWhileReadAfterWriteMaskByte(ptr, ptr); |
| 26 | + |
| 27 | + for (int i = 0; i < Vector<byte>.Count; i++) |
| 28 | + { |
| 29 | + if (mask.GetElement(i) == 0) |
| 30 | + { |
| 31 | + throw new Exception( |
| 32 | + $"CreateWhileReadAfterWriteMaskByte(ptr, ptr): Expected all elements true, but element {i} was false."); |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + [Fact] |
| 38 | + public static unsafe void CreateWhileReadAfterWriteMaskByte_OffsetByOne() |
| 39 | + { |
| 40 | + if (!Sve2.IsSupported) |
| 41 | + { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + // When pointers differ by one element, first element of returned mask is "1", the rest are "0" |
| 46 | + byte* ptr = stackalloc byte[Vector<byte>.Count + 1]; |
| 47 | + Vector<byte> mask = Sve2.CreateWhileReadAfterWriteMaskByte(ptr, ptr + 1); |
| 48 | + |
| 49 | + if (mask.GetElement(0) == 0) |
| 50 | + { |
| 51 | + throw new Exception( |
| 52 | + $"CreateWhileReadAfterWriteMaskByte(ptr, ptr+1): Expected element 0 to be true, but was false."); |
| 53 | + } |
| 54 | + |
| 55 | + for (int i = 1; i < Vector<byte>.Count; i++) |
| 56 | + { |
| 57 | + if (mask.GetElement(i) != 0) |
| 58 | + { |
| 59 | + throw new Exception( |
| 60 | + $"CreateWhileReadAfterWriteMaskByte(ptr, ptr+1): Expected element {i} to be false, but was true."); |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +} |
0 commit comments