From: Daniel Kochmański Date: Tue, 22 Sep 2015 18:36:20 +0000 (+0200) Subject: random-state: use portable solution X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=f1dda6384ca828e5f439de4ec7ed6e94070d44cb;p=ecl.git random-state: use portable solution This results in twice as big array as we could use if uint32_t was granted with C99 - half of the bytes on 64 bit platforms are filled with 0. Despite that it's clean and portable solution without immediate imposing dependency on C99. Signed-off-by: Daniel Kochmański --- diff --git a/src/c/hash.d b/src/c/hash.d index ed76513..3d34d74 100644 --- a/src/c/hash.d +++ b/src/c/hash.d @@ -120,8 +120,8 @@ _hash_equal(int depth, cl_hashkey h, cl_object x) case t_random: { cl_object array = x->random.value; return hash_string - (h, (unsigned char*)array->vector.self.b32, - array->vector.fillp * sizeof(ecl_uint32_t)); + (h, (unsigned char*)array->vector.self.b8, + array->vector.fillp); } #ifdef ECL_SIGNED_ZERO case t_singlefloat: { diff --git a/src/c/num_rand.d b/src/c/num_rand.d index 93355af..ab13ea1 100644 --- a/src/c/num_rand.d +++ b/src/c/num_rand.d @@ -45,16 +45,16 @@ n*/ /* INV: for 64 bit implementation modify accordingly _hash_equal in hash.d file for case t_random */ -#define ulong ecl_uint32_t +#define ulong unsigned long cl_object init_genrand(ulong seed) { cl_object array = ecl_alloc_simple_vector - ((MT_N + 1), - ecl_symbol_to_elttype(@'ext::byte32')); - ulong *mt = (ulong*)(array->vector.self.b32); + ((MT_N + 1) * sizeof(ulong), + ecl_symbol_to_elttype(@'ext::byte8')); + ulong *mt = (ulong*)(array->vector.self.b8); int j = 0; mt[0] = seed & 0xffffffffUL; for (j=1; j < MT_N; j++) @@ -92,7 +92,7 @@ generate_int32(cl_object state) { static ulong mag01[2]={0x0UL, MATRIX_A}; ulong y; - ulong *mt = (ulong*)state->vector.self.b32; + ulong *mt = (ulong*)state->vector.self.b8; if (mt[MT_N] >= MT_N){ /* refresh data */ int kk; @@ -223,8 +223,7 @@ ecl_make_random_state(cl_object rs) with ecl_to_ulong_long from number.d, which takes widest available type (32 or 64 bit) automatically. */ - z->random.value = init_genrand - (ecl_to_uint32_t(rs)); + z->random.value = init_genrand(ecl_fixnum(rs)); break; default: { const char *type