misc. updates, mostly about portability and warnings

removing some unnecessary #includes
This commit is contained in:
JeffBezanson 2010-08-04 19:03:19 +00:00
parent 561e0b07e1
commit eaac150672
21 changed files with 164 additions and 216 deletions

View File

@ -411,7 +411,7 @@ static value_t fl_rand(value_t *args, u_int32_t nargs)
static value_t fl_rand32(value_t *args, u_int32_t nargs) static value_t fl_rand32(value_t *args, u_int32_t nargs)
{ {
(void)args; (void)nargs; (void)args; (void)nargs;
ulong r = random(); uint32_t r = random();
#ifdef BITS64 #ifdef BITS64
return fixnum(r); return fixnum(r);
#else #else

View File

@ -651,7 +651,7 @@ value_t cvalue_typeof(value_t *args, u_int32_t nargs)
return cv_type((cvalue_t*)ptr(args[0])); return cv_type((cvalue_t*)ptr(args[0]));
} }
value_t cvalue_relocate(value_t v) static value_t cvalue_relocate(value_t v)
{ {
size_t nw; size_t nw;
cvalue_t *cv = (cvalue_t*)ptr(v); cvalue_t *cv = (cvalue_t*)ptr(v);
@ -840,7 +840,7 @@ static value_t cvalue_array_aref(value_t *args)
{ {
char *data; ulong_t index; char *data; ulong_t index;
fltype_t *eltype = cv_class((cvalue_t*)ptr(args[0]))->eltype; fltype_t *eltype = cv_class((cvalue_t*)ptr(args[0]))->eltype;
value_t el; value_t el = 0;
numerictype_t nt = eltype->numtype; numerictype_t nt = eltype->numtype;
if (nt >= T_INT32) if (nt >= T_INT32)
el = cvalue(eltype, eltype->size); el = cvalue(eltype, eltype->size);
@ -885,7 +885,7 @@ value_t fl_builtin(value_t *args, u_int32_t nargs)
symbol_t *name = tosymbol(args[0], "builtin"); symbol_t *name = tosymbol(args[0], "builtin");
cvalue_t *cv; cvalue_t *cv;
if (ismanaged(args[0]) || (cv=name->dlcache) == NULL) { if (ismanaged(args[0]) || (cv=name->dlcache) == NULL) {
lerror(ArgError, "builtin: function not found"); lerrorf(ArgError, "builtin: function %s not found", name->name);
} }
return tagptr(cv, TAG_CVALUE); return tagptr(cv, TAG_CVALUE);
} }

View File

@ -7,7 +7,10 @@
#include "llt.h" #include "llt.h"
#include "flisp.h" #include "flisp.h"
#include "equalhash.h"
#include "htable.inc" #include "htable.inc"
HTIMPL(equalhash, hash_lispvalue, equal_lispvalue) #define _equal_lispvalue_(x,y) equal_lispvalue((value_t)(x),(value_t)(y))
HTIMPL(equalhash, hash_lispvalue, _equal_lispvalue_)

View File

@ -393,7 +393,7 @@ value_t alloc_vector(size_t n, int init)
// print ---------------------------------------------------------------------- // print ----------------------------------------------------------------------
static int isnumtok(char *tok, value_t *pval); static int isnumtok(char *tok, value_t *pval);
static int symchar(char c); static inline int symchar(char c);
#include "print.c" #include "print.c"
@ -593,7 +593,7 @@ void gc(int mustgrow)
tospace = temp; tospace = temp;
if (grew) { if (grew) {
heapsize*=2; heapsize*=2;
temp = bitvector_resize(consflags, heapsize/sizeof(cons_t), 1); temp = bitvector_resize(consflags, 0, heapsize/sizeof(cons_t), 1);
if (temp == NULL) if (temp == NULL)
fl_raise(memory_exception_value); fl_raise(memory_exception_value);
consflags = (uint32_t*)temp; consflags = (uint32_t*)temp;
@ -936,7 +936,7 @@ static value_t apply_cl(uint32_t nargs)
VM_APPLY_LABELS; VM_APPLY_LABELS;
uint32_t top_frame = curr_frame; uint32_t top_frame = curr_frame;
// frame variables // frame variables
uint32_t n, captured; uint32_t n=0, captured;
uint32_t bp; uint32_t bp;
const uint8_t *ip; const uint8_t *ip;
fixnum_t s, hi; fixnum_t s, hi;

View File

@ -489,6 +489,7 @@ static void print_string(ios_t *f, char *str, size_t sz)
char buf[512]; char buf[512];
size_t i = 0; size_t i = 0;
uint8_t c; uint8_t c;
static char hexdig[] = "0123456789abcdef";
outc('"', f); outc('"', f);
if (!u8_isvalid(str, sz)) { if (!u8_isvalid(str, sz)) {
@ -501,8 +502,11 @@ static void print_string(ios_t *f, char *str, size_t sz)
outsn("\\\"", f, 2); outsn("\\\"", f, 2);
else if (c >= 32 && c < 0x7f) else if (c >= 32 && c < 0x7f)
outc(c, f); outc(c, f);
else else {
HPOS += ios_printf(f, "\\x%02x", c); outsn("\\x", f, 2);
outc(hexdig[c>>4], f);
outc(hexdig[c&0xf], f);
}
} }
} }
else { else {
@ -709,10 +713,14 @@ static void cvalue_print(ios_t *f, value_t v)
(unsigned long)(builtin_t)fptr); (unsigned long)(builtin_t)fptr);
} }
else { else {
if (print_princ) if (print_princ) {
outs(symbol_name(label), f); outs(symbol_name(label), f);
else }
HPOS += ios_printf(f, "#fn(%s)", symbol_name(label)); else {
outsn("#fn(", f, 4);
outs(symbol_name(label), f);
outc(')', f);
}
} }
} }
else if (cv_class(cv)->vtable != NULL && else if (cv_class(cv)->vtable != NULL &&

View File

@ -339,9 +339,9 @@ value_t fl_string_dec(value_t *args, u_int32_t nargs)
return size_wrap(i); return size_wrap(i);
} }
static ulong get_radix_arg(value_t arg, char *fname) static unsigned long get_radix_arg(value_t arg, char *fname)
{ {
ulong radix = toulong(arg, fname); unsigned long radix = toulong(arg, fname);
if (radix < 2 || radix > 36) if (radix < 2 || radix > 36)
lerrorf(ArgError, "%s: invalid radix", fname); lerrorf(ArgError, "%s: invalid radix", fname);
return radix; return radix;
@ -362,7 +362,7 @@ value_t fl_numbertostring(value_t *args, u_int32_t nargs)
num = -num; num = -num;
neg = 1; neg = 1;
} }
ulong radix = 10; unsigned long radix = 10;
if (nargs == 2) if (nargs == 2)
radix = get_radix_arg(args[1], "number->string"); radix = get_radix_arg(args[1], "number->string");
char buf[128]; char buf[128];

