]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/intrinsics/etime.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / intrinsics / etime.c
CommitLineData
2bd74949 1/* Implementation of the ETIME intrinsic.
a945c346 2 Copyright (C) 2004-2024 Free Software Foundation, Inc.
2bd74949
SK
3 Contributed by Steven G. Kargl <kargls@comcast.net>.
4
b6e7a3d1 5This file is part of the GNU Fortran runtime library (libgfortran).
2bd74949
SK
6
7Libgfortran is free software; you can redistribute it and/or
57dea9f6 8modify it under the terms of the GNU General Public
2bd74949 9License as published by the Free Software Foundation; either
748086b7 10version 3 of the License, or (at your option) any later version.
2bd74949
SK
11
12Libgfortran is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57dea9f6 15GNU General Public License for more details.
2bd74949 16
748086b7
JJ
17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24<http://www.gnu.org/licenses/>. */
2bd74949 25
2bd74949 26#include "libgfortran.h"
a1ba31ce 27#include "time_1.h"
2bd74949 28
7d7b8bfe
RH
29extern void etime_sub (gfc_array_r4 *t, GFC_REAL_4 *result);
30iexport_proto(etime_sub);
31
2bd74949 32void
7d7b8bfe 33etime_sub (gfc_array_r4 *t, GFC_REAL_4 *result)
2bd74949
SK
34{
35 GFC_REAL_4 tu, ts, tt, *tp;
a1ba31ce 36 long user_sec, user_usec, system_sec, system_usec;
2bd74949 37
dfb55fdc 38 if (((GFC_DESCRIPTOR_EXTENT(t,0))) < 2)
a1ba31ce 39 runtime_error ("Insufficient number of elements in TARRAY.");
2bd74949 40
b6e7a3d1 41 if (gf_cputime (&user_sec, &user_usec, &system_sec, &system_usec) == 0)
2bd74949 42 {
a1ba31ce
DF
43 tu = (GFC_REAL_4)(user_sec + 1.e-6 * user_usec);
44 ts = (GFC_REAL_4)(system_sec + 1.e-6 * system_usec);
2bd74949
SK
45 tt = tu + ts;
46 }
47 else
48 {
a1ba31ce
DF
49 tu = (GFC_REAL_4)-1.0;
50 ts = (GFC_REAL_4)-1.0;
51 tt = (GFC_REAL_4)-1.0;
2bd74949 52 }
2bd74949 53
21d1335b 54 tp = t->base_addr;
2bd74949
SK
55
56 *tp = tu;
dfb55fdc 57 tp += GFC_DESCRIPTOR_STRIDE(t,0);
2bd74949
SK
58 *tp = ts;
59 *result = tt;
60}
7d7b8bfe
RH
61iexport(etime_sub);
62
63extern GFC_REAL_4 etime (gfc_array_r4 *t);
64export_proto(etime);
2bd74949
SK
65
66GFC_REAL_4
7d7b8bfe 67etime (gfc_array_r4 *t)
2bd74949
SK
68{
69 GFC_REAL_4 val;
7d7b8bfe 70 etime_sub (t, &val);
2bd74949
SK
71 return val;
72}