Go to the documentation of this file.
181 #define LOAD16LE(p) ( \
182 ((uint16_t)(((uint8_t *)(p))[0]) << 0) | \
183 ((uint16_t)(((uint8_t *)(p))[1]) << 8))
186 #define LOAD16BE(p) ( \
187 ((uint16_t)(((uint8_t *)(p))[0]) << 8) | \
188 ((uint16_t)(((uint8_t *)(p))[1]) << 0))
191 #define LOAD24LE(p) ( \
192 ((uint32_t)(((uint8_t *)(p))[0]) << 0)| \
193 ((uint32_t)(((uint8_t *)(p))[1]) << 8) | \
194 ((uint32_t)(((uint8_t *)(p))[2]) << 16))
197 #define LOAD24BE(p) ( \
198 ((uint32_t)(((uint8_t *)(p))[0]) << 16) | \
199 ((uint32_t)(((uint8_t *)(p))[1]) << 8) | \
200 ((uint32_t)(((uint8_t *)(p))[2]) << 0))
203 #define LOAD32LE(p) ( \
204 ((uint32_t)(((uint8_t *)(p))[0]) << 0) | \
205 ((uint32_t)(((uint8_t *)(p))[1]) << 8) | \
206 ((uint32_t)(((uint8_t *)(p))[2]) << 16) | \
207 ((uint32_t)(((uint8_t *)(p))[3]) << 24))
210 #define LOAD32BE(p) ( \
211 ((uint32_t)(((uint8_t *)(p))[0]) << 24) | \
212 ((uint32_t)(((uint8_t *)(p))[1]) << 16) | \
213 ((uint32_t)(((uint8_t *)(p))[2]) << 8) | \
214 ((uint32_t)(((uint8_t *)(p))[3]) << 0))
217 #define LOAD48LE(p) ( \
218 ((uint64_t)(((uint8_t *)(p))[0]) << 0) | \
219 ((uint64_t)(((uint8_t *)(p))[1]) << 8) | \
220 ((uint64_t)(((uint8_t *)(p))[2]) << 16) | \
221 ((uint64_t)(((uint8_t *)(p))[3]) << 24) | \
222 ((uint64_t)(((uint8_t *)(p))[4]) << 32) | \
223 ((uint64_t)(((uint8_t *)(p))[5]) << 40)
226 #define LOAD48BE(p) ( \
227 ((uint64_t)(((uint8_t *)(p))[0]) << 40) | \
228 ((uint64_t)(((uint8_t *)(p))[1]) << 32) | \
229 ((uint64_t)(((uint8_t *)(p))[2]) << 24) | \
230 ((uint64_t)(((uint8_t *)(p))[3]) << 16) | \
231 ((uint64_t)(((uint8_t *)(p))[4]) << 8) | \
232 ((uint64_t)(((uint8_t *)(p))[5]) << 0))
235 #define LOAD64LE(p) ( \
236 ((uint64_t)(((uint8_t *)(p))[0]) << 0) | \
237 ((uint64_t)(((uint8_t *)(p))[1]) << 8) | \
238 ((uint64_t)(((uint8_t *)(p))[2]) << 16) | \
239 ((uint64_t)(((uint8_t *)(p))[3]) << 24) | \
240 ((uint64_t)(((uint8_t *)(p))[4]) << 32) | \
241 ((uint64_t)(((uint8_t *)(p))[5]) << 40) | \
242 ((uint64_t)(((uint8_t *)(p))[6]) << 48) | \
243 ((uint64_t)(((uint8_t *)(p))[7]) << 56))
246 #define LOAD64BE(p) ( \
247 ((uint64_t)(((uint8_t *)(p))[0]) << 56) | \
248 ((uint64_t)(((uint8_t *)(p))[1]) << 48) | \
249 ((uint64_t)(((uint8_t *)(p))[2]) << 40) | \
250 ((uint64_t)(((uint8_t *)(p))[3]) << 32) | \
251 ((uint64_t)(((uint8_t *)(p))[4]) << 24) | \
252 ((uint64_t)(((uint8_t *)(p))[5]) << 16) | \
253 ((uint64_t)(((uint8_t *)(p))[6]) << 8) | \
254 ((uint64_t)(((uint8_t *)(p))[7]) << 0))
257 #define STORE16LE(a, p) \
258 ((uint8_t *)(p))[0] = ((uint16_t)(a) >> 0) & 0xFFU, \
259 ((uint8_t *)(p))[1] = ((uint16_t)(a) >> 8) & 0xFFU
262 #define STORE16BE(a, p) \
263 ((uint8_t *)(p))[0] = ((uint16_t)(a) >> 8) & 0xFFU, \
264 ((uint8_t *)(p))[1] = ((uint16_t)(a) >> 0) & 0xFFU
267 #define STORE24LE(a, p) \
268 ((uint8_t *)(p))[0] = ((uint32_t)(a) >> 0) & 0xFFU, \
269 ((uint8_t *)(p))[1] = ((uint32_t)(a) >> 8) & 0xFFU, \
270 ((uint8_t *)(p))[2] = ((uint32_t)(a) >> 16) & 0xFFU
273 #define STORE24BE(a, p) \
274 ((uint8_t *)(p))[0] = ((uint32_t)(a) >> 16) & 0xFFU, \
275 ((uint8_t *)(p))[1] = ((uint32_t)(a) >> 8) & 0xFFU, \
276 ((uint8_t *)(p))[2] = ((uint32_t)(a) >> 0) & 0xFFU
279 #define STORE32LE(a, p) \
280 ((uint8_t *)(p))[0] = ((uint32_t)(a) >> 0) & 0xFFU, \
281 ((uint8_t *)(p))[1] = ((uint32_t)(a) >> 8) & 0xFFU, \
282 ((uint8_t *)(p))[2] = ((uint32_t)(a) >> 16) & 0xFFU, \
283 ((uint8_t *)(p))[3] = ((uint32_t)(a) >> 24) & 0xFFU
286 #define STORE32BE(a, p) \
287 ((uint8_t *)(p))[0] = ((uint32_t)(a) >> 24) & 0xFFU, \
288 ((uint8_t *)(p))[1] = ((uint32_t)(a) >> 16) & 0xFFU, \
289 ((uint8_t *)(p))[2] = ((uint32_t)(a) >> 8) & 0xFFU, \
290 ((uint8_t *)(p))[3] = ((uint32_t)(a) >> 0) & 0xFFU
293 #define STORE48LE(a, p) \
294 ((uint8_t *)(p))[0] = ((uint64_t)(a) >> 0) & 0xFFU, \
295 ((uint8_t *)(p))[1] = ((uint64_t)(a) >> 8) & 0xFFU, \
296 ((uint8_t *)(p))[2] = ((uint64_t)(a) >> 16) & 0xFFU, \
297 ((uint8_t *)(p))[3] = ((uint64_t)(a) >> 24) & 0xFFU, \
298 ((uint8_t *)(p))[4] = ((uint64_t)(a) >> 32) & 0xFFU, \
299 ((uint8_t *)(p))[5] = ((uint64_t)(a) >> 40) & 0xFFU,
302 #define STORE48BE(a, p) \
303 ((uint8_t *)(p))[0] = ((uint64_t)(a) >> 40) & 0xFFU, \
304 ((uint8_t *)(p))[1] = ((uint64_t)(a) >> 32) & 0xFFU, \
305 ((uint8_t *)(p))[2] = ((uint64_t)(a) >> 24) & 0xFFU, \
306 ((uint8_t *)(p))[3] = ((uint64_t)(a) >> 16) & 0xFFU, \
307 ((uint8_t *)(p))[4] = ((uint64_t)(a) >> 8) & 0xFFU, \
308 ((uint8_t *)(p))[5] = ((uint64_t)(a) >> 0) & 0xFFU
311 #define STORE64LE(a, p) \
312 ((uint8_t *)(p))[0] = ((uint64_t)(a) >> 0) & 0xFFU, \
313 ((uint8_t *)(p))[1] = ((uint64_t)(a) >> 8) & 0xFFU, \
314 ((uint8_t *)(p))[2] = ((uint64_t)(a) >> 16) & 0xFFU, \
315 ((uint8_t *)(p))[3] = ((uint64_t)(a) >> 24) & 0xFFU, \
316 ((uint8_t *)(p))[4] = ((uint64_t)(a) >> 32) & 0xFFU, \
317 ((uint8_t *)(p))[5] = ((uint64_t)(a) >> 40) & 0xFFU, \
318 ((uint8_t *)(p))[6] = ((uint64_t)(a) >> 48) & 0xFFU, \
319 ((uint8_t *)(p))[7] = ((uint64_t)(a) >> 56) & 0xFFU
322 #define STORE64BE(a, p) \
323 ((uint8_t *)(p))[0] = ((uint64_t)(a) >> 56) & 0xFFU, \
324 ((uint8_t *)(p))[1] = ((uint64_t)(a) >> 48) & 0xFFU, \
325 ((uint8_t *)(p))[2] = ((uint64_t)(a) >> 40) & 0xFFU, \
326 ((uint8_t *)(p))[3] = ((uint64_t)(a) >> 32) & 0xFFU, \
327 ((uint8_t *)(p))[4] = ((uint64_t)(a) >> 24) & 0xFFU, \
328 ((uint8_t *)(p))[5] = ((uint64_t)(a) >> 16) & 0xFFU, \
329 ((uint8_t *)(p))[6] = ((uint64_t)(a) >> 8) & 0xFFU, \
330 ((uint8_t *)(p))[7] = ((uint64_t)(a) >> 0) & 0xFFU
333 #define SWAPINT16(x) ( \
334 (((uint16_t)(x) & 0x00FFU) << 8) | \
335 (((uint16_t)(x) & 0xFF00U) >> 8))
338 #define SWAPINT32(x) ( \
339 (((uint32_t)(x) & 0x000000FFUL) << 24) | \
340 (((uint32_t)(x) & 0x0000FF00UL) << 8) | \
341 (((uint32_t)(x) & 0x00FF0000UL) >> 8) | \
342 (((uint32_t)(x) & 0xFF000000UL) >> 24))
345 #define SWAPINT64(x) ( \
346 (((uint64_t)(x) & 0x00000000000000FFULL) << 56) | \
347 (((uint64_t)(x) & 0x000000000000FF00ULL) << 40) | \
348 (((uint64_t)(x) & 0x0000000000FF0000ULL) << 24) | \
349 (((uint64_t)(x) & 0x00000000FF000000ULL) << 8) | \
350 (((uint64_t)(x) & 0x000000FF00000000ULL) >> 8) | \
351 (((uint64_t)(x) & 0x0000FF0000000000ULL) >> 24) | \
352 (((uint64_t)(x) & 0x00FF000000000000ULL) >> 40) | \
353 (((uint64_t)(x) & 0xFF00000000000000ULL) >> 56))
356 #ifdef _CPU_BIG_ENDIAN
359 #define HTONS(value) (value)
360 #define HTONL(value) (value)
361 #define HTONLL(value) (value)
362 #define htons(value) ((uint16_t) (value))
363 #define htonl(value) ((uint32_t) (value))
364 #define htonll(value) ((uint64_t) (value))
367 #define NTOHS(value) (value)
368 #define NTOHL(value) (value)
369 #define NTOHLL(value) (value)
370 #define ntohs(value) ((uint16_t) (value))
371 #define ntohl(value) ((uint32_t) (value))
372 #define ntohll(value) ((uint64_t) (value))
375 #define HTOLE16(value) SWAPINT16(value)
376 #define HTOLE32(value) SWAPINT32(value)
377 #define HTOLE64(value) SWAPINT64(value)
378 #define htole16(value) swapInt16((uint16_t) (value))
379 #define htole32(value) swapInt32((uint32_t) (value))
380 #define htole64(value) swapInt64((uint64_t) (value))
383 #define LETOH16(value) SWAPINT16(value)
384 #define LETOH32(value) SWAPINT32(value)
385 #define LETOH64(value) SWAPINT64(value)
386 #define letoh16(value) swapInt16((uint16_t) (value))
387 #define letoh32(value) swapInt32((uint32_t) (value))
388 #define letoh64(value) swapInt64((uint64_t) (value))
391 #define HTOBE16(value) (value)
392 #define HTOBE32(value) (value)
393 #define HTOBE64(value) (value)
394 #define htobe16(value) ((uint16_t) (value))
395 #define htobe32(value) ((uint32_t) (value))
396 #define htobe64(value) ((uint64_t) (value))
399 #define BETOH16(value) (value)
400 #define BETOH32(value) (value)
401 #define BETOH64(value) (value)
402 #define betoh16(value) ((uint16_t) (value))
403 #define betoh32(value) ((uint32_t) (value))
404 #define betoh64(value) ((uint64_t) (value))
410 #define HTONS(value) SWAPINT16(value)
411 #define HTONL(value) SWAPINT32(value)
412 #define HTONLL(value) SWAPINT64(value)
413 #define htons(value) swapInt16((uint16_t) (value))
414 #define htonl(value) swapInt32((uint32_t) (value))
415 #define htonll(value) swapInt64((uint64_t) (value))
418 #define NTOHS(value) SWAPINT16(value)
419 #define NTOHL(value) SWAPINT32(value)
420 #define NTOHLL(value) SWAPINT64(value)
421 #define ntohs(value) swapInt16((uint16_t) (value))
422 #define ntohl(value) swapInt32((uint32_t) (value))
423 #define ntohll(value) swapInt64((uint64_t) (value))
426 #define HTOLE16(value) (value)
427 #define HTOLE32(value) (value)
428 #define HTOLE64(value) (value)
429 #define htole16(value) ((uint16_t) (value))
430 #define htole32(value) ((uint32_t) (value))
431 #define htole64(value) ((uint64_t) (value))
434 #define LETOH16(value) (value)
435 #define LETOH32(value) (value)
436 #define LETOH64(value) (value)
437 #define letoh16(value) ((uint16_t) (value))
438 #define letoh32(value) ((uint32_t) (value))
439 #define letoh64(value) ((uint64_t) (value))
442 #define HTOBE16(value) SWAPINT16(value)
443 #define HTOBE32(value) SWAPINT32(value)
444 #define HTOBE64(value) SWAPINT64(value)
445 #define htobe16(value) swapInt16((uint16_t) (value))
446 #define htobe32(value) swapInt32((uint32_t) (value))
447 #define htobe64(value) swapInt64((uint64_t) (value))
450 #define BETOH16(value) SWAPINT16(value)
451 #define BETOH32(value) SWAPINT32(value)
452 #define BETOH64(value) SWAPINT64(value)
453 #define betoh16(value) swapInt16((uint16_t) (value))
454 #define betoh32(value) swapInt32((uint32_t) (value))
455 #define betoh64(value) swapInt64((uint64_t) (value))
uint32_t swapInt32(uint32_t value)
Reverse the byte order of a 32-bit word.
uint16_t swapInt16(uint16_t value)
Reverse the byte order of a 16-bit word.
uint8_t reverseInt8(uint8_t value)
Reverse bit order in a byte.
uint32_t reverseInt32(uint32_t value)
Reverse bit order in a 32-bit word.
uint64_t swapInt64(uint64_t value)
Reverse the byte order of a 64-bit word.
uint64_t reverseInt64(uint64_t value)
Reverse bit order in a 64-bit word.
uint8_t reverseInt4(uint8_t value)
Reverse bit order in a 4-bit word.
uint16_t reverseInt16(uint16_t value)
Reverse bit order in a 16-bit word.