View File

@ -40,19 +40,23 @@
#include <malloc.h> #include <malloc.h>
#endif #endif
u_int32_t *bitvector_resize(u_int32_t *b, u_int64_t n, int initzero) u_int32_t *bitvector_resize(u_int32_t *b, uint64_t oldsz, uint64_t newsz,
int initzero)
{ {
u_int32_t *p; u_int32_t *p;
size_t sz = ((n+31)>>5) * 4; size_t sz = ((newsz+31)>>5) * sizeof(uint32_t);
p = LLT_REALLOC(b, sz); p = LLT_REALLOC(b, sz);
if (p == NULL) return NULL; if (p == NULL) return NULL;
if (initzero) memset(p, 0, sz); if (initzero && newsz>oldsz) {
size_t osz = ((oldsz+31)>>5) * sizeof(uint32_t);
memset(&p[osz], 0, sz-osz);
}
return p; return p;
} }
u_int32_t *bitvector_new(u_int64_t n, int initzero) u_int32_t *bitvector_new(u_int64_t n, int initzero)
{ {
return bitvector_resize(NULL, n, initzero); return bitvector_resize(NULL, 0, n, initzero);
} }
size_t bitvector_nwords(u_int64_t nbits) size_t bitvector_nwords(u_int64_t nbits)
@ -72,3 +76,50 @@ u_int32_t bitvector_get(u_int32_t *b, u_int64_t n)
{ {
return b[n>>5] & (1<<(n&31)); return b[n>>5] & (1<<(n&31));
} }
static int ntz(uint32_t x)
{
int n;
if (x == 0) return 32;
n = 1;
if ((x & 0x0000FFFF) == 0) {n = n +16; x = x >>16;}
if ((x & 0x000000FF) == 0) {n = n + 8; x = x >> 8;}
if ((x & 0x0000000F) == 0) {n = n + 4; x = x >> 4;}
if ((x & 0x00000003) == 0) {n = n + 2; x = x >> 2;}
return n - (x & 1);
}
// given a bitvector of n bits, starting at bit n0 find the next
// set bit, including n0.
// returns n if no set bits.
uint32_t bitvector_next(uint32_t *b, uint64_t n0, uint64_t n)
{
if (n == 0) return 0;
uint32_t i = n0>>5;
uint32_t nb = n0&31;
uint32_t nw = (n+31)>>5;
uint32_t w = b[i]>>nb;
if (w != 0)
return ntz(w)+n0;
if (nw == 1)
return n;
i++;
while (i < nw-1) {
w = b[i];
if (w != 0) {
return ntz(w) + (i<<5);
}
i++;
}
w = b[i];
nb = n&31;
i = ntz(w);
if (nb == 0)
return i + (n-32);
if (i >= nb)
return n;
return i + (n-nb);
}

