summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorAlex Waterman <alexw@nvidia.com>2018-05-22 14:24:22 -0400
committermobile promotions <svcmobile_promotions@nvidia.com>2018-05-25 18:15:47 -0400
commit64b6918ea9ab897d6c6bff1ae351ff950519e831 (patch)
tree00dfbbf15c3690ea7046290f0d0ce58a34413d6d /drivers
parenta3a9ed3b126f13fff52973159d171eb44ae71a43 (diff)
gpu: nvgpu: posix: Use GCC builtins for ffs(), fls()
These intrinsics will be fast for the given platform that the compiler is targeting. This also reduces complexity in the code. Change-Id: I6cfb761d6f881056446fa9a5de53dca50ed93c34 Signed-off-by: Alex Waterman <alexw@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/1727383 Reviewed-by: Konsta Holtta <kholtta@nvidia.com> Reviewed-by: Richard Zhao <rizhao@nvidia.com> GVS: Gerrit_Virtual_Submit Reviewed-by: Terje Bergstrom <tbergstrom@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpu/nvgpu/common/posix/bitmap.c57
1 files changed, 2 insertions, 55 deletions
diff --git a/drivers/gpu/nvgpu/common/posix/bitmap.c b/drivers/gpu/nvgpu/common/posix/bitmap.c
index 51361777..b45838df 100644
--- a/drivers/gpu/nvgpu/common/posix/bitmap.c
+++ b/drivers/gpu/nvgpu/common/posix/bitmap.c
@@ -31,65 +31,12 @@
31 31
32unsigned long __nvgpu_posix_fls(unsigned long word) 32unsigned long __nvgpu_posix_fls(unsigned long word)
33{ 33{
34 int num = BITS_PER_LONG - 1; 34 return __builtin_clzl(word);
35
36#if BITS_PER_LONG == 64
37 if (!(word & (~0ul << 32))) {
38 num -= 32;
39 word <<= 32;
40 }
41#endif
42 if (!(word & (~0ul << (BITS_PER_LONG-16)))) {
43 num -= 16;
44 word <<= 16;
45 }
46 if (!(word & (~0ul << (BITS_PER_LONG-8)))) {
47 num -= 8;
48 word <<= 8;
49 }
50 if (!(word & (~0ul << (BITS_PER_LONG-4)))) {
51 num -= 4;
52 word <<= 4;
53 }
54 if (!(word & (~0ul << (BITS_PER_LONG-2)))) {
55 num -= 2;
56 word <<= 2;
57 }
58 if (!(word & (~0ul << (BITS_PER_LONG-1))))
59 num -= 1;
60 return num;
61} 35}
62 36
63unsigned long __nvgpu_posix_ffs(unsigned long word) 37unsigned long __nvgpu_posix_ffs(unsigned long word)
64{ 38{
65 int num = 0; 39 return __builtin_ffsl(word);
66
67#if BITS_PER_LONG == 64
68 if ((word & 0xffffffff) == 0) {
69 num += 32;
70 word >>= 32;
71 }
72#endif
73 if ((word & 0xffff) == 0) {
74 num += 16;
75 word >>= 16;
76 }
77 if ((word & 0xff) == 0) {
78 num += 8;
79 word >>= 8;
80 }
81 if ((word & 0xf) == 0) {
82 num += 4;
83 word >>= 4;
84 }
85 if ((word & 0x3) == 0) {
86 num += 2;
87 word >>= 2;
88 }
89 if ((word & 0x1) == 0)
90 num += 1;
91
92 return num;
93} 40}
94 41
95static unsigned long __find_next_bit(const unsigned long *addr, 42static unsigned long __find_next_bit(const unsigned long *addr,