… | |
… | |
58 | |
58 | |
59 | =head2 TYPES / TYPE SUPPORT |
59 | =head2 TYPES / TYPE SUPPORT |
60 | |
60 | |
61 | ecb.h makes sure that the following types are defined (in the expected way): |
61 | ecb.h makes sure that the following types are defined (in the expected way): |
62 | |
62 | |
63 | int8_t uint8_t int16_t uint16_t |
63 | int8_t uint8_ |
64 | int32_t uint32_t int64_t uint64_t |
64 | int16_t uint16_t |
|
|
65 | int32_t uint32_ |
|
|
66 | int64_t uint64_t |
|
|
67 | int_fast8_t uint_fast8_t |
|
|
68 | int_fast16_t uint_fast16_t |
|
|
69 | int_fast32_t uint_fast32_t |
|
|
70 | int_fast64_t uint_fast64_t |
65 | intptr_t uintptr_t |
71 | intptr_t uintptr_t |
66 | |
72 | |
67 | The macro C<ECB_PTRSIZE> is defined to the size of a pointer on this |
73 | The macro C<ECB_PTRSIZE> is defined to the size of a pointer on this |
68 | platform (currently C<4> or C<8>) and can be used in preprocessor |
74 | platform (currently C<4> or C<8>) and can be used in preprocessor |
69 | expressions. |
75 | expressions. |
70 | |
76 | |
… | |
… | |
662 | |
668 | |
663 | These functions return the value of the 16-bit (32-bit, 64-bit) value |
669 | These functions return the value of the 16-bit (32-bit, 64-bit) value |
664 | C<x> after reversing the order of bytes (0x11223344 becomes 0x44332211 in |
670 | C<x> after reversing the order of bytes (0x11223344 becomes 0x44332211 in |
665 | C<ecb_bswap32>). |
671 | C<ecb_bswap32>). |
666 | |
672 | |
|
|
673 | =item T ecb_bswap (T x) [C++] |
|
|
674 | |
|
|
675 | For C++, an additional generic bswap function is provided. It supports |
|
|
676 | C<uint8_t>, C<uint16_t>, C<uint32_t> and C<uint64_t>. |
|
|
677 | |
667 | =item uint8_t ecb_rotl8 (uint8_t x, unsigned int count) |
678 | =item uint8_t ecb_rotl8 (uint8_t x, unsigned int count) |
668 | |
679 | |
669 | =item uint16_t ecb_rotl16 (uint16_t x, unsigned int count) |
680 | =item uint16_t ecb_rotl16 (uint16_t x, unsigned int count) |
670 | |
681 | |
671 | =item uint32_t ecb_rotl32 (uint32_t x, unsigned int count) |
682 | =item uint32_t ecb_rotl32 (uint32_t x, unsigned int count) |
… | |
… | |
685 | (C<ecb_rotl>). |
696 | (C<ecb_rotl>). |
686 | |
697 | |
687 | Current GCC versions understand these functions and usually compile them |
698 | Current GCC versions understand these functions and usually compile them |
688 | to "optimal" code (e.g. a single C<rol> or a combination of C<shld> on |
699 | to "optimal" code (e.g. a single C<rol> or a combination of C<shld> on |
689 | x86). |
700 | x86). |
|
|
701 | |
|
|
702 | =back |
|
|
703 | |
|
|
704 | =head2 HOST ENDIANNESS CONVERSION |
|
|
705 | |
|
|
706 | =over 4 |
|
|
707 | |
|
|
708 | =item uint_fast16_t ecb_be_u16_to_host (uint_fast16_t v) |
|
|
709 | |
|
|
710 | =item uint_fast32_t ecb_be_u32_to_host (uint_fast32_t v) |
|
|
711 | |
|
|
712 | =item uint_fast64_t ecb_be_u64_to_host (uint_fast64_t v) |
|
|
713 | |
|
|
714 | =item uint_fast16_t ecb_le_u16_to_host (uint_fast16_t v) |
|
|
715 | |
|
|
716 | =item uint_fast32_t ecb_le_u32_to_host (uint_fast32_t v) |
|
|
717 | |
|
|
718 | =item uint_fast64_t ecb_le_u64_to_host (uint_fast64_t v) |
|
|
719 | |
|
|
720 | Convert an unsigned 16, 32 or 64 bit value from big or little endian to host byte order. |
|
|
721 | |
|
|
722 | The naming convention is C<ecb_>(C<be>|C<le>)C<_u>C<16|32|64>C<_to_host>, |
|
|
723 | where be and le stand for big endian and little endian, respectively. |
|
|
724 | |
|
|
725 | =item uint_fast16_t ecb_host_to_be_u16 (uint_fast16_t v) |
|
|
726 | |
|
|
727 | =item uint_fast32_t ecb_host_to_be_u32 (uint_fast32_t v) |
|
|
728 | |
|
|
729 | =item uint_fast64_t ecb_host_to_be_u64 (uint_fast64_t v) |
|
|
730 | |
|
|
731 | =item uint_fast16_t ecb_host_to_le_u16 (uint_fast16_t v) |
|
|
732 | |
|
|
733 | =item uint_fast32_t ecb_host_to_le_u32 (uint_fast32_t v) |
|
|
734 | |
|
|
735 | =item uint_fast64_t ecb_host_to_le_u64 (uint_fast64_t v) |
|
|
736 | |
|
|
737 | Like above, but converts I<from> host byte order to the specified |
|
|
738 | endianness. |
|
|
739 | |
|
|
740 | =back |
|
|
741 | |
|
|
742 | In C++ the following additional functions are supported: |
|
|
743 | |
|
|
744 | =over 4 |
|
|
745 | |
|
|
746 | =item T ecb_be_to_host (T v) |
|
|
747 | |
|
|
748 | =item T ecb_le_to_host (T v) |
|
|
749 | |
|
|
750 | =item T ecb_host_to_be (T v) |
|
|
751 | |
|
|
752 | =item T ecb_host_to_le (T v) |
|
|
753 | |
|
|
754 | These work like their C counterparts, above, but use templates for the |
|
|
755 | type, which make them useful in generic code. |
|
|
756 | |
|
|
757 | C<T> must be one of C<uint8_t>, C<uint16_t>, C<uint32_t> or C<uint64_t> |
|
|
758 | (so unlike their C counterparts, there is a version for C<uint8_t>, which |
|
|
759 | again can be useful in generic code). |
|
|
760 | |
|
|
761 | =head2 UNALIGNED LOAD/STORE |
|
|
762 | |
|
|
763 | These function load or store unaligned multi-byte values. |
|
|
764 | |
|
|
765 | =over 4 |
|
|
766 | |
|
|
767 | =item uint_fast16_t ecb_peek_u16_u (const void *ptr) |
|
|
768 | |
|
|
769 | =item uint_fast32_t ecb_peek_u32_u (const void *ptr) |
|
|
770 | |
|
|
771 | =item uint_fast64_t ecb_peek_u64_u (const void *ptr) |
|
|
772 | |
|
|
773 | These functions load an unaligned, unsigned 16, 32 or 64 bit value from |
|
|
774 | memory. |
|
|
775 | |
|
|
776 | =item uint_fast16_t ecb_peek_be_u16_u (const void *ptr) |
|
|
777 | |
|
|
778 | =item uint_fast32_t ecb_peek_be_u32_u (const void *ptr) |
|
|
779 | |
|
|
780 | =item uint_fast64_t ecb_peek_be_u64_u (const void *ptr) |
|
|
781 | |
|
|
782 | =item uint_fast16_t ecb_peek_le_u16_u (const void *ptr) |
|
|
783 | |
|
|
784 | =item uint_fast32_t ecb_peek_le_u32_u (const void *ptr) |
|
|
785 | |
|
|
786 | =item uint_fast64_t ecb_peek_le_u64_u (const void *ptr) |
|
|
787 | |
|
|
788 | Like above, but additionally convert from big endian (C<be>) or little |
|
|
789 | endian (C<le>) byte order to host byte order while doing so. |
|
|
790 | |
|
|
791 | =item ecb_poke_u16_u (void *ptr, uint16_t v) |
|
|
792 | |
|
|
793 | =item ecb_poke_u32_u (void *ptr, uint32_t v) |
|
|
794 | |
|
|
795 | =item ecb_poke_u64_u (void *ptr, uint64_t v) |
|
|
796 | |
|
|
797 | These functions store an unaligned, unsigned 16, 32 or 64 bit value to |
|
|
798 | memory. |
|
|
799 | |
|
|
800 | =item ecb_poke_be_u16_u (void *ptr, uint_fast16_t v) |
|
|
801 | |
|
|
802 | =item ecb_poke_be_u32_u (void *ptr, uint_fast32_t v) |
|
|
803 | |
|
|
804 | =item ecb_poke_be_u64_u (void *ptr, uint_fast64_t v) |
|
|
805 | |
|
|
806 | =item ecb_poke_le_u16_u (void *ptr, uint_fast16_t v) |
|
|
807 | |
|
|
808 | =item ecb_poke_le_u32_u (void *ptr, uint_fast32_t v) |
|
|
809 | |
|
|
810 | =item ecb_poke_le_u64_u (void *ptr, uint_fast64_t v) |
|
|
811 | |
|
|
812 | Like above, but additionally convert from host byte order to big endian |
|
|
813 | (C<be>) or little endian (C<le>) byte order while doing so. |
|
|
814 | |
|
|
815 | =back |
|
|
816 | |
|
|
817 | In C++ the following additional functions are supported: |
|
|
818 | |
|
|
819 | =over 4 |
|
|
820 | |
|
|
821 | =item T ecb_peek (const void *ptr) |
|
|
822 | |
|
|
823 | =item T ecb_peek_be (const void *ptr) |
|
|
824 | |
|
|
825 | =item T ecb_peek_le (const void *ptr) |
|
|
826 | |
|
|
827 | =item T ecb_peek_u (const void *ptr) |
|
|
828 | |
|
|
829 | =item T ecb_peek_be_u (const void *ptr) |
|
|
830 | |
|
|
831 | =item T ecb_peek_le_u (const void *ptr) |
|
|
832 | |
|
|
833 | Similarly to their C counterparts, these functions load an unsigned 8, 16, |
|
|
834 | 32 or 64 bit value from memory, with optional conversion from big/little |
|
|
835 | endian. |
|
|
836 | |
|
|
837 | Since the type cannot be deduced, it has top be specified explicitly, e.g. |
|
|
838 | |
|
|
839 | uint_fast16_t v = ecb_peek<uint16_t> (ptr); |
|
|
840 | |
|
|
841 | C<T> must be one of C<uint8_t>, C<uint16_t>, C<uint32_t> or C<uint64_t>. |
|
|
842 | |
|
|
843 | Unlike their C counterparts, these functions support 8 bit quantities |
|
|
844 | (C<uint8_t>) and also have an aligned version (without the C<_u> prefix), |
|
|
845 | all of which hopefully makes them more useful in generic code. |
|
|
846 | |
|
|
847 | =item ecb_poke (void *ptr, T v) |
|
|
848 | |
|
|
849 | =item ecb_poke_be (void *ptr, T v) |
|
|
850 | |
|
|
851 | =item ecb_poke_le (void *ptr, T v) |
|
|
852 | |
|
|
853 | =item ecb_poke_u (void *ptr, T v) |
|
|
854 | |
|
|
855 | =item ecb_poke_be_u (void *ptr, T v) |
|
|
856 | |
|
|
857 | =item ecb_poke_le_u (void *ptr, T v) |
|
|
858 | |
|
|
859 | Again, similarly to their C counterparts, these functions store an |
|
|
860 | unsigned 8, 16, 32 or z64 bit value to memory, with optional conversion to |
|
|
861 | big/little endian. |
|
|
862 | |
|
|
863 | C<T> must be one of C<uint8_t>, C<uint16_t>, C<uint32_t> or C<uint64_t>. |
|
|
864 | |
|
|
865 | Unlike their C counterparts, these functions support 8 bit quantities |
|
|
866 | (C<uint8_t>) and also have an aligned version (without the C<_u> prefix), |
|
|
867 | all of which hopefully makes them more useful in generic code. |
690 | |
868 | |
691 | =back |
869 | =back |
692 | |
870 | |
693 | =head2 FLOATING POINT FIDDLING |
871 | =head2 FLOATING POINT FIDDLING |
694 | |
872 | |