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

Commit ff39b0f

Browse files
committed
Fixing the LoadAlignedVector128 HWIntrinsic test to ensure that we always read from an aligned address.
1 parent 5a17ad5 commit ff39b0f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tests/src/JIT/HardwareIntrinsics/X86/Sse/LoadAlignedVector128.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ static unsafe int Main(string[] args)
2222

2323
if (Sse.IsSupported)
2424
{
25-
float* inArray = stackalloc float[4];
25+
byte* inBuffer = stackalloc byte[32];
26+
float* inArray = Align(inBuffer, 16);
2627
float* outArray = stackalloc float[4];
2728

2829
var vf = Sse.LoadAlignedVector128(inArray);
@@ -47,5 +48,15 @@ static unsafe int Main(string[] args)
4748

4849
return testResult;
4950
}
51+
52+
static unsafe float* Align(byte* buffer, byte expectedAlignment)
53+
{
54+
// Compute how bad the misalignment is, which is at most (expectedAlignment - 1).
55+
// Then subtract that from the expectedAlignment and add it to the original address
56+
// to compute the aligned address.
57+
58+
var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment);
59+
return (float*)(buffer + misalignment);
60+
}
5061
}
5162
}

0 commit comments

Comments
 (0)