Lines Matching full:a
74 /* toolchain-specific implementations. LFS_NO_INTRINSICS falls back to a more */
78 static inline uint32_t lfs_max(uint32_t a, uint32_t b) in lfs_max() argument
80 return (a > b) ? a : b; in lfs_max()
83 static inline uint32_t lfs_min(uint32_t a, uint32_t b) in lfs_min() argument
85 return (a < b) ? a : b; in lfs_min()
88 /* Align to nearest multiple of a size */
89 static inline uint32_t lfs_aligndown(uint32_t a, uint32_t alignment) in lfs_aligndown() argument
91 return a - (a % alignment); in lfs_aligndown()
94 static inline uint32_t lfs_alignup(uint32_t a, uint32_t alignment) in lfs_alignup() argument
96 return lfs_aligndown(a + alignment-1, alignment); in lfs_alignup()
99 /* Find the smallest power of 2 greater than or equal to a */
100 static inline uint32_t lfs_npw2(uint32_t a) in lfs_npw2() argument
103 return 32 - __builtin_clz(a-1); in lfs_npw2()
108 a -= 1; in lfs_npw2()
109 s = (a > 0xffff) << 4; a >>= s; r |= s; in lfs_npw2()
110 s = (a > 0xff) << 3; a >>= s; r |= s; in lfs_npw2()
111 s = (a > 0xf) << 2; a >>= s; r |= s; in lfs_npw2()
112 s = (a > 0x3) << 1; a >>= s; r |= s; in lfs_npw2()
113 return (r | (a >> 1)) + 1; in lfs_npw2()
117 /* Count the number of trailing binary zeros in a */
119 static inline uint32_t lfs_ctz(uint32_t a) in lfs_ctz() argument
122 return __builtin_ctz(a); in lfs_ctz()
124 return lfs_npw2((a & -a) + 1) - 1; in lfs_ctz()
128 /* Count the number of binary ones in a */
129 static inline uint32_t lfs_popc(uint32_t a) in lfs_popc() argument
132 return __builtin_popcount(a); in lfs_popc()
134 a = a - ((a >> 1) & 0x55555555); in lfs_popc()
135 a = (a & 0x33333333) + ((a >> 2) & 0x33333333); in lfs_popc()
136 return (((a + (a >> 4)) & 0xf0f0f0f) * 0x1010101) >> 24; in lfs_popc()
140 /* Find the sequence comparison of a and b, this is the distance */
141 /* between a and b ignoring overflow */
142 static inline int lfs_scmp(uint32_t a, uint32_t b) in lfs_scmp() argument
144 return (int)(unsigned int)(a - b); in lfs_scmp()
148 static inline uint32_t lfs_fromle32(uint32_t a) in lfs_fromle32() argument
151 return a; in lfs_fromle32()
153 return __builtin_bswap32(a); in lfs_fromle32()
155 return (((uint8_t *)&a)[0] << 0) | in lfs_fromle32()
156 (((uint8_t *)&a)[1] << 8) | in lfs_fromle32()
157 (((uint8_t *)&a)[2] << 16) | in lfs_fromle32()
158 (((uint8_t *)&a)[3] << 24); in lfs_fromle32()
162 static inline uint32_t lfs_tole32(uint32_t a) in lfs_tole32() argument
164 return lfs_fromle32(a); in lfs_tole32()
168 static inline uint32_t lfs_frombe32(uint32_t a) in lfs_frombe32() argument
171 return a; in lfs_frombe32()
173 return __builtin_bswap32(a); in lfs_frombe32()
175 return (((uint8_t *)&a)[0] << 24) | in lfs_frombe32()
176 (((uint8_t *)&a)[1] << 16) | in lfs_frombe32()
177 (((uint8_t *)&a)[2] << 8) | in lfs_frombe32()
178 (((uint8_t *)&a)[3] << 0); in lfs_frombe32()
182 static inline uint32_t lfs_tobe32(uint32_t a) in lfs_tobe32() argument
184 return lfs_frombe32(a); in lfs_tobe32()