Skip to content

Instantly share code, notes, and snippets.

@pps83
Created June 10, 2019 02:01
Show Gist options
  • Save pps83/1fbeed8ec599861075d7b7de7fe1ed9f to your computer and use it in GitHub Desktop.
Save pps83/1fbeed8ec599861075d7b7de7fe1ed9f to your computer and use it in GitHub Desktop.
Test simdfastpfor128
#undef NDEBUG
#include "compositecodec.h"
#include "simdfastpfor.h"
#include "variablebyte.h"
#include <stdlib.h>
#include <vector>
// typedef for simdfastpfor128 codec from FastPFor
typedef FastPForLib::CompositeCodec<FastPForLib::SIMDFastPFor<4>, FastPForLib::VariableByte> IntCodec;
class Coder
{
public:
size_t encode(const uint32_t* input, size_t inputSize, std::vector<uint32_t>& output)
{
size_t outputSize = output.size();
size_t sz = inputSize + std::max(1024u, inputSize / 8);
output.resize(outputSize + sz);
iCodec.encodeArray(input, inputSize, output.data() + outputSize, sz);
output.resize(outputSize + sz);
return sz;
}
size_t encode(const std::vector<uint32_t>& input, std::vector<uint32_t>& output)
{
return encode(input.data(), input.size(), output);
}
private:
IntCodec iCodec;
};
int main()
{
srand(123);
Coder c;
const int sz = 2731;
std::vector<uint32_t> input, output;
for (int i = 0; i < 1000; ++i)
{
size_t outputSize = output.size();
size_t inputSize = input.size();
std::vector<uint32_t> input2;
for (int i = 0; i < sz; ++i)
input2.push_back(rand());
input.insert(input.end(), input2.begin(), input2.end());
std::vector<uint32_t> output2, output3;
size_t sz1 = c.encode(input.data() + inputSize, sz, output);
size_t sz2 = c.encode(input2, output2);
output3.insert(output3.end(), output.begin() + outputSize, output.end());
assert(sz1 == sz2);
assert(output2 == output3);
assert(std::equal(output.begin() + outputSize, output.end(), output2.begin(), output2.end()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment