]>
Commit | Line | Data |
---|---|---|
86e1a7ff | 1 | /* High precision, low overhead timing functions. Generic version. |
04277e02 | 2 | Copyright (C) 1998-2019 Free Software Foundation, Inc. |
86e1a7ff RH |
3 | This file is part of the GNU C Library. |
4 | Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. | |
5 | ||
6 | The GNU C Library is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Lesser General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2.1 of the License, or (at your option) any later version. | |
10 | ||
11 | The GNU C Library 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 GNU | |
14 | Lesser General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Lesser General Public | |
17 | License along with the GNU C Library; if not, see | |
5a82c748 | 18 | <https://www.gnu.org/licenses/>. */ |
86e1a7ff RH |
19 | |
20 | /* In case a platform supports timers in the hardware the following macros | |
21 | and types must be defined: | |
22 | ||
86e1a7ff RH |
23 | - HP_TIMING_INLINE: this macro is non-zero if the functionality is not |
24 | implemented using function calls but instead uses some inlined code | |
25 | which might simply consist of a few assembler instructions. We have to | |
26 | know this since we might want to use the macros here in places where we | |
27 | cannot make function calls. | |
28 | ||
29 | - hp_timing_t: This is the type for variables used to store the time | |
30 | values. This type must be integral. | |
31 | ||
32 | - HP_TIMING_NOW: place timestamp for current time in variable given as | |
33 | parameter. | |
34 | */ | |
35 | ||
36 | /* The target supports hp-timing. Share the common infrastructure. */ | |
37 | ||
38 | #include <string.h> | |
39 | #include <sys/param.h> | |
40 | #include <_itoa.h> | |
41 | ||
42 | /* Compute the difference between START and END, storing into DIFF. */ | |
43 | #define HP_TIMING_DIFF(Diff, Start, End) ((Diff) = (End) - (Start)) | |
44 | ||
45 | /* Accumulate ADD into SUM. No attempt is made to be thread-safe. */ | |
46 | #define HP_TIMING_ACCUM_NT(Sum, Diff) ((Sum) += (Diff)) | |
47 | ||
1e372ded AZ |
48 | #define HP_TIMING_PRINT_SIZE (3 * sizeof (hp_timing_t) + 1) |
49 | ||
86e1a7ff RH |
50 | /* Write a decimal representation of the timing value into the given string. */ |
51 | #define HP_TIMING_PRINT(Dest, Len, Val) \ | |
52 | do { \ | |
1e372ded | 53 | char __buf[HP_TIMING_PRINT_SIZE]; \ |
86e1a7ff RH |
54 | char *__dest = (Dest); \ |
55 | size_t __len = (Len); \ | |
56 | char *__cp = _itoa ((Val), __buf + sizeof (__buf), 10, 0); \ | |
57 | size_t __cp_len = MIN (__buf + sizeof (__buf) - __cp, __len); \ | |
58 | memcpy (__dest, __cp, __cp_len); \ | |
86e1a7ff RH |
59 | __dest[__len - 1] = '\0'; \ |
60 | } while (0) |