gpu: nvgpu: posix: Fix ffs() and fls() impl in POSIX

The GCC builtins act slightly differently than the Linux versions
of these functions. This patch adds the necessary glue to emulate
the Linux versions identically.

JIRA NVGPU-525

Change-Id: Idadbecdfd516c68f3d3eb20eca495dc1eaa02c5b
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1741951
GVS: Gerrit_Virtual_Submit
Reviewed-by: Konsta Holtta <kholtta@nvidia.com>
Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Alex Waterman
2018-05-30 09:16:06 -07:00
committed by mobile promotions
parent 0b0b820911
commit 2ac6fb4253

View File

@@ -29,14 +29,15 @@
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
unsigned long __nvgpu_posix_fls(unsigned long word)
{
return __builtin_clzl(word);
}
unsigned long __nvgpu_posix_ffs(unsigned long word)
{
return __builtin_ffsl(word);
return (__builtin_ffsl(word) - 1) &
((sizeof(unsigned long) * 8UL) - 1UL);
}
unsigned long __nvgpu_posix_fls(unsigned long word)
{
return ((sizeof(unsigned long) * 8UL) - 1UL) - __builtin_clzl(word);
}
static unsigned long __find_next_bit(const unsigned long *addr,