Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 17de92e

Browse files
authored
Merge pull request #17314 from fiigii/fixgctests
Fix GCStress failures from hardware intrinsic tests
2 parents cce06fb + 10f51a0 commit 17de92e

10 files changed

+185
-213
lines changed

tests/src/JIT/HardwareIntrinsics/X86/Shared/AlternatingBinOpTest_DataTable.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,35 @@ public unsafe struct AlternatingBinaryOpTest__DataTable<TResult, TOp1, TOp2> : I
2424
private GCHandle inHandle2;
2525
private GCHandle outHandle;
2626

27-
private byte simdSize;
27+
private ulong alignment;
2828

29-
public AlternatingBinaryOpTest__DataTable(TOp1[] inArray1, TOp2[] inArray2, TResult[] outArray, int simdSize)
29+
public AlternatingBinaryOpTest__DataTable(TOp1[] inArray1, TOp2[] inArray2, TResult[] outArray, int alignment)
3030
{
31-
this.inArray1 = new byte[simdSize * 2];
32-
this.inArray2 = new byte[simdSize * 2];
33-
this.outArray = new byte[simdSize * 2];
31+
int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf<TOp1>();
32+
int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf<TOp2>();
33+
int sizeOfoutArray = outArray.Length * Unsafe.SizeOf<TResult>();
34+
if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2 || (alignment * 2) < sizeOfoutArray)
35+
{
36+
throw new ArgumentException("Invalid value of alignment");
37+
}
38+
39+
this.inArray1 = new byte[alignment * 2];
40+
this.inArray2 = new byte[alignment * 2];
41+
this.outArray = new byte[alignment * 2];
3442

3543
this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned);
3644
this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned);
3745
this.outHandle = GCHandle.Alloc(this.outArray, GCHandleType.Pinned);
3846

39-
this.simdSize = unchecked((byte)(simdSize));
47+
this.alignment = (ulong)alignment;
4048

41-
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<TOp1, byte>(ref inArray1[0]), this.simdSize);
42-
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<TOp2, byte>(ref inArray2[0]), this.simdSize);
49+
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<TOp1, byte>(ref inArray1[0]), (uint)sizeOfinArray1);
50+
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<TOp2, byte>(ref inArray2[0]), (uint)sizeOfinArray2);
4351
}
4452

45-
public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), simdSize);
46-
public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), simdSize);
47-
public void* outArrayPtr => Align((byte*)(outHandle.AddrOfPinnedObject().ToPointer()), simdSize);
53+
public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment);
54+
public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment);
55+
public void* outArrayPtr => Align((byte*)(outHandle.AddrOfPinnedObject().ToPointer()), alignment);
4856

4957
public void Dispose()
5058
{
@@ -53,19 +61,9 @@ public void Dispose()
5361
outHandle.Free();
5462
}
5563

56-
private static unsafe void* Align(byte* buffer, byte expectedAlignment)
64+
private static unsafe void* Align(byte* buffer, ulong expectedAlignment)
5765
{
58-
// Compute how bad the misalignment is, which is at most (expectedAlignment - 1).
59-
// Then subtract that from the expectedAlignment and add it to the original address
60-
// to compute the aligned address.
61-
62-
var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment);
63-
var result = (void*)(buffer + misalignment);
64-
65-
Debug.Assert(((ulong)(result) % expectedAlignment) == 0);
66-
Debug.Assert((ulong)(result) <= ((ulong)(result) + expectedAlignment));
67-
68-
return result;
66+
return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1));
6967
}
7068
}
7169
}

tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanBinOpTest_DataTable.cs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,41 @@ public unsafe struct BooleanBinaryOpTest__DataTable<TOp1, TOp2> : IDisposable
2121
private GCHandle inHandle1;
2222
private GCHandle inHandle2;
2323

24-
private byte simdSize;
24+
private ulong alignment;
2525

26-
public BooleanBinaryOpTest__DataTable(TOp1[] inArray1, TOp2[] inArray2, int simdSize)
26+
public BooleanBinaryOpTest__DataTable(TOp1[] inArray1, TOp2[] inArray2, int alignment)
2727
{
28-
this.inArray1 = new byte[simdSize * 2];
29-
this.inArray2 = new byte[simdSize * 2];
28+
int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf<TOp1>();
29+
int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf<TOp2>();
30+
if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2)
31+
{
32+
throw new ArgumentException("Invalid value of alignment");
33+
}
34+
35+
this.inArray1 = new byte[alignment * 2];
36+
this.inArray2 = new byte[alignment * 2];
3037

