diff options
author | Richard Henderson <rth@redhat.com> | 2004-12-12 00:59:05 -0800 |
---|---|---|
committer | Richard Henderson <rth@gcc.gnu.org> | 2004-12-12 00:59:05 -0800 |
commit | 7d7b8bfe55f8598f2fa0f842fb7f95060c45fa35 (patch) | |
tree | cb0ecd2cd7b8c21d4d1c38261b5b7116e8dd2782 /libgfortran/intrinsics/random.c | |
parent | c431e4997fcca052667b780341ddf4df5f6eb55c (diff) | |
download | gcc-7d7b8bfe55f8598f2fa0f842fb7f95060c45fa35.zip gcc-7d7b8bfe55f8598f2fa0f842fb7f95060c45fa35.tar.gz gcc-7d7b8bfe55f8598f2fa0f842fb7f95060c45fa35.tar.bz2 |
acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
* acinclude.m4 (LIBGFOR_CHECK_ATTRIBUTE_VISIBILITY): New.
(LIBGFOR_CHECK_ATTRIBUTE_DLLEXPORT): New.
(LIBGFOR_CHECK_ATTRIBUTE_ALIAS): New.
* configure.ac: Use them.
* configure, config.h.in, aclocal.m4: Rebuild.
* libgfortran.h (prefix): Remove.
(PREFIX, IPREFIX): New.
(sym_rename, sym_rename1, sym_rename2): New.
(internal_proto, export_proto, export_proto_np): New.
(iexport_proto, iexport): New.
(iexport_data_proto, iexport_data): New.
* intrinsics/abort.c, intrinsics/args.c, intrinsics/associated.c,
intrinsics/cpu_time.c, intrinsics/cshift0.c,
intrinsics/date_and_time.c, intrinsics/env.c, intrinsics/eoshift0.c,
intrinsics/eoshift2.c, intrinsics/etime.c, intrinsics/exit.c,
intrinsics/flush.c, intrinsics/fnum.c, intrinsics/getXid.c,
intrinsics/getcwd.c, intrinsics/ishftc.c, intrinsics/mvbits.c,
intrinsics/pack_generic.c, intrinsics/rand.c, intrinsics/random.c,
intrinsics/reshape_generic.c, intrinsics/size.c,
intrinsics/spread_generic.c, intrinsics/stat.c,
intrinsics/string_intrinsics.c, intrinsics/system.c,
intrinsics/system_clock.c, intrinsics/transpose_generic.c,
intrinsics/umask.c, intrinsics/unlink.c, intrinsics/unpack_generic.c,
io/backspace.c, io/close.c, io/endfile.c, io/inquire.c, io/io.h,
io/open.c, io/rewind.c, io/transfer.c, libgfortran.h, m4/cshift1.m4,
m4/dotprod.m4, m4/dotprodc.m4, m4/dotprodl.m4, m4/eoshift1.m4,
m4/eoshift3.m4, m4/exponent.m4, m4/fraction.m4, m4/iforeach.m4,
m4/ifunction.m4, m4/matmul.m4, m4/matmull.m4, m4/nearest.m4,
m4/pow.m4, m4/reshape.m4, m4/set_exponent.m4, m4/shape.m4,
m4/transpose.m4, runtime/environ.c, runtime/error.c,
runtime/in_pack_generic.c, runtime/in_unpack_generic.c,
runtime/main.c, runtime/memory.c, runtime/pause.c, runtime/select.c,
runtime/stop.c: Use them to mark symbols internal or external.
* generated/*: Rebuild.
From-SVN: r92045
Diffstat (limited to 'libgfortran/intrinsics/random.c')
-rw-r--r-- | libgfortran/intrinsics/random.c | 57 |
1 files changed, 32 insertions, 25 deletions
diff --git a/libgfortran/intrinsics/random.c b/libgfortran/intrinsics/random.c index 2cc5d20..0ea60ecc 100644 --- a/libgfortran/intrinsics/random.c +++ b/libgfortran/intrinsics/random.c @@ -20,6 +20,20 @@ License along with libgfor; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "libgfortran.h" + +extern void random_r4 (GFC_REAL_4 *); +iexport_proto(random_r4); + +extern void random_r8 (GFC_REAL_8 *); +iexport_proto(random_r8); + +extern void arandom_r4 (gfc_array_r4 *); +export_proto(arandom_r4); + +extern void arandom_r8 (gfc_array_r8 *); +export_proto(arandom_r8); + #if 0 /* The Mersenne Twister code is currently commented out due to @@ -45,7 +59,6 @@ Boston, MA 02111-1307, USA. */ Generation. ( Early in 1998 ). */ -#include "config.h" #include <stdio.h> #include <stdlib.h> #include <sys/types.h> @@ -56,8 +69,6 @@ Boston, MA 02111-1307, USA. */ #include <unistd.h> #endif -#include "libgfortran.h" - /*Use the 'big' generator by default ( period -> 2**19937 ). */ #define MT19937 @@ -89,8 +100,7 @@ static unsigned int seed[N]; and also reading and writing of the seed. */ void -random_seed (GFC_INTEGER_4 * size, const gfc_array_i4 * put, - const gfc_array_i4 * get) +random_seed (GFC_INTEGER_4 *size, gfc_array_i4 *put, gfc_array_i4 *get) { /* Initialize the seed in system dependent manner. */ if (get == NULL && put == NULL && size == NULL) @@ -167,6 +177,7 @@ random_seed (GFC_INTEGER_4 * size, const gfc_array_i4 * put, get->data[i * get->dim[0].stride] = seed[i]; } } +iexport(random_seed); /* Here is the internal routine which generates the random numbers in 'batches' based upon the need for a new batch. @@ -197,7 +208,6 @@ random_generate (void) /* A routine to return a REAL(KIND=4). */ -#define random_r4 prefix(random_r4) void random_r4 (GFC_REAL_4 * harv) { @@ -209,10 +219,10 @@ random_r4 (GFC_REAL_4 * harv) *harv = (GFC_REAL_4) ((GFC_REAL_4) (GFC_UINTEGER_4) seed[i++] / (GFC_REAL_4) (~(GFC_UINTEGER_4) 0)); } +iexport(random_r4); /* A routine to return a REAL(KIND=8). */ -#define random_r8 prefix(random_r8) void random_r8 (GFC_REAL_8 * harv) { @@ -225,12 +235,12 @@ random_r8 (GFC_REAL_8 * harv) (GFC_REAL_8) (~(GFC_UINTEGER_8) 0); i += 2; } +iexport(random_r8); /* Code to handle arrays will follow here. */ /* REAL(KIND=4) REAL array. */ -#define arandom_r4 prefix(arandom_r4) void arandom_r4 (gfc_array_r4 * harv) { @@ -304,7 +314,6 @@ arandom_r4 (gfc_array_r4 * harv) /* REAL(KIND=8) array. */ -#define arandom_r8 prefix(arandom_r8) void arandom_r8 (gfc_array_r8 * harv) { @@ -376,8 +385,8 @@ arandom_r8 (gfc_array_r8 * harv) } } } -#endif /* Mersenne Twister code */ +#else /* George Marsaglia's KISS (Keep It Simple Stupid) random number generator. @@ -418,9 +427,6 @@ arandom_r8 (gfc_array_r8 * harv) "There is no copyright on the code below." included the original KISS algorithm. */ -#include "config.h" -#include "libgfortran.h" - #define GFC_SL(k, n) ((k)^((k)<<(n))) #define GFC_SR(k, n) ((k)^((k)>>(n))) @@ -436,7 +442,6 @@ static GFC_UINTEGER_4 kiss_seed[4] = KISS_DEFAULT_SEED; static GFC_UINTEGER_4 kiss_random_kernel(void) { - GFC_UINTEGER_4 kiss; kiss_seed[0] = 69069 * kiss_seed[0] + 1327217885; @@ -446,16 +451,14 @@ kiss_random_kernel(void) kiss = kiss_seed[0] + kiss_seed[1] + (kiss_seed[2] << 16) + kiss_seed[3]; return kiss; - } /* This function produces a REAL(4) value from the uniform distribution with range [0,1). */ void -prefix(random_r4) (GFC_REAL_4 *x) +random_r4 (GFC_REAL_4 *x) { - GFC_UINTEGER_4 kiss; kiss = kiss_random_kernel (); @@ -464,26 +467,27 @@ prefix(random_r4) (GFC_REAL_4 *x) kiss_random_kernel (); *x = normalize_r4_i4 (kiss, ~(GFC_UINTEGER_4) 0); } +iexport(random_r4); /* This function produces a REAL(8) value from the uniform distribution with range [0,1). */ void -prefix(random_r8) (GFC_REAL_8 *x) +random_r8 (GFC_REAL_8 *x) { - GFC_UINTEGER_8 kiss; kiss = ((GFC_UINTEGER_8)kiss_random_kernel ()) << 32; kiss += kiss_random_kernel (); *x = normalize_r8_i8 (kiss, ~(GFC_UINTEGER_8) 0); } +iexport(random_r8); /* This function fills a REAL(4) array with values from the uniform distribution with range [0,1). */ void -prefix(arandom_r4) (gfc_array_r4 *x) +arandom_r4 (gfc_array_r4 *x) { index_type count[GFC_MAX_DIMENSIONS - 1]; index_type extent[GFC_MAX_DIMENSIONS - 1]; @@ -513,7 +517,7 @@ prefix(arandom_r4) (gfc_array_r4 *x) while (dest) { - prefix(random_r4) (dest); + random_r4 (dest); /* Advance to the next element. */ dest += stride0; @@ -547,7 +551,7 @@ prefix(arandom_r4) (gfc_array_r4 *x) distribution with range [0,1). */ void -prefix(arandom_r8) (gfc_array_r8 *x) +arandom_r8 (gfc_array_r8 *x) { index_type count[GFC_MAX_DIMENSIONS - 1]; index_type extent[GFC_MAX_DIMENSIONS - 1]; @@ -577,7 +581,7 @@ prefix(arandom_r8) (gfc_array_r8 *x) while (dest) { - prefix(random_r8) (dest); + random_r8 (dest); /* Advance to the next element. */ dest += stride0; @@ -607,8 +611,8 @@ prefix(arandom_r8) (gfc_array_r8 *x) } } -/* prefix(random_seed) is used to seed the PRNG with either a default - set of seeds or user specified set of seeds. prefix(random_seed) +/* random_seed is used to seed the PRNG with either a default + set of seeds or user specified set of seeds. random_seed must be called with no argument or exactly one argument. */ void @@ -666,3 +670,6 @@ random_seed (GFC_INTEGER_4 *size, gfc_array_i4 *put, gfc_array_i4 *get) get->data[i * get->dim[0].stride] = (GFC_INTEGER_4) kiss_seed[i]; } } +iexport(random_seed); + +#endif /* mersenne twister */ |