grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / timer / timer_macros.h
blob855f5fcd94eabcd9d08871053057781f33d4f4f7
1 /*
2 * These are often used by timer.device itself, and inlining
3 * them saves us from function call overhead.
4 */
6 /* Add, then normalize */
7 #define ADDTIME(dest, src) \
8 (dest)->tv_micro += (src)->tv_micro; \
9 (dest)->tv_secs += (src)->tv_secs; \
10 while((dest)->tv_micro > 999999) \
11 { \
12 (dest)->tv_secs++; \
13 (dest)->tv_micro -= 1000000; \
17 * Subtraction algorithm:
18 * 1. Normalize values
19 * 2. Check if wrap around will happen, when subtracting src->tv_micro
20 * from dest->tv_micro. If yes, then normalize, by adding 1 sec to
21 * micros and subtracting 1 sec from secs. Note: this check must be
22 * before subtracting src timeval from dest timeval!
24 #define SUBTIME(dest, src) \
25 while ((src)->tv_micro > 999999) \
26 { \
27 (src)->tv_secs++; \
28 (src)->tv_micro -= 1000000; \
29 } \
30 while ((dest)->tv_micro > 999999) \
31 { \
32 (dest)->tv_secs++; \
33 (dest)->tv_micro -= 1000000; \
34 } \
35 if ((dest)->tv_micro < (src)->tv_micro) \
36 { \
37 (dest)->tv_micro += 1000000; \
38 (dest)->tv_secs--; \
39 } \
40 (dest)->tv_micro -= (src)->tv_micro; \
41 (dest)->tv_secs -= (src)->tv_secs;
43 static inline LONG CMPTIME(struct timeval *dest, struct timeval *src)
45 LONG diff;
47 if (dest->tv_secs == src->tv_secs)
48 diff = src->tv_micro - dest->tv_micro;
49 else
50 diff = src->tv_secs - dest->tv_secs;
52 if (diff < 0)
53 return -1;
54 else if (diff > 0)
55 return 1;
56 else
57 return 0;
61 * Add 'diff' EClock ticks to timeval in 'time'.
62 * Fraction of second value is stored in in 'frac'.
63 * This macro relies on (CPU-specific) tick2usec() implementation
65 #define INCTIME(time, frac, diff) \
66 (frac) += diff; \
67 if ((frac) >= TimerBase->tb_eclock_rate) \
68 { \
69 (frac) -= TimerBase->tb_eclock_rate; \
70 (time).tv_secs++; \
71 } \
72 (time).tv_micro = tick2usec(frac);