*
***/
+/****d* silcutil/SilcFloat32
+ *
+ * NAME
+ *
+ * typedef float SilcFloat32;
+ *
+ * DESCRIPTION
+ *
+ * 32-bit floating point number.
+ *
+ ***/
+typedef float SilcFloat32;
+
+/****d* silcutil/SilcFloat64
+ *
+ * NAME
+ *
+ * typedef double SilcFloat64;
+ *
+ * DESCRIPTION
+ *
+ * 64-bit floating point number.
+ *
+ ***/
+typedef double SilcFloat64;
+
#if SILC_SIZEOF_VOID_P < 4
typedef SilcUInt32 * void *;
#endif
#define SILC_PARAM_ALLOC 0x00010000 /* Allocate, bitmask */
#define SILC_PARAM_REPLACE 0x00020000 /* Replace, bitmask */
+/****d* silcutil/SilcCompareValue
+ *
+ * NAME
+ *
+ * typedef enum { ... } SilcCompareValue
+ *
+ * DESCRIPTION
+ *
+ * Values that can be returned by the SilcCompare function. Note that
+ * not all routines may respect all of the return values.
+ *
+ * SOURCE
+ */
+typedef enum {
+ SILC_COMPARE_LESS_THAN_EQUAL_TO = -2, /* Value 1 <= value 2 */
+ SILC_COMPARE_LESS_THAN = -1, /* Value 1 < value 2 */
+ SILC_COMPARE_EQUAL_TO = 0, /* Value 1 == value 2 */
+ SILC_COMPARE_GREATER_THAN = 1, /* Value 1 > value 2 */
+ SILC_COMPARE_GREATER_THAN_EQUAL_TO = 2, /* Value 1 >= value 2 */
+ SILC_COMPARE_STOP = 3, /* Stop comparison */
+} SilcCompareValue;
+/***/
+
+/****f* silcutil/SilcCompare
+ *
+ * SYNOPSIS
+ *
+ * typedef SilcCompareValue (*SilcCompare)(void *value1, void *value2,
+ * void *context);
+ *
+ * DESCRIPTION
+ *
+ * A comparison function used by many routines in SILC Runtime Toolkit.
+ *
+ ***/
+typedef SilcCompareValue (*SilcCompare)(void *value1, void *value2,
+ void *context);
+
/* Macros */
#if (defined(SILC_I486) || defined(SILC_X86_64)) && defined(__GNUC__)
| ((SilcUInt32)(SilcUInt8)(cp)[3])
#endif /* (SILC_I486 || SILC_X86_64) && __GNUC__ */
+/****d* silcutil/SILC_MAX
+ *
+ * NAME
+ *
+ * #define SILC_MAX(a, b)
+ *
+ * DESCRIPTION
+ *
+ * Return `a' if it is bigger than `b', otherwise return `b'.
+ *
+ ***/
+#define SILC_MAX(a, b) ((a) > (b) ? (a) : (b))
+
+/****d* silcutil/SILC_MIN
+ *
+ * NAME
+ *
+ * #define SILC_MIN(a, b)
+ *
+ * DESCRIPTION
+ *
+ * Return `a' if it is smaller than `b', otherwise return `b'.
+ *
+ ***/
+#define SILC_MIN(a, b) ((a) < (b) ? (a) : (b))
+
/****d* silcutil/SILC_GET16_MSB
*
* NAME
{
#if (defined(SILC_I386) || defined(SILC_X86_64)) && defined(__GNUC__)
asm volatile ("roll %%cl, %0"
- : "=q" (val) : "0" (val), "c" (num));
+ : "=r" (val) : "0" (val), "c" (num));
+ return val;
+#else
+ return ((val << (SilcUInt32)num) | (val >> (32 - (SilcUInt32)num)));
+#endif /* (SILC_I486 || SILC_X86_64) && __GNUC__ */
+}
+
+/****d* silcutil/silc_rolc
+ *
+ * NAME
+ *
+ * static inline SilcUInt32 silc_rolc(SilcUInt32 val, const int num);
+ *
+ * DESCRIPTION
+ *
+ * Rotate 32-bit integer's bits to left `num' times. Bits pushed to the
+ * left will appear from the right side of the integer, thus rotating.
+ * Returns the rotated value.
+ *
+ ***/
+static inline SilcUInt32 silc_rolc(SilcUInt32 val, const int num)
+{
+#if (defined(SILC_I386) || defined(SILC_X86_64)) && defined(__GNUC__)
+ asm volatile ("roll %2, %0"
+ : "=r" (val) : "0" (val), "I" (num));
return val;
#else
return ((val << (SilcUInt32)num) | (val >> (32 - (SilcUInt32)num)));
{
#if (defined(SILC_I386) || defined(SILC_X86_64)) && defined(__GNUC__)
asm volatile ("rorl %%cl, %0"
- : "=q" (val) : "0" (val), "c" (num));
+ : "=r" (val) : "0" (val), "c" (num));
+ return val;
+#else
+ return ((val >> (SilcUInt32)num) | (val << (32 - (SilcUInt32)num)));
+#endif /* (SILC_I486 || SILC_X86_64) && __GNUC__ */
+}
+
+/****d* silcutil/silc_rorc
+ *
+ * NAME
+ *
+ * static inline SilcUInt32 silc_ror(SilcUInt32 val, const int num);
+ *
+ * DESCRIPTION
+ *
+ * Rotate 32-bit integer's bits to right `num' times. Bits pushed to the
+ * right will appear from the left side of the integer, thus rotating.
+ * Returns the rotated value.
+ *
+ ***/
+static inline SilcUInt32 silc_rorc(SilcUInt32 val, const int num)
+{
+#if (defined(SILC_I386) || defined(SILC_X86_64)) && defined(__GNUC__)
+ asm volatile ("rorl %2, %0"
+ : "=r" (val) : "0" (val), "I" (num));
return val;
#else
return ((val >> (SilcUInt32)num) | (val << (32 - (SilcUInt32)num)));
{
#if defined(SILC_X86_64) && defined(__GNUC__)
asm volatile ("rolq %%cl, %0"
- : "=q" (val) : "0" (val), "c" (num));
+ : "=r" (val) : "0" (val), "c" (num));
+ return val;
+#else
+ return ((val << (SilcUInt64)num) | (val >> (64 - (SilcUInt64)num)));
+#endif /* SILC_X86_64 && __GNUC__ */
+}
+
+/****d* silcutil/silc_rolc64
+ *
+ * NAME
+ *
+ * static inline SilcUInt64 silc_rolc64(SilcUInt64 val, const int num);
+ *
+ * DESCRIPTION
+ *
+ * Rotate 64-bit integer's bits to left `num' times. Bits pushed to the
+ * left will appear from the right side of the integer, thus rotating.
+ * Returns the rotated value.
+ *
+ ***/
+static inline SilcUInt64 silc_rolc64(SilcUInt64 val, const int num)
+{
+#if defined(SILC_X86_64) && defined(__GNUC__)
+ asm volatile ("rolq %2, %0"
+ : "=r" (val) : "0" (val), "J" (num));
return val;
#else
return ((val << (SilcUInt64)num) | (val >> (64 - (SilcUInt64)num)));
{
#if defined(SILC_X86_64) && defined(__GNUC__)
asm volatile ("rorq %%cl, %0"
- : "=q" (val) : "0" (val), "c" (num));
+ : "=r" (val) : "0" (val), "c" (num));
+ return val;
+#else
+ return ((val >> (SilcUInt64)num) | (val << (64 - (SilcUInt64)num)));
+#endif /* SILC_X86_64 && __GNUC__ */
+}
+
+/****d* silcutil/silc_rorc64
+ *
+ * NAME
+ *
+ * static inline SilcUInt64 silc_rorc64(SilcUInt64 val, const int num);
+ *
+ * DESCRIPTION
+ *
+ * Rotate 64-bit integer's bits to right `num' times. Bits pushed to the
+ * right will appear from the left side of the integer, thus rotating.
+ * Returns the rotated value.
+ *
+ ***/
+static inline SilcUInt64 silc_rorc64(SilcUInt64 val, const int num)
+{
+#if defined(SILC_X86_64) && defined(__GNUC__)
+ asm volatile ("rorq %2, %0"
+ : "=r" (val) : "0" (val), "J" (num));
return val;
#else
return ((val >> (SilcUInt64)num) | (val << (64 - (SilcUInt64)num)));
*
***/
#if defined(__GNUC__)
-#define silc_attribute(attrlist) __attribute__(attrlist)
+#define silc_attribute(attrlist) __attribute__ (attrlist)
#else
#define silc_attribute(attrlist)
#endif /* __GNUC__ */