Changeset 3525 for trunk/kLdr/kLdrHlp.h
- Timestamp:
- Aug 20, 2007, 12:14:55 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrHlp.h
r2958 r3525 32 32 * @internal 33 33 * @{ */ 34 35 /** Get the minimum of two values. */36 #define KLDR_MIN(a, b) ((a) <= (b) ? (a) : (b))37 /** Get the maximum of two values. */38 #define KLDR_MAX(a, b) ((a) >= (b) ? (a) : (b))39 /** Calculate the offset of a structure member. */40 #define KLDR_OFFSETOF(strct, memb) ( (size_t)( &((strct *)0)->memb ) )41 /** Align a size_t value. */42 #define KLDR_ALIGN_Z(val, align) ( ((val) + ((align) - 1)) & ~(size_t)((align) - 1) )43 /** Align a void * value. */44 #define KLDR_ALIGN_P(pv, align) ( (void *)( ((uintptr_t)(pv) + ((align) - 1)) & ~(uintptr_t)((align) - 1) ) )45 /** Align a size_t value. */46 #define KLDR_ALIGN_ADDR(val, align) ( ((val) + ((align) - 1)) & ~(KLDRADDR)((align) - 1) )47 /** Number of elements in an array. */48 #define KLDR_ELEMENTS(a) ( sizeof(a) / sizeof((a)[0]) )49 50 51 /** @name Endian Conversion52 * @{ */53 54 /** @def KLDRHLP_E2E_U1655 * Convert the endian of an unsigned 16-bit value. */56 # define KLDRHLP_E2E_U16(u16) ( (uint16_t) (((u16) >> 8) | ((u16) << 8)) )57 /** @def KLDRHLP_E2E_U3258 * Convert the endian of an unsigned 32-bit value. */59 # define KLDRHLP_E2E_U32(u32) ( ( ((u32) & UINT32_C(0xff000000)) >> 24 ) \60 | ( ((u32) & UINT32_C(0x00ff0000)) >> 8 ) \61 | ( ((u32) & UINT32_C(0x0000ff00)) << 8 ) \62 | ( ((u32) & UINT32_C(0x000000ff)) << 24 ) \63 )64 /** @def KLDRHLP_E2E_U6465 * Convert the endian of an unsigned 64-bit value. */66 # define KLDRHLP_E2E_U64(u64) ( ( ((u64) & UINT64_C(0xff00000000000000)) >> 56 ) \67 | ( ((u64) & UINT64_C(0x00ff000000000000)) >> 40 ) \68 | ( ((u64) & UINT64_C(0x0000ff0000000000)) >> 24 ) \69 | ( ((u64) & UINT64_C(0x000000ff00000000)) >> 8 ) \70 | ( ((u64) & UINT64_C(0x00000000ff000000)) << 8 ) \71 | ( ((u64) & UINT64_C(0x0000000000ff0000)) << 24 ) \72 | ( ((u64) & UINT64_C(0x000000000000ff00)) << 40 ) \73 | ( ((u64) & UINT64_C(0x00000000000000ff)) << 56 ) \74 )75 76 /** @def KLDRHLP_LE2H_U1677 * Unsigned 16-bit little-endian to host endian. */78 /** @def KLDRHLP_LE2H_U3279 * Unsigned 32-bit little-endian to host endian. */80 /** @def KLDRHLP_LE2H_U6481 * Unsigned 64-bit little-endian to host endian. */82 /** @def KLDRHLP_BE2H_U1683 * Unsigned 16-bit big-endian to host endian. */84 /** @def KLDRHLP_BE2H_U3285 * Unsigned 32-bit big-endian to host endian. */86 /** @def KLDRHLP_BE2H_U6487 * Unsigned 64-bit big-endian to host endian. */88 #ifdef KLDR_LITTLE_ENDIAN89 # define KLDRHLP_LE2H_U16(u16) ((uint16_t)(u16))90 # define KLDRHLP_LE2H_U32(u32) ((uint32_t)(u32))91 # define KLDRHLP_LE2H_U64(u64) ((uint32_t)(u32))92 # define KLDRHLP_BE2H_U16(u16) KLDRHLP_E2E_U16(u16)93 # define KLDRHLP_BE2H_U32(u32) KLDRHLP_E2E_U32(u32)94 # define KLDRHLP_BE2H_U64(u64) KLDRHLP_E2E_U64(u64)95 #elif defined(KLDR_BIG_ENDIAN)96 # define KLDRHLP_LE2H_U16(u16) KLDRHLP_E2E_U16(u16)97 # define KLDRHLP_LE2H_U32(u32) KLDRHLP_E2E_U32(u32)98 # define KLDRHLP_LE2H_U32(u64) KLDRHLP_E2E_U64(u64)99 # define KLDRHLP_BE2H_U16(u16) ((uint16_t)(u16))100 # define KLDRHLP_BE2H_U32(u32) ((uint32_t)(u32))101 # define KLDRHLP_BE2H_U64(u64) ((uint32_t)(u32))102 #else103 # error "KLDR_BIG_ENDIAN or KLDR_LITTLE_ENDIAN is supposed to be defined."104 #endif105 106 /** @} */107 108 34 109 35 /*
Note:
See TracChangeset
for help on using the changeset viewer.