X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilctypes.h;h=7500b1fb22d71a403d09f99267f47ed58d3bfe2e;hb=9905799a86c606304fd7df2cd401de1740a272a1;hp=fbbc6d1dba22e736b61d3fea5863231f19ccada3;hpb=ee7652060361bbd40542e133158bf5c2d05e41be;p=silc.git diff --git a/lib/silcutil/silctypes.h b/lib/silcutil/silctypes.h index fbbc6d1d..7500b1fb 100644 --- a/lib/silcutil/silctypes.h +++ b/lib/silcutil/silctypes.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2002 - 2004 Pekka Riikonen + Copyright (C) 2002 - 2006 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -65,11 +65,24 @@ #endif /***/ +/****d* silcutil/SILCTypes/SilcBool + * + * NAME + * + * typedef unigned char SilcBool; + * + * DESCRIPTION + * + * Boolean value, and is always 8-bits. Represents value 0 or 1. + * + ***/ +typedef unsigned char SilcBool; + /****d* silcutil/SILCTypes/bool * * NAME * - * #define bool ... + * #define SilcBool ... * * DESCRIPTION * @@ -94,21 +107,19 @@ #endif /***/ -/****d* silcutil/SILCTypes/SilcBool - * - * NAME - * - * typedef unigned char SilcBool; - * - * DESCRIPTION - * - * Boolean value, and is always 8-bits. Represents value 0 or 1. - * - ***/ -typedef unigned char SilcBool; - +/* Our offsetof macro */ #define silc_offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +/* silc_likely and silc_unlikely GCC branch prediction macros. Use only if + you have profiled the code first. */ +#if __GNUC__ >= 3 +#define silc_likely(expr) __builtin_expect(!!(expr), 1) +#define silc_unlikely(expr) __builtin_expect(!!(expr), 0) +#else +#define silc_likely(expr) (expr) +#define silc_unlikely(expr) (expr) +#endif /* __GNUC__ >= 3 */ + #if SILC_SIZEOF_SHORT > 2 #error "size of the short must be 2 bytes" #endif @@ -264,6 +275,28 @@ typedef SilcInt32 SilcInt64; typedef SilcUInt32 * void *; #endif +/****d* silcutil/SILCTypes/SilcSocket + * + * NAME + * + * SilcSocket + * + * DESCRIPTION + * + * Platform specific socket. On POSIX compliant systems this is simply + * an integer, representing the socket. On other systems it is platform + * specific socket context. Access it only through routines that can + * handle SilcSocket types, unless you know what you are doing. + * + * SOURCE + */ +#if defined(SILC_UNIX) || defined(SILC_WIN32) +typedef int SilcSocket; +#elif defined(SILC_SYMBIAN) +typedef void * SilcSocket; +#endif +/***/ + /* Macros */ #define SILC_GET_WORD(cp) ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \ @@ -285,8 +318,8 @@ typedef SilcUInt32 * void *; */ #define SILC_GET16_MSB(l, cp) \ do { \ - (l) = ((SilcUInt32)(SilcUInt8)(cp)[0] << 8) \ - | ((SilcUInt32)(SilcUInt8)(cp)[1]); \ + (l) = ((SilcUInt32)(SilcUInt8)(cp)[0] << 8) \ + | ((SilcUInt32)(SilcUInt8)(cp)[1]); \ } while(0) /***/ @@ -304,10 +337,10 @@ do { \ */ #define SILC_GET32_MSB(l, cp) \ do { \ - (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \ - | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \ - | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \ - | ((SilcUInt32)(SilcUInt8)(cp)[3]); \ + (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) << 24 \ + | ((SilcUInt32)(SilcUInt8)(cp)[1] << 16) \ + | ((SilcUInt32)(SilcUInt8)(cp)[2] << 8) \ + | ((SilcUInt32)(SilcUInt8)(cp)[3]); \ } while(0) /***/ @@ -325,8 +358,8 @@ do { \ */ #define SILC_GET64_MSB(l, cp) \ do { \ - (l) = ((((SilcUInt64)SILC_GET_WORD((cp))) << 32) | \ - ((SilcUInt64)SILC_GET_WORD((cp) + 4))); \ + (l) = ((((SilcUInt64)SILC_GET_WORD((cp))) << 32) | \ + ((SilcUInt64)SILC_GET_WORD((cp) + 4))); \ } while(0) /***/ @@ -342,11 +375,15 @@ do { \ * * SOURCE */ +#if defined(SILC_I486) && defined(__GNUC__) +#define SILC_GET16_LSB(l, cp) (l) = (*(SilcUInt16 *)(cp)) +#else #define SILC_GET16_LSB(l, cp) \ do { \ - (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \ - | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8); \ + (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \ + | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8); \ } while(0) +#endif /* SILC_I486 && __GNUC__ */ /***/ /****d* silcutil/SILCTypes/SILC_GET32_LSB @@ -361,20 +398,28 @@ do { \ * * SOURCE */ +#if defined(SILC_I486) && defined(__GNUC__) +#define SILC_GET32_LSB(l, cp) (l) = (*(SilcUInt32 *)(cp)) +#else #define SILC_GET32_LSB(l, cp) \ do { \ - (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \ - | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \ - | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \ - | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24); \ + (l) = ((SilcUInt32)(SilcUInt8)(cp)[0]) \ + | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \ + | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \ + | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24); \ } while(0) +#endif /* SILC_I486 && __GNUC__ */ /* Same as upper but XOR the result always. Special purpose macro. */ +#if defined(SILC_I486) && defined(__GNUC__) +#define SILC_GET32_X_LSB(l, cp) (l) ^= (*(SilcUInt32 *)(cp)) +#else #define SILC_GET32_X_LSB(l, cp) \ - (l) ^= ((SilcUInt32)(SilcUInt8)(cp)[0]) \ - | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \ - | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \ - | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24) + (l) ^= ((SilcUInt32)(SilcUInt8)(cp)[0]) \ + | ((SilcUInt32)(SilcUInt8)(cp)[1] << 8) \ + | ((SilcUInt32)(SilcUInt8)(cp)[2] << 16) \ + | ((SilcUInt32)(SilcUInt8)(cp)[3] << 24) +#endif /* SILC_I486 && __GNUC__ */ /***/ /****d* silcutil/SILCTypes/SILC_PUT16_MSB @@ -391,8 +436,8 @@ do { \ */ #define SILC_PUT16_MSB(l, cp) \ do { \ - (cp)[0] = (SilcUInt8)((l) >> 8); \ - (cp)[1] = (SilcUInt8)(l); \ + (cp)[0] = (SilcUInt8)((l) >> 8); \ + (cp)[1] = (SilcUInt8)(l); \ } while(0) /***/ @@ -410,10 +455,10 @@ do { \ */ #define SILC_PUT32_MSB(l, cp) \ do { \ - (cp)[0] = (SilcUInt8)((l) >> 24); \ - (cp)[1] = (SilcUInt8)((l) >> 16); \ - (cp)[2] = (SilcUInt8)((l) >> 8); \ - (cp)[3] = (SilcUInt8)(l); \ + (cp)[0] = (SilcUInt8)((l) >> 24); \ + (cp)[1] = (SilcUInt8)((l) >> 16); \ + (cp)[2] = (SilcUInt8)((l) >> 8); \ + (cp)[3] = (SilcUInt8)(l); \ } while(0) /***/ @@ -448,11 +493,15 @@ do { \ * * SOURCE */ +#if defined(SILC_I486) && defined(__GNUC__) +#define SILC_PUT16_LSB(l, cp) (*(SilcUInt16 *)(cp)) = (l) +#else #define SILC_PUT16_LSB(l, cp) \ do { \ - (cp)[0] = (SilcUInt8)(l); \ - (cp)[1] = (SilcUInt8)((l) >> 8); \ + (cp)[0] = (SilcUInt8)(l); \ + (cp)[1] = (SilcUInt8)((l) >> 8); \ } while(0) +#endif /* SILC_I486 && __GNUC__ */ /***/ /****d* silcutil/SILCTypes/SILC_PUT32_LSB @@ -467,13 +516,17 @@ do { \ * * SOURCE */ +#if defined(SILC_I486) && defined(__GNUC__) +#define SILC_PUT32_LSB(l, cp) (*(SilcUInt32 *)(cp)) = (l) +#else #define SILC_PUT32_LSB(l, cp) \ do { \ - (cp)[0] = (SilcUInt8)(l); \ - (cp)[1] = (SilcUInt8)((l) >> 8); \ - (cp)[2] = (SilcUInt8)((l) >> 16); \ - (cp)[3] = (SilcUInt8)((l) >> 24); \ + (cp)[0] = (SilcUInt8)(l); \ + (cp)[1] = (SilcUInt8)((l) >> 8); \ + (cp)[2] = (SilcUInt8)((l) >> 16); \ + (cp)[3] = (SilcUInt8)((l) >> 24); \ } while(0) +#endif /* SILC_I486 && __GNUC__ */ /***/ /****d* silcutil/SILCTypes/SILC_SWAB_16 @@ -551,8 +604,7 @@ do { \ #if SILC_SIZEOF_VOID_P < 8 #define SILC_PTR_TO_64(_ptr__) ((SilcUInt64)((SilcUInt32)(_ptr__))) #else -#define SILC_PTR_TO_64(_ptr__) \ - ((SilcUInt64)((SilcUInt64)(_ptr__) & (SilcUInt32)0xFFFFFFFFUL)) +#define SILC_PTR_TO_64(_ptr__) ((SilcUInt64)((SilcUInt64)(_ptr__))) #endif /***/ @@ -560,7 +612,7 @@ do { \ * * NAME * - * #define SILC_PTR_TO_32 ... + * #define SILC_32_TO_PTR ... * * DESCRIPTION * @@ -581,7 +633,7 @@ do { \ * * NAME * - * #define SILC_PTR_TO_64 ... + * #define SILC_64_TO_PTR ... * * DESCRIPTION *