diff --git a/openmp/libomptarget/plugins/common/MemoryManager/MemoryManager.h b/openmp/libomptarget/plugins/common/MemoryManager/MemoryManager.h --- a/openmp/libomptarget/plugins/common/MemoryManager/MemoryManager.h +++ b/openmp/libomptarget/plugins/common/MemoryManager/MemoryManager.h @@ -63,8 +63,8 @@ #else #error Unsupported architecture #endif - Num += 1; - return Num >> 1; + Num = Num >> 1; + return Num + 1; } /// Find a suitable bucket @@ -74,21 +74,23 @@ DP("findBucket: Size %zu is floored to %zu.\n", Size, F); int L = 0, H = NumBuckets - 1; - while (H - L > 1) { + while (H >= L) { int M = (L + H) >> 1; - if (BucketSize[M] == F) + if (BucketSize[M] == F) { + DP("findBucket: Size %zu goes to bucket %d\n", Size, M); return M; + } if (BucketSize[M] > F) H = M - 1; else - L = M; + L = M + 1; } - assert(L >= 0 && L < NumBuckets && "L is out of range"); + assert(H >= 0 && H < NumBuckets && "H is out of range"); - DP("findBucket: Size %zu goes to bucket %d\n", Size, L); + DP("findBucket: Size %zu goes to bucket %d\n", Size, H); - return L; + return H; } /// A structure stores the meta data of a target pointer