guile-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Guile-commits] 03/03: Add fast paths to intrinsics


From: Andy Wingo
Subject: [Guile-commits] 03/03: Add fast paths to intrinsics
Date: Wed, 29 Aug 2018 12:44:55 -0400 (EDT)

wingo pushed a commit to branch lightning
in repository guile.

commit f2089ceee98a261b7e4ea9f9ad0f0ff21b6b05c7
Author: Andy Wingo <address@hidden>
Date:   Wed Aug 29 18:40:56 2018 +0200

    Add fast paths to intrinsics
    
    * libguile/intrinsics.c (add_immediate, sub_immediate, less_p)
      (numerically_equal_p): Add fast paths.  Makes one test locally go from
      .77s interpreted to .60s.
      (scm_to_uint64_truncate): Add a likelihood annotation.
---
 libguile/intrinsics.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/libguile/intrinsics.c b/libguile/intrinsics.c
index 89eed18..0e7fbb4 100644
--- a/libguile/intrinsics.c
+++ b/libguile/intrinsics.c
@@ -64,12 +64,28 @@ SCM_DEFINE (scm_intrinsic_list, "intrinsic-list", 0, 0, 0,
 static SCM
 add_immediate (SCM a, uint8_t b)
 {
+  if (SCM_LIKELY (SCM_I_INUMP (a)))
+    {
+      scm_t_signed_bits sum = SCM_I_INUM (a) + b;
+
+      if (SCM_LIKELY (SCM_POSFIXABLE (sum)))
+        return SCM_I_MAKINUM (sum);
+    }
+
   return scm_sum (a, scm_from_uint8 (b));
 }
 
 static SCM
 sub_immediate (SCM a, uint8_t b)
 {
+  if (SCM_LIKELY (SCM_I_INUMP (a)))
+    {
+      scm_t_signed_bits diff = SCM_I_INUM (a) - b;
+
+      if (SCM_LIKELY (SCM_NEGFIXABLE (diff)))
+        return SCM_I_MAKINUM (diff);
+    }
+
   return scm_difference (a, scm_from_uint8 (b));
 }
 
@@ -90,7 +106,7 @@ string_to_number (SCM str)
 static uint64_t
 scm_to_uint64_truncate (SCM x)
 {
-  if (SCM_I_INUMP (x))
+  if (SCM_LIKELY (SCM_I_INUMP (x)))
     return (uint64_t) SCM_I_INUM (x);
   else
     return scm_to_uint64 (scm_logand (x, scm_from_uint64 ((uint64_t) -1)));
@@ -263,6 +279,13 @@ rsh_immediate (SCM a, uint8_t b)
 static enum scm_compare
 less_p (SCM a, SCM b)
 {
+  if (SCM_LIKELY (SCM_I_INUMP (a) && SCM_I_INUMP (b)))
+    {
+      scm_t_signed_bits a_bits = SCM_UNPACK (a);
+      scm_t_signed_bits b_bits = SCM_UNPACK (b);
+      return a_bits < b_bits ? SCM_F_COMPARE_LESS_THAN : SCM_F_COMPARE_NONE;
+    }
+
   if (scm_is_true (scm_nan_p (a)) || scm_is_true (scm_nan_p (b)))
     return SCM_F_COMPARE_INVALID;
   else if (scm_is_true (scm_less_p (a, b)))
@@ -274,6 +297,9 @@ less_p (SCM a, SCM b)
 static int
 numerically_equal_p (SCM a, SCM b)
 {
+  if (SCM_LIKELY (SCM_I_INUMP (a) && SCM_I_INUMP (b)))
+    return scm_is_eq (a, b);
+
   return scm_is_true (scm_num_eq_p (a, b));
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]