ahci: centralize, fix port reset
[minix.git] / include / minix / u64.h
blobaa0059c1591377f15a424ab2d967eb6f258a47a5
1 /* minix/u64.h Author: Kees J. Bot
2 * 7 Dec 1995
3 * Functions to manipulate 64 bit disk addresses.
4 */
5 #ifndef _MINIX__U64_H
6 #define _MINIX__U64_H
8 #include <sys/types.h>
10 #include <limits.h>
12 #define is_zero64(i) ((i) == 0)
13 #define make_zero64(i) ((i) = 0)
14 #define neg64(i) ((i) = -(i))
16 static inline u64_t add64(u64_t i, u64_t j)
18 return i + j;
21 static inline u64_t add64u(u64_t i, unsigned j)
23 return i + j;
26 static inline u64_t add64ul(u64_t i, unsigned long j)
28 return i + j;
31 static inline int bsr64(u64_t i)
33 int index;
34 u64_t mask;
36 for (index = 63, mask = 1ULL << 63; index >= 0; --index, mask >>= 1) {
37 if (i & mask)
38 return index;
41 return -1;
44 static inline int cmp64(u64_t i, u64_t j)
46 if (i > j)
47 return 1;
48 else if (i < j)
49 return -1;
50 else /* (i == j) */
51 return 0;
54 static inline int cmp64u(u64_t i, unsigned j)
56 if (i > j)
57 return 1;
58 else if (i < j)
59 return -1;
60 else /* (i == j) */
61 return 0;
64 static inline int cmp64ul(u64_t i, unsigned long j)
66 if (i > j)
67 return 1;
68 else if (i < j)
69 return -1;
70 else /* (i == j) */
71 return 0;
74 static inline unsigned cv64u(u64_t i)
76 /* return ULONG_MAX if really big */
77 if (i>>32)
78 return ULONG_MAX;
80 return (unsigned)i;
83 static inline unsigned long cv64ul(u64_t i)
85 /* return ULONG_MAX if really big */
86 if (i>>32)
87 return ULONG_MAX;
89 return (unsigned long)i;
92 static inline u64_t cvu64(unsigned i)
94 return i;
97 static inline u64_t cvul64(unsigned long i)
99 return i;
102 static inline unsigned diff64(u64_t i, u64_t j)
104 return (unsigned)(i - j);
107 static inline u64_t div64(u64_t i, u64_t j)
109 return i / j;
112 static inline u64_t rem64(u64_t i, u64_t j)
114 return i % j;
117 static inline unsigned long div64u(u64_t i, unsigned j)
119 return (unsigned long)(i / j);
122 static inline u64_t div64u64(u64_t i, unsigned j)
124 return i / j;
127 static inline unsigned rem64u(u64_t i, unsigned j)
129 return (unsigned)(i % j);
132 static inline unsigned long ex64lo(u64_t i)
134 return (unsigned long)i;
137 static inline unsigned long ex64hi(u64_t i)
139 return (unsigned long)(i>>32);
142 static inline u64_t make64(unsigned long lo, unsigned long hi)
144 return ((u64_t)hi << 32) | (u64_t)lo;
147 static inline u64_t mul64(u64_t i, u64_t j)
149 return i * j;
152 static inline u64_t mul64u(unsigned long i, unsigned j)
154 return (u64_t)i * j;
157 static inline u64_t sub64(u64_t i, u64_t j)
159 return i - j;
162 static inline u64_t sub64u(u64_t i, unsigned j)
164 return i - j;
167 static inline u64_t sub64ul(u64_t i, unsigned long j)
169 return i - j;
172 u64_t rrotate64(u64_t x, unsigned short b);
173 u64_t rshift64(u64_t x, unsigned short b);
174 u64_t xor64(u64_t a, u64_t b);
175 u64_t and64(u64_t a, u64_t b);
176 u64_t not64(u64_t a);
178 #endif /* _MINIX__U64_H */