VirtualBox

Changeset 10998 in vbox for trunk/include


Ignore:
Timestamp:
Jul 30, 2008 4:22:30 PM (17 years ago)
Author:
vboxsync
Message:

iprt: Use the byte swapper routines from iprt/asm.h.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cdefs.h

    r10386 r10998  
    10211021
    10221022
     1023/** @def RT_BSWAP_U64
     1024 * Reverses the byte order of an uint64_t value. */
     1025#if 0
     1026# define RT_BSWAP_U64(u64)  RT_MAKE_U64(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
     1027#else
     1028# define RT_BSWAP_U64(u64)  ASMByteSwapU64(u64)
     1029#endif
     1030
     1031/** @def RT_BSWAP_U32
     1032 * Converts uint32_t value from host to big endian byte order. */
     1033#if 0
     1034# define RT_BSWAP_U32(u32)  (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
     1035#else
     1036# define RT_BSWAP_U32(u32)  ASMByteSwapU32(u32)
     1037#endif
     1038
     1039/** @def RT_BSWAP_U16
     1040 * Converts uint16_t value from host to big endian byte order. */
     1041#if 0
     1042# define RT_BSWAP_U16(u16)  (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
     1043#else
     1044# define RT_BSWAP_U16(u16)  ASMByteSwapU16(u16)
     1045#endif
     1046
     1047
    10231048/** @def RT_H2LE_U64
    1024  * Converts uint64_t value from host to little endian byte order. */
    1025 #define RT_H2LE_U64(u64) (u64)
     1049 * Converts an uint64_t value from host to little endian byte order. */
     1050#ifdef RT_BIG_ENDIAN
     1051# define RT_H2LE_U64(u64)   RT_BSWAP_U64(u64)
     1052#else
     1053# define RT_H2LE_U64(u64)   (u64)
     1054#endif
    10261055
    10271056/** @def RT_H2LE_U32
    1028  * Converts uint32_t value from host to little endian byte order. */
    1029 #define RT_H2LE_U32(u32) (u32)
     1057 * Converts an uint32_t value from host to little endian byte order. */
     1058#ifdef RT_BIG_ENDIAN
     1059# define RT_H2LE_U32(u32)   RT_BSWAP_U32(u32)
     1060#else
     1061# define RT_H2LE_U32(u32)   (u32)
     1062#endif
    10301063
    10311064/** @def RT_H2LE_U16
    1032  * Converts uint16_t value from host to little endian byte order. */
    1033 #define RT_H2LE_U16(u16) (u16)
     1065 * Converts an uint16_t value from host to little endian byte order. */
     1066#ifdef RT_BIG_ENDIAN
     1067# define RT_H2LE_U16(u16)   RT_BSWAP_U16(u16)
     1068#else
     1069# define RT_H2LE_U16(u16)   (u16)
     1070#endif
    10341071
    10351072/** @def RT_LE2H_U64
    1036  * Converts uint64_t value from little endian to host byte order. */
    1037 #define RT_LE2H_U64(u64) (u64)
     1073 * Converts an uint64_t value from little endian to host byte order. */
     1074#ifdef RT_BIG_ENDIAN
     1075# define RT_LE2H_U64(u64)   RT_BSWAP_U64(u64)
     1076#else
     1077# define RT_LE2H_U64(u64)   (u64)
     1078#endif
    10381079
    10391080/** @def RT_LE2H_U32
    1040  * Converts uint32_t value from little endian to host byte order. */
    1041 #define RT_LE2H_U32(u32) (u32)
     1081 * Converts an uint32_t value from little endian to host byte order. */
     1082#ifdef RT_BIG_ENDIAN
     1083# define RT_LE2H_U32(u32)   RT_BSWAP_U32(u32)
     1084#else
     1085# define RT_LE2H_U32(u32)   (u32)
     1086#endif
    10421087
    10431088/** @def RT_LE2H_U16
    1044  * Converts uint16_t value from little endian to host byte order. */
    1045 #define RT_LE2H_U16(u16) (u16)
     1089 * Converts an uint16_t value from little endian to host byte order. */
     1090#ifdef RT_BIG_ENDIAN
     1091# define RT_LE2H_U16(u16)   RT_BSWAP_U16(u16)
     1092#else
     1093# define RT_LE2H_U16(u16)   (u16)
     1094#endif
    10461095
    10471096
    10481097/** @def RT_H2BE_U64
    1049  * Converts uint64_t value from host to big endian byte order. */
    1050 #define RT_H2BE_U64(u64) RT_MAKE_U64(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
     1098 * Converts an uint64_t value from host to big endian byte order. */
     1099#ifdef RT_BIG_ENDIAN
     1100# define RT_H2BE_U64(u64)   (u64)
     1101#else
     1102# define RT_H2BE_U64(u64)   RT_BSWAP_U64(u64)
     1103#endif
    10511104
    10521105/** @def RT_H2BE_U32
    1053  * Converts uint32_t value from host to big endian byte order. */
    1054 #define RT_H2BE_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
     1106 * Converts an uint32_t value from host to big endian byte order. */
     1107#ifdef RT_BIG_ENDIAN
     1108# define RT_H2BE_U32(u32)   (u32)
     1109#else
     1110# define RT_H2BE_U32(u32)   RT_BSWAP_U32(u32)
     1111#endif
    10551112
    10561113/** @def RT_H2BE_U16
    1057  * Converts uint16_t value from host to big endian byte order. */
    1058 #define RT_H2BE_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
     1114 * Converts an uint16_t value from host to big endian byte order. */
     1115#ifdef RT_BIG_ENDIAN
     1116# define RT_H2BE_U16(u16)   (u16)
     1117#else
     1118# define RT_H2BE_U16(u16)   RT_BSWAP_U16(u16)
     1119#endif
    10591120
    10601121/** @def RT_BE2H_U64
    1061  * Converts uint64_t value from big endian to host byte order. */
    1062 #define RT_BE2H_U64(u64) RT_MAKE_U64(RT_H2BE_U32((u64) >> 32), RT_H2BE_U32((u64) & 0xffffffff))
     1122 * Converts an uint64_t value from big endian to host byte order. */
     1123#ifdef RT_BIG_ENDIAN
     1124# define RT_BE2H_U64(u64)   (u64)
     1125#else
     1126# define RT_BE2H_U64(u64)   RT_BSWAP_U64(u64)
     1127#endif
    10631128
    10641129/** @def RT_BE2H_U32
    1065  * Converts uint32_t value from big endian to host byte order. */
    1066 #define RT_BE2H_U32(u32) (RT_BYTE4(u32) | (RT_BYTE3(u32) << 8) | (RT_BYTE2(u32) << 16) | (RT_BYTE1(u32) << 24))
     1130 * Converts an uint32_t value from big endian to host byte order. */
     1131#ifdef RT_BIG_ENDIAN
     1132# define RT_BE2H_U32(u32)   (u32)
     1133#else
     1134# define RT_BE2H_U32(u32)   RT_BSWAP_U32(u32)
     1135#endif
    10671136
    10681137/** @def RT_BE2H_U16
    1069  * Converts uint16_t value from big endian to host byte order. */
    1070 #define RT_BE2H_U16(u16) (RT_HIBYTE(u16) | (RT_LOBYTE(u16) << 8))
    1071 
     1138 * Converts an uint16_t value from big endian to host byte order. */
     1139#ifdef RT_BIG_ENDIAN
     1140# define RT_BE2H_U16(u16)   (u16)
     1141#else
     1142# define RT_BE2H_U16(u16)   RT_BSWAP_U16(u16)
     1143#endif
     1144
     1145
     1146/** @def RT_H2N_U64
     1147 * Converts an uint64_t value from host to network byte order. */
     1148#define RT_H2N_U64(u64)     RT_H2BE_U64(u64)
    10721149
    10731150/** @def RT_H2N_U32
    1074  * Converts uint32_t value from host to network byte order. */
    1075 #define RT_H2N_U32(u32) RT_H2BE_U32(u32)
     1151 * Converts an uint32_t value from host to network byte order. */
     1152#define RT_H2N_U32(u32)     RT_H2BE_U32(u32)
    10761153
    10771154/** @def RT_H2N_U16
    1078  * Converts uint16_t value from host to network byte order. */
    1079 #define RT_H2N_U16(u16) RT_H2BE_U16(u16)
     1155 * Converts an uint16_t value from host to network byte order. */
     1156#define RT_H2N_U16(u16)     RT_H2BE_U16(u16)
     1157
     1158/** @def RT_N2H_U64
     1159 * Converts an uint64_t value from network to host byte order. */
     1160#define RT_N2H_U64(u64)     RT_BE2H_U64(u64)
    10801161
    10811162/** @def RT_N2H_U32
    1082  * Converts uint32_t value from network to host byte order. */
    1083 #define RT_N2H_U32(u32) RT_BE2H_U32(u32)
     1163 * Converts an uint32_t value from network to host byte order. */
     1164#define RT_N2H_U32(u32)     RT_BE2H_U32(u32)
    10841165
    10851166/** @def RT_N2H_U16
    1086  * Converts uint16_t value from network to host byte order. */
    1087 #define RT_N2H_U16(u16) RT_BE2H_U16(u16)
     1167 * Converts an uint16_t value from network to host byte order. */
     1168#define RT_N2H_U16(u16)     RT_BE2H_U16(u16)
    10881169
    10891170
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette