Skip to content

Commit

Permalink
Merge pull request fast-pack#103 from pps83/clear-padding
Browse files Browse the repository at this point in the history
Clear padding in fastpfor, simdfastpfor, simdgroupsimple
  • Loading branch information
lemire authored Feb 20, 2023
2 parents 2ec76c3 + d67c7ab commit 024eed0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions headers/fastpfor.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ class FastPForImpl {
static_cast<uint32_t>(bc - &bytescontainer[0]);
*(out++) = bytescontainersize;
memcpy(out, &bytescontainer[0], bytescontainersize);
uint8_t* pad8 = (uint8_t*)out + bytescontainersize;
out += (bytescontainersize + sizeof(uint32_t) - 1) / sizeof(uint32_t);
while (pad8 < (uint8_t*)out)
*pad8++ = 0; // clear padding bytes

IntType bitmap = 0;
for (uint32_t k = 2; k <= sizeof(IntType) * 8; ++k) {
Expand Down Expand Up @@ -472,7 +475,11 @@ class SimplePFor : public IntegerCODEC {
static_cast<uint32_t>(bc - &bytescontainer[0]);
*(out++) = bytescontainersize;
memcpy(out, &bytescontainer[0], bytescontainersize);
uint8_t* pad8 = (uint8_t*)out + bytescontainersize;
out += (bytescontainersize + sizeof(uint32_t) - 1) / sizeof(uint32_t);
while (pad8 < (uint8_t*)out)
*pad8++ = 0; // clear padding bytes

size_t outcap = 0;
ecoder.encodeArray(datatobepacked.data(), datatobepacked.size(), out,
outcap);
Expand Down
8 changes: 8 additions & 0 deletions headers/simdfastpfor.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ class SIMDFastPFor : public IntegerCODEC {
static_cast<uint32_t>(bc - &bytescontainer[0]);
*(out++) = bytescontainersize;
memcpy(out, &bytescontainer[0], bytescontainersize);
uint8_t* pad8 = (uint8_t*)out + bytescontainersize;
out += (bytescontainersize + sizeof(uint32_t) - 1) / sizeof(uint32_t);
while (pad8 < (uint8_t*)out)
*pad8++ = 0; // clear padding bytes

uint32_t bitmap = 0;
for (uint32_t k = 2; k <= 32; ++k) {
if (datatobepacked[k].size() != 0)
Expand Down Expand Up @@ -508,7 +512,11 @@ class SIMDSimplePFor : public IntegerCODEC {
static_cast<uint32_t>(bc - &bytescontainer[0]);
*(out++) = bytescontainersize;
memcpy(out, &bytescontainer[0], bytescontainersize);
uint8_t* pad8 = (uint8_t*)out + bytescontainersize;
out += (bytescontainersize + sizeof(uint32_t) - 1) / sizeof(uint32_t);
while (pad8 < (uint8_t*)out)
*pad8++ = 0; // clear padding bytes

size_t outcap = 0;
ecoder.encodeArray(datatobepacked.data(), datatobepacked.size(), out,
outcap);
Expand Down
3 changes: 3 additions & 0 deletions headers/simdgroupsimple.h
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,9 @@ class SIMDGroupSimple : public IntegerCODEC {
__m128i *outDataArea128 = reinterpret_cast<__m128i *>(initOutSelArea8 +
countSelArea8 + sizeof(uint8_t) + countPadBytes);
const __m128i *const initOutDataArea128 = outDataArea128;
uint8_t* pad8 = (uint8_t*)outDataArea128 - countPadBytes;
while (pad8 < (uint8_t*)outDataArea128)
*pad8++ = 0; // clear padding bytes

const __m128i *in128 = reinterpret_cast<const __m128i *>(in);

Expand Down

0 comments on commit 024eed0

Please sign in to comment.