View File

@ -32,11 +32,14 @@ static inline u_int32_t count_bits(u_int32_t b)
u_int32_t bitreverse(u_int32_t x); u_int32_t bitreverse(u_int32_t x);
u_int32_t *bitvector_new(u_int64_t n, int initzero); u_int32_t *bitvector_new(u_int64_t n, int initzero);
u_int32_t *bitvector_resize(u_int32_t *b, u_int64_t n, int initzero); u_int32_t *bitvector_resize(u_int32_t *b, uint64_t oldsz, uint64_t newsz,
int initzero);
size_t bitvector_nwords(u_int64_t nbits); size_t bitvector_nwords(u_int64_t nbits);
void bitvector_set(u_int32_t *b, u_int64_t n, u_int32_t c); void bitvector_set(u_int32_t *b, u_int64_t n, u_int32_t c);
u_int32_t bitvector_get(u_int32_t *b, u_int64_t n); u_int32_t bitvector_get(u_int32_t *b, u_int64_t n);
uint32_t bitvector_next(uint32_t *b, uint64_t n0, uint64_t n);
void bitvector_shr(u_int32_t *b, size_t n, u_int32_t s); void bitvector_shr(u_int32_t *b, size_t n, u_int32_t s);
void bitvector_shr_to(u_int32_t *dest, u_int32_t *b, size_t n, u_int32_t s); void bitvector_shr_to(u_int32_t *dest, u_int32_t *b, size_t n, u_int32_t s);
void bitvector_shl(u_int32_t *b, size_t n, u_int32_t s); void bitvector_shl(u_int32_t *b, size_t n, u_int32_t s);

View File

@ -1,7 +1,6 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "ieee754.h"
#include "dtypes.h" #include "dtypes.h"
#include "utils.h" #include "utils.h"

View File

