Lely core libraries 2.3.4
endian.h
Go to the documentation of this file.
1
22#ifndef LELY_UTIL_ENDIAN_H_
23#define LELY_UTIL_ENDIAN_H_
24
25#include <lely/util/bits.h>
26#include <lely/util/float.h>
27
28#include <string.h>
29
30#ifdef __linux__
31#include <endian.h>
32#define betoh16 be16toh
33#define letoh16 le16toh
34#define betoh32 be32toh
35#define letoh32 le32toh
36#define betoh64 be64toh
37#define letoh64 le64toh
38#endif
39
40#ifndef LELY_UTIL_ENDIAN_INLINE
41#define LELY_UTIL_ENDIAN_INLINE static inline
42#endif
43
44#ifndef LELY_BIG_ENDIAN
45#if defined(__BIG_ENDIAN__) || defined(__big_endian__) \
46 || (__GNUC__ && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) \
47 || defined(__ARMEB__) || defined(__AARCH64EB__) \
48 || defined(__THUMBEB__)
50#define LELY_BIG_ENDIAN 1
51#endif
52#endif
53
54#if LELY_BIG_ENDIAN
55#undef LELY_LITTLE_ENDIAN
56#endif
57
58#ifndef LELY_LITTLE_ENDIAN
59#if defined(__LITTLE_ENDIAN__) || defined(__little_endian__) \
60 || (__GNUC__ && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) \
61 || defined(__i386__) || defined(_M_IX86) \
62 || defined(__x86_64__) || defined(_M_AMD64) \
63 || defined(__ARMEL__) || defined(__AARCH64EL__) \
64 || defined(__THUMBEL__)
66#define LELY_LITTLE_ENDIAN 1
67#endif
68#endif
69
70#if LELY_LITTLE_ENDIAN
71#undef LELY_BIG_ENDIAN
72#endif
73
74#if !LELY_BIG_ENDIAN && !LELY_LITTLE_ENDIAN
75#error Unable to determine byte order or byte order is not supported.
76#endif
77
78#ifdef __cplusplus
79extern "C" {
80#endif
81
82#ifndef htobe16
84LELY_UTIL_ENDIAN_INLINE uint_least16_t htobe16(uint_least16_t x);
85#endif
86
87#ifndef betoh16
89LELY_UTIL_ENDIAN_INLINE uint_least16_t betoh16(uint_least16_t x);
90#endif
91
92#ifndef htole16
94LELY_UTIL_ENDIAN_INLINE uint_least16_t htole16(uint_least16_t x);
95#endif
96
97#ifndef letoh16
99LELY_UTIL_ENDIAN_INLINE uint_least16_t letoh16(uint_least16_t x);
100#endif
101
102#ifndef htobe32
104LELY_UTIL_ENDIAN_INLINE uint_least32_t htobe32(uint_least32_t x);
105#endif
106
107#ifndef betoh32
109LELY_UTIL_ENDIAN_INLINE uint_least32_t betoh32(uint_least32_t x);
110#endif
111
112#ifndef htole32
114LELY_UTIL_ENDIAN_INLINE uint_least32_t htole32(uint_least32_t x);
115#endif
116
117#ifndef letoh32
119LELY_UTIL_ENDIAN_INLINE uint_least32_t letoh32(uint_least32_t x);
120#endif
121
122#ifndef htobe64
124LELY_UTIL_ENDIAN_INLINE uint_least64_t htobe64(uint_least64_t x);
125#endif
126
127#ifndef betoh64
129LELY_UTIL_ENDIAN_INLINE uint_least64_t betoh64(uint_least64_t x);
130#endif
131
132#ifndef htole64
134LELY_UTIL_ENDIAN_INLINE uint_least64_t htole64(uint_least64_t x);
135#endif
136
137#ifndef letoh64
139LELY_UTIL_ENDIAN_INLINE uint_least64_t letoh64(uint_least64_t x);
140#endif
141
143LELY_UTIL_ENDIAN_INLINE void stbe_i16(uint_least8_t dst[2], int_least16_t x);
144
146LELY_UTIL_ENDIAN_INLINE int_least16_t ldbe_i16(const uint_least8_t src[2]);
147
149LELY_UTIL_ENDIAN_INLINE void stbe_u16(uint_least8_t dst[2], uint_least16_t x);
150
152LELY_UTIL_ENDIAN_INLINE uint_least16_t ldbe_u16(const uint_least8_t src[2]);
153
155LELY_UTIL_ENDIAN_INLINE void stle_i16(uint_least8_t dst[2], int_least16_t x);
156
158LELY_UTIL_ENDIAN_INLINE int_least16_t ldle_i16(const uint_least8_t src[2]);
159
161LELY_UTIL_ENDIAN_INLINE void stle_u16(uint_least8_t dst[2], uint_least16_t x);
162
164LELY_UTIL_ENDIAN_INLINE uint_least16_t ldle_u16(const uint_least8_t src[2]);
165
167LELY_UTIL_ENDIAN_INLINE void stbe_i32(uint_least8_t dst[4], int_least32_t x);
168
170LELY_UTIL_ENDIAN_INLINE int_least32_t ldbe_i32(const uint_least8_t src[4]);
171
173LELY_UTIL_ENDIAN_INLINE void stbe_u32(uint_least8_t dst[4], uint_least32_t x);
174
176LELY_UTIL_ENDIAN_INLINE uint_least32_t ldbe_u32(const uint_least8_t src[4]);
177
179LELY_UTIL_ENDIAN_INLINE void stle_i32(uint_least8_t dst[4], int_least32_t x);
180
182LELY_UTIL_ENDIAN_INLINE int_least32_t ldle_i32(const uint_least8_t src[4]);
183
185LELY_UTIL_ENDIAN_INLINE void stle_u32(uint_least8_t dst[4], uint_least32_t x);
186
188LELY_UTIL_ENDIAN_INLINE uint_least32_t ldle_u32(const uint_least8_t src[4]);
189
191LELY_UTIL_ENDIAN_INLINE void stbe_i64(uint_least8_t dst[8], int_least64_t x);
192
194LELY_UTIL_ENDIAN_INLINE int_least64_t ldbe_i64(const uint_least8_t src[8]);
195
197LELY_UTIL_ENDIAN_INLINE void stbe_u64(uint_least8_t dst[8], uint_least64_t x);
198
200LELY_UTIL_ENDIAN_INLINE uint_least64_t ldbe_u64(const uint_least8_t src[8]);
201
203LELY_UTIL_ENDIAN_INLINE void stle_i64(uint_least8_t dst[8], int_least64_t x);
204
206LELY_UTIL_ENDIAN_INLINE int_least64_t ldle_i64(const uint_least8_t src[8]);
207
209LELY_UTIL_ENDIAN_INLINE void stle_u64(uint_least8_t dst[8], uint_least64_t x);
210
212LELY_UTIL_ENDIAN_INLINE uint_least64_t ldle_u64(const uint_least8_t src[8]);
213
214#ifdef LELY_FLT16_TYPE
215
220LELY_UTIL_ENDIAN_INLINE void stbe_flt16(uint_least8_t dst[2], flt16_t x);
221
226LELY_UTIL_ENDIAN_INLINE flt16_t ldbe_flt16(const uint_least8_t src[2]);
227
232LELY_UTIL_ENDIAN_INLINE void stle_flt16(uint_least8_t dst[2], flt16_t x);
233
238LELY_UTIL_ENDIAN_INLINE flt16_t ldle_flt16(const uint_least8_t src[2]);
239
240#endif // LELY_FLT16_TYPE
241
242#ifdef LELY_FLT32_TYPE
243
248LELY_UTIL_ENDIAN_INLINE void stbe_flt32(uint_least8_t dst[4], flt32_t x);
249
254LELY_UTIL_ENDIAN_INLINE flt32_t ldbe_flt32(const uint_least8_t src[4]);
255
260LELY_UTIL_ENDIAN_INLINE void stle_flt32(uint_least8_t dst[4], flt32_t x);
261
266LELY_UTIL_ENDIAN_INLINE flt32_t ldle_flt32(const uint_least8_t src[4]);
267
268#endif // LELY_FLT32_TYPE
269
270#ifdef LELY_FLT64_TYPE
271
276LELY_UTIL_ENDIAN_INLINE void stbe_flt64(uint_least8_t dst[8], flt64_t x);
277
282LELY_UTIL_ENDIAN_INLINE flt64_t ldbe_flt64(const uint_least8_t src[8]);
283
288LELY_UTIL_ENDIAN_INLINE void stle_flt64(uint_least8_t dst[8], flt64_t x);
289
294LELY_UTIL_ENDIAN_INLINE flt64_t ldle_flt64(const uint_least8_t src[8]);
295
296#endif // LELY_FLT64_TYPE
297
310void bcpybe(uint_least8_t *dst, int dstbit, const uint_least8_t *src,
311 int srcbit, size_t n);
312
325void bcpyle(uint_least8_t *dst, int dstbit, const uint_least8_t *src,
326 int srcbit, size_t n);
327
328#ifndef htobe16
329LELY_UTIL_ENDIAN_INLINE uint_least16_t
330htobe16(uint_least16_t x)
331{
332 x &= UINT16_C(0xffff);
333#if LELY_BIG_ENDIAN
334 return x;
335#elif LELY_LITTLE_ENDIAN
336 return bswap16(x);
337#endif
338}
339#endif
340
341#ifndef betoh16
342LELY_UTIL_ENDIAN_INLINE uint_least16_t
343betoh16(uint_least16_t x)
344{
345 return htobe16(x);
346}
347#endif
348
349#ifndef htole16
350LELY_UTIL_ENDIAN_INLINE uint_least16_t
351htole16(uint_least16_t x)
352{
353 x &= UINT16_C(0xffff);
354#if LELY_BIG_ENDIAN
355 return bswap16(x);
356#elif LELY_LITTLE_ENDIAN
357 return x;
358#endif
359}
360#endif
361
362#ifndef letoh16
363LELY_UTIL_ENDIAN_INLINE uint_least16_t
364letoh16(uint_least16_t x)
365{
366 return htole16(x);
367}
368#endif
369
370#ifndef htobe32
371LELY_UTIL_ENDIAN_INLINE uint_least32_t
372htobe32(uint_least32_t x)
373{
374 x &= UINT32_C(0xffffffff);
375#if LELY_BIG_ENDIAN
376 return x;
377#elif LELY_LITTLE_ENDIAN
378 return bswap32(x);
379#endif
380}
381#endif
382
383#ifndef betoh32
384LELY_UTIL_ENDIAN_INLINE uint_least32_t
385betoh32(uint_least32_t x)
386{
387 return htobe32(x);
388}
389#endif
390
391#ifndef htole32
392LELY_UTIL_ENDIAN_INLINE uint_least32_t
393htole32(uint_least32_t x)
394{
395 x &= UINT32_C(0xffffffff);
396#if LELY_BIG_ENDIAN
397 return bswap32(x);
398#elif LELY_LITTLE_ENDIAN
399 return x;
400#endif
401}
402#endif
403
404#ifndef letoh32
405LELY_UTIL_ENDIAN_INLINE uint_least32_t
406letoh32(uint_least32_t x)
407{
408 return htole32(x);
409}
410#endif
411
412#ifndef htobe64
413LELY_UTIL_ENDIAN_INLINE uint_least64_t
414htobe64(uint_least64_t x)
415{
416 x &= UINT64_C(0xffffffffffffffff);
417#if LELY_BIG_ENDIAN
418 return x;
419#elif LELY_LITTLE_ENDIAN
420 return bswap64(x);
421#endif
422}
423#endif
424
425#ifndef betoh64
426LELY_UTIL_ENDIAN_INLINE uint_least64_t
427betoh64(uint_least64_t x)
428{
429 return htobe64(x);
430}
431#endif
432
433#ifndef htole64
434LELY_UTIL_ENDIAN_INLINE uint_least64_t
435htole64(uint_least64_t x)
436{
437 x &= UINT64_C(0xffffffffffffffff);
438#if LELY_BIG_ENDIAN
439 return bswap64(x);
440#elif LELY_LITTLE_ENDIAN
441 return x;
442#endif
443}
444#endif
445
446#ifndef letoh64
447LELY_UTIL_ENDIAN_INLINE uint_least64_t
448letoh64(uint_least64_t x)
449{
450 return htole64(x);
451}
452#endif
453
454LELY_UTIL_ENDIAN_INLINE void
455stbe_i16(uint_least8_t dst[2], int_least16_t x)
456{
457 stbe_u16(dst, x);
458}
459
460LELY_UTIL_ENDIAN_INLINE int_least16_t
461ldbe_i16(const uint_least8_t src[2])
462{
463 return ldbe_u16(src);
464}
465
466LELY_UTIL_ENDIAN_INLINE void
467stbe_u16(uint_least8_t dst[2], uint_least16_t x)
468{
469#if CHAR_BIT == 8
470 x = htobe16(x);
471 memcpy(dst, &x, sizeof(x));
472#else
473 dst[0] = (x >> 8) & 0xff;
474 dst[1] = x & 0xff;
475#endif
476}
477
478LELY_UTIL_ENDIAN_INLINE uint_least16_t
479ldbe_u16(const uint_least8_t src[2])
480{
481#if CHAR_BIT == 8
482 uint_least16_t x = 0;
483 memcpy(&x, src, sizeof(x));
484 return betoh16(x);
485#else
486 return ((uint_least16_t)(src[0] & 0xff) << 8)
487 | ((uint_least16_t)(src[1] & 0xff));
488#endif
489}
490
491LELY_UTIL_ENDIAN_INLINE void
492stle_i16(uint_least8_t dst[2], int_least16_t x)
493{
494 stle_u16(dst, x);
495}
496
497LELY_UTIL_ENDIAN_INLINE int_least16_t
498ldle_i16(const uint_least8_t src[2])
499{
500 return ldle_u16(src);
501}
502
503LELY_UTIL_ENDIAN_INLINE void
504stle_u16(uint_least8_t dst[2], uint_least16_t x)
505{
506#if CHAR_BIT == 8
507 x = htole16(x);
508 memcpy(dst, &x, sizeof(x));
509#else
510 dst[0] = x & 0xff;
511 dst[1] = (x >> 8) & 0xff;
512#endif
513}
514
515LELY_UTIL_ENDIAN_INLINE uint_least16_t
516ldle_u16(const uint_least8_t src[2])
517{
518#if CHAR_BIT == 8
519 uint_least16_t x = 0;
520 memcpy(&x, src, sizeof(x));
521 return letoh16(x);
522#else
523 return (uint_least16_t)(src[0] & 0xff)
524 | ((uint_least16_t)(src[1] & 0xff) << 8);
525#endif
526}
527
528LELY_UTIL_ENDIAN_INLINE void
529stbe_i32(uint_least8_t dst[4], int_least32_t x)
530{
531 stbe_u32(dst, x);
532}
533
534LELY_UTIL_ENDIAN_INLINE int_least32_t
535ldbe_i32(const uint_least8_t src[4])
536{
537 return ldbe_u32(src);
538}
539
540LELY_UTIL_ENDIAN_INLINE void
541stbe_u32(uint_least8_t dst[4], uint_least32_t x)
542{
543#if CHAR_BIT == 8
544 x = htobe32(x);
545 memcpy(dst, &x, sizeof(x));
546#else
547 dst[0] = (x >> 24) & 0xff;
548 dst[1] = (x >> 16) & 0xff;
549 dst[2] = (x >> 8) & 0xff;
550 dst[3] = x & 0xff;
551#endif
552}
553
554LELY_UTIL_ENDIAN_INLINE uint_least32_t
555ldbe_u32(const uint_least8_t src[4])
556{
557#if CHAR_BIT == 8
558 uint_least32_t x = 0;
559 memcpy(&x, src, sizeof(x));
560 return betoh32(x);
561#else
562 return ((uint_least32_t)(src[0] & 0xff) << 24)
563 | ((uint_least32_t)(src[1] & 0xff) << 16)
564 | ((uint_least32_t)(src[2] & 0xff) << 8)
565 | ((uint_least32_t)(src[3] & 0xff));
566#endif
567}
568
569LELY_UTIL_ENDIAN_INLINE void
570stle_i32(uint_least8_t dst[4], int_least32_t x)
571{
572 stle_u32(dst, x);
573}
574
575LELY_UTIL_ENDIAN_INLINE int_least32_t
576ldle_i32(const uint_least8_t src[4])
577{
578 return ldle_u32(src);
579}
580
581LELY_UTIL_ENDIAN_INLINE void
582stle_u32(uint_least8_t dst[4], uint_least32_t x)
583{
584#if CHAR_BIT == 8
585 x = htole32(x);
586 memcpy(dst, &x, sizeof(x));
587#else
588 dst[0] = x & 0xff;
589 dst[1] = (x >> 8) & 0xff;
590 dst[2] = (x >> 16) & 0xff;
591 dst[3] = (x >> 24) & 0xff;
592#endif
593}
594
595LELY_UTIL_ENDIAN_INLINE uint_least32_t
596ldle_u32(const uint_least8_t src[4])
597{
598#if CHAR_BIT == 8
599 uint_least32_t x = 0;
600 memcpy(&x, src, sizeof(x));
601 return letoh32(x);
602#else
603 return (uint_least32_t)(src[0] & 0xff)
604 | ((uint_least32_t)(src[1] & 0xff) << 8)
605 | ((uint_least32_t)(src[2] & 0xff) << 16)
606 | ((uint_least32_t)(src[3] & 0xff) << 24);
607#endif
608}
609
610LELY_UTIL_ENDIAN_INLINE void
611stbe_i64(uint_least8_t dst[8], int_least64_t x)
612{
613 stbe_u64(dst, x);
614}
615
616LELY_UTIL_ENDIAN_INLINE int_least64_t
617ldbe_i64(const uint_least8_t src[8])
618{
619 return ldbe_u64(src);
620}
621
622LELY_UTIL_ENDIAN_INLINE void
623stbe_u64(uint_least8_t dst[8], uint_least64_t x)
624{
625#if CHAR_BIT == 8
626 x = htobe64(x);
627 memcpy(dst, &x, sizeof(x));
628#else
629 dst[0] = (x >> 56) & 0xff;
630 dst[1] = (x >> 48) & 0xff;
631 dst[2] = (x >> 40) & 0xff;
632 dst[3] = (x >> 32) & 0xff;
633 dst[4] = (x >> 24) & 0xff;
634 dst[5] = (x >> 16) & 0xff;
635 dst[6] = (x >> 8) & 0xff;
636 dst[7] = x & 0xff;
637#endif
638}
639
640LELY_UTIL_ENDIAN_INLINE uint_least64_t
641ldbe_u64(const uint_least8_t src[8])
642{
643#if CHAR_BIT == 8
644 uint_least64_t x = 0;
645 memcpy(&x, src, sizeof(x));
646 return betoh64(x);
647#else
648 return ((uint_least64_t)(src[0] & 0xff) << 56)
649 | ((uint_least64_t)(src[1] & 0xff) << 48)
650 | ((uint_least64_t)(src[2] & 0xff) << 40)
651 | ((uint_least64_t)(src[3] & 0xff) << 32)
652 | ((uint_least64_t)(src[4] & 0xff) << 24)
653 | ((uint_least64_t)(src[5] & 0xff) << 16)
654 | ((uint_least64_t)(src[6] & 0xff) << 8)
655 | ((uint_least64_t)(src[7] & 0xff));
656#endif
657}
658
659LELY_UTIL_ENDIAN_INLINE void
660stle_i64(uint_least8_t dst[8], int_least64_t x)
661{
662 stle_u64(dst, x);
663}
664
665LELY_UTIL_ENDIAN_INLINE int_least64_t
666ldle_i64(const uint_least8_t src[8])
667{
668 return ldle_u64(src);
669}
670
671LELY_UTIL_ENDIAN_INLINE void
672stle_u64(uint_least8_t dst[8], uint_least64_t x)
673{
674#if CHAR_BIT == 8
675 x = htole64(x);
676 memcpy(dst, &x, sizeof(x));
677#else
678 dst[0] = x & 0xff;
679 dst[1] = (x >> 8) & 0xff;
680 dst[2] = (x >> 16) & 0xff;
681 dst[3] = (x >> 24) & 0xff;
682 dst[4] = (x >> 32) & 0xff;
683 dst[5] = (x >> 40) & 0xff;
684 dst[6] = (x >> 48) & 0xff;
685 dst[7] = (x >> 56) & 0xff;
686#endif
687}
688
689LELY_UTIL_ENDIAN_INLINE uint_least64_t
690ldle_u64(const uint_least8_t src[8])
691{
692#if CHAR_BIT == 8
693 uint_least64_t x = 0;
694 memcpy(&x, src, sizeof(x));
695 return letoh64(x);
696#else
697 return (uint_least64_t)(src[0] & 0xff)
698 | ((uint_least64_t)(src[1] & 0xff) << 8)
699 | ((uint_least64_t)(src[2] & 0xff) << 16)
700 | ((uint_least64_t)(src[3] & 0xff) << 24)
701 | ((uint_least64_t)(src[4] & 0xff) << 32)
702 | ((uint_least64_t)(src[5] & 0xff) << 40)
703 | ((uint_least64_t)(src[6] & 0xff) << 48)
704 | ((uint_least64_t)(src[7] & 0xff) << 56);
705#endif
706}
707
708#ifdef LELY_FLT16_TYPE
709
710LELY_UTIL_ENDIAN_INLINE void
711stbe_flt16(uint_least8_t dst[2], flt16_t x)
712{
713 uint_least16_t tmp = 0;
714 memcpy(&tmp, &x, sizeof(x));
715 stbe_u16(dst, tmp);
716}
717
718LELY_UTIL_ENDIAN_INLINE flt16_t
719ldbe_flt16(const uint_least8_t src[2])
720{
721 flt16_t x = 0;
722 uint_least16_t tmp = ldbe_u16(src);
723 memcpy(&x, &tmp, sizeof(x));
724 return x;
725}
726
727LELY_UTIL_ENDIAN_INLINE void
728stle_flt16(uint_least8_t dst[2], flt16_t x)
729{
730 uint_least16_t tmp = 0;
731 memcpy(&tmp, &x, sizeof(x));
732 stle_u16(dst, tmp);
733}
734
735LELY_UTIL_ENDIAN_INLINE flt16_t
736ldle_flt16(const uint_least8_t src[2])
737{
738 flt16_t x = 0;
739 uint_least16_t tmp = ldle_u16(src);
740 memcpy(&x, &tmp, sizeof(x));
741 return x;
742}
743
744#endif // LELY_FLT16_TYPE
745
746#ifdef LELY_FLT32_TYPE
747
748LELY_UTIL_ENDIAN_INLINE void
749stbe_flt32(uint_least8_t dst[4], flt32_t x)
750{
751 uint_least32_t tmp = 0;
752 memcpy(&tmp, &x, sizeof(x));
753 stbe_u32(dst, tmp);
754}
755
756LELY_UTIL_ENDIAN_INLINE flt32_t
757ldbe_flt32(const uint_least8_t src[4])
758{
759 flt32_t x = 0;
760 uint_least32_t tmp = ldbe_u32(src);
761 memcpy(&x, &tmp, sizeof(x));
762 return x;
763}
764
765LELY_UTIL_ENDIAN_INLINE void
766stle_flt32(uint_least8_t dst[4], flt32_t x)
767{
768 uint_least32_t tmp = 0;
769 memcpy(&tmp, &x, sizeof(x));
770 stle_u32(dst, tmp);
771}
772
773LELY_UTIL_ENDIAN_INLINE flt32_t
774ldle_flt32(const uint_least8_t src[4])
775{
776 flt32_t x = 0;
777 uint_least32_t tmp = ldle_u32(src);
778 memcpy(&x, &tmp, sizeof(x));
779 return x;
780}
781
782#endif // LELY_FLT32_TYPE
783
784#ifdef LELY_FLT64_TYPE
785
786LELY_UTIL_ENDIAN_INLINE void
787stbe_flt64(uint_least8_t dst[8], flt64_t x)
788{
789 uint_least64_t tmp = 0;
790 memcpy(&tmp, &x, sizeof(x));
791 stbe_u64(dst, tmp);
792}
793
794LELY_UTIL_ENDIAN_INLINE flt64_t
795ldbe_flt64(const uint_least8_t src[8])
796{
797 flt64_t x = 0;
798 uint_least64_t tmp = ldbe_u64(src);
799 memcpy(&x, &tmp, sizeof(x));
800 return x;
801}
802
803LELY_UTIL_ENDIAN_INLINE void
804stle_flt64(uint_least8_t dst[8], flt64_t x)
805{
806 uint_least64_t tmp = 0;
807 memcpy(&tmp, &x, sizeof(x));
808 stle_u64(dst, tmp);
809}
810
811LELY_UTIL_ENDIAN_INLINE flt64_t
812ldle_flt64(const uint_least8_t src[8])
813{
814 flt64_t x = 0;
815 uint_least64_t tmp = ldle_u64(src);
816 memcpy(&x, &tmp, sizeof(x));
817 return x;
818}
819
820#endif // LELY_FLT64_TYPE
821
822#ifdef __cplusplus
823}
824#endif
825
826#endif // !LELY_UTIL_ENDIAN_H_
This header file is part of the utilities library; it contains the bit function definitions.
uint_least64_t bswap64(uint_least64_t x)
Reverses the byte order of the 64-bit unsigned integer x.
Definition: bits.h:308
uint_least16_t bswap16(uint_least16_t x)
Reverses the byte order of the 16-bit unsigned integer x.
Definition: bits.h:283
uint_least32_t bswap32(uint_least32_t x)
Reverses the byte order of the 32-bit unsigned integer x.
Definition: bits.h:295
This header file is part of the utilities library; it contains the byte order (endianness) function d...
void stbe_i64(uint_least8_t dst[8], int_least64_t x)
Stores a 64-bit signed integer in big-endian byte order.
Definition: endian.h:611
void stbe_i16(uint_least8_t dst[2], int_least16_t x)
Stores a 16-bit signed integer in big-endian byte order.
Definition: endian.h:455
int_least32_t ldbe_i32(const uint_least8_t src[4])
Loads a 32-bit signed integer in big-endian byte order.
Definition: endian.h:535
void stle_u64(uint_least8_t dst[8], uint_least64_t x)
Stores a 64-bit unsigned integer in little-endian byte order.
Definition: endian.h:672
uint_least16_t ldbe_u16(const uint_least8_t src[2])
Loads a 16-bit unsigned integer in big-endian byte order.
Definition: endian.h:479
uint_least32_t ldbe_u32(const uint_least8_t src[4])
Loads a 32-bit unsigned integer in big-endian byte order.
Definition: endian.h:555
uint_least16_t htole16(uint_least16_t x)
Converts a 16-bit unsigned integer from host to little-endian byte order.
Definition: endian.h:351
void stbe_i32(uint_least8_t dst[4], int_least32_t x)
Stores a 32-bit signed integer in big-endian byte order.
Definition: endian.h:529
uint_least32_t ldle_u32(const uint_least8_t src[4])
Loads a 32-bit unsigned integer in little-endian byte order.
Definition: endian.h:596
uint_least64_t ldbe_u64(const uint_least8_t src[8])
Loads a 64-bit unsigned integer in big-endian byte order.
Definition: endian.h:641
uint_least32_t htole32(uint_least32_t x)
Converts a 32-bit unsigned integer from host to little-endian byte order.
Definition: endian.h:393
void bcpyle(uint_least8_t *dst, int dstbit, const uint_least8_t *src, int srcbit, size_t n)
Copies n bits from a source to a destination buffer.
Definition: endian.c:123
void stle_i64(uint_least8_t dst[8], int_least64_t x)
Stores a 64-bit signed integer in little-endian byte order.
Definition: endian.h:660
int_least64_t ldbe_i64(const uint_least8_t src[8])
Loads a 64-bit signed integer in big-endian byte order.
Definition: endian.h:617
void stbe_u64(uint_least8_t dst[8], uint_least64_t x)
Stores a 64-bit unsigned integer in big-endian byte order.
Definition: endian.h:623
void bcpybe(uint_least8_t *dst, int dstbit, const uint_least8_t *src, int srcbit, size_t n)
Copies n bits from a source to a destination buffer.
Definition: endian.c:39
uint_least16_t htobe16(uint_least16_t x)
Converts a 16-bit unsigned integer from host to big-endian byte order.
Definition: endian.h:330
int_least32_t ldle_i32(const uint_least8_t src[4])
Loads a 32-bit signed integer in little-endian byte order.
Definition: endian.h:576
int_least16_t ldle_i16(const uint_least8_t src[2])
Loads a 16-bit signed integer in little-endian byte order.
Definition: endian.h:498
int_least64_t ldle_i64(const uint_least8_t src[8])
Loads a 64-bit signed integer in little-endian byte order.
Definition: endian.h:666
uint_least32_t htobe32(uint_least32_t x)
Converts a 32-bit unsigned integer from host to big-endian byte order.
Definition: endian.h:372
void stbe_u16(uint_least8_t dst[2], uint_least16_t x)
Stores a 16-bit unsigned integer in big-endian byte order.
Definition: endian.h:467
uint_least16_t ldle_u16(const uint_least8_t src[2])
Loads a 16-bit unsigned integer in little-endian byte order.
Definition: endian.h:516
void stle_i16(uint_least8_t dst[2], int_least16_t x)
Stores a 16-bit signed integer in little-endian byte order.
Definition: endian.h:492
uint_least64_t htobe64(uint_least64_t x)
Converts a 64-bit unsigned integer from host to big-endian byte order.
Definition: endian.h:414
uint_least64_t ldle_u64(const uint_least8_t src[8])
Loads a 64-bit unsigned integer in little-endian byte order.
Definition: endian.h:690
uint_least64_t htole64(uint_least64_t x)
Converts a 64-bit unsigned integer from host to little-endian byte order.
Definition: endian.h:435
int_least16_t ldbe_i16(const uint_least8_t src[2])
Loads a 16-bit signed integer in big-endian byte order.
Definition: endian.h:461
void stle_i32(uint_least8_t dst[4], int_least32_t x)
Stores a 32-bit signed integer in little-endian byte order.
Definition: endian.h:570
void stle_u16(uint_least8_t dst[2], uint_least16_t x)
Stores a 16-bit unsigned integer in little-endian byte order.
Definition: endian.h:504
void stbe_u32(uint_least8_t dst[4], uint_least32_t x)
Stores a 32-bit unsigned integer in big-endian byte order.
Definition: endian.h:541
void stle_u32(uint_least8_t dst[4], uint_least32_t x)
Stores a 32-bit unsigned integer in little-endian byte order.
Definition: endian.h:582
This header file is part of the utilities library; it contains the IEEE 754 floating-point format typ...
This header file is part of the C11 and POSIX compatibility library; it includes <string....