[CodeGenPrepare] Drop nsw flags in `optimizeLoadExt` (#118180)
[llvm-project.git] / libc / include / llvm-libc-macros / linux / sys-time-macros.h
blobe97819594adcb18af7c25ea3bda1e56f5bbc7f95
1 //===-- Definition of macros from sys/time.h ------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_MACROS_LINUX_SYS_TIME_MACROS_H
10 #define LLVM_LIBC_MACROS_LINUX_SYS_TIME_MACROS_H
12 // Add two timevals and put the result in timeval_ptr_result. If the resulting
13 // usec value is greater than 999,999 then the microseconds are turned into full
14 // seconds (1,000,000 is subtracted from usec and 1 is added to sec).
15 #define timeradd(timeval_ptr_a, timeval_ptr_b, timeval_ptr_result) \
16 (timeval_ptr_result)->tv_sec = \
17 (timeval_ptr_a)->tv_sec + (timeval_ptr_b)->tv_sec + \
18 (((timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec) >= 1000000 ? 1 \
19 : 0); \
20 (timeval_ptr_result)->tv_usec = \
21 (timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec - \
22 (((timeval_ptr_a)->tv_usec + (timeval_ptr_b)->tv_usec) >= 1000000 \
23 ? 1000000 \
24 : 0);
26 // Subtract two timevals and put the result in timeval_ptr_result. If the
27 // resulting usec value is less than 0 then 1,000,000 is added to usec and 1 is
28 // subtracted from sec.
29 #define timersub(timeval_ptr_a, timeval_ptr_b, timeval_ptr_result) \
30 (timeval_ptr_result)->tv_sec = \
31 (timeval_ptr_a)->tv_sec - (timeval_ptr_b)->tv_sec - \
32 (((timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec) < 0 ? 1 : 0); \
33 (timeval_ptr_result)->tv_usec = \
34 (timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec + \
35 (((timeval_ptr_a)->tv_usec - (timeval_ptr_b)->tv_usec) < 0 ? 1000000 \
36 : 0);
38 // Reset a timeval to the epoch.
39 #define timerclear(timeval_ptr) \
40 (timeval_ptr)->tv_sec = 0; \
41 (timeval_ptr)->tv_usec = 0;
43 // Determine if a timeval is set to the epoch.
44 #define timerisset(timeval_ptr) \
45 (timeval_ptr)->tv_sec != 0 || (timeval_ptr)->tv_usec != 0;
47 // Compare two timevals using CMP.
48 #define timercmp(timeval_ptr_a, timeval_ptr_b, CMP) \
49 (((timeval_ptr_a)->tv_sec == (timeval_ptr_b)->tv_sec) \
50 ? ((timeval_ptr_a)->tv_usec CMP(timeval_ptr_b)->tv_usec) \
51 : ((timeval_ptr_a)->tv_sec CMP(timeval_ptr_b)->tv_sec))
53 #endif // LLVM_LIBC_MACROS_LINUX_SYS_TIME_MACROS_H