@ -4,6 +4,7 @@
#include <stdio.h> #include <stdio.h>
#include "dtypes.h" #include "dtypes.h"
#include "ieee754.h" #include "ieee754.h"
#include "utils.h"
int double_exponent(double d) int double_exponent(double d)
{ {

View File

@ -16,6 +16,18 @@
We assume the LP64 convention for 64-bit platforms. We assume the LP64 convention for 64-bit platforms.
*/ */
#ifdef WIN32
#define STDCALL __stdcall
# ifdef IMPORT_EXPORTS
# define DLLEXPORT __declspec(dllimport)
# else
# define DLLEXPORT __declspec(dllexport)
# endif
#else
#define STDCALL
#define DLLEXPORT __attribute__ ((visibility("default")))
#endif
#ifdef LINUX #ifdef LINUX
#include <features.h> #include <features.h>
#include <endian.h> #include <endian.h>

View File

@ -1,5 +1,4 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h>
#include "dtypes.h" #include "dtypes.h"
#include "ios.h" #include "ios.h"
#include "utils.h" #include "utils.h"

View File

@ -4,7 +4,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include "ieee754.h"
#include "dtypes.h" #include "dtypes.h"
#include "utils.h" #include "utils.h"
#include "hashing.h" #include "hashing.h"

View File

@ -1,192 +1,67 @@
/* Copyright (C) 1992, 1995, 1996, 1999 Free Software Foundation, Inc. #ifndef __IEEE754_H_
This file is part of the GNU C Library. #define __IEEE754_H_
The GNU C Library is free software; you can redistribute it and/or union ieee754_float {
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#ifndef _IEEE754_H
#define _IEEE754_H 1
union ieee754_float
{
float f; float f;
/* This is the IEEE 754 single-precision format. */ struct {
struct #if BYTE_ORDER == BIG_ENDIAN
{
#if __BYTE_ORDER == __BIG_ENDIAN
unsigned int negative:1; unsigned int negative:1;
unsigned int exponent:8; unsigned int exponent:8;
unsigned int mantissa:23; unsigned int mantissa:23;
#endif /* Big endian. */ #endif
#if __BYTE_ORDER == __LITTLE_ENDIAN #if BYTE_ORDER == LITTLE_ENDIAN
unsigned int mantissa:23; unsigned int mantissa:23;
unsigned int exponent:8; unsigned int exponent:8;
unsigned int negative:1; unsigned int negative:1;
#endif /* Little endian. */ #endif
} ieee; } ieee;
};
/* This format makes it easier to see if a NaN is a signalling NaN. */ #define IEEE754_FLOAT_BIAS 0x7f
struct
{
#if __BYTE_ORDER == __BIG_ENDIAN
unsigned int negative:1;
unsigned int exponent:8;
unsigned int quiet_nan:1;
unsigned int mantissa:22;
#endif /* Big endian. */
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned int mantissa:22;
unsigned int quiet_nan:1;
unsigned int exponent:8;
unsigned int negative:1;
#endif /* Little endian. */
} ieee_nan;
};
#define IEEE754_FLOAT_BIAS 0x7f /* Added to exponent. */ union ieee754_double {
union ieee754_double
{
double d; double d;
/* This is the IEEE 754 double-precision format. */ struct {
struct #if BYTE_ORDER == BIG_ENDIAN
{
#if __BYTE_ORDER == __BIG_ENDIAN
unsigned int negative:1; unsigned int negative:1;
unsigned int exponent:11; unsigned int exponent:11;
/* Together these comprise the mantissa. */
unsigned int mantissa0:20; unsigned int mantissa0:20;
unsigned int mantissa1:32; unsigned int mantissa1:32;
#endif /* Big endian. */
#if __BYTE_ORDER == __LITTLE_ENDIAN
# if __FLOAT_WORD_ORDER == BIG_ENDIAN
unsigned int mantissa0:20;
unsigned int exponent:11;
unsigned int negative:1;
unsigned int mantissa1:32;
# else
/* Together these comprise the mantissa. */
unsigned int mantissa1:32;
unsigned int mantissa0:20;
unsigned int exponent:11;
unsigned int negative:1;
# endif
#endif /* Little endian. */
} ieee;
/* This format makes it easier to see if a NaN is a signalling NaN. */
struct
{
#if __BYTE_ORDER == __BIG_ENDIAN
unsigned int negative:1;
unsigned int exponent:11;
unsigned int quiet_nan:1;
/* Together these comprise the mantissa. */
unsigned int mantissa0:19;
unsigned int mantissa1:32;
#else
# if __FLOAT_WORD_ORDER == BIG_ENDIAN
unsigned int mantissa0:19;
unsigned int quiet_nan:1;
unsigned int exponent:11;
unsigned int negative:1;
unsigned int mantissa1:32;
# else
/* Together these comprise the mantissa. */
unsigned int mantissa1:32;
unsigned int mantissa0:19;
unsigned int quiet_nan:1;
unsigned int exponent:11;
unsigned int negative:1;
# endif
#endif #endif
} ieee_nan; #if BYTE_ORDER == LITTLE_ENDIAN
}; unsigned int mantissa1:32;
unsigned int mantissa0:20;
unsigned int exponent:11;
unsigned int negative:1;
#endif
} ieee;
};
#define IEEE754_DOUBLE_BIAS 0x3ff /* Added to exponent. */ #define IEEE754_DOUBLE_BIAS 0x3ff
union ieee854_long_double {
union ieee854_long_double
{
long double d; long double d;
/* This is the IEEE 854 double-extended-precision format. */ struct {
struct #if BYTE_ORDER == BIG_ENDIAN
{
#if __BYTE_ORDER == __BIG_ENDIAN
unsigned int negative:1; unsigned int negative:1;
unsigned int exponent:15; unsigned int exponent:15;
unsigned int empty:16; unsigned int empty:16;
unsigned int mantissa0:32; unsigned int mantissa0:32;
unsigned int mantissa1:32; unsigned int mantissa1:32;
#endif #endif
#if __BYTE_ORDER == __LITTLE_ENDIAN #if BYTE_ORDER == LITTLE_ENDIAN
# if __FLOAT_WORD_ORDER == BIG_ENDIAN
unsigned int exponent:15;
unsigned int negative:1;
unsigned int empty:16;
unsigned int mantissa0:32;
unsigned int mantissa1:32;
# else
unsigned int mantissa1:32; unsigned int mantissa1:32;
unsigned int mantissa0:32; unsigned int mantissa0:32;
unsigned int exponent:15; unsigned int exponent:15;
unsigned int negative:1; unsigned int negative:1;
unsigned int empty:16; unsigned int empty:16;
# endif
#endif #endif
} ieee; } ieee;
};
/* This is for NaNs in the IEEE 854 double-extended-precision format. */
struct
{
#if __BYTE_ORDER == __BIG_ENDIAN
unsigned int negative:1;
unsigned int exponent:15;
unsigned int empty:16;
unsigned int one:1;
unsigned int quiet_nan:1;
unsigned int mantissa0:30;
unsigned int mantissa1:32;
#endif
#if __BYTE_ORDER == __LITTLE_ENDIAN
# if __FLOAT_WORD_ORDER == BIG_ENDIAN
unsigned int exponent:15;
unsigned int negative:1;
unsigned int empty:16;
unsigned int mantissa0:30;
unsigned int quiet_nan:1;
unsigned int one:1;
unsigned int mantissa1:32;
# else
unsigned int mantissa1:32;
unsigned int mantissa0:30;
unsigned int quiet_nan:1;
unsigned int one:1;
unsigned int exponent:15;
unsigned int negative:1;
unsigned int empty:16;
# endif
#endif
} ieee_nan;
};
#define IEEE854_LONG_DOUBLE_BIAS 0x3fff #define IEEE854_LONG_DOUBLE_BIAS 0x3fff
#endif /* ieee754.h */ #endif

