diff --git a/sim_atomic.h b/sim_atomic.h index 1ad301525..ebcc7639a 100644 --- a/sim_atomic.h +++ b/sim_atomic.h @@ -172,12 +172,18 @@ static SIM_INLINE sim_atomic_type_t sim_atomic_add(sim_atomic_value_t *p, sim_at (void) __atomic_fetch_add_8(&p->value, x, __ATOMIC_ACQ_REL); # endif /* Return the updated value. */ - retval = sim_atomic_get(p); + retval = p->value; # else # error "sim_atomic_add: No __ATOMIC_ACQ_REL intrinsic?" # endif # elif defined(_WIN32) || defined(_WIN64) +# if defined(InterlockedAdd) retval = InterlockedAdd(&p->value, x); +# else + /* Older Windows InterlockedExchangeAdd, which returns the original value in p->value. */ + InterlockedExchangeAdd(&p->value, x); + retval = p->value; +# endif # else # error "sim_atomic_add: No intrinsic?" # endif @@ -206,13 +212,19 @@ static SIM_INLINE sim_atomic_type_t sim_atomic_sub(sim_atomic_value_t *p, sim_at __atomic_fetch_sub_8(&p->value, x, __ATOMIC_ACQ_REL); # endif /* Return the updated value. */ - retval = sim_atomic_get(p); + retval = p->value; # else # error "sim_atomic_sub: No __ATOMIC_ACQ_REL intrinsic?" # endif # elif defined(_WIN32) || defined(_WIN64) - /* No InterlockedSub() -- use the math identity. */ - retval = sim_atomic_add(p, -x); + /* There isn't a InterlockedSub function. Revert to basic math(s). */ +# if defined(InterlockedAdd) + retval = InterlockedAdd(&p->value, -x); +# else + /* Older Windows InterlockedExchangeAdd, which returns the original value in p->value. */ + InterlockedExchangeAdd(&p->value, -x); + retval = p->value; +# endif # else # error "sim_atomic_sub: No intrinsic?" # endif diff --git a/sim_fio.c b/sim_fio.c index 6707d9ec1..ed1f54deb 100644 --- a/sim_fio.c +++ b/sim_fio.c @@ -129,15 +129,17 @@ sim_byte_swap_data (bptr, size, count); void sim_byte_swap_data (void *bptr, size_t size, size_t count) { -uint32 j; -int32 k; +size_t j; unsigned char by, *sptr, *dptr; if (sim_end || (count == 0) || (size == sizeof (char))) return; -for (j = 0, dptr = sptr = (unsigned char *) bptr; /* loop on items */ - j < count; j++) { - for (k = (int32)(size - 1); k >= (((int32) size + 1) / 2); k--) { +dptr = sptr = (unsigned char *) bptr; +for (j = 0; j < count; j++) { /* loop on items */ + size_t k; + const size_t midpoint = (size + 1) / 2; + + for (k = size - 1; k >= midpoint; k--) { by = *sptr; /* swap end-for-end */ *sptr++ = *(dptr + k); *(dptr + k) = by;