From 55525fa4662ea6fa26123ee3bb25d4ef7c67ed16 Mon Sep 17 00:00:00 2001 From: "Yaxun (Sam) Liu" Date: Fri, 10 Jan 2020 03:16:57 -0500 Subject: [PATCH] Fix test hip_bitextract.cpp (#1784) The randomly generated offset+width may exceeds 32, which causes a left shift operation with 32-offset-width. As an unsigned number that is greater than 32 and causes undefined behavior. When the test is compiled without -mavx it is still OK. However when the test is compiled with -mavx, the undefined behavior causes wrong results and test failure. This patch adjusts width so that offset+width<=32 always. --- hipamd/tests/src/deviceLib/hip_bitextract.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hipamd/tests/src/deviceLib/hip_bitextract.cpp b/hipamd/tests/src/deviceLib/hip_bitextract.cpp index 5ee3974107..5c686f5705 100644 --- a/hipamd/tests/src/deviceLib/hip_bitextract.cpp +++ b/hipamd/tests/src/deviceLib/hip_bitextract.cpp @@ -123,6 +123,8 @@ int main() { hostSrc032[i] = uint32_src0_dist(rd); hostSrc132[i] = uint32_src12_dist(rd); hostSrc232[i] = uint32_src12_dist(rd); + if (hostSrc132[i] + hostSrc232[i] > 32) + hostSrc232[i] = 32 - hostSrc132[i]; hostOut64[i] = 0; hostSrc064[i] = uint64_src0_dist(rd); hostSrc164[i] = uint64_src12_dist(rd);