]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgfortran/intrinsics/cpu_time.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / intrinsics / cpu_time.c
CommitLineData
4ee9c684 1/* Implementation of the CPU_TIME intrinsic.
f1717362 2 Copyright (C) 2003-2016 Free Software Foundation, Inc.
4ee9c684 3
a2c0dc0f 4This file is part of the GNU Fortran runtime library (libgfortran).
4ee9c684 5
b417ea8c 6Libgfortran is free software; you can redistribute it and/or
7modify it under the terms of the GNU General Public
4ee9c684 8License as published by the Free Software Foundation; either
6bc9506f 9version 3 of the License, or (at your option) any later version.
b417ea8c 10
11Libgfortran is distributed in the hope that it will be useful,
4ee9c684 12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b417ea8c 14GNU General Public License for more details.
4ee9c684 15
6bc9506f 16Under Section 7 of GPL version 3, you are granted additional
17permissions described in the GCC Runtime Library Exception, version
183.1, as published by the Free Software Foundation.
19
20You should have received a copy of the GNU General Public License and
21a copy of the GCC Runtime Library Exception along with this program;
22see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23<http://www.gnu.org/licenses/>. */
4ee9c684 24
4ee9c684 25#include "libgfortran.h"
dd6c1457 26#include "time_1.h"
4ee9c684 27
4ee9c684 28
15aefa66 29static void
4ee9c684 30__cpu_time_1 (long *sec, long *usec)
31{
dd6c1457 32 long user_sec, user_usec, system_sec, system_usec;
a2c0dc0f 33 if (gf_cputime (&user_sec, &user_usec, &system_sec, &system_usec) == 0)
34 {
35 *sec = user_sec + system_sec;
36 *usec = user_usec + system_usec;
37 }
38 else
39 {
40 *sec = -1;
41 *usec = 0;
42 }
4ee9c684 43}
44
17f41f1a 45
7b6cb5bd 46extern void cpu_time_4 (GFC_REAL_4 *);
47iexport_proto(cpu_time_4);
48
49void cpu_time_4 (GFC_REAL_4 *time)
50{
51 long sec, usec;
52 __cpu_time_1 (&sec, &usec);
e099d7cd 53 *time = sec + usec * GFC_REAL_4_LITERAL(1.e-6);
4ee9c684 54}
7b6cb5bd 55iexport(cpu_time_4);
4ee9c684 56
7b6cb5bd 57extern void cpu_time_8 (GFC_REAL_8 *);
58export_proto(cpu_time_8);
59
60void cpu_time_8 (GFC_REAL_8 *time)
61{
62 long sec, usec;
63 __cpu_time_1 (&sec, &usec);
e099d7cd 64 *time = sec + usec * GFC_REAL_8_LITERAL(1.e-6);
7b6cb5bd 65}
66
a60b7686 67#ifdef HAVE_GFC_REAL_10
68extern void cpu_time_10 (GFC_REAL_10 *);
69export_proto(cpu_time_10);
70
71void cpu_time_10 (GFC_REAL_10 *time)
72{
73 long sec, usec;
74 __cpu_time_1 (&sec, &usec);
e099d7cd 75 *time = sec + usec * GFC_REAL_10_LITERAL(1.e-6);
a60b7686 76}
77#endif
78
79#ifdef HAVE_GFC_REAL_16
80extern void cpu_time_16 (GFC_REAL_16 *);
81export_proto(cpu_time_16);
82
83void cpu_time_16 (GFC_REAL_16 *time)
84{
85 long sec, usec;
86 __cpu_time_1 (&sec, &usec);
e099d7cd 87 *time = sec + usec * GFC_REAL_16_LITERAL(1.e-6);
a60b7686 88}
89#endif
90
7b6cb5bd 91extern void second_sub (GFC_REAL_4 *);
92export_proto(second_sub);
4ee9c684 93
041de113 94void
7b6cb5bd 95second_sub (GFC_REAL_4 *s)
041de113 96{
7b6cb5bd 97 cpu_time_4 (s);
041de113 98}
99
7b6cb5bd 100extern GFC_REAL_4 second (void);
101export_proto(second);
102
041de113 103GFC_REAL_4
7b6cb5bd 104second (void)
041de113 105{
106 GFC_REAL_4 s;
7b6cb5bd 107 cpu_time_4 (&s);
041de113 108 return s;
109}