diff options
author | pbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-05-22 12:47:42 +0000 |
---|---|---|
committer | pbrook <pbrook@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-05-22 12:47:42 +0000 |
commit | 3db98e11f48c95a4b2dd11d2a2f3f8aa8162968b (patch) | |
tree | 861dbef282074d370fa3d6efc8e98b40d0c69ccd /libgfortran | |
parent | 9857bf0dc83841c6d888c517d8bce5c48e59d6bf (diff) | |
download | gcc-3db98e11f48c95a4b2dd11d2a2f3f8aa8162968b.tar.gz |
* check.c (gfc_check_system_clock): New function.
* intrinsic.c (add_sym_3s): New function.
(add_subroutines): Use it.
* intrinsic.h (gfc_check_system_clock, gfc_resolve_system_clock):
Add prototypes.
* iresolve.c (gfc_resolve_system_clock): New function.
libgfortran/
* intrinsics/system_clock: New file.
* Makefile.am: Add intrinsics/system_clock.c.
* Makefile.in: Regenerate.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@82131 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 6 | ||||
-rw-r--r-- | libgfortran/Makefile.am | 1 | ||||
-rw-r--r-- | libgfortran/Makefile.in | 31 | ||||
-rw-r--r-- | libgfortran/intrinsics/system_clock.c | 200 |
4 files changed, 236 insertions, 2 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 3eedff3926a..e6cfffb132c 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2004-05-22 Steven G. Kargl <kargls@comcast.net> + + * intrinsics/system_clock: New file. + * Makefile.am: Add intrinsics/system_clock.c. + * Makefile.in: Regenerate. + 2004-05-21 Roger Sayle <roger@eyesopen.com> * io/format.c (parse_format_list): Allow the comma after a string diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am index 12977f5bd3d..b451b381146 100644 --- a/libgfortran/Makefile.am +++ b/libgfortran/Makefile.am @@ -49,6 +49,7 @@ intrinsics/random.c \ intrinsics/reshape_generic.c \ intrinsics/reshape_packed.c \ intrinsics/selected_kind.f90 \ +intrinsics/system_clock.c \ intrinsics/transpose_generic.c \ intrinsics/unpack_generic.c \ runtime/in_pack_generic.c \ diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in index 1bb1dd57627..9c878de3f5d 100644 --- a/libgfortran/Makefile.in +++ b/libgfortran/Makefile.in @@ -121,8 +121,8 @@ am__objects_33 = associated.lo abort.lo cpu_time.lo cshift0.lo \ eoshift0.lo eoshift2.lo ishftc.lo pack_generic.lo size.lo \ spread_generic.lo string_intrinsics.lo random.lo \ reshape_generic.lo reshape_packed.lo selected_kind.lo \ - transpose_generic.lo unpack_generic.lo in_pack_generic.lo \ - in_unpack_generic.lo + system_clock.lo transpose_generic.lo unpack_generic.lo \ + in_pack_generic.lo in_unpack_generic.lo am__objects_34 = am__objects_35 = _abs_c4.lo _abs_c8.lo _abs_i4.lo _abs_i8.lo \ _abs_r4.lo _abs_r8.lo _exp_r4.lo _exp_r8.lo _exp_c4.lo \ @@ -272,6 +272,7 @@ am__depfiles_maybe = depfiles @AMDEP_TRUE@ ./$(DEPDIR)/sum_c4.Plo ./$(DEPDIR)/sum_c8.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/sum_i4.Plo ./$(DEPDIR)/sum_i8.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/sum_r4.Plo ./$(DEPDIR)/sum_r8.Plo \ +@AMDEP_TRUE@ ./$(DEPDIR)/system_clock.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/transfer.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/transpose_generic.Plo \ @AMDEP_TRUE@ ./$(DEPDIR)/transpose_i4.Plo \ @@ -442,6 +443,7 @@ intrinsics/random.c \ intrinsics/reshape_generic.c \ intrinsics/reshape_packed.c \ intrinsics/selected_kind.f90 \ +intrinsics/system_clock.c \ intrinsics/transpose_generic.c \ intrinsics/unpack_generic.c \ runtime/in_pack_generic.c \ @@ -1009,6 +1011,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sum_i8.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sum_r4.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sum_r8.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/system_clock.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/transfer.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/transpose_generic.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/transpose_i4.Plo@am__quote@ @@ -4596,6 +4599,30 @@ reshape_packed.lo: intrinsics/reshape_packed.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o reshape_packed.lo `test -f 'intrinsics/reshape_packed.c' || echo '$(srcdir)/'`intrinsics/reshape_packed.c +system_clock.o: intrinsics/system_clock.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT system_clock.o -MD -MP -MF "$(DEPDIR)/system_clock.Tpo" -c -o system_clock.o `test -f 'intrinsics/system_clock.c' || echo '$(srcdir)/'`intrinsics/system_clock.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/system_clock.Tpo" "$(DEPDIR)/system_clock.Po"; else rm -f "$(DEPDIR)/system_clock.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='intrinsics/system_clock.c' object='system_clock.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/system_clock.Po' tmpdepfile='$(DEPDIR)/system_clock.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o system_clock.o `test -f 'intrinsics/system_clock.c' || echo '$(srcdir)/'`intrinsics/system_clock.c + +system_clock.obj: intrinsics/system_clock.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT system_clock.obj -MD -MP -MF "$(DEPDIR)/system_clock.Tpo" -c -o system_clock.obj `if test -f 'intrinsics/system_clock.c'; then $(CYGPATH_W) 'intrinsics/system_clock.c'; else $(CYGPATH_W) '$(srcdir)/intrinsics/system_clock.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/system_clock.Tpo" "$(DEPDIR)/system_clock.Po"; else rm -f "$(DEPDIR)/system_clock.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='intrinsics/system_clock.c' object='system_clock.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/system_clock.Po' tmpdepfile='$(DEPDIR)/system_clock.TPo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o system_clock.obj `if test -f 'intrinsics/system_clock.c'; then $(CYGPATH_W) 'intrinsics/system_clock.c'; else $(CYGPATH_W) '$(srcdir)/intrinsics/system_clock.c'; fi` + +system_clock.lo: intrinsics/system_clock.c +@am__fastdepCC_TRUE@ if $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT system_clock.lo -MD -MP -MF "$(DEPDIR)/system_clock.Tpo" -c -o system_clock.lo `test -f 'intrinsics/system_clock.c' || echo '$(srcdir)/'`intrinsics/system_clock.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/system_clock.Tpo" "$(DEPDIR)/system_clock.Plo"; else rm -f "$(DEPDIR)/system_clock.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='intrinsics/system_clock.c' object='system_clock.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ depfile='$(DEPDIR)/system_clock.Plo' tmpdepfile='$(DEPDIR)/system_clock.TPlo' @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o system_clock.lo `test -f 'intrinsics/system_clock.c' || echo '$(srcdir)/'`intrinsics/system_clock.c + transpose_generic.o: intrinsics/transpose_generic.c @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT transpose_generic.o -MD -MP -MF "$(DEPDIR)/transpose_generic.Tpo" -c -o transpose_generic.o `test -f 'intrinsics/transpose_generic.c' || echo '$(srcdir)/'`intrinsics/transpose_generic.c; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/transpose_generic.Tpo" "$(DEPDIR)/transpose_generic.Po"; else rm -f "$(DEPDIR)/transpose_generic.Tpo"; exit 1; fi diff --git a/libgfortran/intrinsics/system_clock.c b/libgfortran/intrinsics/system_clock.c new file mode 100644 index 00000000000..6b6ae9d06a3 --- /dev/null +++ b/libgfortran/intrinsics/system_clock.c @@ -0,0 +1,200 @@ +/* Implementation of the SYSTEM_CLOCK intrinsic. + Copyright (C) 2004 Free Software Foundation, Inc. + +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 libgfortran; 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 <limits.h> + +#if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY) +# include <sys/time.h> +# define TCK 1000 +#elif defined(HAVE_TIME_H) +# include <time.h> +# define TCK 1 +#else +#define TCK 0 +#endif + + +#if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY) +static struct timeval tp0 = {-1, 0}; +#elif defined(HAVE_TIME_H) +static time_t t0 = (time_t) -2; +#endif + +/* prefix(system_clock_4) is the INTEGER(4) version of the SYSTEM_CLOCK + intrinsic subroutine. It returns the number of clock ticks for the current + system time, the number of ticks per second, and the maximum possible value + for COUNT. On the first call to SYSTEM_CLOCK, COUNT is set to zero. */ + +void +prefix(system_clock_4)(GFC_INTEGER_4 *count, GFC_INTEGER_4 *count_rate, + GFC_INTEGER_4 *count_max) +{ + GFC_INTEGER_4 cnt; + GFC_INTEGER_4 rate; + GFC_INTEGER_4 mx; + +#if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY) + struct timeval tp1; + struct timezone tzp; + double t; + + if (gettimeofday(&tp1, &tzp) == 0) + { + if (tp0.tv_sec < 0) + { + tp0 = tp1; + cnt = 0; + } + else + { + /* TODO: Convert this to integer arithmetic. */ + t = (double) (tp1.tv_sec - tp0.tv_sec); + t += (double) (tp1.tv_usec - tp0.tv_usec) * 1.e-6; + t *= TCK; + + if (t > (double) GFC_INTEGER_4_HUGE) + { + /* Time has wrapped. */ + while (t > (double) GFC_INTEGER_4_HUGE) + t -= (double) GFC_INTEGER_4_HUGE; + tp0 = tp1; + } + cnt = (GFC_INTEGER_4) t; + } + rate = TCK; + mx = GFC_INTEGER_4_HUGE; + } + else + { + if (count != NULL) *count = - GFC_INTEGER_4_HUGE; + if (count_rate != NULL) *count_rate = 0; + if (count_max != NULL) *count_max = 0; + } +#elif defined(HAVE_TIME_H) + time_t t, t1; + + t1 = time(NULL); + + if (t1 == (time_t) -1) + { + cnt = - GFC_INTEGER_4_HUGE; + mx = 0; + } + else if (t0 == (time_t) -2) + t0 = t1; + else + { + /* The timer counts in seconts, so for simplicity assume it never wraps. + Even with 32-bit counters this only happens once every 68 years. */ + cnt = t1 - t0; + mx = GFC_INTEGER_4_HUGE; + } +#else + cnt = - GFC_INTEGER_4_HUGE; + mx = 0; +#endif + if (count != NULL) *count = cnt; + if (count_rate != NULL) *count_rate = TCK; + if (count_max != NULL) *count_max = mx; +} + + +/* INTEGER(8) version of the above routine. */ + +void +prefix(system_clock_8)(GFC_INTEGER_8 *count, GFC_INTEGER_8 *count_rate, + GFC_INTEGER_8 *count_max) +{ + GFC_INTEGER_8 cnt; + GFC_INTEGER_8 rate; + GFC_INTEGER_8 mx; + +#if defined(HAVE_SYS_TIME_H) && defined(HAVE_GETTIMEOFDAY) + struct timeval tp1; + struct timezone tzp; + double t; + + if (gettimeofday(&tp1, &tzp) == 0) + { + if (tp0.tv_sec < 0) + { + tp0 = tp1; + cnt = 0; + } + else + { + /* TODO: Convert this to integer arithmetic. */ + t = (double) (tp1.tv_sec - tp0.tv_sec); + t += (double) (tp1.tv_usec - tp0.tv_usec) * 1.e-6; + t *= TCK; + + if (t > (double) GFC_INTEGER_8_HUGE) + { + /* Time has wrapped. */ + while (t > (double) GFC_INTEGER_8_HUGE) + t -= (double) GFC_INTEGER_8_HUGE; + tp0 = tp1; + } + cnt = (GFC_INTEGER_8) t; + } + rate = TCK; + mx = GFC_INTEGER_8_HUGE; + } + else + { + if (count != NULL) *count = - GFC_INTEGER_8_HUGE; + if (count_rate != NULL) *count_rate = 0; + if (count_max != NULL) *count_max = 0; + } +#elif defined(HAVE_TIME_H) + time_t t, t1; + + t1 = time(NULL); + + if (t1 == (time_t) -1) + { + cnt = - GFC_INTEGER_8_HUGE; + mx = 0; + } + else if (t0 == (time_t) -2) + t0 = t1; + else + { + /* The timer counts in seconts, so for simplicity assume it never wraps. + Even with 32-bit counters this only happens once every 68 years. */ + cnt = t1 - t0; + mx = GFC_INTEGER_8_HUGE; + } +#else + cnt = - GFC_INTEGER_8_HUGE; + mx = 0; +#endif + if (count != NULL) + *count = cnt; + if (count_rate != NULL) + *count_rate = TCK; + if (count_max != NULL) + *count_max = mx; +} + |