]>
Commit | Line | Data |
---|---|---|
6de9cd9a | 1 | /* Implementation of the CPU_TIME intrinsic. |
7adcbafe | 2 | Copyright (C) 2003-2022 Free Software Foundation, Inc. |
6de9cd9a | 3 | |
b6e7a3d1 | 4 | This file is part of the GNU Fortran runtime library (libgfortran). |
6de9cd9a | 5 | |
57dea9f6 TM |
6 | Libgfortran is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU General Public | |
6de9cd9a | 8 | License as published by the Free Software Foundation; either |
748086b7 | 9 | version 3 of the License, or (at your option) any later version. |
57dea9f6 TM |
10 | |
11 | Libgfortran is distributed in the hope that it will be useful, | |
6de9cd9a DN |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
57dea9f6 | 14 | GNU General Public License for more details. |
6de9cd9a | 15 | |
748086b7 JJ |
16 | Under Section 7 of GPL version 3, you are granted additional |
17 | permissions described in the GCC Runtime Library Exception, version | |
18 | 3.1, as published by the Free Software Foundation. | |
19 | ||
20 | You should have received a copy of the GNU General Public License and | |
21 | a copy of the GCC Runtime Library Exception along with this program; | |
22 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | <http://www.gnu.org/licenses/>. */ | |
6de9cd9a | 24 | |
6de9cd9a | 25 | #include "libgfortran.h" |
a1ba31ce | 26 | #include "time_1.h" |
6de9cd9a | 27 | |
6de9cd9a | 28 | |
992b0aa1 | 29 | static void |
6de9cd9a DN |
30 | __cpu_time_1 (long *sec, long *usec) |
31 | { | |
a1ba31ce | 32 | long user_sec, user_usec, system_sec, system_usec; |
b6e7a3d1 JB |
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 | } | |
6de9cd9a DN |
43 | } |
44 | ||
399a39c7 | 45 | |
7d7b8bfe RH |
46 | extern void cpu_time_4 (GFC_REAL_4 *); |
47 | iexport_proto(cpu_time_4); | |
48 | ||
49 | void cpu_time_4 (GFC_REAL_4 *time) | |
50 | { | |
51 | long sec, usec; | |
52 | __cpu_time_1 (&sec, &usec); | |
a83169cd | 53 | *time = sec + usec * GFC_REAL_4_LITERAL(1.e-6); |
6de9cd9a | 54 | } |
7d7b8bfe | 55 | iexport(cpu_time_4); |
6de9cd9a | 56 | |
7d7b8bfe RH |
57 | extern void cpu_time_8 (GFC_REAL_8 *); |
58 | export_proto(cpu_time_8); | |
59 | ||
60 | void cpu_time_8 (GFC_REAL_8 *time) | |
61 | { | |
62 | long sec, usec; | |
63 | __cpu_time_1 (&sec, &usec); | |
a83169cd | 64 | *time = sec + usec * GFC_REAL_8_LITERAL(1.e-6); |
7d7b8bfe RH |
65 | } |
66 | ||
d68d3a3d SK |
67 | #ifdef HAVE_GFC_REAL_10 |
68 | extern void cpu_time_10 (GFC_REAL_10 *); | |
69 | export_proto(cpu_time_10); | |
70 | ||
71 | void cpu_time_10 (GFC_REAL_10 *time) | |
72 | { | |
73 | long sec, usec; | |
74 | __cpu_time_1 (&sec, &usec); | |
a83169cd | 75 | *time = sec + usec * GFC_REAL_10_LITERAL(1.e-6); |
d68d3a3d SK |
76 | } |
77 | #endif | |
78 | ||
79 | #ifdef HAVE_GFC_REAL_16 | |
80 | extern void cpu_time_16 (GFC_REAL_16 *); | |
81 | export_proto(cpu_time_16); | |
82 | ||
83 | void cpu_time_16 (GFC_REAL_16 *time) | |
84 | { | |
85 | long sec, usec; | |
86 | __cpu_time_1 (&sec, &usec); | |
a83169cd | 87 | *time = sec + usec * GFC_REAL_16_LITERAL(1.e-6); |
d68d3a3d SK |
88 | } |
89 | #endif | |
90 | ||
7d7b8bfe RH |
91 | extern void second_sub (GFC_REAL_4 *); |
92 | export_proto(second_sub); | |
6de9cd9a | 93 | |
2bd74949 | 94 | void |
7d7b8bfe | 95 | second_sub (GFC_REAL_4 *s) |
2bd74949 | 96 | { |
7d7b8bfe | 97 | cpu_time_4 (s); |
2bd74949 SK |
98 | } |
99 | ||
7d7b8bfe RH |
100 | extern GFC_REAL_4 second (void); |
101 | export_proto(second); | |
102 | ||
2bd74949 | 103 | GFC_REAL_4 |
7d7b8bfe | 104 | second (void) |
2bd74949 SK |
105 | { |
106 | GFC_REAL_4 s; | |
7d7b8bfe | 107 | cpu_time_4 (&s); |
2bd74949 SK |
108 | return s; |
109 | } |