commit 54f4031ad8b5dba6e8b54f399694aa9105b29d09
parent 59b190fe3b8c1dae705cf860ed39087c49df10bd
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 20 Jan 2021 10:26:15 +0100
Fix the suvm_volume_compute_hash function
Diffstat:
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/src/suvm_volume.c b/src/suvm_volume.c
@@ -540,19 +540,28 @@ get_chunk(char dst[64], const size_t ichunk, void* context)
const char* chunk = NULL;
size_t cpnt_offset = 0;
size_t chunk_sz = 0;
- ASSERT(dst && ctx);
+ ASSERT(dst && ctx && ctx->icpnt < 4);
+ /* Fetch the component to handle */
cpnt = ctx->cpnts + ctx->icpnt;
ASSERT(cpnt->chunk_min <= ichunk);
ASSERT(cpnt->chunk_max > ichunk);
+ /* Compute the offset into the component up to the data to copy */
cpnt_offset = (ichunk - cpnt->chunk_min) * 64;
+
+ /* Fetch the address toward the data to copy and compute the data size */
chunk = (const char*)cpnt->mem + cpnt_offset;
chunk_sz = MMIN(cpnt->size - cpnt_offset, 64);
+
+ /* Copy the component data toward the chunk */
memcpy(dst, chunk, chunk_sz);
+
+ /* Clean up the chunk from the last written byte to the end of the chunk */
if(chunk_sz < 64) memset(dst + chunk_sz, 0, 64 - chunk_sz);
- if(ichunk == cpnt->chunk_max - 1) {
+ /* Progress into the component */
+ while(ichunk == ctx->cpnts[ctx->icpnt].chunk_max - 1 && ctx->icpnt < 4) {
++ctx->icpnt;
}
}
@@ -711,10 +720,11 @@ suvm_volume_compute_hash
res_T res = RES_OK;
if(!vol || !hash) {
- res = RES_OK;
+ res = RES_BAD_ARG;
goto error;
}
+ /* Setup the components to hash */
if(cpnt_mask & SUVM_POSITIONS) {
ctx.cpnts[i].mem = darray_float_cdata_get(&vol->positions);
ctx.cpnts[i].size = darray_float_size_get(&vol->positions) * sizeof(float);
@@ -737,23 +747,23 @@ suvm_volume_compute_hash
}
ctx.ncpnts = i;
+ /* Precompute the range of chunks overlapped by each component */
FOR_EACH(i, 0, ctx.ncpnts) {
const size_t nchunks = (ctx.cpnts[i].size + 63/*ceil*/) / 64;
- if(i == ctx.ncpnts-1) {
- sz += ctx.cpnts[i].size;
- } else {
- sz += nchunks * 64;
- }
+ sz += nchunks * 64;
if(i == 0) {
ctx.cpnts[i].chunk_min = 0;
ctx.cpnts[i].chunk_max = nchunks;
} else {
- ctx.cpnts[i].chunk_max = ctx.cpnts[i-1].chunk_max;
+ ctx.cpnts[i].chunk_min = ctx.cpnts[i-1].chunk_max;
ctx.cpnts[i].chunk_max = ctx.cpnts[i-1].chunk_max + nchunks;
}
}
+
+ /* Setup the index of the 1st component to hash */
ctx.icpnt = 0;
+ /* Hash the volume data */
chunked_data.get_chunk512 = get_chunk;
chunked_data.size = sz;
chunked_data.context = &ctx;