3138
this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned);
3239
this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned);
3340

34-
this.simdSize = unchecked((byte)(simdSize));
41+
this.alignment = (ulong)alignment;
3542

36-
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<TOp1, byte>(ref inArray1[0]), this.simdSize);
37-
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<TOp2, byte>(ref inArray2[0]), this.simdSize);
43+
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<TOp1, byte>(ref inArray1[0]), (uint)sizeOfinArray1);
44+
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<TOp2, byte>(ref inArray2[0]), (uint)sizeOfinArray2);
3845
}
3946

40-
public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), simdSize);
41-
public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), simdSize);
47+
public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment);
48+
public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment);
4249

4350
public void Dispose()
4451
{
4552
inHandle1.Free();
4653
inHandle2.Free();
4754
}
4855

49-
private static unsafe void* Align(byte* buffer, byte expectedAlignment)
56+
private static unsafe void* Align(byte* buffer, ulong expectedAlignment)
5057
{
51-
// Compute how bad the misalignment is, which is at most (expectedAlignment - 1).
52-
// Then subtract that from the expectedAlignment and add it to the original address
53-
// to compute the aligned address.
54-
55-
var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment);
56-
var result = (void*)(buffer + misalignment);
57-
58-
Debug.Assert(((ulong)(result) % expectedAlignment) == 0);
59-
Debug.Assert((ulong)(result) <= ((ulong)(result) + expectedAlignment));
60-
61-
return result;
58+
return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1));
6259
}
6360
}
6461
}

tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanCmpOpTest_DataTable.cs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,41 @@ public unsafe struct BooleanComparisonOpTest__DataTable<TOp1, TOp2> : IDisposabl
2121
private GCHandle inHandle1;
2222
private GCHandle inHandle2;
2323

24-
private byte simdSize;
24+
private ulong alignment;
2525

26-
public BooleanComparisonOpTest__DataTable(TOp1[] inArray1, TOp2[] inArray2, int simdSize)
26+
public BooleanComparisonOpTest__DataTable(TOp1[] inArray1, TOp2[] inArray2, int alignment)
2727
{
28-
this.inArray1 = new byte[simdSize * 2];
29-
this.inArray2 = new byte[simdSize * 2];
28+
int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf<TOp1>();
29+
int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf<TOp2>();
30+
if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2)
31+
{
32+
throw new ArgumentException("Invalid value of alignment");
33+
}
34+
35+
this.inArray1 = new byte[alignment * 2];
36+
this.inArray2 = new byte[alignment * 2];
3037

3138
this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned);
3239
this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned);
3340

34-
this.simdSize = unchecked((byte)(simdSize));
41+
this.alignment = (ulong)alignment;
3542

36-
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<TOp1, byte>(ref inArray1[0]), this.simdSize);
37-
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<TOp2, byte>(ref inArray2[0]), this.simdSize);
43+
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<TOp1, byte>(ref inArray1[0]), (uint)sizeOfinArray1);
44+
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<TOp2, byte>(ref inArray2[0]), (uint)sizeOfinArray2);
3845
}
3946

40-
public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), simdSize);
41-
public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), simdSize);
47+
public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment);
48+
public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment);
4249

4350
public void Dispose()
4451
{
4552
inHandle1.Free();
4653
inHandle2.Free();
4754
}
4855

49-
private static unsafe void* Align(byte* buffer, byte expectedAlignment)
56+
private static unsafe void* Align(byte* buffer, ulong expectedAlignment)
5057
{
51-
// Compute how bad the misalignment is, which is at most (expectedAlignment - 1).
52-
// Then subtract that from the expectedAlignment and add it to the original address
53-
// to compute the aligned address.
54-
55-
var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment);
56-
var result = (void*)(buffer + misalignment);
57-
58-
Debug.Assert(((ulong)(result) % expectedAlignment) == 0);
59-
Debug.Assert((ulong)(result) <= ((ulong)(result) + expectedAlignment));
60-
61-
return result;
58+
return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1));
6259
}
6360
}
6461
}

tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanTwoCmpOpTest_DataTable.cs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,41 @@ public unsafe struct BooleanTwoComparisonOpTest__DataTable<TOp1, TOp2> : IDispos
2121
private GCHandle inHandle1;
2222
private GCHandle inHandle2;
2323

24-
private byte simdSize;
24+
private ulong alignment;
2525

