From ff39b0f050378d935304db36cb0060730457acab Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Wed, 17 Jan 2018 07:51:43 -0800 Subject: [PATCH] Fixing the `LoadAlignedVector128` HWIntrinsic test to ensure that we always read from an aligned address. --- .../JIT/HardwareIntrinsics/X86/Sse/LoadAlignedVector128.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/src/JIT/HardwareIntrinsics/X86/Sse/LoadAlignedVector128.cs b/tests/src/JIT/HardwareIntrinsics/X86/Sse/LoadAlignedVector128.cs index fdaf40a..eaf6909 100644 --- a/tests/src/JIT/HardwareIntrinsics/X86/Sse/LoadAlignedVector128.cs +++ b/tests/src/JIT/HardwareIntrinsics/X86/Sse/LoadAlignedVector128.cs @@ -22,7 +22,8 @@ namespace IntelHardwareIntrinsicTest if (Sse.IsSupported) { - float* inArray = stackalloc float[4]; + byte* inBuffer = stackalloc byte[32]; + float* inArray = Align(inBuffer, 16); float* outArray = stackalloc float[4]; var vf = Sse.LoadAlignedVector128(inArray); @@ -47,5 +48,15 @@ namespace IntelHardwareIntrinsicTest return testResult; } + + static unsafe float* Align(byte* buffer, byte expectedAlignment) + { + // Compute how bad the misalignment is, which is at most (expectedAlignment - 1). + // Then subtract that from the expectedAlignment and add it to the original address + // to compute the aligned address. + + var misalignment = expectedAlignment - ((ulong)(buffer) % expectedAlignment); + return (float*)(buffer + misalignment); + } } } -- 2.7.4