Optimize 'string-hash'.
[bpt/guile.git] / libguile / vm-i-scheme.c
index bcd8134..162efab 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+/* Copyright (C) 2001, 2009-2014 Free Software Foundation, Inc.
  * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
@@ -236,10 +236,12 @@ VM_DEFINE_FUNCTION (149, ge, "ge?", 2)
 #if SCM_GNUC_PREREQ (4, 5) && (defined __x86_64__ || defined __i386__)
 
 # undef _CX
-# ifdef __x86_64__
+# if SIZEOF_VOID_P == 8
 #  define _CX "rcx"
-# else
+# elif SIZEOF_VOID_P == 4
 #  define _CX "ecx"
+# else
+#  error unsupported word size
 # endif
 
 /* The macros below check the CPU's overflow flag to improve fixnum
@@ -360,7 +362,7 @@ VM_DEFINE_FUNCTION (149, ge, "ge?", 2)
       {                                                                        \
        scm_t_signed_bits rlo, rhi;                                     \
        asm ("smull %0, %1, %2, %3\n"                                   \
-            : "=r" (rlo), "=r" (rhi)                                   \
+            : "=&r" (rlo), "=&r" (rhi)                                 \
             : "r" (SCM_UNPACK (x) - scm_tc2_int),                      \
               "r" (SCM_I_INUM (y)));                                   \
        if (SCM_LIKELY (SCM_SRS (rlo, 31) == rhi))                      \
@@ -486,12 +488,11 @@ VM_DEFINE_FUNCTION (159, ash, "ash", 2)
   if (SCM_I_INUMP (x) && SCM_I_INUMP (y))
     {
       if (SCM_I_INUM (y) < 0)
-        {
-          /* Right shift, will be a fixnum. */
-          if (SCM_I_INUM (y) > -SCM_I_FIXNUM_BIT)
-            RETURN (SCM_I_MAKINUM (SCM_I_INUM (x) >> -SCM_I_INUM (y)));
-          /* fall through */
-        }
+        /* Right shift, will be a fixnum. */
+        RETURN (SCM_I_MAKINUM
+                (SCM_SRS (SCM_I_INUM (x),
+                          (-SCM_I_INUM (y) <= SCM_I_FIXNUM_BIT-1)
+                          ? -SCM_I_INUM (y) : SCM_I_FIXNUM_BIT-1)));
       else
         /* Left shift. See comments in scm_ash. */
         {
@@ -504,7 +505,9 @@ VM_DEFINE_FUNCTION (159, ash, "ash", 2)
               && ((scm_t_bits)
                   (SCM_SRS (nn, (SCM_I_FIXNUM_BIT-1 - bits_to_shift)) + 1)
                   <= 1))
-            RETURN (SCM_I_MAKINUM (nn << bits_to_shift));
+            RETURN (SCM_I_MAKINUM (nn < 0
+                                   ? -(-nn << bits_to_shift)
+                                   : (nn << bits_to_shift)));
           /* fall through */
         }
       /* fall through */