summaryrefslogtreecommitdiffstats
path: root/src/H5V.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/H5V.c')
-rw-r--r--src/H5V.c390
1 files changed, 204 insertions, 186 deletions
diff --git a/src/H5V.c b/src/H5V.c
index ccdfffc..b2720f5 100644
--- a/src/H5V.c
+++ b/src/H5V.c
@@ -32,15 +32,15 @@
/* Local prototypes */
static void
H5V_stride_optimize1(unsigned *np/*in,out*/, hsize_t *elmt_size/*in,out*/,
- const hsize_t *size, hssize_t *stride1);
+ const hsize_t *size, hsize_t *stride1);
static void
H5V_stride_optimize2(unsigned *np/*in,out*/, hsize_t *elmt_size/*in,out*/,
- const hsize_t *size, hssize_t *stride1, hssize_t *stride2);
+ const hsize_t *size, hsize_t *stride1, hsize_t *stride2);
#ifdef LATER
static void
H5V_stride_copy2(hsize_t nelmts, hsize_t elmt_size,
- unsigned dst_n, const hsize_t *dst_size, const hssize_t *dst_stride, void *_dst,
- unsigned src_n, const hsize_t *src_size, const hssize_t *src_stride, const void *_src);
+ unsigned dst_n, const hsize_t *dst_size, const ssize_t *dst_stride, void *_dst,
+ unsigned src_n, const hsize_t *src_size, const ssize_t *src_stride, const void *_src);
#endif /* LATER */
@@ -66,7 +66,7 @@ H5V_stride_copy2(hsize_t nelmts, hsize_t elmt_size,
*/
static void
H5V_stride_optimize1(unsigned *np/*in,out*/, hsize_t *elmt_size/*in,out*/,
- const hsize_t *size, hssize_t *stride1)
+ const hsize_t *size, hsize_t *stride1)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5V_stride_optimize1);
@@ -82,10 +82,8 @@ H5V_stride_optimize1(unsigned *np/*in,out*/, hsize_t *elmt_size/*in,out*/,
while (*np && stride1[*np-1]>0 &&
(hsize_t)(stride1[*np-1])==*elmt_size) {
*elmt_size *= size[*np-1];
- if (--*np) {
- H5_CHECK_OVERFLOW(size[*np],hsize_t,hssize_t);
- stride1[*np-1] += (hssize_t)size[*np] * stride1[*np];
- }
+ if (--*np)
+ stride1[*np-1] += size[*np] * stride1[*np];
}
FUNC_LEAVE_NOAPI_VOID
@@ -117,7 +115,7 @@ H5V_stride_optimize1(unsigned *np/*in,out*/, hsize_t *elmt_size/*in,out*/,
*/
static void
H5V_stride_optimize2(unsigned *np/*in,out*/, hsize_t *elmt_size/*in,out*/,
- const hsize_t *size, hssize_t *stride1, hssize_t *stride2)
+ const hsize_t *size, hsize_t *stride1, hsize_t *stride2)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5V_stride_optimize2)
@@ -135,24 +133,20 @@ H5V_stride_optimize2(unsigned *np/*in,out*/, hsize_t *elmt_size/*in,out*/,
/* Unroll loop for common cases */
switch(*np) {
case 1: /* For 0-D datasets (dunno if this ever gets used...) */
- if((hsize_t)(stride1[0]) == *elmt_size &&
- (hsize_t)(stride2[0]) == *elmt_size) {
+ if(stride1[0] == *elmt_size && stride2[0] == *elmt_size) {
*elmt_size *= size[0];
--*np; /* *np decrements to a value of 0 now */
} /* end if */
break;
case 2: /* For 1-D datasets */
- if((hsize_t)(stride1[1]) == *elmt_size &&
- (hsize_t)(stride2[1]) == *elmt_size) {
+ if(stride1[1] == *elmt_size && stride2[1] == *elmt_size) {
*elmt_size *= size[1];
--*np; /* *np decrements to a value of 1 now */
- H5_CHECK_OVERFLOW(size[1],hsize_t,hssize_t);
- stride1[0] += (hssize_t)size[1] * stride1[1];
- stride2[0] += (hssize_t)size[1] * stride2[1];
+ stride1[0] += size[1] * stride1[1];
+ stride2[0] += size[1] * stride2[1];
- if((hsize_t)(stride1[0]) == *elmt_size &&
- (hsize_t)(stride2[0]) == *elmt_size) {
+ if(stride1[0] == *elmt_size && stride2[0] == *elmt_size) {
*elmt_size *= size[0];
--*np; /* *np decrements to a value of 0 now */
} /* end if */
@@ -160,24 +154,19 @@ H5V_stride_optimize2(unsigned *np/*in,out*/, hsize_t *elmt_size/*in,out*/,
break;
case 3: /* For 2-D datasets */
- if((hsize_t)(stride1[2]) == *elmt_size &&
- (hsize_t)(stride2[2]) == *elmt_size) {
+ if(stride1[2] == *elmt_size && stride2[2] == *elmt_size) {
*elmt_size *= size[2];
--*np; /* *np decrements to a value of 2 now */
- H5_CHECK_OVERFLOW(size[2],hsize_t,hssize_t);
- stride1[1] += (hssize_t)size[2] * stride1[2];
- stride2[1] += (hssize_t)size[2] * stride2[2];
+ stride1[1] += size[2] * stride1[2];
+ stride2[1] += size[2] * stride2[2];
- if((hsize_t)(stride1[1]) == *elmt_size &&
- (hsize_t)(stride2[1]) == *elmt_size) {
+ if(stride1[1] == *elmt_size && stride2[1] == *elmt_size) {
*elmt_size *= size[1];
--*np; /* *np decrements to a value of 1 now */
- H5_CHECK_OVERFLOW(size[1],hsize_t,hssize_t);
- stride1[0] += (hssize_t)size[1] * stride1[1];
- stride2[0] += (hssize_t)size[1] * stride2[1];
+ stride1[0] += size[1] * stride1[1];
+ stride2[0] += size[1] * stride2[1];
- if((hsize_t)(stride1[0]) == *elmt_size &&
- (hsize_t)(stride2[0]) == *elmt_size) {
+ if(stride1[0] == *elmt_size && stride2[0] == *elmt_size) {
*elmt_size *= size[0];
--*np; /* *np decrements to a value of 0 now */
} /* end if */
@@ -186,32 +175,25 @@ H5V_stride_optimize2(unsigned *np/*in,out*/, hsize_t *elmt_size/*in,out*/,
break;
case 4: /* For 3-D datasets */
- if((hsize_t)(stride1[3]) == *elmt_size &&
- (hsize_t)(stride2[3]) == *elmt_size) {
+ if(stride1[3] == *elmt_size && stride2[3] == *elmt_size) {
*elmt_size *= size[3];
--*np; /* *np decrements to a value of 3 now */
- H5_CHECK_OVERFLOW(size[3],hsize_t,hssize_t);
- stride1[2] += (hssize_t)size[3] * stride1[3];
- stride2[2] += (hssize_t)size[3] * stride2[3];
+ stride1[2] += size[3] * stride1[3];
+ stride2[2] += size[3] * stride2[3];
- if((hsize_t)(stride1[2]) == *elmt_size &&
- (hsize_t)(stride2[2]) == *elmt_size) {
+ if(stride1[2] == *elmt_size && stride2[2] == *elmt_size) {
*elmt_size *= size[2];
--*np; /* *np decrements to a value of 2 now */
- H5_CHECK_OVERFLOW(size[2],hsize_t,hssize_t);
- stride1[1] += (hssize_t)size[2] * stride1[2];
- stride2[1] += (hssize_t)size[2] * stride2[2];
+ stride1[1] += size[2] * stride1[2];
+ stride2[1] += size[2] * stride2[2];
- if((hsize_t)(stride1[1]) == *elmt_size &&
- (hsize_t)(stride2[1]) == *elmt_size) {
+ if(stride1[1] == *elmt_size && stride2[1] == *elmt_size) {
*elmt_size *= size[1];
--*np; /* *np decrements to a value of 1 now */
- H5_CHECK_OVERFLOW(size[1],hsize_t,hssize_t);
- stride1[0] += (hssize_t)size[1] * stride1[1];
- stride2[0] += (hssize_t)size[1] * stride2[1];
+ stride1[0] += size[1] * stride1[1];
+ stride2[0] += size[1] * stride2[1];
- if((hsize_t)(stride1[0]) == *elmt_size &&
- (hsize_t)(stride2[0]) == *elmt_size) {
+ if(stride1[0] == *elmt_size && stride2[0] == *elmt_size) {
*elmt_size *= size[0];
--*np; /* *np decrements to a value of 0 now */
} /* end if */
@@ -222,13 +204,12 @@ H5V_stride_optimize2(unsigned *np/*in,out*/, hsize_t *elmt_size/*in,out*/,
default:
while (*np &&
- (hsize_t)(stride1[*np-1]) == *elmt_size &&
- (hsize_t)(stride2[*np-1]) == *elmt_size) {
+ stride1[*np-1] == *elmt_size &&
+ stride2[*np-1] == *elmt_size) {
*elmt_size *= size[*np-1];
if (--*np) {
- H5_CHECK_OVERFLOW(size[*np],hsize_t,hssize_t);
- stride1[*np-1] += (hssize_t)size[*np] * stride1[*np];
- stride2[*np-1] += (hssize_t)size[*np] * stride2[*np];
+ stride1[*np-1] += size[*np] * stride1[*np];
+ stride2[*np-1] += size[*np] * stride2[*np];
}
}
break;
@@ -272,12 +253,11 @@ H5V_stride_optimize2(unsigned *np/*in,out*/, hsize_t *elmt_size/*in,out*/,
*/
hsize_t
H5V_hyper_stride(unsigned n, const hsize_t *size,
- const hsize_t *total_size, const hssize_t *offset,
- hssize_t *stride/*out*/)
+ const hsize_t *total_size, const hsize_t *offset,
+ hsize_t *stride/*out*/)
{
hsize_t skip; /*starting point byte offset */
hsize_t acc; /*accumulator */
- hsize_t tmp;
int i; /*counter */
hsize_t ret_value; /* Return value */
@@ -291,47 +271,41 @@ H5V_hyper_stride(unsigned n, const hsize_t *size,
/* init */
assert(n>0);
stride[n-1] = 1;
- skip = offset ? (hsize_t)offset[n-1] : 0;
+ skip = offset ? offset[n-1] : 0;
switch(n) {
case 2: /* 1-D dataset */
- tmp = total_size[1] - size[1];
- assert (tmp<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- stride[0] = (hssize_t)tmp; /*overflow checked*/
+ assert (total_size[1]>=size[1]);
+ stride[0] = total_size[1]-size[1]; /*overflow checked*/
acc = total_size[1];
- skip += acc * (offset ? (hsize_t)offset[0] : 0);
+ skip += acc * (offset ? offset[0] : 0);
break;
case 3: /* 2-D dataset */
- tmp = total_size[2] - size[2];
- assert (tmp<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- stride[1] = (hssize_t)tmp; /*overflow checked*/
+ assert (total_size[2]>=size[2]);
+ stride[1] = total_size[2]-size[2]; /*overflow checked*/
acc = total_size[2];
skip += acc * (offset ? (hsize_t)offset[1] : 0);
- tmp = acc * (total_size[1] - size[1]);
- assert (tmp<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- stride[0] = (hssize_t)tmp; /*overflow checked*/
+ assert (total_size[1]>=size[1]);
+ stride[0] = acc * (total_size[1] - size[1]); /*overflow checked*/
acc *= total_size[1];
skip += acc * (offset ? (hsize_t)offset[0] : 0);
break;
case 4: /* 3-D dataset */
- tmp = total_size[3] - size[3];
- assert (tmp<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- stride[2] = (hssize_t)tmp; /*overflow checked*/
+ assert (total_size[3]>=size[3]);
+ stride[2] = total_size[3]-size[3]; /*overflow checked*/
acc = total_size[3];
skip += acc * (offset ? (hsize_t)offset[2] : 0);
- tmp = acc * (total_size[2] - size[2]);
- assert (tmp<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- stride[1] = (hssize_t)tmp; /*overflow checked*/
+ assert (total_size[2]>=size[2]);
+ stride[1] = acc * (total_size[2] - size[2]); /*overflow checked*/
acc *= total_size[2];
skip += acc * (offset ? (hsize_t)offset[1] : 0);
- tmp = acc * (total_size[1] - size[1]);
- assert (tmp<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- stride[0] = (hssize_t)tmp; /*overflow checked*/
+ assert (total_size[1]>=size[1]);
+ stride[0] = acc * (total_size[1] - size[1]); /*overflow checked*/
acc *= total_size[1];
skip += acc * (offset ? (hsize_t)offset[0] : 0);
break;
@@ -339,9 +313,8 @@ H5V_hyper_stride(unsigned n, const hsize_t *size,
default:
/* others */
for (i=(int)(n-2), acc=1; i>=0; --i) {
- tmp = acc * (total_size[i+1] - size[i+1]);
- assert (tmp<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- stride[i] = (hssize_t)tmp; /*overflow checked*/
+ assert (total_size[i+1]>=size[i+1]);
+ stride[i] = acc * (total_size[i+1] - size[i+1]); /*overflow checked*/
acc *= total_size[i+1];
skip += acc * (offset ? (hsize_t)offset[i] : 0);
}
@@ -379,18 +352,18 @@ H5V_hyper_stride(unsigned n, const hsize_t *size,
*-------------------------------------------------------------------------
*/
htri_t
-H5V_hyper_eq(int n,
- const hssize_t *offset1, const hsize_t *size1,
- const hssize_t *offset2, const hsize_t *size2)
+H5V_hyper_eq(unsigned n,
+ const hsize_t *offset1, const hsize_t *size1,
+ const hsize_t *offset2, const hsize_t *size2)
{
hsize_t nelmts1 = 1, nelmts2 = 1;
- int i;
+ unsigned i;
htri_t ret_value=TRUE; /* Return value */
/* Use FUNC_ENTER_NOAPI_NOINIT_NOFUNC here to avoid performance issues */
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5V_hyper_eq)
- if (n <= 0) HGOTO_DONE(TRUE)
+ if (n == 0) HGOTO_DONE(TRUE)
for (i=0; i<n; i++) {
if ((offset1 ? offset1[i] : 0) != (offset2 ? offset2[i] : 0))
@@ -428,8 +401,8 @@ done:
*/
htri_t
H5V_hyper_disjointp(unsigned n,
- const hssize_t *offset1, const size_t *size1,
- const hssize_t *offset2, const size_t *size2)
+ const hsize_t *offset1, const size_t *size1,
+ const hsize_t *offset2, const size_t *size2)
{
unsigned u;
htri_t ret_value=FALSE; /* Return value */
@@ -440,17 +413,15 @@ H5V_hyper_disjointp(unsigned n,
if (!n || !size1 || !size2) HGOTO_DONE(TRUE)
for (u=0; u<n; u++) {
- assert (size1[u]<HSSIZET_MAX);
- assert (size2[u]<HSSIZET_MAX);
+ assert (size1[u]<HSIZET_MAX);
+ assert (size2[u]<HSIZET_MAX);
if (0==size1[u] || 0==size2[u])
HGOTO_DONE(TRUE)
if (((offset1?offset1[u]:0) < (offset2?offset2[u]:0) &&
- ((offset1?offset1[u]:0) + (hssize_t)size1[u] <=
- (offset2?offset2[u]:0))) ||
+ ((offset1?offset1[u]:0) + size1[u] <= (offset2?offset2[u]:0))) ||
((offset2?offset2[u]:0) < (offset1?offset1[u]:0) &&
- ((offset2?offset2[u]:0) + (hssize_t)size2[u] <=
- (offset1?offset1[u]:0))))
+ ((offset2?offset2[u]:0) + size2[u] <= (offset1?offset1[u]:0))))
HGOTO_DONE(TRUE)
}
@@ -482,12 +453,12 @@ done:
*/
herr_t
H5V_hyper_fill(unsigned n, const hsize_t *_size,
- const hsize_t *total_size, const hssize_t *offset, void *_dst,
+ const hsize_t *total_size, const hsize_t *offset, void *_dst,
unsigned fill_value)
{
uint8_t *dst = (uint8_t*)_dst; /*cast for ptr arithmetic */
hsize_t size[H5V_HYPER_NDIMS]; /*a modifiable copy of _size */
- hssize_t dst_stride[H5V_HYPER_NDIMS]; /*destination stride info */
+ hsize_t dst_stride[H5V_HYPER_NDIMS]; /*destination stride info */
hsize_t dst_start; /*byte offset to start of stride*/
hsize_t elmt_size = 1; /*bytes per element */
herr_t ret_value; /*function return status */
@@ -562,22 +533,20 @@ herr_t
H5V_hyper_copy(unsigned n, const hsize_t *_size,
/*destination*/
- const hsize_t *dst_size, const hssize_t *dst_offset,
+ const hsize_t *dst_size, const hsize_t *dst_offset,
void *_dst,
/*source*/
- const hsize_t *src_size, const hssize_t *src_offset,
+ const hsize_t *src_size, const hsize_t *src_offset,
const void *_src)
{
const uint8_t *src = (const uint8_t*)_src; /*cast for ptr arithmtc */
uint8_t *dst = (uint8_t*) _dst; /*cast for ptr arithmtc */
hsize_t size[H5V_HYPER_NDIMS]; /*a modifiable _size */
- hssize_t src_stride[H5V_HYPER_NDIMS]; /*source stride info */
- hssize_t dst_stride[H5V_HYPER_NDIMS]; /*dest stride info */
+ hsize_t src_stride[H5V_HYPER_NDIMS]; /*source stride info */
+ hsize_t dst_stride[H5V_HYPER_NDIMS]; /*dest stride info */
hsize_t dst_start, src_start; /*offset to start at */
hsize_t elmt_size = 1; /*element size in bytes */
- hsize_t tmp1;
- hsize_t tmp2;
herr_t ret_value; /*return status */
#ifndef NDEBUG
unsigned u;
@@ -618,96 +587,82 @@ H5V_hyper_copy(unsigned n, const hsize_t *_size,
assert(n>0);
dst_stride[n-1] = 1;
src_stride[n-1] = 1;
- dst_start = dst_offset ? (hsize_t)dst_offset[n-1] : 0;
- src_start = src_offset ? (hsize_t)src_offset[n-1] : 0;
+ dst_start = dst_offset ? dst_offset[n-1] : 0;
+ src_start = src_offset ? src_offset[n-1] : 0;
/* Unroll loop for common cases */
switch(n) {
case 2:
- tmp1 = (dst_size[1] - size[1]);
- tmp2 = (src_size[1] - size[1]);
- assert (tmp1<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- assert (tmp2<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- dst_stride[0] = (hssize_t)tmp1; /*overflow checked*/
- src_stride[0] = (hssize_t)tmp2; /*overflow checked*/
+ assert (dst_size[1]>=size[1]);
+ assert (src_size[1]>=size[1]);
+ dst_stride[0] = dst_size[1] - size[1]; /*overflow checked*/
+ src_stride[0] = src_size[1] - size[1]; /*overflow checked*/
dst_acc = dst_size[1];
src_acc = src_size[1];
- dst_start += dst_acc * (dst_offset ? (hsize_t)dst_offset[0] : 0);
- src_start += src_acc * (src_offset ? (hsize_t)src_offset[0] : 0);
+ dst_start += dst_acc * (dst_offset ? dst_offset[0] : 0);
+ src_start += src_acc * (src_offset ? src_offset[0] : 0);
break;
case 3:
- tmp1 = (dst_size[2] - size[2]);
- tmp2 = (src_size[2] - size[2]);
- assert (tmp1<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- assert (tmp2<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- dst_stride[1] = (hssize_t)tmp1; /*overflow checked*/
- src_stride[1] = (hssize_t)tmp2; /*overflow checked*/
+ assert (dst_size[2]>=size[2]);
+ assert (src_size[2]>=size[2]);
+ dst_stride[1] = dst_size[2] - size[2]; /*overflow checked*/
+ src_stride[1] = src_size[2] - size[2]; /*overflow checked*/
dst_acc = dst_size[2];
src_acc = src_size[2];
- dst_start += dst_acc * (dst_offset ? (hsize_t)dst_offset[1] : 0);
- src_start += src_acc * (src_offset ? (hsize_t)src_offset[1] : 0);
-
- tmp1 = dst_acc * (dst_size[1] - size[1]);
- tmp2 = src_acc * (src_size[1] - size[1]);
- assert (tmp1<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- assert (tmp2<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- dst_stride[0] = (hssize_t)tmp1; /*overflow checked*/
- src_stride[0] = (hssize_t)tmp2; /*overflow checked*/
+ dst_start += dst_acc * (dst_offset ? dst_offset[1] : 0);
+ src_start += src_acc * (src_offset ? src_offset[1] : 0);
+
+ assert (dst_size[1]>=size[1]);
+ assert (src_size[1]>=size[1]);
+ dst_stride[0] = dst_acc * (dst_size[1] - size[1]); /*overflow checked*/
+ src_stride[0] = src_acc * (src_size[1] - size[1]); /*overflow checked*/
dst_acc *= dst_size[1];
src_acc *= src_size[1];
- dst_start += dst_acc * (dst_offset ? (hsize_t)dst_offset[0] : 0);
- src_start += src_acc * (src_offset ? (hsize_t)src_offset[0] : 0);
+ dst_start += dst_acc * (dst_offset ? dst_offset[0] : 0);
+ src_start += src_acc * (src_offset ? src_offset[0] : 0);
break;
case 4:
- tmp1 = (dst_size[3] - size[3]);
- tmp2 = (src_size[3] - size[3]);
- assert (tmp1<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- assert (tmp2<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- dst_stride[2] = (hssize_t)tmp1; /*overflow checked*/
- src_stride[2] = (hssize_t)tmp2; /*overflow checked*/
+ assert (dst_size[3]>=size[3]);
+ assert (src_size[3]>=size[3]);
+ dst_stride[2] = dst_size[3] - size[3]; /*overflow checked*/
+ src_stride[2] = src_size[3] - size[3]; /*overflow checked*/
dst_acc = dst_size[3];
src_acc = src_size[3];
- dst_start += dst_acc * (dst_offset ? (hsize_t)dst_offset[2] : 0);
- src_start += src_acc * (src_offset ? (hsize_t)src_offset[2] : 0);
-
- tmp1 = dst_acc * (dst_size[2] - size[2]);
- tmp2 = src_acc * (src_size[2] - size[2]);
- assert (tmp1<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- assert (tmp2<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- dst_stride[1] = (hssize_t)tmp1; /*overflow checked*/
- src_stride[1] = (hssize_t)tmp2; /*overflow checked*/
+ dst_start += dst_acc * (dst_offset ? dst_offset[2] : 0);
+ src_start += src_acc * (src_offset ? src_offset[2] : 0);
+
+ assert (dst_size[2]>=size[2]);
+ assert (src_size[2]>=size[2]);
+ dst_stride[1] = dst_acc * (dst_size[2] - size[2]); /*overflow checked*/
+ src_stride[1] = src_acc * (src_size[2] - size[2]); /*overflow checked*/
dst_acc *= dst_size[2];
src_acc *= src_size[2];
- dst_start += dst_acc * (dst_offset ? (hsize_t)dst_offset[1] : 0);
- src_start += src_acc * (src_offset ? (hsize_t)src_offset[1] : 0);
-
- tmp1 = dst_acc * (dst_size[1] - size[1]);
- tmp2 = src_acc * (src_size[1] - size[1]);
- assert (tmp1<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- assert (tmp2<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- dst_stride[0] = (hssize_t)tmp1; /*overflow checked*/
- src_stride[0] = (hssize_t)tmp2; /*overflow checked*/
+ dst_start += dst_acc * (dst_offset ? dst_offset[1] : 0);
+ src_start += src_acc * (src_offset ? src_offset[1] : 0);
+
+ assert (dst_size[1]>=size[1]);
+ assert (src_size[1]>=size[1]);
+ dst_stride[0] = dst_acc * (dst_size[1] - size[1]); /*overflow checked*/
+ src_stride[0] = src_acc * (src_size[1] - size[1]); /*overflow checked*/
dst_acc *= dst_size[1];
src_acc *= src_size[1];
- dst_start += dst_acc * (dst_offset ? (hsize_t)dst_offset[0] : 0);
- src_start += src_acc * (src_offset ? (hsize_t)src_offset[0] : 0);
+ dst_start += dst_acc * (dst_offset ? dst_offset[0] : 0);
+ src_start += src_acc * (src_offset ? src_offset[0] : 0);
break;
default:
/* others */
for (ii=(int)(n-2), dst_acc=1, src_acc=1; ii>=0; --ii) {
- tmp1 = dst_acc * (dst_size[ii+1] - size[ii+1]);
- tmp2 = src_acc * (src_size[ii+1] - size[ii+1]);
- assert (tmp1<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- assert (tmp2<((hsize_t)1<<(8*sizeof(hssize_t)-1)));
- dst_stride[ii] = (hssize_t)tmp1; /*overflow checked*/
- src_stride[ii] = (hssize_t)tmp2; /*overflow checked*/
+ assert (dst_size[ii+1]>=size[ii+1]);
+ assert (src_size[ii+1]>=size[ii+1]);
+ dst_stride[ii] = dst_acc * (dst_size[ii+1] - size[ii+1]); /*overflow checked*/
+ src_stride[ii] = src_acc * (src_size[ii+1] - size[ii+1]); /*overflow checked*/
dst_acc *= dst_size[ii+1];
src_acc *= src_size[ii+1];
- dst_start += dst_acc * (dst_offset ? (hsize_t)dst_offset[ii] : 0);
- src_start += src_acc * (src_offset ? (hsize_t)src_offset[ii] : 0);
+ dst_start += dst_acc * (dst_offset ? dst_offset[ii] : 0);
+ src_start += src_acc * (src_offset ? src_offset[ii] : 0);
}
break;
} /* end switch */
@@ -742,7 +697,7 @@ H5V_hyper_copy(unsigned n, const hsize_t *_size,
*/
herr_t
H5V_stride_fill(unsigned n, hsize_t elmt_size, const hsize_t *size,
- const hssize_t *stride, void *_dst, unsigned fill_value)
+ const hsize_t *stride, void *_dst, unsigned fill_value)
{
uint8_t *dst = (uint8_t*)_dst; /*cast for ptr arithmetic */
hsize_t idx[H5V_HYPER_NDIMS]; /*1-origin indices */
@@ -801,6 +756,74 @@ H5V_stride_fill(unsigned n, hsize_t elmt_size, const hsize_t *size,
*/
herr_t
H5V_stride_copy(unsigned n, hsize_t elmt_size, const hsize_t *size,
+ const hsize_t *dst_stride, void *_dst,
+ const hsize_t *src_stride, const void *_src)
+{
+ uint8_t *dst = (uint8_t*)_dst; /*cast for ptr arithmetic*/
+ const uint8_t *src = (const uint8_t*) _src; /*cast for ptr arithmetic*/
+ hsize_t idx[H5V_HYPER_NDIMS]; /*1-origin indices */
+ hsize_t nelmts; /*num elements to copy */
+ hsize_t i; /*counter */
+ int j; /*counters */
+ hbool_t carry; /*carray for subtraction*/
+
+ FUNC_ENTER_NOAPI_NOFUNC(H5V_stride_copy)
+ assert (elmt_size<SIZET_MAX);
+
+ if (n) {
+ H5V_vector_cpy(n, idx, size);
+ nelmts = H5V_vector_reduce_product(n, size);
+ for (i=0; i<nelmts; i++) {
+
+ /* Copy an element */
+ H5_CHECK_OVERFLOW(elmt_size,hsize_t,size_t);
+ HDmemcpy(dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */
+
+ /* Decrement indices and advance pointers */
+ for (j=(int)(n-1), carry=TRUE; j>=0 && carry; --j) {
+ src += src_stride[j];
+ dst += dst_stride[j];
+
+ if (--idx[j])
+ carry = FALSE;
+ else {
+ assert(size);
+ idx[j] = size[j];
+ }
+ }
+ }
+ } else {
+ H5_CHECK_OVERFLOW(elmt_size,hsize_t,size_t);
+ HDmemcpy (dst, src, (size_t)elmt_size); /*lint !e671 The elmt_size will be OK */
+ }
+
+ FUNC_LEAVE_NOAPI(SUCCEED)
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: H5V_stride_copy_s
+ *
+ * Purpose: Uses DST_STRIDE and SRC_STRIDE to advance through the arrays
+ * DST and SRC while copying bytes from SRC to DST. This
+ * function minimizes the number of calls to memcpy() by
+ * combining various strides, but it will never touch memory
+ * outside the hyperslab defined by the strides.
+ *
+ * Note: If the src_stride is all zero and elmt_size is one, then it's
+ * probably more efficient to use H5V_stride_fill() instead.
+ *
+ * Return: Non-negative on success/Negative on failure
+ *
+ * Programmer: Robb Matzke
+ * Saturday, October 11, 1997
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+herr_t
+H5V_stride_copy_s(unsigned n, hsize_t elmt_size, const hsize_t *size,
const hssize_t *dst_stride, void *_dst,
const hssize_t *src_stride, const void *_src)
{
@@ -812,7 +835,7 @@ H5V_stride_copy(unsigned n, hsize_t elmt_size, const hsize_t *size,
int j; /*counters */
hbool_t carry; /*carray for subtraction*/
- FUNC_ENTER_NOAPI_NOFUNC(H5V_stride_copy)
+ FUNC_ENTER_NOAPI_NOFUNC(H5V_stride_copy_s)
assert (elmt_size<SIZET_MAX);
if (n) {
@@ -869,12 +892,12 @@ H5V_stride_copy2(hsize_t nelmts, hsize_t elmt_size,
/* destination */
unsigned dst_n, const hsize_t *dst_size,
- const hssize_t *dst_stride,
+ const hsize_t *dst_stride,
void *_dst,
/* source */
unsigned src_n, const hsize_t *src_size,
- const hssize_t *src_stride,
+ const hsize_t *src_stride,
const void *_src)
{
uint8_t *dst = (uint8_t *) _dst;
@@ -1046,9 +1069,8 @@ H5V_array_down(unsigned n, const hsize_t *total_size, hsize_t *down)
*-------------------------------------------------------------------------
*/
hsize_t
-H5V_array_offset_pre(unsigned n, const hsize_t *acc, const hssize_t *offset)
+H5V_array_offset_pre(unsigned n, const hsize_t *acc, const hsize_t *offset)
{
- hsize_t skip; /*starting point byte offset */
int i; /*counter */
hsize_t ret_value; /* Return value */
@@ -1059,13 +1081,8 @@ H5V_array_offset_pre(unsigned n, const hsize_t *acc, const hssize_t *offset)
assert(offset);
/* Compute offset in array */
- for (i=(int)(n-1), skip=0; i>=0; --i) {
- H5_CHECK_OVERFLOW(offset[i],hssize_t,hsize_t);
- skip += acc[i] * (hsize_t)offset[i];
- } /* end for */
-
- /* Set return value */
- ret_value=skip;
+ for (i=(int)(n-1), ret_value=0; i>=0; --i)
+ ret_value += acc[i] * offset[i];
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5V_array_offset_pre() */
@@ -1092,7 +1109,7 @@ H5V_array_offset_pre(unsigned n, const hsize_t *acc, const hssize_t *offset)
*-------------------------------------------------------------------------
*/
hsize_t
-H5V_array_offset(unsigned n, const hsize_t *total_size, const hssize_t *offset)
+H5V_array_offset(unsigned n, const hsize_t *total_size, const hsize_t *offset)
{
hsize_t acc_arr[H5V_HYPER_NDIMS]; /* Accumulated size of down dimensions */
hsize_t ret_value; /* Return value */
@@ -1136,7 +1153,7 @@ done:
*-------------------------------------------------------------------------
*/
herr_t
-H5V_array_calc(hsize_t offset, unsigned n, const hsize_t *total_size, hssize_t *coords)
+H5V_array_calc(hsize_t offset, unsigned n, const hsize_t *total_size, hsize_t *coords)
{
hsize_t idx[H5V_HYPER_NDIMS]; /* Size of each dimension in bytes */
hsize_t acc; /* Size accumulator */
@@ -1159,8 +1176,7 @@ H5V_array_calc(hsize_t offset, unsigned n, const hsize_t *total_size, hssize_t *
/* Compute the coordinates from the offset */
for(u=0; u<n; u++) {
- H5_CHECK_OVERFLOW(offset/idx[u],hsize_t,hssize_t); /*lint !e771 idx will always be initialized */
- coords[u]=(hssize_t)(offset/idx[u]);
+ coords[u]=offset/idx[u];
offset %= idx[u];
} /* end for */
@@ -1211,10 +1227,10 @@ H5V_array_calc(hsize_t offset, unsigned n, const hsize_t *total_size, hssize_t *
*-------------------------------------------------------------------------
*/
herr_t
-H5V_chunk_index(unsigned ndims, const hssize_t *coord, const size_t *chunk,
+H5V_chunk_index(unsigned ndims, const hsize_t *coord, const size_t *chunk,
const hsize_t *down_nchunks, hsize_t *chunk_idx)
{
- hssize_t scaled_coord[H5V_HYPER_NDIMS]; /* Scaled, coordinates, in terms of chunks */
+ hsize_t scaled_coord[H5V_HYPER_NDIMS]; /* Scaled, coordinates, in terms of chunks */
unsigned u; /* Local index variable */
FUNC_ENTER_NOAPI_NOFUNC(H5V_chunk_index)
@@ -1226,10 +1242,8 @@ H5V_chunk_index(unsigned ndims, const hssize_t *coord, const size_t *chunk,
assert(chunk_idx);
/* Compute the scaled coordinates for actual coordinates */
- for(u=0; u<ndims; u++) {
- H5_CHECK_OVERFLOW(chunk[u],size_t,hssize_t);
- scaled_coord[u]=coord[u]/(hssize_t)chunk[u];
- } /* end for */
+ for(u=0; u<ndims; u++)
+ scaled_coord[u]=coord[u]/chunk[u];
/* Compute the chunk index */
*chunk_idx=H5V_array_offset_pre(ndims,down_nchunks,scaled_coord); /*lint !e772 scaled_coord will always be initialized */
@@ -1268,9 +1282,10 @@ H5V_memcpyvv(void *_dst,
{
unsigned char *dst; /* Destination buffer pointer */
const unsigned char *src; /* Source buffer pointer */
+ size_t total_size=0; /* Total size of sequence in bytes */
size_t size; /* Size of sequence in bytes */
size_t u,v; /* Local index variables */
- ssize_t ret_value=0; /* Return value */
+ ssize_t ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOFUNC(H5V_memcpyvv)
@@ -1316,13 +1331,16 @@ H5V_memcpyvv(void *_dst,
u++;
/* Increment number of bytes copied */
- ret_value+=(ssize_t)size;
+ total_size+=size;
} /* end for */
/* Update current sequence vectors */
*dst_curr_seq=u;
*src_curr_seq=v;
+ /* Set return value */
+ H5_ASSIGN_OVERFLOW(ret_value,total_size,size_t,ssize_t);
+
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5V_memcpyvv() */