PR 47571 Fix HPUX bootstrap regression, cleanup
[official-gcc.git] / libgfortran / intrinsics / cpu_time.c
blob619f8d25246409e0f32c96299db724213aa62b45
1 /* Implementation of the CPU_TIME intrinsic.
2 Copyright (C) 2003, 2007, 2009, 2010, 2011 Free Software Foundation, Inc.
4 This file is part of the GNU Fortran runtime library (libgfortran).
6 Libgfortran is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public
8 License as published by the Free Software Foundation; either
9 version 3 of the License, or (at your option) any later version.
11 Libgfortran is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
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.
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/>. */
25 #include "libgfortran.h"
26 #include "time_1.h"
29 static inline void __cpu_time_1 (long *, long *) ATTRIBUTE_ALWAYS_INLINE;
31 static inline void
32 __cpu_time_1 (long *sec, long *usec)
34 long user_sec, user_usec, system_sec, system_usec;
35 if (gf_cputime (&user_sec, &user_usec, &system_sec, &system_usec) == 0)
37 *sec = user_sec + system_sec;
38 *usec = user_usec + system_usec;
40 else
42 *sec = -1;
43 *usec = 0;
48 extern void cpu_time_4 (GFC_REAL_4 *);
49 iexport_proto(cpu_time_4);
51 void cpu_time_4 (GFC_REAL_4 *time)
53 long sec, usec;
54 __cpu_time_1 (&sec, &usec);
55 *time = sec + usec * GFC_REAL_4_LITERAL(1.e-6);
57 iexport(cpu_time_4);
59 extern void cpu_time_8 (GFC_REAL_8 *);
60 export_proto(cpu_time_8);
62 void cpu_time_8 (GFC_REAL_8 *time)
64 long sec, usec;
65 __cpu_time_1 (&sec, &usec);
66 *time = sec + usec * GFC_REAL_8_LITERAL(1.e-6);
69 #ifdef HAVE_GFC_REAL_10
70 extern void cpu_time_10 (GFC_REAL_10 *);
71 export_proto(cpu_time_10);
73 void cpu_time_10 (GFC_REAL_10 *time)
75 long sec, usec;
76 __cpu_time_1 (&sec, &usec);
77 *time = sec + usec * GFC_REAL_10_LITERAL(1.e-6);
79 #endif
81 #ifdef HAVE_GFC_REAL_16
82 extern void cpu_time_16 (GFC_REAL_16 *);
83 export_proto(cpu_time_16);
85 void cpu_time_16 (GFC_REAL_16 *time)
87 long sec, usec;
88 __cpu_time_1 (&sec, &usec);
89 *time = sec + usec * GFC_REAL_16_LITERAL(1.e-6);
91 #endif
93 extern void second_sub (GFC_REAL_4 *);
94 export_proto(second_sub);
96 void
97 second_sub (GFC_REAL_4 *s)
99 cpu_time_4 (s);
102 extern GFC_REAL_4 second (void);
103 export_proto(second);
105 GFC_REAL_4
106 second (void)
108 GFC_REAL_4 s;
109 cpu_time_4 (&s);
110 return s;