Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle headers for integer types with precision cascades #21

Merged
merged 3 commits into from
Sep 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions core/accelogic/src/ZipAccelogic.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void R__zipBLAST(unsigned char *cxlevels, int *srcsize, char *src, int *tgtsize,
bool isfloat = (rawtype == EDataType::kFloat_t);
bool isdouble = (rawtype == EDataType::kDouble_t);

size_t out_sizes[MAX_ZIG_BUFFERS];
size_t out_sizes[MAX_ZIG_BUFFERS] = { };

if (isfloat || isdouble) {
const size_t elsize = isfloat ? sizeof(float) : sizeof(double);
Expand Down Expand Up @@ -106,23 +106,16 @@ void R__zipBLAST(unsigned char *cxlevels, int *srcsize, char *src, int *tgtsize,
else
blast1_compress<true>(absSensLevels, source.d, float_number, staging, out_sizes, absSens_tgt_number, needresidual);

// Skip transfer any of the buffers to their targets if any one of them is over-sized, and return
auto excessive_size = false;
for (int tgt_idx=0; tgt_idx<tgt_number && !excessive_size; tgt_idx++)
excessive_size |= ( ( out_sizes[tgt_idx] + kHeaderSize) > (size_t)tgtsize[tgt_idx] );

if (excessive_size) {
for (int tgt_idx=0; tgt_idx<tgt_number; tgt_idx++)
delete [] (staging[tgt_idx]);
return;
}

for (int tgt_idx=0; tgt_idx<tgt_number; tgt_idx++) {
memcpy(tgts[tgt_idx] + kHeaderSize, staging[tgt_idx], out_sizes[tgt_idx]);
tgts[tgt_idx][2] = cxlevels[tgt_idx];
if (!excessive_size) memcpy(tgts[tgt_idx] + kHeaderSize, staging[tgt_idx], out_sizes[tgt_idx]);
delete [] (staging[tgt_idx]);
// irep points to an array of all buffer sizes
irep[tgt_idx] = out_sizes[tgt_idx] + kHeaderSize;
}
if (excessive_size) return;
} else {
// Use "RLE".
// Note: We need to check the source really start of a boundary.
Expand Down Expand Up @@ -174,9 +167,7 @@ void R__zipBLAST(unsigned char *cxlevels, int *srcsize, char *src, int *tgtsize,
return;
}
memcpy(tgt + kHeaderSize, staging, out_size);
tgt[2] = *cxlevels; // inconsequential with RLE, which has no levels
delete [] staging;
*irep = out_size + kHeaderSize;
}

unsigned in_size = (unsigned) (*srcsize);
Expand All @@ -185,7 +176,7 @@ void R__zipBLAST(unsigned char *cxlevels, int *srcsize, char *src, int *tgtsize,

tgt[0] = 'B'; /* Signature of Accelogic BLAST */
tgt[1] = 'L';
// tgt[2] is set for each target buffer above
tgt[2] = cxlevels[tgt_idx]; // inconsequential with RLE, which has no levels

// Include the 2 extra header byte into the out size.
const size_t out_size = out_sizes[tgt_idx] + 2;
Expand All @@ -200,6 +191,9 @@ void R__zipBLAST(unsigned char *cxlevels, int *srcsize, char *src, int *tgtsize,
// Blast specific
tgt[9] = datatype;
tgt[10] = tgt_number;

// irep points to an array of all buffer sizes
irep[tgt_idx] = out_sizes[tgt_idx] + kHeaderSize; // out_sizes will be 0 for RLE auxiliary targets
}
}

Expand Down