mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-19787 Speedup Table_map_iterator, via compiler intrinsics
Use __builtin_ctzll on GCC/Clang and _BitScanForward/_BitScanForward64 on MSVC to speed up Table_map_iterator::next_bit(), up to 3 times in benchmarks
This commit is contained in:
@ -27,29 +27,20 @@
|
||||
#include <my_bitmap.h>
|
||||
#include <my_bit.h>
|
||||
|
||||
/* An iterator to quickly walk over bits in unlonglong bitmap. */
|
||||
|
||||
/* An iterator to quickly walk over bits in ulonglong bitmap. */
|
||||
class Table_map_iterator
|
||||
{
|
||||
ulonglong bmp;
|
||||
uint no;
|
||||
public:
|
||||
Table_map_iterator(ulonglong t) : bmp(t), no(0) {}
|
||||
int next_bit()
|
||||
Table_map_iterator(ulonglong t): bmp(t){}
|
||||
uint next_bit()
|
||||
{
|
||||
static const char last_bit[16] = { 32, 0, 1, 0,
|
||||
2, 0, 1, 0,
|
||||
3, 0, 1, 0,
|
||||
2, 0, 1, 0 };
|
||||
uint bit;
|
||||
while ((bit= last_bit[bmp & 0xF]) == 32)
|
||||
{
|
||||
no += 4;
|
||||
bmp= bmp >> 4;
|
||||
if (!bmp)
|
||||
return BITMAP_END;
|
||||
}
|
||||
bmp &= ~(1LL << bit);
|
||||
return no + bit;
|
||||
if (!bmp)
|
||||
return BITMAP_END;
|
||||
uint bit= my_find_first_bit(bmp);
|
||||
bmp &= ~(1ULL << bit);
|
||||
return bit;
|
||||
}
|
||||
int operator++(int) { return next_bit(); }
|
||||
enum { BITMAP_END= 64 };
|
||||
|
Reference in New Issue
Block a user