Added silc_rolc, silc_rorc, silc_rolc64 and silc_rorc64
authorPekka Riikonen <priikone@silcnet.org>
Sat, 23 Feb 2008 13:39:16 +0000 (15:39 +0200)
committerPekka Riikonen <priikone@silcnet.org>
Sat, 23 Feb 2008 13:39:16 +0000 (15:39 +0200)
configure.ad
lib/silcutil/silctypes.h

index 5b6c9510ea798d671642b2a8eaa34673ff01374d..c9c292c9367acf22e662677823281f3bd9ca9dc7 100644 (file)
@@ -197,17 +197,15 @@ if test x$want_cpu_optimizations = xtrue; then
   # Set some compiler options based on CPU
   if test "x$CC" = "xicc"; then
     # ICC flags
-    if test x$x_have_cpu_sse2 = xtrue; then
-      SILC_ADD_CFLAGS(-axW)
-    fi
-    if test x$x_have_cpu_sse3 = xtrue; then
-      SILC_ADD_CFLAGS(-axP)
+    if test x$x_have_cpu_sse4 = xtrue; then
+      SILC_ADD_CFLAGS(-axS)
     fi
     if test x$x_have_cpu_ssse3 = xtrue; then
       SILC_ADD_CFLAGS(-axT)
-    fi
-    if test x$x_have_cpu_sse4 = xtrue; then
-      SILC_ADD_CFLAGS(-axS)
+    elif test x$x_have_cpu_pni = xtrue; then
+      SILC_ADD_CFLAGS(-axP)
+    elif test x$x_have_cpu_sse2 = xtrue; then
+      SILC_ADD_CFLAGS(-axW)
     fi
   else
     # Other compilers
index 8a9c53bca431c6bea869c6aedbca4d2d3e1a3a2d..bd93559bbb53f33fb655e33c69b6227af54bbc19 100644 (file)
@@ -821,7 +821,31 @@ static inline SilcUInt32 silc_rol(SilcUInt32 val, int num)
 {
 #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)));
@@ -845,7 +869,31 @@ static inline SilcUInt32 silc_ror(SilcUInt32 val, int 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)));
@@ -869,7 +917,31 @@ static inline SilcUInt64 silc_rol64(SilcUInt64 val, int 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)));
@@ -893,7 +965,31 @@ static inline SilcUInt64 silc_ror64(SilcUInt64 val, int 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)));
@@ -931,7 +1027,7 @@ static inline SilcUInt64 silc_ror64(SilcUInt64 val, int num)
  *
  ***/
 #if defined(__GNUC__)
-#define silc_attribute(attrlist) __attribute__(attrlist)
+#define silc_attribute(attrlist) __attribute__ (attrlist)
 #else
 #define silc_attribute(attrlist)
 #endif /* __GNUC__ */