26-
public BooleanTwoComparisonOpTest__DataTable(TOp1[] inArray1, TOp2[] inArray2, int simdSize)
26+
public BooleanTwoComparisonOpTest__DataTable(TOp1[] inArray1, TOp2[] inArray2, int alignment)
2727
{
28-
this.inArray1 = new byte[simdSize * 2];
29-
this.inArray2 = new byte[simdSize * 2];
28+
int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf<TOp1>();
29+
int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf<TOp2>();
30+
if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2)
31+
{
32+
throw new ArgumentException("Invalid value of alignment");
33+
}
34+
35+
this.inArray1 = new byte[alignment * 2];
36+
this.inArray2 = new byte[alignment * 2];
3037

3138
this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned);
3239
this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned);
3340

34-
this.simdSize = unchecked((byte)(simdSize));
41+
this.alignment = (ulong)alignment;
3542

36-
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<TOp1, byte>(ref inArray1[0]), this.simdSize);
37-
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<TOp2, byte>(ref inArray2[0]), this.simdSize);
43+
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<TOp1, byte>(ref inArray1[0]), (uint)sizeOfinArray1);
44+
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<TOp2, byte>(ref inArray2[0]), (uint)sizeOfinArray2);
3845
}
3946

40-
public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), simdSize);
41-
public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), simdSize);
47+
public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment);
48+
public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment);
4249

4350
public void Dispose()
4451
{
4552
inHandle1.Free();
4653
inHandle2.Free();
4754
}
4855

49-
private static unsafe void* Align(byte* buffer, byte expectedAlignment)
56+
private static unsafe void* Align(byte* buffer, ulong expectedAlignment)
5057
{
51-
// Compute how bad the misalignment is, which is at most (expectedAlignment - 1).
52-
// Then subtract that from the expectedAlignment and add it to the original address
53-
// to compute the aligned address.
54-
55-
var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment);
56-
var result = (void*)(buffer + misalignment);
57-
58-
Debug.Assert(((ulong)(result) % expectedAlignment) == 0);
59-
Debug.Assert((ulong)(result) <= ((ulong)(result) + expectedAlignment));
60-
61-
return result;
58+
return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1));
6259
}
6360
}
6461
}

tests/src/JIT/HardwareIntrinsics/X86/Shared/BooleanUnOpTest_DataTable.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,34 @@ public unsafe struct BooleanUnaryOpTest__DataTable<TOp1> : IDisposable
1818

1919
private GCHandle inHandle;
2020

21-
private byte simdSize;
21+
private ulong alignment;
2222

23-
public BooleanUnaryOpTest__DataTable(TOp1[] inArray, int simdSize)
23+
public BooleanUnaryOpTest__DataTable(TOp1[] inArray, int alignment)
2424
{
25-
this.inArray = new byte[simdSize * 2];
25+
int sizeOfinArray = inArray.Length * Unsafe.SizeOf<TOp1>();
26+
if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray)
27+
{
28+
throw new ArgumentException("Invalid value of alignment");
29+
}
30+
this.inArray = new byte[alignment * 2];
2631

2732
this.inHandle = GCHandle.Alloc(this.inArray, GCHandleType.Pinned);
2833

29-
this.simdSize = unchecked((byte)(simdSize));
34+
this.alignment = (ulong)alignment;
3035

31-
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArrayPtr), ref Unsafe.As<TOp1, byte>(ref inArray[0]), this.simdSize);
36+
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArrayPtr), ref Unsafe.As<TOp1, byte>(ref inArray[0]), (uint)sizeOfinArray);
3237
}
3338

34-
public void* inArrayPtr => Align((byte*)(inHandle.AddrOfPinnedObject().ToPointer()), simdSize);
39+
public void* inArrayPtr => Align((byte*)(inHandle.AddrOfPinnedObject().ToPointer()), alignment);
3540

3641
public void Dispose()
3742
{
3843
inHandle.Free();
3944
}
4045

41-
private static unsafe void* Align(byte* buffer, byte expectedAlignment)
46+
private static unsafe void* Align(byte* buffer, ulong expectedAlignment)
4247
{
43-
// Compute how bad the misalignment is, which is at most (expectedAlignment - 1).
44-
// Then subtract that from the expectedAlignment and add it to the original address
45-
// to compute the aligned address.
46-
47-
var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment);
48-
var result = (void*)(buffer + misalignment);
49-
50-
Debug.Assert(((ulong)(result) % expectedAlignment) == 0);
51-
Debug.Assert((ulong)(result) <= ((ulong)(result) + expectedAlignment));
52-
53-
return result;
48+
return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1));
5449
}
5550
}
5651
}

