gpu: nvgpu: posix: fix implementation of fls()

The POSIX implementation of fls() wasn't compliant with the Linux which
returns fls(0)=0 fls(1)=1, etc.

Bug found as result of JIRA NVGPU-1042.

Change-Id: Id0279e36332ffe236ed792c013c32f2da841f557
Signed-off-by: Philip Elcan <pelcan@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1828361
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: svc-misra-checker <svc-misra-checker@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Alex Waterman <alexw@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Philip Elcan
2018-09-17 11:39:37 -04:00
committed by mobile promotions
parent cec1d92300
commit 8c4b073537

View File

@@ -37,7 +37,18 @@ unsigned long __nvgpu_posix_ffs(unsigned long word)
unsigned long __nvgpu_posix_fls(unsigned long word)
{
return ((sizeof(unsigned long) * 8UL) - 1UL) - __builtin_clzl(word);
unsigned long ret;
if (word == 0UL) {
/* __builtin_clzl() below is undefined for 0, so we have
* to handle that as a special case.
*/
ret = 0UL;
} else {
ret = (sizeof(unsigned long) * 8UL) - __builtin_clzl(word);
}
return ret;
}
static unsigned long __find_next_bit(const unsigned long *addr,