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