Skip to content
Snippets Groups Projects
Commit 8a78a673 authored by Dominik Loidolt's avatar Dominik Loidolt
Browse files

Change the chunk pointer type to void* in the compress_chunk function

parent 16d97d9a
Branches
Tags
1 merge request!26Adapt cmp_tool to the chunk decompression
...@@ -60,7 +60,7 @@ static int demo_comperss_chunk_1d(void) ...@@ -60,7 +60,7 @@ static int demo_comperss_chunk_1d(void)
struct offset offset_data[2] = {{1, 2}, {3, 4}}; struct offset offset_data[2] = {{1, 2}, {3, 4}};
enum { CHUNK_SIZE = 2*COLLECTION_HDR_SIZE + sizeof(background_data) enum { CHUNK_SIZE = 2*COLLECTION_HDR_SIZE + sizeof(background_data)
+ sizeof(offset_data) }; + sizeof(offset_data) };
uint32_t chunk[ROUND_UP_TO_4(CHUNK_SIZE)/4] = {0}; /* Do not put large amount of data on the stack! */ uint8_t chunk[CHUNK_SIZE] = {0}; /* Do not put large amount of data on the stack! */
uint32_t *compressed_data; uint32_t *compressed_data;
int cmp_size_bytes; int cmp_size_bytes;
...@@ -74,7 +74,7 @@ static int demo_comperss_chunk_1d(void) ...@@ -74,7 +74,7 @@ static int demo_comperss_chunk_1d(void)
return -1; return -1;
memcpy(col->entry, background_data, sizeof(background_data)); memcpy(col->entry, background_data, sizeof(background_data));
col = (struct collection_hdr *)((uint8_t *)chunk + cmp_col_get_size(col)); col = (struct collection_hdr *)(chunk + cmp_col_get_size(col));
if (cmp_col_set_subservice(col, SST_NCxx_S_SCIENCE_OFFSET)) if (cmp_col_set_subservice(col, SST_NCxx_S_SCIENCE_OFFSET))
return -1; return -1;
if (cmp_col_set_data_length(col, sizeof(offset_data))) if (cmp_col_set_data_length(col, sizeof(offset_data)))
...@@ -166,16 +166,16 @@ static int demo_comperss_chunk_model(void) ...@@ -166,16 +166,16 @@ static int demo_comperss_chunk_model(void)
struct offset offset_data[2] = {{1, 32}, {23, 42}}; struct offset offset_data[2] = {{1, 32}, {23, 42}};
enum { CHUNK_SIZE = 2*COLLECTION_HDR_SIZE + sizeof(background_data) enum { CHUNK_SIZE = 2*COLLECTION_HDR_SIZE + sizeof(background_data)
+ sizeof(offset_data) }; + sizeof(offset_data) };
uint32_t chunk[ROUND_UP_TO_4(CHUNK_SIZE)/4] = {0}; /* Do not put large amount of data on the stack! */ uint8_t chunk[CHUNK_SIZE] = {0}; /* Do not put large amount of data on the stack! */
uint32_t model_chunk[ROUND_UP_TO_4(CHUNK_SIZE)/4] = {0}; /* Do not put large amount of data on the stack! */ uint8_t model_chunk[(CHUNK_SIZE)] = {0}; /* Do not put large amount of data on the stack! */
uint32_t updated_chunk_model[ROUND_UP_TO_4(CHUNK_SIZE)/4] = {0}; /* Do not put large amount of data on the stack! */ uint8_t updated_chunk_model[CHUNK_SIZE] = {0}; /* Do not put large amount of data on the stack! */
/* /*
* Here we use the COMPRESS_CHUNK_BOUND macro to determine the worst * Here we use the COMPRESS_CHUNK_BOUND macro to determine the worst
* case compression size; to do this we need to know the chunk_size and * case compression size; to do this we need to know the chunk_size and
* the number of collections in the chunk (2 in this demo) * the number of collections in the chunk (2 in this demo)
*/ */
uint32_t compressed_data[COMPRESS_CHUNK_BOUND(CHUNK_SIZE, 2)]; /* Do not put large amount of data on the stack! */ uint32_t compressed_data[COMPRESS_CHUNK_BOUND(CHUNK_SIZE, 2)/4]; /* Do not put large amount of data on the stack! */
int cmp_size_bytes; int cmp_size_bytes;
{ /* build a chunk of a background and an offset collection */ { /* build a chunk of a background and an offset collection */
...@@ -187,7 +187,7 @@ static int demo_comperss_chunk_model(void) ...@@ -187,7 +187,7 @@ static int demo_comperss_chunk_model(void)
return -1; return -1;
memcpy(col->entry, background_data, sizeof(background_data)); memcpy(col->entry, background_data, sizeof(background_data));
col = (struct collection_hdr *)((uint8_t *)chunk + cmp_col_get_size(col)); col = (struct collection_hdr *)(chunk + cmp_col_get_size(col));
if (cmp_col_set_subservice(col, SST_NCxx_S_SCIENCE_OFFSET)) if (cmp_col_set_subservice(col, SST_NCxx_S_SCIENCE_OFFSET))
return -1; return -1;
if (cmp_col_set_data_length(col, sizeof(offset_data))) if (cmp_col_set_data_length(col, sizeof(offset_data)))
...@@ -203,7 +203,7 @@ static int demo_comperss_chunk_model(void) ...@@ -203,7 +203,7 @@ static int demo_comperss_chunk_model(void)
return -1; return -1;
memcpy(col->entry, background_model, sizeof(background_model)); memcpy(col->entry, background_model, sizeof(background_model));
col = (struct collection_hdr *)((uint8_t *)model_chunk + cmp_col_get_size(col)); col = (struct collection_hdr *)(model_chunk + cmp_col_get_size(col));
if (cmp_col_set_subservice(col, SST_NCxx_S_SCIENCE_OFFSET)) if (cmp_col_set_subservice(col, SST_NCxx_S_SCIENCE_OFFSET))
return -1; return -1;
if (cmp_col_set_data_length(col, sizeof(offset_model))) if (cmp_col_set_data_length(col, sizeof(offset_model)))
...@@ -269,7 +269,7 @@ int main(void) ...@@ -269,7 +269,7 @@ int main(void)
int error = 0; int error = 0;
error |= demo_comperss_chunk_1d(); error |= demo_comperss_chunk_1d();
/* error |= demo_comperss_chunk_model(); */ error |= demo_comperss_chunk_model();
if (error) if (error)
return EXIT_FAILURE; return EXIT_FAILURE;
......
...@@ -109,8 +109,9 @@ void compress_chunk_init(uint64_t(return_timestamp)(void), uint32_t version_id); ...@@ -109,8 +109,9 @@ void compress_chunk_init(uint64_t(return_timestamp)(void), uint32_t version_id);
* small to hold the whole compressed data * small to hold the whole compressed data
*/ */
int compress_chunk(uint32_t *chunk, uint32_t chunk_size, uint32_t *chunk_model, int32_t compress_chunk(void *chunk, uint32_t chunk_size,
uint32_t *updated_chunk_model, uint32_t *dst, uint32_t dst_capacity, void *chunk_model, void *updated_chunk_model,
uint32_t *dst, uint32_t dst_capacity,
const struct cmp_par *cmp_par); const struct cmp_par *cmp_par);
/** /**
......
...@@ -2314,10 +2314,11 @@ static int set_cmp_col_size(uint8_t *p, int cmp_col_size) ...@@ -2314,10 +2314,11 @@ static int set_cmp_col_size(uint8_t *p, int cmp_col_size)
/* TODO: doc string */ /* TODO: doc string */
static int cmp_collection(uint8_t *col, uint8_t *model, uint8_t *updated_model, uint32_t *dst, static int32_t cmp_collection(uint8_t *col, uint8_t *model, uint8_t *updated_model,
uint32_t dst_capacity, struct cmp_cfg *cfg, int dst_size) uint32_t *dst, uint32_t dst_capacity,
struct cmp_cfg *cfg, int32_t dst_size)
{ {
int dst_size_begin = dst_size; int32_t dst_size_begin = dst_size;
int dst_size_bits; int dst_size_bits;
if (dst_size < 0) if (dst_size < 0)
...@@ -2387,7 +2388,7 @@ static int cmp_collection(uint8_t *col, uint8_t *model, uint8_t *updated_model, ...@@ -2387,7 +2388,7 @@ static int cmp_collection(uint8_t *col, uint8_t *model, uint8_t *updated_model,
return dst_size_bits; return dst_size_bits;
} }
dst_size = (int)cmp_bit_to_byte((unsigned int)dst_size_bits); /*TODO: fix casts */ dst_size = (int32_t)cmp_bit_to_byte((unsigned int)dst_size_bits); /*TODO: fix casts */
if (dst && cfg->cmp_mode != CMP_MODE_RAW) if (dst && cfg->cmp_mode != CMP_MODE_RAW)
if (set_cmp_col_size((uint8_t *)dst+dst_size_begin, dst_size-dst_size_begin)) if (set_cmp_col_size((uint8_t *)dst+dst_size_begin, dst_size-dst_size_begin))
return -1; return -1;
...@@ -2618,14 +2619,15 @@ void compress_chunk_init(uint64_t(return_timestamp)(void), uint32_t version_id) ...@@ -2618,14 +2619,15 @@ void compress_chunk_init(uint64_t(return_timestamp)(void), uint32_t version_id)
* small to hold the whole compressed data * small to hold the whole compressed data
*/ */
int compress_chunk(uint32_t *chunk, uint32_t chunk_size, uint32_t *chunk_model, int32_t compress_chunk(void *chunk, uint32_t chunk_size,
uint32_t *updated_chunk_model, uint32_t *dst, uint32_t dst_capacity, void *chunk_model, void *updated_chunk_model,
uint32_t *dst, uint32_t dst_capacity,
const struct cmp_par *cmp_par) const struct cmp_par *cmp_par)
{ {
uint64_t start_timestamp = get_timestamp(); uint64_t start_timestamp = get_timestamp();
size_t read_bytes; size_t read_bytes;
struct collection_hdr *col = (struct collection_hdr *)chunk; struct collection_hdr *col = (struct collection_hdr *)chunk;
int cmp_size_byte; /* size of the compressed data in bytes */ int32_t cmp_size_byte; /* size of the compressed data in bytes */
enum chunk_type chunk_type; enum chunk_type chunk_type;
struct cmp_cfg cfg; struct cmp_cfg cfg;
int err; int err;
...@@ -2649,11 +2651,11 @@ int compress_chunk(uint32_t *chunk, uint32_t chunk_size, uint32_t *chunk_model, ...@@ -2649,11 +2651,11 @@ int compress_chunk(uint32_t *chunk, uint32_t chunk_size, uint32_t *chunk_model,
else else
cmp_size_byte = NON_IMAGETTE_HEADER_SIZE; cmp_size_byte = NON_IMAGETTE_HEADER_SIZE;
if (dst) { if (dst) {
if (dst_capacity < (size_t)cmp_size_byte) { if (dst_capacity < (uint32_t)cmp_size_byte) {
debug_print("Error: The destination capacity is smaller than the minimum compression entity size.\n"); debug_print("Error: The destination capacity is smaller than the minimum compression entity size.\n");
return CMP_ERROR_SMALL_BUF; return CMP_ERROR_SMALL_BUF;
} }
memset(dst, 0, (size_t)cmp_size_byte); memset(dst, 0, (uint32_t)cmp_size_byte);
} }
chunk_type = cmp_col_get_chunk_type(col); chunk_type = cmp_col_get_chunk_type(col);
...@@ -2666,11 +2668,11 @@ int compress_chunk(uint32_t *chunk, uint32_t chunk_size, uint32_t *chunk_model, ...@@ -2666,11 +2668,11 @@ int compress_chunk(uint32_t *chunk, uint32_t chunk_size, uint32_t *chunk_model,
uint8_t *col_model = NULL; uint8_t *col_model = NULL;
uint8_t *col_up_model = NULL; uint8_t *col_up_model = NULL;
/* setup pointers for the next collection we want to compress */ /* setup pointers for the next collection we want to compress */
col = (struct collection_hdr *)((uint8_t *)chunk + read_bytes); /* TODO: ARE ALL COLLECTION 4 BYTE ALLIED? */ col = (struct collection_hdr *)((uint8_t *)chunk + read_bytes);
if (chunk_model) if (chunk_model)
col_model = ((uint8_t *)chunk_model + read_bytes); /* TODO: ARE ALL COLLECTION 4 BYTE ALLIED?*/ col_model = ((uint8_t *)chunk_model + read_bytes);
if (updated_chunk_model) if (updated_chunk_model)
col_up_model = ((uint8_t *)updated_chunk_model + read_bytes); /* TODO: ARE ALL COLLECTION 4 BYTE ALLIED?*/ col_up_model = ((uint8_t *)updated_chunk_model + read_bytes);
if (cmp_col_get_chunk_type(col) != chunk_type) { if (cmp_col_get_chunk_type(col) != chunk_type) {
debug_print("Error: The chunk contains collections with an incompatible mix of subservices.\n"); debug_print("Error: The chunk contains collections with an incompatible mix of subservices.\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment