This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [gfortran] g77 compatibility patch
- From: Paul Brook <paul at codesourcery dot com>
- To: fortran at gcc dot gnu dot org
- Cc: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>,gcc-patches at gcc dot gnu dot org
- Date: Sat, 12 Jun 2004 18:38:19 +0100
- Subject: Re: [gfortran] g77 compatibility patch
- Organization: CodeSourcery
- References: <20040601021500.GA70719@troutmask.apl.washington.edu>
On Tuesday 01 June 2004 03:15, Steve Kargl wrote:
> The patches and files included here implement the
> following g77 functions and subroutines:
> intrinsic functions: dtime, etime, irand, rand, second.
> intrinsic subroutines: dtime, etime, second, srand.
> I have tried to address the rounding issues in rand() that
> were discussed in other emails. I'm sure there are problems
> or changes that someone will want to these routines. Feel
> free to fix them. I will not have time to work on gfortran
> for the next 2 to 4 weeks. The documentation of each function
> or subroutine is contained in g77.info.
Unfortunately g77.info no longer exists. Please add a description of these
intrinsics to the gfortran manual.
> 2004-05-31 Steven G. Kargl <kargls@comcast.net>
> * check.c (gfc_check_second_sub, gfc_check_irand, gfc_check_rand
> gfc_check_srand, gfc_check_etime, gfc_check_etime_sub): New
> functions. * gfortran.h (gfc_generic_isym_id): New symbols GFC_ISYM_ETIME,
> GFC_ISYM_IRAND, GFC_ISYM_RAND, GFC_ISYM_SECOND.
> * trans-intrinsic.c: Use symbols.
> * intrinsic.c (add_sym_2s): New function.
> * intrinsic.c: Add etime, dtime, irand, rand, second, srand.
> * intrinsic.h: Function prototypes.
> * iresolve.c (gfc_resolve_etime_sub, gfc_resolve_second_sub
> gfc_resolve_srand): New functions.
>
> ChangeLog for libgfortran
>
> 2004-05-31 Steven G. Kargl <kargls@comcast.net>
> * Makefile.am: Add rand.c and etime.c
> * Makefile.in: Regenerated.
> * aclocal.in: Regenerated.
> * cpu_time.c (second_sub, second): New functions.
> * rand.c (irand, rand, srand): New file.
> * etime.c (etime_sub, etime): New file.
I changed the compiler bits to require kind=4 arguments, and applied as
attached.
Paul
Index: gcc/fortran/check.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/fortran/check.c,v
retrieving revision 1.5
diff -u -p -r1.5 check.c
--- gcc/fortran/check.c 23 May 2004 11:06:09 -0000 1.5
+++ gcc/fortran/check.c 12 Jun 2004 17:15:57 -0000
@@ -1877,6 +1877,23 @@ gfc_check_random_seed (gfc_expr * size,
return SUCCESS;
}
+try
+gfc_check_second_sub (gfc_expr * time)
+{
+
+ if (scalar_check (time, 0) == FAILURE)
+ return FAILURE;
+
+ if (type_check (time, 0, BT_REAL) == FAILURE)
+ return FAILURE;
+
+ if (kind_value_check(time, 0, 4) == FAILURE)
+ return FAILURE;
+
+ return SUCCESS;
+}
+
+
/* The arguments of SYSTEM_CLOCK are scalar, integer variables. Note,
count, count_rate, and count_max are all optional arguments */
@@ -1935,3 +1952,99 @@ gfc_check_system_clock (gfc_expr * count
return SUCCESS;
}
+
+try
+gfc_check_irand (gfc_expr * x)
+{
+ if (scalar_check (x, 0) == FAILURE)
+ return FAILURE;
+
+ if (type_check (x, 0, BT_INTEGER) == FAILURE)
+ return FAILURE;
+
+ if (kind_value_check(x, 0, 4) == FAILURE)
+ return FAILURE;
+
+ return SUCCESS;
+}
+
+try
+gfc_check_rand (gfc_expr * x)
+{
+ if (scalar_check (x, 0) == FAILURE)
+ return FAILURE;
+
+ if (type_check (x, 0, BT_INTEGER) == FAILURE)
+ return FAILURE;
+
+ if (kind_value_check(x, 0, 4) == FAILURE)
+ return FAILURE;
+
+ return SUCCESS;
+}
+
+try
+gfc_check_srand (gfc_expr * x)
+{
+ if (scalar_check (x, 0) == FAILURE)
+ return FAILURE;
+
+ if (type_check (x, 0, BT_INTEGER) == FAILURE)
+ return FAILURE;
+
+ if (kind_value_check(x, 0, 4) == FAILURE)
+ return FAILURE;
+
+ return SUCCESS;
+}
+
+try
+gfc_check_etime (gfc_expr * x)
+{
+ if (array_check (x, 0) == FAILURE)
+ return FAILURE;
+
+ if (rank_check (x, 0, 1) == FAILURE)
+ return FAILURE;
+
+ if (variable_check (x, 0) == FAILURE)
+ return FAILURE;
+
+ if (type_check (x, 0, BT_REAL) == FAILURE)
+ return FAILURE;
+
+ if (kind_value_check(x, 0, 4) == FAILURE)
+ return FAILURE;
+
+ return SUCCESS;
+}
+
+try
+gfc_check_etime_sub (gfc_expr * values, gfc_expr * time)
+{
+ if (array_check (values, 0) == FAILURE)
+ return FAILURE;
+
+ if (rank_check (values, 0, 1) == FAILURE)
+ return FAILURE;
+
+ if (variable_check (values, 0) == FAILURE)
+ return FAILURE;
+
+ if (type_check (values, 0, BT_REAL) == FAILURE)
+ return FAILURE;
+
+ if (kind_value_check(values, 0, 4) == FAILURE)
+ return FAILURE;
+
+ if (scalar_check (time, 1) == FAILURE)
+ return FAILURE;
+
+ if (type_check (time, 1, BT_REAL) == FAILURE)
+ return FAILURE;
+
+ if (kind_value_check(time, 1, 4) == FAILURE)
+ return FAILURE;
+
+ return SUCCESS;
+}
Index: gcc/fortran/gfortran.h
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/fortran/gfortran.h,v
retrieving revision 1.11
diff -u -p -r1.11 gfortran.h
--- gcc/fortran/gfortran.h 3 Jun 2004 22:35:39 -0000 1.11
+++ gcc/fortran/gfortran.h 12 Jun 2004 17:14:30 -0000
@@ -301,6 +301,7 @@ enum gfc_generic_isym_id
GFC_ISYM_DOT_PRODUCT,
GFC_ISYM_DPROD,
GFC_ISYM_EOSHIFT,
+ GFC_ISYM_ETIME,
GFC_ISYM_EXP,
GFC_ISYM_EXPONENT,
GFC_ISYM_FLOOR,
@@ -315,6 +316,7 @@ enum gfc_generic_isym_id
GFC_ISYM_INDEX,
GFC_ISYM_INT,
GFC_ISYM_IOR,
+ GFC_ISYM_IRAND,
GFC_ISYM_ISHFT,
GFC_ISYM_ISHFTC,
GFC_ISYM_LBOUND,
@@ -343,12 +345,14 @@ enum gfc_generic_isym_id
GFC_ISYM_PACK,
GFC_ISYM_PRESENT,
GFC_ISYM_PRODUCT,
+ GFC_ISYM_RAND,
GFC_ISYM_REAL,
GFC_ISYM_REPEAT,
GFC_ISYM_RESHAPE,
GFC_ISYM_RRSPACING,
GFC_ISYM_SCALE,
GFC_ISYM_SCAN,
+ GFC_ISYM_SECOND,
GFC_ISYM_SET_EXPONENT,
GFC_ISYM_SHAPE,
GFC_ISYM_SI_KIND,
Index: gcc/fortran/intrinsic.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/fortran/intrinsic.c,v
retrieving revision 1.7
diff -u -p -r1.7 intrinsic.c
--- gcc/fortran/intrinsic.c 5 Jun 2004 11:34:51 -0000 1.7
+++ gcc/fortran/intrinsic.c 12 Jun 2004 17:17:48 -0000
@@ -429,6 +429,32 @@ static void add_sym_2 (const char *name,
}
+/* Add the name of an intrinsic subroutine with two arguments to the list
+ of intrinsic names. */
+
+static void add_sym_2s (const char *name, int elemental, int actual_ok, bt type,
+ int kind,
+ try (*check)(gfc_expr *,gfc_expr *,gfc_expr *),
+ gfc_expr *(*simplify)(gfc_expr *,gfc_expr *,gfc_expr *),
+ void (*resolve)(gfc_code *),
+ const char* a1, bt type1, int kind1, int optional1,
+ const char* a2, bt type2, int kind2, int optional2
+ ) {
+ gfc_check_f cf;
+ gfc_simplify_f sf;
+ gfc_resolve_f rf;
+
+ cf.f3 = check;
+ sf.f3 = simplify;
+ rf.s1 = resolve;
+
+ add_sym (name, elemental, actual_ok, type, kind, cf, sf, rf,
+ a1, type1, kind1, optional1,
+ a2, type2, kind2, optional2,
+ (void*)0);
+}
+
+
static void add_sym_3 (const char *name, int elemental, int actual_ok, bt type,
int kind,
try (*check)(gfc_expr *,gfc_expr *,gfc_expr *),
@@ -989,6 +1015,16 @@ add_functions (void)
make_generic ("epsilon", GFC_ISYM_NONE);
+ /* G77 compatibility */
+ add_sym_1 ("etime", 0, 1, BT_REAL, 4,
+ gfc_check_etime, NULL, NULL,
+ x, BT_REAL, 4, 0);
+
+ make_alias ("dtime");
+
+ make_generic ("etime", GFC_ISYM_ETIME);
+
+
add_sym_1 ("exp", 1, 1, BT_REAL, dr,
NULL, gfc_simplify_exp, gfc_resolve_exp, x, BT_REAL, dr, 0);
@@ -1098,6 +1134,13 @@ add_functions (void)
make_generic ("ior", GFC_ISYM_IOR);
+ /* The following function is for G77 compatibility. */
+ add_sym_1 ("irand", 0, 1, BT_INTEGER, 4,
+ gfc_check_irand, NULL, NULL,
+ i, BT_INTEGER, 4, 0);
+
+ make_generic ("irand", GFC_ISYM_IRAND);
+
add_sym_2 ("ishft", 1, 1, BT_INTEGER, di,
gfc_check_ishft, gfc_simplify_ishft, gfc_resolve_ishft,
i, BT_INTEGER, di, 0, sh, BT_INTEGER, di, 0);
@@ -1386,6 +1429,13 @@ add_functions (void)
make_generic ("radix", GFC_ISYM_NONE);
+ /* The following function is for G77 compatibility. */
+ add_sym_1 ("rand", 0, 1, BT_REAL, 4,
+ gfc_check_rand, NULL, NULL,
+ i, BT_INTEGER, 4, 0);
+
+ make_generic ("rand", GFC_ISYM_RAND);
+
add_sym_1 ("range", 0, 1, BT_INTEGER, di,
gfc_check_range, gfc_simplify_range, NULL,
x, BT_REAL, dr, 0);
@@ -1436,6 +1486,11 @@ add_functions (void)
make_generic ("scan", GFC_ISYM_SCAN);
+ /* Added for G77 compatibility garbage. */
+ add_sym_0 ("second", 0, 1, BT_REAL, 4, NULL, NULL, NULL);
+
+ make_generic ("second", GFC_ISYM_SECOND);
+
add_sym_1 ("selected_int_kind", 0, 1, BT_INTEGER, di,
NULL, gfc_simplify_selected_int_kind, NULL,
r, BT_INTEGER, di, 0);
@@ -1606,6 +1661,8 @@ add_functions (void)
bck, BT_LOGICAL, dl, 1);
make_generic ("verify", GFC_ISYM_VERIFY);
+
+
}
@@ -1634,11 +1691,25 @@ add_subroutines (void)
gfc_check_cpu_time, NULL, gfc_resolve_cpu_time,
tm, BT_REAL, dr, 0);
+ /* More G77 compatibility garbage. */
+ add_sym_1s ("second", 0, 1, BT_UNKNOWN, 0,
+ gfc_check_second_sub, NULL, gfc_resolve_second_sub,
+ tm, BT_REAL, dr, 0);
+
add_sym_4 ("date_and_time", 0, 1, BT_UNKNOWN, 0,
gfc_check_date_and_time, NULL, NULL,
dt, BT_CHARACTER, dc, 1, tm, BT_CHARACTER, dc, 1,
zn, BT_CHARACTER, dc, 1, vl, BT_INTEGER, di, 1);
+ /* More G77 compatibility garbage. */
+ add_sym_2s ("etime", 0, 1, BT_UNKNOWN, 0,
+ gfc_check_etime_sub, NULL, gfc_resolve_etime_sub,
+ vl, BT_REAL, 4, 0, tm, BT_REAL, 4, 0);
+
+ add_sym_2s ("dtime", 0, 1, BT_UNKNOWN, 0,
+ gfc_check_etime_sub, NULL, gfc_resolve_etime_sub,
+ vl, BT_REAL, 4, 0, tm, BT_REAL, 4, 0);
+
add_sym_2 ("getarg", 0, 1, BT_UNKNOWN, 0,
NULL, NULL, NULL,
c, BT_INTEGER, di, 0, vl, BT_CHARACTER, dc, 0);
@@ -1659,6 +1730,11 @@ add_subroutines (void)
sz, BT_INTEGER, di, 1, pt, BT_INTEGER, di, 1,
gt, BT_INTEGER, di, 1);
+ /* More G77 compatibility garbage. */
+ add_sym_1s ("srand", 0, 1, BT_UNKNOWN, di,
+ gfc_check_srand, NULL, gfc_resolve_srand,
+ c, BT_INTEGER, 4, 0);
+
add_sym_3s ("system_clock", 0, 1, BT_UNKNOWN, 0,
gfc_check_system_clock, NULL, gfc_resolve_system_clock,
c, BT_INTEGER, di, 1, cr, BT_INTEGER, di, 1,
Index: gcc/fortran/intrinsic.h
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/fortran/intrinsic.h,v
retrieving revision 1.5
diff -u -p -r1.5 intrinsic.h
--- gcc/fortran/intrinsic.h 22 May 2004 12:47:38 -0000 1.5
+++ gcc/fortran/intrinsic.h 12 Jun 2004 17:14:30 -0000
@@ -1,6 +1,6 @@
/* Header file for intrinsics check, resolve and simplify function
prototypes.
- Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
Contributed by Andy Vaught & Katherine Holcomb
This file is part of GCC.
@@ -44,6 +44,8 @@ try gfc_check_dble (gfc_expr *);
try gfc_check_digits (gfc_expr *);
try gfc_check_dot_product (gfc_expr *, gfc_expr *);
try gfc_check_eoshift (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
+try gfc_check_etime (gfc_expr *);
+try gfc_check_etime_sub (gfc_expr *, gfc_expr *);
try gfc_check_huge (gfc_expr *);
try gfc_check_i (gfc_expr *);
try gfc_check_iand (gfc_expr *, gfc_expr *);
@@ -55,6 +57,7 @@ try gfc_check_ieor (gfc_expr *, gfc_expr
try gfc_check_index (gfc_expr *, gfc_expr *, gfc_expr *);
try gfc_check_int (gfc_expr *, gfc_expr *);
try gfc_check_ior (gfc_expr *, gfc_expr *);
+try gfc_check_irand (gfc_expr *);
try gfc_check_ishft (gfc_expr *, gfc_expr *);
try gfc_check_ishftc (gfc_expr *, gfc_expr *, gfc_expr *);
try gfc_check_kind (gfc_expr *);
@@ -75,18 +78,21 @@ try gfc_check_precision (gfc_expr *);
try gfc_check_present (gfc_expr *);
try gfc_check_product (gfc_expr *, gfc_expr *, gfc_expr *);
try gfc_check_radix (gfc_expr *);
+try gfc_check_rand (gfc_expr *);
try gfc_check_range (gfc_expr *);
try gfc_check_real (gfc_expr *, gfc_expr *);
try gfc_check_repeat (gfc_expr *, gfc_expr *);
try gfc_check_reshape (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
try gfc_check_scale (gfc_expr *, gfc_expr *);
try gfc_check_scan (gfc_expr *, gfc_expr *, gfc_expr *);
+try gfc_check_second_sub (gfc_expr *);
try gfc_check_selected_real_kind (gfc_expr *, gfc_expr *);
try gfc_check_set_exponent (gfc_expr *, gfc_expr *);
try gfc_check_shape (gfc_expr *);
try gfc_check_size (gfc_expr *, gfc_expr *);
try gfc_check_sign (gfc_expr *, gfc_expr *);
try gfc_check_spread (gfc_expr *, gfc_expr *, gfc_expr *);
+try gfc_check_srand (gfc_expr *);
try gfc_check_sum (gfc_expr *, gfc_expr *, gfc_expr *);
try gfc_check_transfer (gfc_expr *, gfc_expr *, gfc_expr *);
try gfc_check_transpose (gfc_expr *);
@@ -240,6 +246,7 @@ void gfc_resolve_dot_product (gfc_expr *
void gfc_resolve_dprod (gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_eoshift (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *,
gfc_expr *);
+void gfc_resolve_etime_sub (gfc_code *);
void gfc_resolve_exp (gfc_expr *, gfc_expr *);
void gfc_resolve_exponent (gfc_expr *, gfc_expr *);
void gfc_resolve_floor (gfc_expr *, gfc_expr *, gfc_expr *);
@@ -283,6 +290,7 @@ void gfc_resolve_reshape (gfc_expr *, gf
void gfc_resolve_rrspacing (gfc_expr *, gfc_expr *);
void gfc_resolve_scale (gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_scan (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
+void gfc_resolve_second_sub (gfc_code *);
void gfc_resolve_set_exponent (gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_shape (gfc_expr *, gfc_expr *);
void gfc_resolve_sign (gfc_expr *, gfc_expr *, gfc_expr *);
@@ -291,6 +299,7 @@ void gfc_resolve_sinh (gfc_expr *, gfc_e
void gfc_resolve_spacing (gfc_expr *, gfc_expr *);
void gfc_resolve_spread (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_sqrt (gfc_expr *, gfc_expr *);
+void gfc_resolve_srand (gfc_code *);
void gfc_resolve_sum (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_tan (gfc_expr *, gfc_expr *);
void gfc_resolve_tanh (gfc_expr *, gfc_expr *);
Index: gcc/fortran/iresolve.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/fortran/iresolve.c,v
retrieving revision 1.6
diff -u -p -r1.6 iresolve.c
--- gcc/fortran/iresolve.c 30 May 2004 10:49:47 -0000 1.6
+++ gcc/fortran/iresolve.c 12 Jun 2004 17:18:18 -0000
@@ -1369,6 +1369,42 @@ gfc_resolve_random_number (gfc_code * c
name = gfc_get_string (PREFIX("arandom_r%d"), kind);
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
+
+}
+
+
+/* G77 compatibility subroutines etime() and dtime(). */
+
+void
+gfc_resolve_etime_sub (gfc_code * c)
+{
+ const char *name;
+
+ name = gfc_get_string (PREFIX("etime_sub"));
+ c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
+}
+
+
+/* G77 compatibility subroutine second(). */
+
+void
+gfc_resolve_second_sub (gfc_code * c)
+{
+ const char *name;
+
+ name = gfc_get_string (PREFIX("second_sub"));
+ c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
+}
+
+
+/* G77 compatibility function srand(). */
+
+void
+gfc_resolve_srand (gfc_code * c)
+{
+ const char *name;
+ name = gfc_get_string (PREFIX("srand"));
+ c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
}
@@ -1393,7 +1429,6 @@ gfc_resolve_system_clock (gfc_code * c)
c->resolved_sym = gfc_get_intrinsic_sub_symbol (name);
}
-
void
gfc_iresolve_init_1 (void)
{
Index: gcc/fortran/trans-intrinsic.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/fortran/trans-intrinsic.c,v
retrieving revision 1.5
diff -u -p -r1.5 trans-intrinsic.c
--- gcc/fortran/trans-intrinsic.c 14 May 2004 15:32:01 -0000 1.5
+++ gcc/fortran/trans-intrinsic.c 12 Jun 2004 17:14:30 -0000
@@ -2867,6 +2867,10 @@ gfc_conv_intrinsic_function (gfc_se * se
case GFC_ISYM_DOT_PRODUCT:
case GFC_ISYM_MATMUL:
+ case GFC_ISYM_IRAND:
+ case GFC_ISYM_RAND:
+ case GFC_ISYM_ETIME:
+ case GFC_ISYM_SECOND:
gfc_conv_intrinsic_funcall (se, expr);
break;
Index: libgfortran/Makefile.am
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/libgfortran/Makefile.am,v
retrieving revision 1.8
diff -u -p -r1.8 Makefile.am
--- libgfortran/Makefile.am 12 Jun 2004 15:15:41 -0000 1.8
+++ libgfortran/Makefile.am 12 Jun 2004 17:18:35 -0000
@@ -42,11 +42,13 @@ intrinsics/cshift0.c \
intrinsics/date_and_time.c \
intrinsics/eoshift0.c \
intrinsics/eoshift2.c \
+intrinsics/etime.c \
intrinsics/ishftc.c \
intrinsics/pack_generic.c \
intrinsics/size.c \
intrinsics/spread_generic.c \
intrinsics/string_intrinsics.c \
+intrinsics/rand.c \
intrinsics/random.c \
intrinsics/reshape_generic.c \
intrinsics/reshape_packed.c \
Index: libgfortran/intrinsics/cpu_time.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/libgfortran/intrinsics/cpu_time.c,v
retrieving revision 1.2
diff -u -p -r1.2 cpu_time.c
--- libgfortran/intrinsics/cpu_time.c 13 May 2004 06:41:02 -0000 1.2
+++ libgfortran/intrinsics/cpu_time.c 12 Jun 2004 17:04:45 -0000
@@ -114,3 +114,16 @@ void prefix(cpu_time_##KIND) (GFC_REAL_#
CPU_TIME(4)
CPU_TIME(8)
+void
+prefix(second_sub) (GFC_REAL_4 *s)
+{
+ prefix(cpu_time_4)(s);
+}
+
+GFC_REAL_4
+prefix(second) (void)
+{
+ GFC_REAL_4 s;
+ prefix(cpu_time_4)(&s);
+ return s;
+}
Index: libgfortran/intrinsics/etime.c
===================================================================
RCS file: libgfortran/intrinsics/etime.c
diff -N libgfortran/intrinsics/etime.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libgfortran/intrinsics/etime.c 12 Jun 2004 17:09:48 -0000
@@ -0,0 +1,81 @@
+/* Implementation of the ETIME intrinsic.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ Contributed by Steven G. Kargl <kargls@comcast.net>.
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+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.
+
+Libgfortran 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 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 "config.h"
+#include <sys/types.h>
+#include "libgfortran.h"
+
+#include <stdio.h>
+
+#if defined (HAVE_SYS_TIME_H) && defined (HAVE_SYS_RESOURCE_H)
+#include <sys/time.h>
+#include <sys/resource.h>
+#endif
+
+void
+prefix(etime_sub) (gfc_array_r4 *t, GFC_REAL_4 *result)
+{
+ GFC_REAL_4 tu, ts, tt, *tp;
+ index_type dim;
+
+#if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H)
+ struct rusage rt;
+
+ if (getrusage(RUSAGE_SELF, &rt) == 0)
+ {
+ tu = (GFC_REAL_4)(rt.ru_utime.tv_sec + 1.e-6 * rt.ru_utime.tv_usec);
+ ts = (GFC_REAL_4)(rt.ru_stime.tv_sec + 1.e-6 * rt.ru_stime.tv_usec);
+ tt = tu + ts;
+ }
+ else
+ {
+ tu = -1.;
+ ts = -1.;
+ tt = -1.;
+ }
+#else
+ tu = -1.;
+ ts = -1.;
+ tt = -1.;
+#endif
+
+ dim = GFC_DESCRIPTOR_RANK (t);
+ if (dim != 1)
+ runtime_error ("Array rank of TARRAY is not 1.");
+
+ if (t->dim[0].stride == 0)
+ t->dim[0].stride = 1;
+
+ tp = t->data;
+
+ *tp = tu;
+ tp += t->dim[0].stride;
+ *tp = ts;
+ *result = tt;
+}
+
+GFC_REAL_4
+prefix(etime) (gfc_array_r4 *t)
+{
+ GFC_REAL_4 val;
+ prefix(etime_sub) (t, &val);
+ return val;
+}
Index: libgfortran/intrinsics/rand.c
===================================================================
RCS file: libgfortran/intrinsics/rand.c
diff -N libgfortran/intrinsics/rand.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libgfortran/intrinsics/rand.c 12 Jun 2004 17:09:26 -0000
@@ -0,0 +1,93 @@
+/* Implementation of the IRAND, RAND, and SRAND intrinsics.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ Contributed by Steven G. Kargl <kargls@comcast.net>.
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+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.
+
+Libgfortran 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 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. */
+
+/* Simple multiplicative congruent algorithm.
+ The period of this generator is approximately 2^31-1, which means that
+ it should not be used for anything serious. The implementation here
+ is based of an algorithm from S.K. Park and K.W. Miller, Comm. ACM,
+ 31, 1192-1201 (1988). It is also provided solely for compatibility
+ with G77. */
+
+#include "config.h"
+#include "libgfortran.h"
+
+#define GFC_RAND_A 16807
+#define GFC_RAND_M 2147483647
+#define GFC_RAND_M1 (GFC_RAND_M - 1)
+
+static GFC_UINTEGER_8 rand_seed = 1;
+
+
+/* Set the seed of the irand generator. Note 0 is a bad seed. */
+
+void
+prefix(srand) (GFC_INTEGER_4 *i)
+{
+ rand_seed = (GFC_UINTEGER_8) (*i != 0) ? *i : 123459876;
+}
+
+
+/* Return an INTEGER in the range [1,GFC_RAND_M-1]. */
+
+GFC_INTEGER_4
+prefix(irand) (GFC_INTEGER_4 *i)
+{
+
+ GFC_INTEGER_4 j = *i;
+
+ switch (j)
+ {
+ /* Return the next RN. */
+ case 0:
+ break;
+
+ /* Reset the RN sequence to system-dependent sequence and return the
+ first value. */
+ case 1:
+ j = 0;
+ prefix(srand) (&j);
+ break;
+
+ /* Seed the RN sequence with j and return the first value. */
+ default:
+ prefix(srand) (&j);
+ }
+
+ rand_seed = GFC_RAND_A * rand_seed % GFC_RAND_M;
+
+ return (GFC_INTEGER_4) rand_seed;
+}
+
+
+/* Return a REAL in the range [0,1). Cast to double to use the full
+ range of pseudo-random numbers returned by irand(). */
+
+GFC_REAL_4
+prefix(rand) (GFC_INTEGER_4 *i)
+{
+ GFC_REAL_4 val;
+
+ do
+ val = (GFC_REAL_4)((double)(prefix(irand) (i) - 1) / (double) GFC_RAND_M1);
+ while (val == 1.0);
+
+ return val;
+}