View File

@ -3,7 +3,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <math.h> #include <math.h>
#include <locale.h> #include <locale.h>
#include "ieee754.h"
#include "dtypes.h" #include "dtypes.h"
#include "timefuncs.h" #include "timefuncs.h"
#include "ios.h" #include "ios.h"

View File

@ -46,25 +46,25 @@
/* Period parameters */ /* Period parameters */
#define mtN 624 #define mtN 624
#define mtM 397 #define mtM 397
#define MATRIX_A 0x9908b0dfUL /* constant vector a */ #define MATRIX_A 0x9908b0dfU /* constant vector a */
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */ #define UPPER_MASK 0x80000000U /* most significant w-r bits */
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */ #define LOWER_MASK 0x7fffffffU /* least significant r bits */
static unsigned long mt[mtN]; /* the array for the state vector */ static uint32_t mt[mtN]; /* the array for the state vector */
static int mti=mtN+1; /* mti==mtN+1 means mt[mtN] is not initialized */ static int mti=mtN+1; /* mti==mtN+1 means mt[mtN] is not initialized */
/* initializes mt[mtN] with a seed */ /* initializes mt[mtN] with a seed */
void init_genrand(unsigned long s) void init_genrand(uint32_t s)
{ {
mt[0]= s & 0xffffffffUL; mt[0]= s & 0xffffffffU;
for (mti=1; mti<mtN; mti++) { for (mti=1; mti<mtN; mti++) {
mt[mti] = mt[mti] =
(1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti); (1812433253U * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */ /* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
/* In the previous versions, MSBs of the seed affect */ /* In the previous versions, MSBs of the seed affect */
/* only MSBs of the array mt[]. */ /* only MSBs of the array mt[]. */
/* 2002/01/09 modified by Makoto Matsumoto */ /* 2002/01/09 modified by Makoto Matsumoto */
mt[mti] &= 0xffffffffUL; mt[mti] &= 0xffffffffU;
/* for >32 bit machines */ /* for >32 bit machines */
} }
} }
@ -73,54 +73,54 @@ void init_genrand(unsigned long s)
/* init_key is the array for initializing keys */ /* init_key is the array for initializing keys */
/* key_length is its length */ /* key_length is its length */
/* slight change for C++, 2004/2/26 */ /* slight change for C++, 2004/2/26 */
void init_by_array(unsigned long init_key[], int key_length) void init_by_array(uint32_t init_key[], int key_length)
{ {
int i, j, k; int i, j, k;
init_genrand(19650218UL); init_genrand(19650218U);
i=1; j=0; i=1; j=0;
k = (mtN>key_length ? mtN : key_length); k = (mtN>key_length ? mtN : key_length);
for (; k; k--) { for (; k; k--) {
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL)) mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525U))
+ init_key[j] + j; /* non linear */ + init_key[j] + j; /* non linear */
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ mt[i] &= 0xffffffffU; /* for WORDSIZE > 32 machines */
i++; j++; i++; j++;
if (i>=mtN) { mt[0] = mt[mtN-1]; i=1; } if (i>=mtN) { mt[0] = mt[mtN-1]; i=1; }
if (j>=key_length) j=0; if (j>=key_length) j=0;
} }
for (k=mtN-1; k; k--) { for (k=mtN-1; k; k--) {
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL)) mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941U))
- i; /* non linear */ - i; /* non linear */
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */ mt[i] &= 0xffffffffU; /* for WORDSIZE > 32 machines */
i++; i++;
if (i>=mtN) { mt[0] = mt[mtN-1]; i=1; } if (i>=mtN) { mt[0] = mt[mtN-1]; i=1; }
} }
mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */ mt[0] = 0x80000000U; /* MSB is 1; assuring non-zero initial array */
} }
/* generates a random number on [0,0xffffffff]-interval */ /* generates a random number on [0,0xffffffff]-interval */
unsigned long genrand_int32(void) uint32_t genrand_int32(void)
{ {
unsigned long y; uint32_t y;
static unsigned long mag01[2]={0x0UL, MATRIX_A}; static uint32_t mag01[2]={0x0U, MATRIX_A};
/* mag01[x] = x * MATRIX_A for x=0,1 */ /* mag01[x] = x * MATRIX_A for x=0,1 */
if (mti >= mtN) { /* generate mtN words at one time */ if (mti >= mtN) { /* generate mtN words at one time */
int kk; int kk;
if (mti == mtN+1) /* if init_genrand() has not been called, */ if (mti == mtN+1) /* if init_genrand() has not been called, */
init_genrand(5489UL); /* a default initial seed is used */ init_genrand(5489U); /* a default initial seed is used */
for (kk=0;kk<mtN-mtM;kk++) { for (kk=0;kk<mtN-mtM;kk++) {
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK); y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
mt[kk] = mt[kk+mtM] ^ (y >> 1) ^ mag01[y & 0x1UL]; mt[kk] = mt[kk+mtM] ^ (y >> 1) ^ mag01[y & 0x1U];
} }
for (;kk<mtN-1;kk++) { for (;kk<mtN-1;kk++) {
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK); y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
mt[kk] = mt[kk+(mtM-mtN)] ^ (y >> 1) ^ mag01[y & 0x1UL]; mt[kk] = mt[kk+(mtM-mtN)] ^ (y >> 1) ^ mag01[y & 0x1U];
} }
y = (mt[mtN-1]&UPPER_MASK)|(mt[0]&LOWER_MASK); y = (mt[mtN-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
mt[mtN-1] = mt[mtM-1] ^ (y >> 1) ^ mag01[y & 0x1UL]; mt[mtN-1] = mt[mtM-1] ^ (y >> 1) ^ mag01[y & 0x1U];
mti = 0; mti = 0;
} }
@ -129,8 +129,8 @@ unsigned long genrand_int32(void)
/* Tempering */ /* Tempering */
y ^= (y >> 11); y ^= (y >> 11);
y ^= (y << 7) & 0x9d2c5680UL; y ^= (y << 7) & 0x9d2c5680U;
y ^= (y << 15) & 0xefc60000UL; y ^= (y << 15) & 0xefc60000U;
y ^= (y >> 18); y ^= (y >> 18);
return y; return y;
@ -167,7 +167,7 @@ double genrand_real3(void)
/* generates a random number on [0,1) with 53-bit resolution*/ /* generates a random number on [0,1) with 53-bit resolution*/
double genrand_res53(void) double genrand_res53(void)
{ {
unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6; uint32_t a=genrand_int32()>>5, b=genrand_int32()>>6;
return(a*67108864.0+b)*(1.0/9007199254740992.0); return(a*67108864.0+b)*(1.0/9007199254740992.0);
} }
#endif #endif
@ -176,7 +176,7 @@ double genrand_res53(void)
int main(void) int main(void)
{ {
int i; int i;
unsigned long init[4]={0x123, 0x234, 0x345, 0x456}, length=4; uint32_t init[4]={0x123, 0x234, 0x345, 0x456}, length=4;
init_by_array(init, length); init_by_array(init, length);
printf("1000 outputs of genrand_int32()\n"); printf("1000 outputs of genrand_int32()\n");
for (i=0; i<1000; i++) { for (i=0; i<1000; i++) {

View File

@ -11,7 +11,6 @@
#include "dtypes.h" #include "dtypes.h"
#include "ptrhash.h" #include "ptrhash.h"
#include "hashing.h"
#define OP_EQ(x,y) ((x)==(y)) #define OP_EQ(x,y) ((x)==(y))

View File

@ -16,8 +16,8 @@ double rand_double()
{ {
union ieee754_double d; union ieee754_double d;
d.ieee.mantissa0 = random(); d.ieee.mantissa0 = genrand_int32();
d.ieee.mantissa1 = random(); d.ieee.mantissa1 = genrand_int32();
d.ieee.negative = 0; d.ieee.negative = 0;
d.ieee.exponent = IEEE754_DOUBLE_BIAS + 0; /* 2^0 */ d.ieee.exponent = IEEE754_DOUBLE_BIAS + 0; /* 2^0 */
return d.d - 1.0; return d.d - 1.0;
@ -27,7 +27,7 @@ float rand_float()
{ {
union ieee754_float f; union ieee754_float f;
f.ieee.mantissa = random(); f.ieee.mantissa = genrand_int32();
f.ieee.negative = 0; f.ieee.negative = 0;
f.ieee.exponent = IEEE754_FLOAT_BIAS + 0; /* 2^0 */ f.ieee.exponent = IEEE754_FLOAT_BIAS + 0; /* 2^0 */
return f.f - 1.0; return f.f - 1.0;
@ -58,5 +58,5 @@ double randn()
void randomize() void randomize()
{ {
u_int64_t tm = i64time(); u_int64_t tm = i64time();
init_by_array((unsigned long*)&tm, 2); init_by_array((uint32_t*)&tm, 2);
} }

View File

@ -7,8 +7,8 @@ double rand_double();
float rand_float(); float rand_float();
double randn(); double randn();
void randomize(); void randomize();
unsigned long genrand_int32(); uint32_t genrand_int32();
void init_genrand(unsigned long s); void init_genrand(uint32_t s);
u_int64_t i64time(); u_int64_t i64time();
#endif #endif

View File

@ -1,5 +1,5 @@
#ifndef __JCSOCKET_H_ #ifndef __LLTSOCKET_H_
#define __JCSOCKET_H_ #define __LLTSOCKET_H_
#ifdef WIN32 #ifdef WIN32
#include <winsock2.h> #include <winsock2.h>

View File

@ -81,9 +81,9 @@ double clock_now()
void timestring(double seconds, char *buffer, size_t len) void timestring(double seconds, char *buffer, size_t len)
{ {
time_t tme = (time_t)seconds; time_t tme = (time_t)seconds;
char *fmt = "%c"; /* needed to suppress GCC warning */
#ifdef LINUX #ifdef LINUX
char *fmt = "%c"; /* needed to suppress GCC warning */
struct tm tm; struct tm tm;
localtime_r(&tme, &tm); localtime_r(&tme, &tm);