16 static inline void tai_pack(unsigned char *s
, struct tai
*t
)
22 s
[7] = x
& 255; x
>>= 8;
23 s
[6] = x
& 255; x
>>= 8;
24 s
[5] = x
& 255; x
>>= 8;
25 s
[4] = x
& 255; x
>>= 8;
26 s
[3] = x
& 255; x
>>= 8;
27 s
[2] = x
& 255; x
>>= 8;
28 s
[1] = x
& 255; x
>>= 8;
32 static inline void tai_unpack(unsigned char *s
, struct tai
*t
)
36 x
= (unsigned char) s
[0];
37 x
<<= 8; x
+= (unsigned char) s
[1];
38 x
<<= 8; x
+= (unsigned char) s
[2];
39 x
<<= 8; x
+= (unsigned char) s
[3];
40 x
<<= 8; x
+= (unsigned char) s
[4];
41 x
<<= 8; x
+= (unsigned char) s
[5];
42 x
<<= 8; x
+= (unsigned char) s
[6];
43 x
<<= 8; x
+= (unsigned char) s
[7];
48 static inline void taia_pack(unsigned char *s
, struct taia
*t
)
58 s
[7] = x
& 255; x
>>= 8;
59 s
[6] = x
& 255; x
>>= 8;
60 s
[5] = x
& 255; x
>>= 8;
65 s
[3] = x
& 255; x
>>= 8;
66 s
[2] = x
& 255; x
>>= 8;
67 s
[1] = x
& 255; x
>>= 8;
71 static inline void taia_unpack(unsigned char *s
, struct taia
*t
)
75 tai_unpack(s
, &t
->sec
);
79 x
= (unsigned char) s
[4];
80 x
<<= 8; x
+= (unsigned char) s
[5];
81 x
<<= 8; x
+= (unsigned char) s
[6];
82 x
<<= 8; x
+= (unsigned char) s
[7];
86 x
= (unsigned char) s
[0];
87 x
<<= 8; x
+= (unsigned char) s
[1];
88 x
<<= 8; x
+= (unsigned char) s
[2];
89 x
<<= 8; x
+= (unsigned char) s
[3];
94 #define tai_unix(t, u) ((void) ((t)->x = 4611686018427387914ULL + (uint64_t) (u)))
96 static inline void taia_now(struct taia
*t
)
100 gettimeofday(&now
, NULL
);
102 tai_unix(&t
->sec
, now
.tv_sec
);
103 t
->nano
= 1000 * now
.tv_usec
+ 500;
107 static inline void taia_sub(struct taia
*res
, const struct taia
*u
,
108 const struct taia
*v
)
110 unsigned long unano
= u
->nano
;
111 unsigned long uatto
= u
->atto
;
113 res
->sec
.x
= u
->sec
.x
- v
->sec
.x
;
114 res
->nano
= unano
- v
->nano
;
115 res
->atto
= uatto
- v
->atto
;
117 if (res
->atto
> uatto
) {
118 res
->atto
+= 1000000000UL;
122 if (res
->nano
> unano
) {
123 res
->nano
+= 1000000000UL;
128 static inline void taia_add(struct taia
*res
, const struct taia
*u
,
129 const struct taia
*v
)
131 res
->sec
.x
= u
->sec
.x
+ v
->sec
.x
;
132 res
->nano
= u
->nano
+ v
->nano
;
133 res
->atto
= u
->atto
+ v
->atto
;
135 if (res
->atto
> 999999999UL) {
136 res
->atto
-= 1000000000UL;
140 if (res
->nano
> 999999999UL) {
141 res
->nano
-= 1000000000UL;
146 static inline int taia_less(const struct taia
*t
, const struct taia
*u
)
148 if (t
->sec
.x
< u
->sec
.x
)
150 if (t
->sec
.x
> u
->sec
.x
)
152 if (t
->nano
< u
->nano
)
154 if (t
->nano
> u
->nano
)
156 return t
->atto
< u
->atto
;