VirtualBox

Changeset 85278 in vbox


Ignore:
Timestamp:
Jul 12, 2020 2:25:29 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139255
Message:

iprt/cdefs.h: Added signed variants of the endian conversion macros. bugref:9790

File:
1 edited

Legend:

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

    r85229 r85278  
    30773077/** @def RT_BSWAP_U64
    30783078 * Reverses the byte order of an uint64_t value. */
    3079 #if 0
    3080 # define RT_BSWAP_U64(u64)  RT_BSWAP_U64_C(u64)
    3081 #elif defined(__GNUC__)
    3082 # define RT_BSWAP_U64(u64)  (__builtin_constant_p((u64)) \
    3083                             ? RT_BSWAP_U64_C(u64) : ASMByteSwapU64(u64))
     3079#if defined(__GNUC__)
     3080# define RT_BSWAP_U64(u64)  (__builtin_constant_p((u64)) ? RT_BSWAP_U64_C(u64) : ASMByteSwapU64(u64))
    30843081#else
    30853082# define RT_BSWAP_U64(u64)  ASMByteSwapU64(u64)
     
    30883085/** @def RT_BSWAP_U32
    30893086 * Reverses the byte order of an uint32_t value. */
    3090 #if 0
    3091 # define RT_BSWAP_U32(u32)  RT_BSWAP_U32_C(u32)
    3092 #elif defined(__GNUC__)
    3093 # define RT_BSWAP_U32(u32)  (__builtin_constant_p((u32)) \
    3094                             ? RT_BSWAP_U32_C(u32) : ASMByteSwapU32(u32))
     3087#if defined(__GNUC__)
     3088# define RT_BSWAP_U32(u32)  (__builtin_constant_p((u32)) ? RT_BSWAP_U32_C(u32) : ASMByteSwapU32(u32))
    30953089#else
    30963090# define RT_BSWAP_U32(u32)  ASMByteSwapU32(u32)
     
    30993093/** @def RT_BSWAP_U16
    31003094 * Reverses the byte order of an uint16_t value. */
    3101 #if 0
    3102 # define RT_BSWAP_U16(u16)  RT_BSWAP_U16_C(u16)
    3103 #elif defined(__GNUC__)
    3104 # define RT_BSWAP_U16(u16)  (__builtin_constant_p((u16)) \
    3105                             ? RT_BSWAP_U16_C(u16) : ASMByteSwapU16(u16))
     3095#if defined(__GNUC__)
     3096# define RT_BSWAP_U16(u16)  (__builtin_constant_p((u16)) ? RT_BSWAP_U16_C(u16) : ASMByteSwapU16(u16))
    31063097#else
    31073098# define RT_BSWAP_U16(u16)  ASMByteSwapU16(u16)
    31083099#endif
     3100
     3101/** @def RT_BSWAP_S64
     3102 * Reverses the byte order of an int64_t value. */
     3103#define RT_BSWAP_S64(i64)   ((int64_t)RT_BSWAP_U64((uint64_t)i64))
     3104
     3105/** @def RT_BSWAP_S32
     3106 * Reverses the byte order of an int32_t value. */
     3107#define RT_BSWAP_S32(i32)   ((int32_t)RT_BSWAP_U32((uint32_t)i32))
     3108
     3109/** @def RT_BSWAP_S16
     3110 * Reverses the byte order of an int16_t value. */
     3111#define RT_BSWAP_S16(i16)   ((int16_t)RT_BSWAP_U16((uint16_t)i16))
    31093112
    31103113
     
    31213124#define RT_BSWAP_U16_C(u16) RT_MAKE_U16(RT_HIBYTE(u16), RT_LOBYTE(u16))
    31223125
     3126/** @def RT_BSWAP_S64_C
     3127 * Reverses the byte order of an int64_t constant. */
     3128#define RT_BSWAP_S64_C(i64) ((int64_t)RT_MAKE_U64(RT_BSWAP_U32_C((uint64_t)(i64) >> 32), RT_BSWAP_U32_C((uint32_t)(i64))))
     3129
     3130/** @def RT_BSWAP_S32_C
     3131 * Reverses the byte order of an int32_t constant. */
     3132#define RT_BSWAP_S32_C(i32) ((int32_t)RT_MAKE_U32_FROM_U8(RT_BYTE4(i32), RT_BYTE3(i32), RT_BYTE2(i32), RT_BYTE1(i)))
     3133
     3134/** @def RT_BSWAP_S16_C
     3135 * Reverses the byte order of an uint16_t constant. */
     3136#define RT_BSWAP_S16_C(i16) ((int16_t)RT_MAKE_U16(RT_HIBYTE(i16), RT_LOBYTE(i16)))
     3137
     3138
     3139
     3140/** @name Host to/from little endian.
     3141 * @note Typically requires iprt/asm.h to be included.
     3142 * @{ */
    31233143
    31243144/** @def RT_H2LE_U64
     
    32193239#endif
    32203240
     3241/** @def RT_H2LE_S64
     3242 * Converts an int64_t value from host to little endian byte order. */
     3243#ifdef RT_BIG_ENDIAN
     3244# define RT_H2LE_S64(i64)   RT_BSWAP_S64(i64)
     3245#else
     3246# define RT_H2LE_S64(i64)   (i64)
     3247#endif
     3248
     3249/** @def RT_H2LE_S64_C
     3250 * Converts an int64_t constant from host to little endian byte order. */
     3251#ifdef RT_BIG_ENDIAN
     3252# define RT_H2LE_S64_C(i64) RT_BSWAP_S64_C(i64)
     3253#else
     3254# define RT_H2LE_S64_C(i64) (i64)
     3255#endif
     3256
     3257/** @def RT_H2LE_S32
     3258 * Converts an int32_t value from host to little endian byte order. */
     3259#ifdef RT_BIG_ENDIAN
     3260# define RT_H2LE_S32(i32)   RT_BSWAP_S32(i32)
     3261#else
     3262# define RT_H2LE_S32(i32)   (i32)
     3263#endif
     3264
     3265/** @def RT_H2LE_S32_C
     3266 * Converts an int32_t constant from host to little endian byte order. */
     3267#ifdef RT_BIG_ENDIAN
     3268# define RT_H2LE_S32_C(i32) RT_BSWAP_S32_C(i32)
     3269#else
     3270# define RT_H2LE_S32_C(i32) (i32)
     3271#endif
     3272
     3273/** @def RT_H2LE_S16
     3274 * Converts an int16_t value from host to little endian byte order. */
     3275#ifdef RT_BIG_ENDIAN
     3276# define RT_H2LE_S16(i16)   RT_BSWAP_S16(i16)
     3277#else
     3278# define RT_H2LE_S16(i16)   (i16)
     3279#endif
     3280
     3281/** @def RT_H2LE_S16_C
     3282 * Converts an int16_t constant from host to little endian byte order. */
     3283#ifdef RT_BIG_ENDIAN
     3284# define RT_H2LE_S16_C(i16) RT_BSWAP_S16_C(i16)
     3285#else
     3286# define RT_H2LE_S16_C(i16) (i16)
     3287#endif
     3288
     3289/** @def RT_LE2H_S64
     3290 * Converts an int64_t value from little endian to host byte order. */
     3291#ifdef RT_BIG_ENDIAN
     3292# define RT_LE2H_S64(i64)   RT_BSWAP_S64(i64)
     3293#else
     3294# define RT_LE2H_S64(i64)   (i64)
     3295#endif
     3296
     3297/** @def RT_LE2H_S64_C
     3298 * Converts an int64_t constant from little endian to host byte order. */
     3299#ifdef RT_BIG_ENDIAN
     3300# define RT_LE2H_S64_C(i64) RT_BSWAP_S64_C(i64)
     3301#else
     3302# define RT_LE2H_S64_C(i64) (i64)
     3303#endif
     3304
     3305/** @def RT_LE2H_S32
     3306 * Converts an int32_t value from little endian to host byte order. */
     3307#ifdef RT_BIG_ENDIAN
     3308# define RT_LE2H_S32(i32)   RT_BSWAP_S32(i32)
     3309#else
     3310# define RT_LE2H_S32(i32)   (i32)
     3311#endif
     3312
     3313/** @def RT_LE2H_S32_C
     3314 * Converts an int32_t constant from little endian to host byte order. */
     3315#ifdef RT_BIG_ENDIAN
     3316# define RT_LE2H_S32_C(i32) RT_BSWAP_S32_C(i32)
     3317#else
     3318# define RT_LE2H_S32_C(i32) (i32)
     3319#endif
     3320
     3321/** @def RT_LE2H_S16
     3322 * Converts an int16_t value from little endian to host byte order. */
     3323#ifdef RT_BIG_ENDIAN
     3324# define RT_LE2H_S16(i16)   RT_BSWAP_S16(i16)
     3325#else
     3326# define RT_LE2H_S16(i16)   (i16)
     3327#endif
     3328
     3329/** @def RT_LE2H_S16_C
     3330 * Converts an int16_t constant from little endian to host byte order. */
     3331#ifdef RT_BIG_ENDIAN
     3332# define RT_LE2H_S16_C(i16) RT_BSWAP_S16_C(i16)
     3333#else
     3334# define RT_LE2H_S16_C(i16) (i16)
     3335#endif
     3336
     3337/** @} */
     3338
     3339/** @name Host to/from big endian.
     3340 * @note Typically requires iprt/asm.h to be included.
     3341 * @{ */
    32213342
    32223343/** @def RT_H2BE_U64
     
    33163437#endif
    33173438
     3439/** @def RT_H2BE_S64
     3440 * Converts an int64_t value from host to big endian byte order. */
     3441#ifdef RT_BIG_ENDIAN
     3442# define RT_H2BE_S64(i64)   (i64)
     3443#else
     3444# define RT_H2BE_S64(i64)   RT_BSWAP_S64(i64)
     3445#endif
     3446
     3447/** @def RT_H2BE_S64_C
     3448 * Converts an int64_t constant from host to big endian byte order. */
     3449#ifdef RT_BIG_ENDIAN
     3450# define RT_H2BE_S64_C(i64) (i64)
     3451#else
     3452# define RT_H2BE_S64_C(i64) RT_BSWAP_S64_C(i64)
     3453#endif
     3454
     3455/** @def RT_H2BE_S32
     3456 * Converts an int32_t value from host to big endian byte order. */
     3457#ifdef RT_BIG_ENDIAN
     3458# define RT_H2BE_S32(i32)   (i32)
     3459#else
     3460# define RT_H2BE_S32(i32)   RT_BSWAP_S32(i32)
     3461#endif
     3462
     3463/** @def RT_H2BE_S32_C
     3464 * Converts an int32_t constant from host to big endian byte order. */
     3465#ifdef RT_BIG_ENDIAN
     3466# define RT_H2BE_S32_C(i32) (i32)
     3467#else
     3468# define RT_H2BE_S32_C(i32) RT_BSWAP_S32_C(i32)
     3469#endif
     3470
     3471/** @def RT_H2BE_S16
     3472 * Converts an int16_t value from host to big endian byte order. */
     3473#ifdef RT_BIG_ENDIAN
     3474# define RT_H2BE_S16(i16)   (i16)
     3475#else
     3476# define RT_H2BE_S16(i16)   RT_BSWAP_S16(i16)
     3477#endif
     3478
     3479/** @def RT_H2BE_S16_C
     3480 * Converts an int16_t constant from host to big endian byte order. */
     3481#ifdef RT_BIG_ENDIAN
     3482# define RT_H2BE_S16_C(i16) (i16)
     3483#else
     3484# define RT_H2BE_S16_C(i16) RT_BSWAP_S16_C(i16)
     3485#endif
     3486
     3487/** @def RT_BE2H_S64
     3488 * Converts an int64_t value from big endian to host byte order. */
     3489#ifdef RT_BIG_ENDIAN
     3490# define RT_BE2H_S64(i64)   (i64)
     3491#else
     3492# define RT_BE2H_S64(i64)   RT_BSWAP_S64(i64)
     3493#endif
     3494
     3495/** @def RT_BE2H_S64
     3496 * Converts an int64_t constant from big endian to host byte order. */
     3497#ifdef RT_BIG_ENDIAN
     3498# define RT_BE2H_S64_C(i64) (i64)
     3499#else
     3500# define RT_BE2H_S64_C(i64) RT_BSWAP_S64_C(i64)
     3501#endif
     3502
     3503/** @def RT_BE2H_S32
     3504 * Converts an int32_t value from big endian to host byte order. */
     3505#ifdef RT_BIG_ENDIAN
     3506# define RT_BE2H_S32(i32)   (i32)
     3507#else
     3508# define RT_BE2H_S32(i32)   RT_BSWAP_S32(i32)
     3509#endif
     3510
     3511/** @def RT_BE2H_S32_C
     3512 * Converts an int32_t value from big endian to host byte order. */
     3513#ifdef RT_BIG_ENDIAN
     3514# define RT_BE2H_S32_C(i32) (i32)
     3515#else
     3516# define RT_BE2H_S32_C(i32) RT_BSWAP_S32_C(i32)
     3517#endif
     3518
     3519/** @def RT_BE2H_S16
     3520 * Converts an int16_t value from big endian to host byte order. */
     3521#ifdef RT_BIG_ENDIAN
     3522# define RT_BE2H_S16(i16)   (i16)
     3523#else
     3524# define RT_BE2H_S16(i16)   RT_BSWAP_S16(i16)
     3525#endif
     3526
     3527/** @def RT_BE2H_S16_C
     3528 * Converts an int16_t constant from big endian to host byte order. */
     3529#ifdef RT_BIG_ENDIAN
     3530# define RT_BE2H_S16_C(i16) (i16)
     3531#else
     3532# define RT_BE2H_S16_C(i16) RT_BSWAP_S16_C(i16)
     3533#endif
     3534/** @} */
     3535
     3536/** @name Host to/from network byte order.
     3537 * @note Typically requires iprt/asm.h to be included.
     3538 * @{ */
    33183539
    33193540/** @def RT_H2N_U64
     
    33643585 * Converts an uint16_t value from network to host byte order. */
    33653586#define RT_N2H_U16_C(u16)   RT_BE2H_U16_C(u16)
     3587
     3588/** @def RT_H2N_S64
     3589 * Converts an int64_t value from host to network byte order. */
     3590#define RT_H2N_S64(i64)     RT_H2BE_S64(i64)
     3591
     3592/** @def RT_H2N_S64_C
     3593 * Converts an int64_t constant from host to network byte order. */
     3594#define RT_H2N_S64_C(i64)   RT_H2BE_S64_C(i64)
     3595
     3596/** @def RT_H2N_S32
     3597 * Converts an int32_t value from host to network byte order. */
     3598#define RT_H2N_S32(i32)     RT_H2BE_S32(i32)
     3599
     3600/** @def RT_H2N_S32_C
     3601 * Converts an int32_t constant from host to network byte order. */
     3602#define RT_H2N_S32_C(i32)   RT_H2BE_S32_C(i32)
     3603
     3604/** @def RT_H2N_S16
     3605 * Converts an int16_t value from host to network byte order. */
     3606#define RT_H2N_S16(i16)     RT_H2BE_S16(i16)
     3607
     3608/** @def RT_H2N_S16_C
     3609 * Converts an int16_t constant from host to network byte order. */
     3610#define RT_H2N_S16_C(i16)   RT_H2BE_S16_C(i16)
     3611
     3612/** @def RT_N2H_S64
     3613 * Converts an int64_t value from network to host byte order. */
     3614#define RT_N2H_S64(i64)     RT_BE2H_S64(i64)
     3615
     3616/** @def RT_N2H_S64_C
     3617 * Converts an int64_t constant from network to host byte order. */
     3618#define RT_N2H_S64_C(i64)   RT_BE2H_S64_C(i64)
     3619
     3620/** @def RT_N2H_S32
     3621 * Converts an int32_t value from network to host byte order. */
     3622#define RT_N2H_S32(i32)     RT_BE2H_S32(i32)
     3623
     3624/** @def RT_N2H_S32_C
     3625 * Converts an int32_t constant from network to host byte order. */
     3626#define RT_N2H_S32_C(i32)   RT_BE2H_S32_C(i32)
     3627
     3628/** @def RT_N2H_S16
     3629 * Converts an int16_t value from network to host byte order. */
     3630#define RT_N2H_S16(i16)     RT_BE2H_S16(i16)
     3631
     3632/** @def RT_N2H_S16_C
     3633 * Converts an int16_t value from network to host byte order. */
     3634#define RT_N2H_S16_C(i16)   RT_BE2H_S16_C(i16)
     3635
     3636/** @} */
    33663637
    33673638
Note: See TracChangeset for help on using the changeset viewer.

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