tests/src/JIT/HardwareIntrinsics/X86/Shared/HorizontalBinOpTest_DataTable.cs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,35 @@ public unsafe struct HorizontalBinaryOpTest__DataTable<TResult, TOp1, TOp2> : ID
2424
private GCHandle inHandle2;
2525
private GCHandle outHandle;
2626

27-
private byte simdSize;
27+
private ulong alignment;
2828

29-
public HorizontalBinaryOpTest__DataTable(TOp1[] inArray1, TOp2[] inArray2, TResult[] outArray, int simdSize)
29+
public HorizontalBinaryOpTest__DataTable(TOp1[] inArray1, TOp2[] inArray2, TResult[] outArray, int alignment)
3030
{
31-
this.inArray1 = new byte[simdSize * 2];
32-
this.inArray2 = new byte[simdSize * 2];
33-
this.outArray = new byte[simdSize * 2];
31+
int sizeOfinArray1 = inArray1.Length * Unsafe.SizeOf<TOp1>();
32+
int sizeOfinArray2 = inArray2.Length * Unsafe.SizeOf<TOp2>();
33+
int sizeOfoutArray = outArray.Length * Unsafe.SizeOf<TResult>();
34+
if ((alignment != 32 && alignment != 16) || (alignment * 2) < sizeOfinArray1 || (alignment * 2) < sizeOfinArray2 || (alignment * 2) < sizeOfoutArray)
35+
{
36+
throw new ArgumentException("Invalid value of alignment");
37+
}
38+
39+
this.inArray1 = new byte[alignment * 2];
40+
this.inArray2 = new byte[alignment * 2];
41+
this.outArray = new byte[alignment * 2];
3442

3543
this.inHandle1 = GCHandle.Alloc(this.inArray1, GCHandleType.Pinned);
3644
this.inHandle2 = GCHandle.Alloc(this.inArray2, GCHandleType.Pinned);
3745
this.outHandle = GCHandle.Alloc(this.outArray, GCHandleType.Pinned);
3846

39-
this.simdSize = unchecked((byte)(simdSize));
47+
this.alignment = (ulong)alignment;
4048

41-
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<TOp1, byte>(ref inArray1[0]), this.simdSize);
42-
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<TOp2, byte>(ref inArray2[0]), this.simdSize);
49+
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray1Ptr), ref Unsafe.As<TOp1, byte>(ref inArray1[0]), (uint)sizeOfinArray1);
50+
Unsafe.CopyBlockUnaligned(ref Unsafe.AsRef<byte>(inArray2Ptr), ref Unsafe.As<TOp2, byte>(ref inArray2[0]), (uint)sizeOfinArray2);
4351
}
4452

45-
public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), simdSize);
46-
public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), simdSize);
47-
public void* outArrayPtr => Align((byte*)(outHandle.AddrOfPinnedObject().ToPointer()), simdSize);
53+
public void* inArray1Ptr => Align((byte*)(inHandle1.AddrOfPinnedObject().ToPointer()), alignment);
54+
public void* inArray2Ptr => Align((byte*)(inHandle2.AddrOfPinnedObject().ToPointer()), alignment);
55+
public void* outArrayPtr => Align((byte*)(outHandle.AddrOfPinnedObject().ToPointer()), alignment);
4856

4957
public void Dispose()
5058
{
@@ -53,19 +61,9 @@ public void Dispose()
5361
outHandle.Free();
5462
}
5563

56-
private static unsafe void* Align(byte* buffer, byte expectedAlignment)
64+
private static unsafe void* Align(byte* buffer, ulong expectedAlignment)
5765
{
58-
// Compute how bad the misalignment is, which is at most (expectedAlignment - 1).
59-
// Then subtract that from the expectedAlignment and add it to the original address
60-
// to compute the aligned address.
61-
62-
var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment);
63-
var result = (void*)(buffer + misalignment);
64-
65-
Debug.Assert(((ulong)(result) % expectedAlignment) == 0);
66-
Debug.Assert((ulong)(result) <= ((ulong)(result) + expectedAlignment));
67-
68-
return result;
66+
return (void*)(((ulong)buffer + expectedAlignment - 1) & ~(expectedAlignment - 1));
6967
}
7068
}
7169
}

0 commit comments

Comments
 (0)