mirror of
https://github.com/jemalloc/jemalloc.git
synced 2026-04-18 00:21:41 +03:00
Reformat the codebase with the clang-format 18.
This commit is contained in:
parent
0a6215c171
commit
f1bba4a87c
346 changed files with 18286 additions and 17770 deletions
739
test/src/SFMT.c
739
test/src/SFMT.c
|
|
@ -50,19 +50,19 @@
|
|||
#include "test/SFMT-params.h"
|
||||
|
||||
#if defined(JEMALLOC_BIG_ENDIAN) && !defined(BIG_ENDIAN64)
|
||||
#define BIG_ENDIAN64 1
|
||||
# define BIG_ENDIAN64 1
|
||||
#endif
|
||||
#if defined(__BIG_ENDIAN__) && !defined(__amd64) && !defined(BIG_ENDIAN64)
|
||||
#define BIG_ENDIAN64 1
|
||||
# define BIG_ENDIAN64 1
|
||||
#endif
|
||||
#if defined(HAVE_ALTIVEC) && !defined(BIG_ENDIAN64)
|
||||
#define BIG_ENDIAN64 1
|
||||
# define BIG_ENDIAN64 1
|
||||
#endif
|
||||
#if defined(ONLY64) && !defined(BIG_ENDIAN64)
|
||||
#if defined(__GNUC__)
|
||||
#error "-DONLY64 must be specified with -DBIG_ENDIAN64"
|
||||
#endif
|
||||
#undef ONLY64
|
||||
# if defined(__GNUC__)
|
||||
# error "-DONLY64 must be specified with -DBIG_ENDIAN64"
|
||||
# endif
|
||||
# undef ONLY64
|
||||
#endif
|
||||
/*------------------------------------------------------
|
||||
128-bit SIMD data type for Altivec, SSE2 or standard C
|
||||
|
|
@ -70,8 +70,8 @@
|
|||
#if defined(HAVE_ALTIVEC)
|
||||
/** 128-bit data structure */
|
||||
union W128_T {
|
||||
vector unsigned int s;
|
||||
uint32_t u[4];
|
||||
vector unsigned int s;
|
||||
uint32_t u[4];
|
||||
};
|
||||
/** 128-bit data type */
|
||||
typedef union W128_T w128_t;
|
||||
|
|
@ -79,8 +79,8 @@ typedef union W128_T w128_t;
|
|||
#elif defined(HAVE_SSE2)
|
||||
/** 128-bit data structure */
|
||||
union W128_T {
|
||||
__m128i si;
|
||||
uint32_t u[4];
|
||||
__m128i si;
|
||||
uint32_t u[4];
|
||||
};
|
||||
/** 128-bit data type */
|
||||
typedef union W128_T w128_t;
|
||||
|
|
@ -89,7 +89,7 @@ typedef union W128_T w128_t;
|
|||
|
||||
/** 128-bit data structure */
|
||||
struct W128_T {
|
||||
uint32_t u[4];
|
||||
uint32_t u[4];
|
||||
};
|
||||
/** 128-bit data type */
|
||||
typedef struct W128_T w128_t;
|
||||
|
|
@ -97,13 +97,13 @@ typedef struct W128_T w128_t;
|
|||
#endif
|
||||
|
||||
struct sfmt_s {
|
||||
/** the 128-bit internal state array */
|
||||
w128_t sfmt[N];
|
||||
/** index counter to the 32-bit internal state array */
|
||||
int idx;
|
||||
/** a flag: it is 0 if and only if the internal state is not yet
|
||||
/** the 128-bit internal state array */
|
||||
w128_t sfmt[N];
|
||||
/** index counter to the 32-bit internal state array */
|
||||
int idx;
|
||||
/** a flag: it is 0 if and only if the internal state is not yet
|
||||
* initialized. */
|
||||
int initialized;
|
||||
int initialized;
|
||||
};
|
||||
|
||||
/*--------------------------------------
|
||||
|
|
@ -119,22 +119,22 @@ static uint32_t parity[4] = {PARITY1, PARITY2, PARITY3, PARITY4};
|
|||
----------------*/
|
||||
static inline int idxof(int i);
|
||||
#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
|
||||
static inline void rshift128(w128_t *out, w128_t const *in, int shift);
|
||||
static inline void lshift128(w128_t *out, w128_t const *in, int shift);
|
||||
static inline void rshift128(w128_t *out, w128_t const *in, int shift);
|
||||
static inline void lshift128(w128_t *out, w128_t const *in, int shift);
|
||||
#endif
|
||||
static inline void gen_rand_all(sfmt_t *ctx);
|
||||
static inline void gen_rand_array(sfmt_t *ctx, w128_t *array, int size);
|
||||
static inline void gen_rand_all(sfmt_t *ctx);
|
||||
static inline void gen_rand_array(sfmt_t *ctx, w128_t *array, int size);
|
||||
static inline uint32_t func1(uint32_t x);
|
||||
static inline uint32_t func2(uint32_t x);
|
||||
static void period_certification(sfmt_t *ctx);
|
||||
static void period_certification(sfmt_t *ctx);
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64)
|
||||
static inline void swap(w128_t *array, int size);
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ALTIVEC)
|
||||
#include "test/SFMT-alti.h"
|
||||
# include "test/SFMT-alti.h"
|
||||
#elif defined(HAVE_SSE2)
|
||||
#include "test/SFMT-sse2.h"
|
||||
# include "test/SFMT-sse2.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
@ -142,12 +142,14 @@ static inline void swap(w128_t *array, int size);
|
|||
* in BIG ENDIAN machine.
|
||||
*/
|
||||
#ifdef ONLY64
|
||||
static inline int idxof(int i) {
|
||||
return i ^ 1;
|
||||
static inline int
|
||||
idxof(int i) {
|
||||
return i ^ 1;
|
||||
}
|
||||
#else
|
||||
static inline int idxof(int i) {
|
||||
return i;
|
||||
static inline int
|
||||
idxof(int i) {
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
|
|
@ -159,37 +161,39 @@ static inline int idxof(int i) {
|
|||
* @param shift the shift value
|
||||
*/
|
||||
#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
|
||||
#ifdef ONLY64
|
||||
static inline void rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
# ifdef ONLY64
|
||||
static inline void
|
||||
rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
|
||||
tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
|
||||
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
|
||||
tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
|
||||
|
||||
oh = th >> (shift * 8);
|
||||
ol = tl >> (shift * 8);
|
||||
ol |= th << (64 - shift * 8);
|
||||
out->u[0] = (uint32_t)(ol >> 32);
|
||||
out->u[1] = (uint32_t)ol;
|
||||
out->u[2] = (uint32_t)(oh >> 32);
|
||||
out->u[3] = (uint32_t)oh;
|
||||
oh = th >> (shift * 8);
|
||||
ol = tl >> (shift * 8);
|
||||
ol |= th << (64 - shift * 8);
|
||||
out->u[0] = (uint32_t)(ol >> 32);
|
||||
out->u[1] = (uint32_t)ol;
|
||||
out->u[2] = (uint32_t)(oh >> 32);
|
||||
out->u[3] = (uint32_t)oh;
|
||||
}
|
||||
#else
|
||||
static inline void rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
# else
|
||||
static inline void
|
||||
rshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
|
||||
tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
|
||||
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
|
||||
tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
|
||||
|
||||
oh = th >> (shift * 8);
|
||||
ol = tl >> (shift * 8);
|
||||
ol |= th << (64 - shift * 8);
|
||||
out->u[1] = (uint32_t)(ol >> 32);
|
||||
out->u[0] = (uint32_t)ol;
|
||||
out->u[3] = (uint32_t)(oh >> 32);
|
||||
out->u[2] = (uint32_t)oh;
|
||||
oh = th >> (shift * 8);
|
||||
ol = tl >> (shift * 8);
|
||||
ol |= th << (64 - shift * 8);
|
||||
out->u[1] = (uint32_t)(ol >> 32);
|
||||
out->u[0] = (uint32_t)ol;
|
||||
out->u[3] = (uint32_t)(oh >> 32);
|
||||
out->u[2] = (uint32_t)oh;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
/**
|
||||
* This function simulates SIMD 128-bit left shift by the standard C.
|
||||
* The 128-bit integer given in in is shifted by (shift * 8) bits.
|
||||
|
|
@ -198,37 +202,39 @@ static inline void rshift128(w128_t *out, w128_t const *in, int shift) {
|
|||
* @param in the 128-bit data to be shifted
|
||||
* @param shift the shift value
|
||||
*/
|
||||
#ifdef ONLY64
|
||||
static inline void lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
# ifdef ONLY64
|
||||
static inline void
|
||||
lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
|
||||
tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
|
||||
th = ((uint64_t)in->u[2] << 32) | ((uint64_t)in->u[3]);
|
||||
tl = ((uint64_t)in->u[0] << 32) | ((uint64_t)in->u[1]);
|
||||
|
||||
oh = th << (shift * 8);
|
||||
ol = tl << (shift * 8);
|
||||
oh |= tl >> (64 - shift * 8);
|
||||
out->u[0] = (uint32_t)(ol >> 32);
|
||||
out->u[1] = (uint32_t)ol;
|
||||
out->u[2] = (uint32_t)(oh >> 32);
|
||||
out->u[3] = (uint32_t)oh;
|
||||
oh = th << (shift * 8);
|
||||
ol = tl << (shift * 8);
|
||||
oh |= tl >> (64 - shift * 8);
|
||||
out->u[0] = (uint32_t)(ol >> 32);
|
||||
out->u[1] = (uint32_t)ol;
|
||||
out->u[2] = (uint32_t)(oh >> 32);
|
||||
out->u[3] = (uint32_t)oh;
|
||||
}
|
||||
#else
|
||||
static inline void lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
# else
|
||||
static inline void
|
||||
lshift128(w128_t *out, w128_t const *in, int shift) {
|
||||
uint64_t th, tl, oh, ol;
|
||||
|
||||
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
|
||||
tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
|
||||
th = ((uint64_t)in->u[3] << 32) | ((uint64_t)in->u[2]);
|
||||
tl = ((uint64_t)in->u[1] << 32) | ((uint64_t)in->u[0]);
|
||||
|
||||
oh = th << (shift * 8);
|
||||
ol = tl << (shift * 8);
|
||||
oh |= tl >> (64 - shift * 8);
|
||||
out->u[1] = (uint32_t)(ol >> 32);
|
||||
out->u[0] = (uint32_t)ol;
|
||||
out->u[3] = (uint32_t)(oh >> 32);
|
||||
out->u[2] = (uint32_t)oh;
|
||||
oh = th << (shift * 8);
|
||||
ol = tl << (shift * 8);
|
||||
oh |= tl >> (64 - shift * 8);
|
||||
out->u[1] = (uint32_t)(ol >> 32);
|
||||
out->u[0] = (uint32_t)ol;
|
||||
out->u[3] = (uint32_t)(oh >> 32);
|
||||
out->u[2] = (uint32_t)oh;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
|
@ -240,41 +246,41 @@ static inline void lshift128(w128_t *out, w128_t const *in, int shift) {
|
|||
* @param d a 128-bit part of the internal state array
|
||||
*/
|
||||
#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
|
||||
#ifdef ONLY64
|
||||
static inline void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
|
||||
w128_t *d) {
|
||||
w128_t x;
|
||||
w128_t y;
|
||||
# ifdef ONLY64
|
||||
static inline void
|
||||
do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c, w128_t *d) {
|
||||
w128_t x;
|
||||
w128_t y;
|
||||
|
||||
lshift128(&x, a, SL2);
|
||||
rshift128(&y, c, SR2);
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK2) ^ y.u[0]
|
||||
^ (d->u[0] << SL1);
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK1) ^ y.u[1]
|
||||
^ (d->u[1] << SL1);
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK4) ^ y.u[2]
|
||||
^ (d->u[2] << SL1);
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK3) ^ y.u[3]
|
||||
^ (d->u[3] << SL1);
|
||||
lshift128(&x, a, SL2);
|
||||
rshift128(&y, c, SR2);
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK2) ^ y.u[0]
|
||||
^ (d->u[0] << SL1);
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK1) ^ y.u[1]
|
||||
^ (d->u[1] << SL1);
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK4) ^ y.u[2]
|
||||
^ (d->u[2] << SL1);
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK3) ^ y.u[3]
|
||||
^ (d->u[3] << SL1);
|
||||
}
|
||||
#else
|
||||
static inline void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
|
||||
w128_t *d) {
|
||||
w128_t x;
|
||||
w128_t y;
|
||||
# else
|
||||
static inline void
|
||||
do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c, w128_t *d) {
|
||||
w128_t x;
|
||||
w128_t y;
|
||||
|
||||
lshift128(&x, a, SL2);
|
||||
rshift128(&y, c, SR2);
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK1) ^ y.u[0]
|
||||
^ (d->u[0] << SL1);
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK2) ^ y.u[1]
|
||||
^ (d->u[1] << SL1);
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK3) ^ y.u[2]
|
||||
^ (d->u[2] << SL1);
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK4) ^ y.u[3]
|
||||
^ (d->u[3] << SL1);
|
||||
lshift128(&x, a, SL2);
|
||||
rshift128(&y, c, SR2);
|
||||
r->u[0] = a->u[0] ^ x.u[0] ^ ((b->u[0] >> SR1) & MSK1) ^ y.u[0]
|
||||
^ (d->u[0] << SL1);
|
||||
r->u[1] = a->u[1] ^ x.u[1] ^ ((b->u[1] >> SR1) & MSK2) ^ y.u[1]
|
||||
^ (d->u[1] << SL1);
|
||||
r->u[2] = a->u[2] ^ x.u[2] ^ ((b->u[2] >> SR1) & MSK3) ^ y.u[2]
|
||||
^ (d->u[2] << SL1);
|
||||
r->u[3] = a->u[3] ^ x.u[3] ^ ((b->u[3] >> SR1) & MSK4) ^ y.u[3]
|
||||
^ (d->u[3] << SL1);
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if (!defined(HAVE_ALTIVEC)) && (!defined(HAVE_SSE2))
|
||||
|
|
@ -282,24 +288,25 @@ static inline void do_recursion(w128_t *r, w128_t *a, w128_t *b, w128_t *c,
|
|||
* This function fills the internal state array with pseudorandom
|
||||
* integers.
|
||||
*/
|
||||
static inline void gen_rand_all(sfmt_t *ctx) {
|
||||
int i;
|
||||
w128_t *r1, *r2;
|
||||
static inline void
|
||||
gen_rand_all(sfmt_t *ctx) {
|
||||
int i;
|
||||
w128_t *r1, *r2;
|
||||
|
||||
r1 = &ctx->sfmt[N - 2];
|
||||
r2 = &ctx->sfmt[N - 1];
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
do_recursion(&ctx->sfmt[i], &ctx->sfmt[i], &ctx->sfmt[i + POS1], r1,
|
||||
r2);
|
||||
r1 = r2;
|
||||
r2 = &ctx->sfmt[i];
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
do_recursion(&ctx->sfmt[i], &ctx->sfmt[i], &ctx->sfmt[i + POS1 - N], r1,
|
||||
r2);
|
||||
r1 = r2;
|
||||
r2 = &ctx->sfmt[i];
|
||||
}
|
||||
r1 = &ctx->sfmt[N - 2];
|
||||
r2 = &ctx->sfmt[N - 1];
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
do_recursion(
|
||||
&ctx->sfmt[i], &ctx->sfmt[i], &ctx->sfmt[i + POS1], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &ctx->sfmt[i];
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
do_recursion(&ctx->sfmt[i], &ctx->sfmt[i],
|
||||
&ctx->sfmt[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &ctx->sfmt[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -309,52 +316,58 @@ static inline void gen_rand_all(sfmt_t *ctx) {
|
|||
* @param array an 128-bit array to be filled by pseudorandom numbers.
|
||||
* @param size number of 128-bit pseudorandom numbers to be generated.
|
||||
*/
|
||||
static inline void gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
||||
int i, j;
|
||||
w128_t *r1, *r2;
|
||||
static inline void
|
||||
gen_rand_array(sfmt_t *ctx, w128_t *array, int size) {
|
||||
int i, j;
|
||||
w128_t *r1, *r2;
|
||||
|
||||
r1 = &ctx->sfmt[N - 2];
|
||||
r2 = &ctx->sfmt[N - 1];
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
do_recursion(&array[i], &ctx->sfmt[i], &ctx->sfmt[i + POS1], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
do_recursion(&array[i], &ctx->sfmt[i], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (; i < size - N; i++) {
|
||||
do_recursion(&array[i], &array[i - N], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (j = 0; j < 2 * N - size; j++) {
|
||||
ctx->sfmt[j] = array[j + size - N];
|
||||
}
|
||||
for (; i < size; i++, j++) {
|
||||
do_recursion(&array[i], &array[i - N], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
ctx->sfmt[j] = array[i];
|
||||
}
|
||||
r1 = &ctx->sfmt[N - 2];
|
||||
r2 = &ctx->sfmt[N - 1];
|
||||
for (i = 0; i < N - POS1; i++) {
|
||||
do_recursion(
|
||||
&array[i], &ctx->sfmt[i], &ctx->sfmt[i + POS1], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (; i < N; i++) {
|
||||
do_recursion(
|
||||
&array[i], &ctx->sfmt[i], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (; i < size - N; i++) {
|
||||
do_recursion(
|
||||
&array[i], &array[i - N], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
}
|
||||
for (j = 0; j < 2 * N - size; j++) {
|
||||
ctx->sfmt[j] = array[j + size - N];
|
||||
}
|
||||
for (; i < size; i++, j++) {
|
||||
do_recursion(
|
||||
&array[i], &array[i - N], &array[i + POS1 - N], r1, r2);
|
||||
r1 = r2;
|
||||
r2 = &array[i];
|
||||
ctx->sfmt[j] = array[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64) && !defined(HAVE_ALTIVEC)
|
||||
static inline void swap(w128_t *array, int size) {
|
||||
int i;
|
||||
uint32_t x, y;
|
||||
static inline void
|
||||
swap(w128_t *array, int size) {
|
||||
int i;
|
||||
uint32_t x, y;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
x = array[i].u[0];
|
||||
y = array[i].u[2];
|
||||
array[i].u[0] = array[i].u[1];
|
||||
array[i].u[2] = array[i].u[3];
|
||||
array[i].u[1] = x;
|
||||
array[i].u[3] = y;
|
||||
}
|
||||
for (i = 0; i < size; i++) {
|
||||
x = array[i].u[0];
|
||||
y = array[i].u[2];
|
||||
array[i].u[0] = array[i].u[1];
|
||||
array[i].u[2] = array[i].u[3];
|
||||
array[i].u[1] = x;
|
||||
array[i].u[3] = y;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
|
|
@ -363,8 +376,9 @@ static inline void swap(w128_t *array, int size) {
|
|||
* @param x 32-bit integer
|
||||
* @return 32-bit integer
|
||||
*/
|
||||
static uint32_t func1(uint32_t x) {
|
||||
return (x ^ (x >> 27)) * (uint32_t)1664525UL;
|
||||
static uint32_t
|
||||
func1(uint32_t x) {
|
||||
return (x ^ (x >> 27)) * (uint32_t)1664525UL;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -373,39 +387,41 @@ static uint32_t func1(uint32_t x) {
|
|||
* @param x 32-bit integer
|
||||
* @return 32-bit integer
|
||||
*/
|
||||
static uint32_t func2(uint32_t x) {
|
||||
return (x ^ (x >> 27)) * (uint32_t)1566083941UL;
|
||||
static uint32_t
|
||||
func2(uint32_t x) {
|
||||
return (x ^ (x >> 27)) * (uint32_t)1566083941UL;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function certificate the period of 2^{MEXP}
|
||||
*/
|
||||
static void period_certification(sfmt_t *ctx) {
|
||||
int inner = 0;
|
||||
int i, j;
|
||||
uint32_t work;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
static void
|
||||
period_certification(sfmt_t *ctx) {
|
||||
int inner = 0;
|
||||
int i, j;
|
||||
uint32_t work;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
inner ^= psfmt32[idxof(i)] & parity[i];
|
||||
for (i = 16; i > 0; i >>= 1)
|
||||
inner ^= inner >> i;
|
||||
inner &= 1;
|
||||
/* check OK */
|
||||
if (inner == 1) {
|
||||
return;
|
||||
}
|
||||
/* check NG, and modification */
|
||||
for (i = 0; i < 4; i++) {
|
||||
work = 1;
|
||||
for (j = 0; j < 32; j++) {
|
||||
if ((work & parity[i]) != 0) {
|
||||
psfmt32[idxof(i)] ^= work;
|
||||
for (i = 0; i < 4; i++)
|
||||
inner ^= psfmt32[idxof(i)] & parity[i];
|
||||
for (i = 16; i > 0; i >>= 1)
|
||||
inner ^= inner >> i;
|
||||
inner &= 1;
|
||||
/* check OK */
|
||||
if (inner == 1) {
|
||||
return;
|
||||
}
|
||||
work = work << 1;
|
||||
}
|
||||
}
|
||||
/* check NG, and modification */
|
||||
for (i = 0; i < 4; i++) {
|
||||
work = 1;
|
||||
for (j = 0; j < 32; j++) {
|
||||
if ((work & parity[i]) != 0) {
|
||||
psfmt32[idxof(i)] ^= work;
|
||||
return;
|
||||
}
|
||||
work = work << 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------
|
||||
|
|
@ -416,8 +432,9 @@ static void period_certification(sfmt_t *ctx) {
|
|||
* The string shows the word size, the Mersenne exponent,
|
||||
* and all parameters of this generator.
|
||||
*/
|
||||
const char *get_idstring(void) {
|
||||
return IDSTR;
|
||||
const char *
|
||||
get_idstring(void) {
|
||||
return IDSTR;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -425,8 +442,9 @@ const char *get_idstring(void) {
|
|||
* fill_array32() function.
|
||||
* @return minimum size of array used for fill_array32() function.
|
||||
*/
|
||||
int get_min_array_size32(void) {
|
||||
return N32;
|
||||
int
|
||||
get_min_array_size32(void) {
|
||||
return N32;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -434,8 +452,9 @@ int get_min_array_size32(void) {
|
|||
* fill_array64() function.
|
||||
* @return minimum size of array used for fill_array64() function.
|
||||
*/
|
||||
int get_min_array_size64(void) {
|
||||
return N64;
|
||||
int
|
||||
get_min_array_size64(void) {
|
||||
return N64;
|
||||
}
|
||||
|
||||
#ifndef ONLY64
|
||||
|
|
@ -444,32 +463,34 @@ int get_min_array_size64(void) {
|
|||
* init_gen_rand or init_by_array must be called before this function.
|
||||
* @return 32-bit pseudorandom number
|
||||
*/
|
||||
uint32_t gen_rand32(sfmt_t *ctx) {
|
||||
uint32_t r;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
uint32_t
|
||||
gen_rand32(sfmt_t *ctx) {
|
||||
uint32_t r;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
|
||||
assert(ctx->initialized);
|
||||
if (ctx->idx >= N32) {
|
||||
gen_rand_all(ctx);
|
||||
ctx->idx = 0;
|
||||
}
|
||||
r = psfmt32[ctx->idx++];
|
||||
return r;
|
||||
assert(ctx->initialized);
|
||||
if (ctx->idx >= N32) {
|
||||
gen_rand_all(ctx);
|
||||
ctx->idx = 0;
|
||||
}
|
||||
r = psfmt32[ctx->idx++];
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Generate a random integer in [0..limit). */
|
||||
uint32_t gen_rand32_range(sfmt_t *ctx, uint32_t limit) {
|
||||
uint32_t ret, above;
|
||||
uint32_t
|
||||
gen_rand32_range(sfmt_t *ctx, uint32_t limit) {
|
||||
uint32_t ret, above;
|
||||
|
||||
above = 0xffffffffU - (0xffffffffU % limit);
|
||||
while (1) {
|
||||
ret = gen_rand32(ctx);
|
||||
if (ret < above) {
|
||||
ret %= limit;
|
||||
break;
|
||||
above = 0xffffffffU - (0xffffffffU % limit);
|
||||
while (1) {
|
||||
ret = gen_rand32(ctx);
|
||||
if (ret < above) {
|
||||
ret %= limit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
|
|
@ -479,47 +500,49 @@ uint32_t gen_rand32_range(sfmt_t *ctx, uint32_t limit) {
|
|||
* unless an initialization is again executed.
|
||||
* @return 64-bit pseudorandom number
|
||||
*/
|
||||
uint64_t gen_rand64(sfmt_t *ctx) {
|
||||
uint64_t
|
||||
gen_rand64(sfmt_t *ctx) {
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64)
|
||||
uint32_t r1, r2;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
uint32_t r1, r2;
|
||||
uint32_t *psfmt32 = &ctx->sfmt[0].u[0];
|
||||
#else
|
||||
uint64_t r;
|
||||
uint64_t *psfmt64 = (uint64_t *)&ctx->sfmt[0].u[0];
|
||||
uint64_t r;
|
||||
uint64_t *psfmt64 = (uint64_t *)&ctx->sfmt[0].u[0];
|
||||
#endif
|
||||
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx % 2 == 0);
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx % 2 == 0);
|
||||
|
||||
if (ctx->idx >= N32) {
|
||||
gen_rand_all(ctx);
|
||||
ctx->idx = 0;
|
||||
}
|
||||
if (ctx->idx >= N32) {
|
||||
gen_rand_all(ctx);
|
||||
ctx->idx = 0;
|
||||
}
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64)
|
||||
r1 = psfmt32[ctx->idx];
|
||||
r2 = psfmt32[ctx->idx + 1];
|
||||
ctx->idx += 2;
|
||||
return ((uint64_t)r2 << 32) | r1;
|
||||
r1 = psfmt32[ctx->idx];
|
||||
r2 = psfmt32[ctx->idx + 1];
|
||||
ctx->idx += 2;
|
||||
return ((uint64_t)r2 << 32) | r1;
|
||||
#else
|
||||
r = psfmt64[ctx->idx / 2];
|
||||
ctx->idx += 2;
|
||||
return r;
|
||||
r = psfmt64[ctx->idx / 2];
|
||||
ctx->idx += 2;
|
||||
return r;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Generate a random integer in [0..limit). */
|
||||
uint64_t gen_rand64_range(sfmt_t *ctx, uint64_t limit) {
|
||||
uint64_t ret, above;
|
||||
uint64_t
|
||||
gen_rand64_range(sfmt_t *ctx, uint64_t limit) {
|
||||
uint64_t ret, above;
|
||||
|
||||
above = KQU(0xffffffffffffffff) - (KQU(0xffffffffffffffff) % limit);
|
||||
while (1) {
|
||||
ret = gen_rand64(ctx);
|
||||
if (ret < above) {
|
||||
ret %= limit;
|
||||
break;
|
||||
above = KQU(0xffffffffffffffff) - (KQU(0xffffffffffffffff) % limit);
|
||||
while (1) {
|
||||
ret = gen_rand64(ctx);
|
||||
if (ret < above) {
|
||||
ret %= limit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef ONLY64
|
||||
|
|
@ -548,14 +571,15 @@ uint64_t gen_rand64_range(sfmt_t *ctx, uint64_t limit) {
|
|||
* memory. Mac OSX doesn't have these functions, but \b malloc of OSX
|
||||
* returns the pointer to the aligned memory block.
|
||||
*/
|
||||
void fill_array32(sfmt_t *ctx, uint32_t *array, int size) {
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx == N32);
|
||||
assert(size % 4 == 0);
|
||||
assert(size >= N32);
|
||||
void
|
||||
fill_array32(sfmt_t *ctx, uint32_t *array, int size) {
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx == N32);
|
||||
assert(size % 4 == 0);
|
||||
assert(size >= N32);
|
||||
|
||||
gen_rand_array(ctx, (w128_t *)array, size / 4);
|
||||
ctx->idx = N32;
|
||||
gen_rand_array(ctx, (w128_t *)array, size / 4);
|
||||
ctx->idx = N32;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -584,17 +608,18 @@ void fill_array32(sfmt_t *ctx, uint32_t *array, int size) {
|
|||
* memory. Mac OSX doesn't have these functions, but \b malloc of OSX
|
||||
* returns the pointer to the aligned memory block.
|
||||
*/
|
||||
void fill_array64(sfmt_t *ctx, uint64_t *array, int size) {
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx == N32);
|
||||
assert(size % 2 == 0);
|
||||
assert(size >= N64);
|
||||
void
|
||||
fill_array64(sfmt_t *ctx, uint64_t *array, int size) {
|
||||
assert(ctx->initialized);
|
||||
assert(ctx->idx == N32);
|
||||
assert(size % 2 == 0);
|
||||
assert(size >= N64);
|
||||
|
||||
gen_rand_array(ctx, (w128_t *)array, size / 2);
|
||||
ctx->idx = N32;
|
||||
gen_rand_array(ctx, (w128_t *)array, size / 2);
|
||||
ctx->idx = N32;
|
||||
|
||||
#if defined(BIG_ENDIAN64) && !defined(ONLY64)
|
||||
swap((w128_t *)array, size /2);
|
||||
swap((w128_t *)array, size / 2);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -604,29 +629,31 @@ void fill_array64(sfmt_t *ctx, uint64_t *array, int size) {
|
|||
*
|
||||
* @param seed a 32-bit integer used as the seed.
|
||||
*/
|
||||
sfmt_t *init_gen_rand(uint32_t seed) {
|
||||
void *p;
|
||||
sfmt_t *ctx;
|
||||
int i;
|
||||
uint32_t *psfmt32;
|
||||
sfmt_t *
|
||||
init_gen_rand(uint32_t seed) {
|
||||
void *p;
|
||||
sfmt_t *ctx;
|
||||
int i;
|
||||
uint32_t *psfmt32;
|
||||
|
||||
if (posix_memalign(&p, sizeof(w128_t), sizeof(sfmt_t)) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = (sfmt_t *)p;
|
||||
psfmt32 = &ctx->sfmt[0].u[0];
|
||||
if (posix_memalign(&p, sizeof(w128_t), sizeof(sfmt_t)) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = (sfmt_t *)p;
|
||||
psfmt32 = &ctx->sfmt[0].u[0];
|
||||
|
||||
psfmt32[idxof(0)] = seed;
|
||||
for (i = 1; i < N32; i++) {
|
||||
psfmt32[idxof(i)] = 1812433253UL * (psfmt32[idxof(i - 1)]
|
||||
^ (psfmt32[idxof(i - 1)] >> 30))
|
||||
+ i;
|
||||
}
|
||||
ctx->idx = N32;
|
||||
period_certification(ctx);
|
||||
ctx->initialized = 1;
|
||||
psfmt32[idxof(0)] = seed;
|
||||
for (i = 1; i < N32; i++) {
|
||||
psfmt32[idxof(i)] = 1812433253UL
|
||||
* (psfmt32[idxof(i - 1)]
|
||||
^ (psfmt32[idxof(i - 1)] >> 30))
|
||||
+ i;
|
||||
}
|
||||
ctx->idx = N32;
|
||||
period_certification(ctx);
|
||||
ctx->initialized = 1;
|
||||
|
||||
return ctx;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -635,85 +662,87 @@ sfmt_t *init_gen_rand(uint32_t seed) {
|
|||
* @param init_key the array of 32-bit integers, used as a seed.
|
||||
* @param key_length the length of init_key.
|
||||
*/
|
||||
sfmt_t *init_by_array(uint32_t *init_key, int key_length) {
|
||||
void *p;
|
||||
sfmt_t *ctx;
|
||||
int i, j, count;
|
||||
uint32_t r;
|
||||
int lag;
|
||||
int mid;
|
||||
int size = N * 4;
|
||||
uint32_t *psfmt32;
|
||||
sfmt_t *
|
||||
init_by_array(uint32_t *init_key, int key_length) {
|
||||
void *p;
|
||||
sfmt_t *ctx;
|
||||
int i, j, count;
|
||||
uint32_t r;
|
||||
int lag;
|
||||
int mid;
|
||||
int size = N * 4;
|
||||
uint32_t *psfmt32;
|
||||
|
||||
if (posix_memalign(&p, sizeof(w128_t), sizeof(sfmt_t)) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = (sfmt_t *)p;
|
||||
psfmt32 = &ctx->sfmt[0].u[0];
|
||||
if (posix_memalign(&p, sizeof(w128_t), sizeof(sfmt_t)) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
ctx = (sfmt_t *)p;
|
||||
psfmt32 = &ctx->sfmt[0].u[0];
|
||||
|
||||
if (size >= 623) {
|
||||
lag = 11;
|
||||
} else if (size >= 68) {
|
||||
lag = 7;
|
||||
} else if (size >= 39) {
|
||||
lag = 5;
|
||||
} else {
|
||||
lag = 3;
|
||||
}
|
||||
mid = (size - lag) / 2;
|
||||
if (size >= 623) {
|
||||
lag = 11;
|
||||
} else if (size >= 68) {
|
||||
lag = 7;
|
||||
} else if (size >= 39) {
|
||||
lag = 5;
|
||||
} else {
|
||||
lag = 3;
|
||||
}
|
||||
mid = (size - lag) / 2;
|
||||
|
||||
memset(ctx->sfmt, 0x8b, sizeof(ctx->sfmt));
|
||||
if (key_length + 1 > N32) {
|
||||
count = key_length + 1;
|
||||
} else {
|
||||
count = N32;
|
||||
}
|
||||
r = func1(psfmt32[idxof(0)] ^ psfmt32[idxof(mid)]
|
||||
^ psfmt32[idxof(N32 - 1)]);
|
||||
psfmt32[idxof(mid)] += r;
|
||||
r += key_length;
|
||||
psfmt32[idxof(mid + lag)] += r;
|
||||
psfmt32[idxof(0)] = r;
|
||||
memset(ctx->sfmt, 0x8b, sizeof(ctx->sfmt));
|
||||
if (key_length + 1 > N32) {
|
||||
count = key_length + 1;
|
||||
} else {
|
||||
count = N32;
|
||||
}
|
||||
r = func1(
|
||||
psfmt32[idxof(0)] ^ psfmt32[idxof(mid)] ^ psfmt32[idxof(N32 - 1)]);
|
||||
psfmt32[idxof(mid)] += r;
|
||||
r += key_length;
|
||||
psfmt32[idxof(mid + lag)] += r;
|
||||
psfmt32[idxof(0)] = r;
|
||||
|
||||
count--;
|
||||
for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
^ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] += r;
|
||||
r += init_key[j] + i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] += r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
for (; j < count; j++) {
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
^ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] += r;
|
||||
r += i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] += r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
for (j = 0; j < N32; j++) {
|
||||
r = func2(psfmt32[idxof(i)] + psfmt32[idxof((i + mid) % N32)]
|
||||
+ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] ^= r;
|
||||
r -= i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] ^= r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
count--;
|
||||
for (i = 1, j = 0; (j < count) && (j < key_length); j++) {
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
^ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] += r;
|
||||
r += init_key[j] + i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] += r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
for (; j < count; j++) {
|
||||
r = func1(psfmt32[idxof(i)] ^ psfmt32[idxof((i + mid) % N32)]
|
||||
^ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] += r;
|
||||
r += i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] += r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
for (j = 0; j < N32; j++) {
|
||||
r = func2(psfmt32[idxof(i)] + psfmt32[idxof((i + mid) % N32)]
|
||||
+ psfmt32[idxof((i + N32 - 1) % N32)]);
|
||||
psfmt32[idxof((i + mid) % N32)] ^= r;
|
||||
r -= i;
|
||||
psfmt32[idxof((i + mid + lag) % N32)] ^= r;
|
||||
psfmt32[idxof(i)] = r;
|
||||
i = (i + 1) % N32;
|
||||
}
|
||||
|
||||
ctx->idx = N32;
|
||||
period_certification(ctx);
|
||||
ctx->initialized = 1;
|
||||
ctx->idx = N32;
|
||||
period_certification(ctx);
|
||||
ctx->initialized = 1;
|
||||
|
||||
return ctx;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void fini_gen_rand(sfmt_t *ctx) {
|
||||
assert(ctx != NULL);
|
||||
void
|
||||
fini_gen_rand(sfmt_t *ctx) {
|
||||
assert(ctx != NULL);
|
||||
|
||||
ctx->initialized = 0;
|
||||
free(ctx);
|
||||
ctx->initialized = 0;
|
||||
free(ctx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
#include "test/jemalloc_test.h"
|
||||
|
||||
#if defined(_WIN32) && !defined(_CRT_SPINCOUNT)
|
||||
#define _CRT_SPINCOUNT 4000
|
||||
# define _CRT_SPINCOUNT 4000
|
||||
#endif
|
||||
|
||||
bool
|
||||
mtx_init(mtx_t *mtx) {
|
||||
#ifdef _WIN32
|
||||
if (!InitializeCriticalSectionAndSpinCount(&mtx->lock,
|
||||
_CRT_SPINCOUNT)) {
|
||||
if (!InitializeCriticalSectionAndSpinCount(
|
||||
&mtx->lock, _CRT_SPINCOUNT)) {
|
||||
return true;
|
||||
}
|
||||
#elif (defined(JEMALLOC_OS_UNFAIR_LOCK))
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
void
|
||||
sleep_ns(unsigned ns) {
|
||||
assert(ns <= 1000*1000*1000);
|
||||
assert(ns <= 1000 * 1000 * 1000);
|
||||
|
||||
#ifdef _WIN32
|
||||
Sleep(ns / 1000 / 1000);
|
||||
|
|
@ -14,7 +14,7 @@ sleep_ns(unsigned ns) {
|
|||
{
|
||||
struct timespec timeout;
|
||||
|
||||
if (ns < 1000*1000*1000) {
|
||||
if (ns < 1000 * 1000 * 1000) {
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_nsec = ns;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
/* Test status state. */
|
||||
|
||||
static unsigned test_count = 0;
|
||||
static test_status_t test_counts[test_status_count] = {0, 0, 0};
|
||||
static test_status_t test_status = test_status_pass;
|
||||
static const char * test_name = "";
|
||||
static unsigned test_count = 0;
|
||||
static test_status_t test_counts[test_status_count] = {0, 0, 0};
|
||||
static test_status_t test_status = test_status_pass;
|
||||
static const char *test_name = "";
|
||||
|
||||
/* Reentrancy testing helpers. */
|
||||
|
||||
|
|
@ -89,10 +89,14 @@ test_fail(const char *format, ...) {
|
|||
static const char *
|
||||
test_status_string(test_status_t current_status) {
|
||||
switch (current_status) {
|
||||
case test_status_pass: return "pass";
|
||||
case test_status_skip: return "skip";
|
||||
case test_status_fail: return "fail";
|
||||
default: not_reached();
|
||||
case test_status_pass:
|
||||
return "pass";
|
||||
case test_status_skip:
|
||||
return "skip";
|
||||
case test_status_fail:
|
||||
return "fail";
|
||||
default:
|
||||
not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,19 +177,16 @@ p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
|
|||
}
|
||||
}
|
||||
|
||||
bool colored = test_counts[test_status_fail] != 0 &&
|
||||
isatty(STDERR_FILENO);
|
||||
bool colored = test_counts[test_status_fail] != 0
|
||||
&& isatty(STDERR_FILENO);
|
||||
const char *color_start = colored ? "\033[1;31m" : "";
|
||||
const char *color_end = colored ? "\033[0m" : "";
|
||||
malloc_printf("%s--- %s: %u/%u, %s: %u/%u, %s: %u/%u ---\n%s",
|
||||
color_start,
|
||||
test_status_string(test_status_pass),
|
||||
color_start, test_status_string(test_status_pass),
|
||||
test_counts[test_status_pass], test_count,
|
||||
test_status_string(test_status_skip),
|
||||
test_counts[test_status_skip], test_count,
|
||||
test_status_string(test_status_fail),
|
||||
test_counts[test_status_fail], test_count,
|
||||
color_end);
|
||||
test_status_string(test_status_skip), test_counts[test_status_skip],
|
||||
test_count, test_status_string(test_status_fail),
|
||||
test_counts[test_status_fail], test_count, color_end);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -193,7 +194,7 @@ p_test_impl(bool do_malloc_init, bool do_reentrant, test_t *t, va_list ap) {
|
|||
test_status_t
|
||||
p_test(test_t *t, ...) {
|
||||
test_status_t ret;
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
|
||||
ret = test_status_pass;
|
||||
va_start(ap, t);
|
||||
|
|
@ -206,7 +207,7 @@ p_test(test_t *t, ...) {
|
|||
test_status_t
|
||||
p_test_no_reentrancy(test_t *t, ...) {
|
||||
test_status_t ret;
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
|
||||
ret = test_status_pass;
|
||||
va_start(ap, t);
|
||||
|
|
@ -219,7 +220,7 @@ p_test_no_reentrancy(test_t *t, ...) {
|
|||
test_status_t
|
||||
p_test_no_malloc_init(test_t *t, ...) {
|
||||
test_status_t ret;
|
||||
va_list ap;
|
||||
va_list ap;
|
||||
|
||||
ret = test_status_pass;
|
||||
va_start(ap, t);
|
||||
|
|
@ -235,12 +236,12 @@ p_test_no_malloc_init(test_t *t, ...) {
|
|||
|
||||
void
|
||||
p_test_fail(bool may_abort, const char *prefix, const char *message) {
|
||||
bool colored = test_counts[test_status_fail] != 0 &&
|
||||
isatty(STDERR_FILENO);
|
||||
bool colored = test_counts[test_status_fail] != 0
|
||||
&& isatty(STDERR_FILENO);
|
||||
const char *color_start = colored ? "\033[1;31m" : "";
|
||||
const char *color_end = colored ? "\033[0m" : "";
|
||||
malloc_cprintf(NULL, NULL, "%s%s%s\n%s", color_start, prefix, message,
|
||||
color_end);
|
||||
malloc_cprintf(
|
||||
NULL, NULL, "%s%s%s\n%s", color_start, prefix, message, color_end);
|
||||
test_status = test_status_fail;
|
||||
if (may_abort) {
|
||||
abort();
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ void
|
|||
thd_join(thd_t thd, void **ret) {
|
||||
if (WaitForSingleObject(thd, INFINITE) == WAIT_OBJECT_0 && ret) {
|
||||
DWORD exit_code;
|
||||
GetExitCodeThread(thd, (LPDWORD) &exit_code);
|
||||
GetExitCodeThread(thd, (LPDWORD)&exit_code);
|
||||
*ret = (void *)(uintptr_t)exit_code;
|
||||
}
|
||||
}
|
||||
|
|
@ -44,7 +44,8 @@ thd_setname(const char *name) {
|
|||
|
||||
bool
|
||||
thd_has_setname(void) {
|
||||
#if defined(JEMALLOC_HAVE_PTHREAD_SETNAME_NP) || defined(JEMALLOC_HAVE_PTHREAD_SET_NAME_NP)
|
||||
#if defined(JEMALLOC_HAVE_PTHREAD_SETNAME_NP) \
|
||||
|| defined(JEMALLOC_HAVE_PTHREAD_SET_NAME_NP)
|
||||
return true;
|
||||
#else
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen) {
|
|||
uint64_t t0 = timer_usec(a);
|
||||
uint64_t t1 = timer_usec(b);
|
||||
uint64_t mult;
|
||||
size_t i = 0;
|
||||
size_t j, n;
|
||||
size_t i = 0;
|
||||
size_t j, n;
|
||||
|
||||
/*
|
||||
* The time difference could be 0 if the two clock readings are
|
||||
|
|
@ -36,11 +36,11 @@ timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen) {
|
|||
* Thus, bump t1 if it is 0 to avoid dividing 0.
|
||||
*/
|
||||
if (t1 == 0) {
|
||||
t1 = 1;
|
||||
t1 = 1;
|
||||
}
|
||||
|
||||
/* Whole. */
|
||||
n = malloc_snprintf(&buf[i], buflen-i, "%"FMTu64, t0 / t1);
|
||||
n = malloc_snprintf(&buf[i], buflen - i, "%" FMTu64, t0 / t1);
|
||||
i += n;
|
||||
if (i >= buflen) {
|
||||
return;
|
||||
|
|
@ -51,15 +51,17 @@ timer_ratio(timedelta_t *a, timedelta_t *b, char *buf, size_t buflen) {
|
|||
}
|
||||
|
||||
/* Decimal. */
|
||||
n = malloc_snprintf(&buf[i], buflen-i, ".");
|
||||
n = malloc_snprintf(&buf[i], buflen - i, ".");
|
||||
i += n;
|
||||
|
||||
/* Fraction. */
|
||||
while (i < buflen-1) {
|
||||
uint64_t round = (i+1 == buflen-1 && ((t0 * mult * 10 / t1) % 10
|
||||
>= 5)) ? 1 : 0;
|
||||
n = malloc_snprintf(&buf[i], buflen-i,
|
||||
"%"FMTu64, (t0 * mult / t1) % 10 + round);
|
||||
while (i < buflen - 1) {
|
||||
uint64_t round = (i + 1 == buflen - 1
|
||||
&& ((t0 * mult * 10 / t1) % 10 >= 5))
|
||||
? 1
|
||||
: 0;
|
||||
n = malloc_snprintf(&buf[i], buflen - i, "%" FMTu64,
|
||||
(t0 * mult / t1) % 10 + round);
|
||||
i += n;
|
||||
mult *= 10;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue