Skip to content
Browse files

Performance Optimizations for mget()

  • Loading branch information...
1 parent acaf8f1 commit 668c0b7c96246f21e6a909e6aedc5f9dff51cc31 @grundprinzip committed Mar 9, 2012
Showing with 11 additions and 15 deletions.
  1. +8 −15 bcv.h
  2. +3 −0 main.cpp
View
23 bcv.h
@@ -133,6 +133,7 @@ class BitCompressedVector
// Check if we are really 64bit
static const uint8_t _width = sizeof(data_t) * 8;
+ static const uint64_t _num_blocks = CACHE_LINE_SIZE / sizeof(data_t);
// Number of bits to use
@@ -163,19 +164,13 @@ class BitCompressedVector
template<typename T>
void BitCompressedVector<T>::mget(const size_t index, value_type_ptr data, size_t *actual) const
{
-
- // Number of blocks to extract
- data_t num_blocks = CACHE_LINE_SIZE / sizeof(data_t);
-
// First get the initial values
data_t pos = _getPos(index);
data_t mask = 0;
// Running values for the loop
data_t currentValue;
- size_t currentIndex = index;
-
- data_t offset = _getOffset(currentIndex, pos * _width);
+ data_t offset = _getOffset(index, pos * _width);
data_t bounds = _width - offset;
// Base Mask
@@ -184,14 +179,14 @@ void BitCompressedVector<T>::mget(const size_t index, value_type_ptr data, size_
mask = baseMask << offset;
- size_t counter = 0;
+ *actual = 0;
- size_t upper = _allocated_blocks < pos + num_blocks ? _allocated_blocks : pos + num_blocks;
- while(pos < upper && counter < _reserved)
+ size_t upper = _allocated_blocks < pos + _num_blocks ? _allocated_blocks : pos + _num_blocks;
+ while(pos < upper && *actual < _reserved)
{
currentValue = (mask & _data[pos]) >> offset;
- if (bounds > _bits)
+ if (__builtin_expect((bounds > _bits), 1))
{
bounds -= _bits;
offset += _bits;
@@ -211,11 +206,9 @@ void BitCompressedVector<T>::mget(const size_t index, value_type_ptr data, size_
}
// Append current value
- data[counter++] = currentValue;
-
+ data[*actual] = currentValue;
+ *actual += 1;
}
-
- *actual = counter;
}
View
3 main.cpp
@@ -119,6 +119,7 @@ void performance(size_t size)
size_t actual;
t.start();
+ int flags = PapiTracer::start();
for(size_t i=0; i < size; )
{
actual = 0;
@@ -129,8 +130,10 @@ void performance(size_t size)
i += actual;
}
+ PapiTracer::result_t papi = PapiTracer::stop(flags);
t.stop();
std::cout << res << " mget time " << (b = t.elapsed_time()) << std::endl;
+ std::cout << papi.first << " " << papi.second << std::endl;
free(tmp);
///////////////////////////////////////////////////////////////////////////

0 comments on commit 668c0b7

Please sign in to comment.
Something went wrong with that request. Please try again.