summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKuan-Wei Chiu <visitorckw@gmail.com>2024-05-02 12:24:43 +0300
committerYury Norov <yury.norov@gmail.com>2024-05-09 19:25:08 +0300
commit1c2aa5619348f7573d6f2269e04fd1dac8eddc47 (patch)
tree50dbfbb13bc09d959235f97e021a33f069232293 /lib
parent0a2c6664e56f0dff7535c3d3d9a6174279e18acc (diff)
downloadlinux-1c2aa5619348f7573d6f2269e04fd1dac8eddc47.tar.xz
bitops: Optimize fns() for improved performance
The current fns() repeatedly uses __ffs() to find the index of the least significant bit and then clears the corresponding bit using __clear_bit(). The method for clearing the least significant bit can be optimized by using word &= word - 1 instead. Typically, the execution time of one __ffs() plus one __clear_bit() is longer than that of a bitwise AND operation and a subtraction. To improve performance, the loop for clearing the least significant bit has been replaced with word &= word - 1, followed by a single __ffs() operation to obtain the answer. This change reduces the number of __ffs() iterations from n to just one, enhancing overall performance. This modification significantly accelerates the fns() function in the test_bitops benchmark, improving its speed by approximately 7.6 times. Additionally, it enhances the performance of find_nth_bit() in the find_bit benchmark by approximately 26%. Before: test_bitops: fns: 58033164 ns find_nth_bit: 4254313 ns, 16525 iterations After: test_bitops: fns: 7637268 ns find_nth_bit: 3362863 ns, 16501 iterations CC: Andrew Morton <akpm@linux-foundation.org> CC: Rasmus Villemoes <linux@rasmusvillemoes.dk> Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com> Signed-off-by: Yury Norov <yury.norov@gmail.com>
Diffstat (limited to 'lib')
0 files changed, 0 insertions, 0 deletions