emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 416adda: ash, lsh avoid code duplication


From: Tino Calancha
Subject: [Emacs-diffs] master 416adda: ash, lsh avoid code duplication
Date: Sun, 27 Nov 2016 03:25:53 +0000 (UTC)

branch: master
commit 416adda38521c6246f77877c57843264fa4ae711
Author: Tino Calancha <address@hidden>
Commit: Tino Calancha <address@hidden>

    ash, lsh avoid code duplication
    
    See discussion in:
    https://lists.gnu.org/archive/html/emacs-devel/2016-11/msg00469.html
    * src/data.c (ash_lsh_impl): New function.
    (ash, lsh): Use it.
---
 src/data.c |   36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

diff --git a/src/data.c b/src/data.c
index d221db4..61b5da8 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2924,11 +2924,8 @@ usage: (logxor &rest INTS-OR-MARKERS)  */)
   return arith_driver (Alogxor, nargs, args);
 }
 
-DEFUN ("ash", Fash, Sash, 2, 2, 0,
-       doc: /* Return VALUE with its bits shifted left by COUNT.
-If COUNT is negative, shifting is actually to the right.
-In this case, the sign bit is duplicated.  */)
-  (register Lisp_Object value, Lisp_Object count)
+static Lisp_Object
+ash_lsh_impl (register Lisp_Object value, Lisp_Object count, bool lsh)
 {
   register Lisp_Object val;
 
@@ -2940,32 +2937,29 @@ In this case, the sign bit is duplicated.  */)
   else if (XINT (count) > 0)
     XSETINT (val, XUINT (value) << XFASTINT (count));
   else if (XINT (count) <= -EMACS_INT_WIDTH)
-    XSETINT (val, XINT (value) < 0 ? -1 : 0);
+    XSETINT (val, lsh ? 0 : XINT (value) < 0 ? -1 : 0);
   else
-    XSETINT (val, XINT (value) >> -XINT (count));
+    XSETINT (val, lsh ? XUINT (value) >> -XINT (count) : \
+                        XINT (value) >> -XINT (count));
   return val;
 }
 
+DEFUN ("ash", Fash, Sash, 2, 2, 0,
+       doc: /* Return VALUE with its bits shifted left by COUNT.
+If COUNT is negative, shifting is actually to the right.
+In this case, the sign bit is duplicated.  */)
+  (register Lisp_Object value, Lisp_Object count)
+{
+  return ash_lsh_impl (value, count, false);
+}
+
 DEFUN ("lsh", Flsh, Slsh, 2, 2, 0,
        doc: /* Return VALUE with its bits shifted left by COUNT.
 If COUNT is negative, shifting is actually to the right.
 In this case, zeros are shifted in on the left.  */)
   (register Lisp_Object value, Lisp_Object count)
 {
-  register Lisp_Object val;
-
-  CHECK_NUMBER (value);
-  CHECK_NUMBER (count);
-
-  if (XINT (count) >= EMACS_INT_WIDTH)
-    XSETINT (val, 0);
-  else if (XINT (count) > 0)
-    XSETINT (val, XUINT (value) << XFASTINT (count));
-  else if (XINT (count) <= -EMACS_INT_WIDTH)
-    XSETINT (val, 0);
-  else
-    XSETINT (val, XUINT (value) >> -XINT (count));
-  return val;
+  return ash_lsh_impl (value, count, true);
 }
 
 DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,



reply via email to

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