From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.devel Subject: [PATCH] ash, lsh: Avoid code duplication Date: Mon, 21 Nov 2016 23:45:36 +0900 Message-ID: <87inrg99in.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1479739558 25139 195.159.176.226 (21 Nov 2016 14:45:58 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 21 Nov 2016 14:45:58 +0000 (UTC) Cc: tino.calancha@gmail.com To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 21 15:45:52 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c8pqx-0005Ou-FT for ged-emacs-devel@m.gmane.org; Mon, 21 Nov 2016 15:45:51 +0100 Original-Received: from localhost ([::1]:49815 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8pr1-0000dm-0E for ged-emacs-devel@m.gmane.org; Mon, 21 Nov 2016 09:45:55 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8pqr-0000b1-4Q for emacs-devel@gnu.org; Mon, 21 Nov 2016 09:45:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c8pqn-0004RN-Tq for emacs-devel@gnu.org; Mon, 21 Nov 2016 09:45:45 -0500 Original-Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:35899) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c8pqn-0004QI-I6 for emacs-devel@gnu.org; Mon, 21 Nov 2016 09:45:41 -0500 Original-Received: by mail-pg0-x243.google.com with SMTP id x23so28785694pgx.3 for ; Mon, 21 Nov 2016 06:45:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:cc:date:message-id:mime-version; bh=sPhMCfpDB79ZnGh0LlAT83qxv7CZy2cYTHr07PS5sZE=; b=Stenjm7PTfokQq8fQYNmdNDW52m+JFgiOg0tvvAnt1sS+8lDq1dP74pL/JP7gWG/Fs 6svSz39wNL5Vowmz73pDwXNDdOWKWzRZvnQpwX0NxKx3sUvpUqFuLCl8RNFNDWuoL7fV 3M5ePEV1rBPi4mDg7g7IFZvfyF4ljXEY8l9ofHRmaEm6remTNaeQQSIAsPGM78DoI06q hhRgHHGu0IPEIAGFZlcR2wFwedpXLcHmrXgaWh6tI79lRgwd/QM89+oCR177n6MQkPLY a2iHVygXIIgRiX6mxdGSdNBt5IoT6JJiX7H/YKnPrjs5Uu49Bdt5wWfTiPvcnGDb+O1S j1Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:cc:date:message-id:mime-version; bh=sPhMCfpDB79ZnGh0LlAT83qxv7CZy2cYTHr07PS5sZE=; b=G4COjBdea7sWP5p+JRZJueF1Dfzi+DKsrTiXTyFGBsOvzUl3Z4Ssnso75MkscqJYVD nRMctoWGnuIvac57ei90+aH0WqOY7+UdL4Kohp3H6zn6EXmVjNvLrw7FrmRGRYhw8gsY xpUmT5i1HTwMXId3J02O12yeTrn1iH9Hz3agWsWMYqZtKoP6h+fcSmIXWcAOFt+Za1lC Rw5ZnaXLUAM4BT/ebTqic4/w/4PLVzzvhGIBUkx/i1DC4S+znmBY+008XbbKLFxPruCv VDBtIIi4yIy+KqDREytxfVQlXleJd+trZpG8ZOK1uScn0AkMKIJ1RRomL1zFbbl9mQ9F kzUQ== X-Gm-Message-State: AKaTC01+DqSvSQGWeU+3AuVJRy/9cqFy0sXU1iwJM+c6QB3hr6gkSIsf8ZjFyd7gfDoebw== X-Received: by 10.98.204.72 with SMTP id a69mr18699106pfg.76.1479739539234; Mon, 21 Nov 2016 06:45:39 -0800 (PST) Original-Received: from calancha-pc (57.92.100.220.dy.bbexcite.jp. [220.100.92.57]) by smtp.gmail.com with ESMTPSA id 74sm20257829pge.2.2016.11.21.06.45.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Nov 2016 06:45:38 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::243 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:209523 Archived-At: Hi, `ash' and `lsh' show some overlap. How about following patch? Thank you. Tino ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From ad93a75357efefa850e6030a2a34aa946fd65332 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Mon, 21 Nov 2016 22:44:53 +0900 Subject: [PATCH] ash, lsh avoid code duplication * src/data.c (ash_lsh_impl): New function. (ash, lsh): Use it. * src/lisp.h (ash_lsh_impl): Declare it. --- src/data.c | 36 +++++++++++++++--------------------- src/lisp.h | 1 + 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/data.c b/src/data.c index d221db4..9391943 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) +Lisp_Object +ash_lsh_impl (register Lisp_Object value, Lisp_Object count, int 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 == 1 ? 0 : XINT (value) < 0 ? -1 : 0); else - XSETINT (val, XINT (value) >> -XINT (count)); + XSETINT (val, lsh == 1 ? 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, 0); +} + 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, 1); } DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0, diff --git a/src/lisp.h b/src/lisp.h index e087828..00687d7 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -602,6 +602,7 @@ extern void char_table_set (Lisp_Object, int, Lisp_Object); /* Defined in data.c. */ extern _Noreturn Lisp_Object wrong_type_argument (Lisp_Object, Lisp_Object); extern _Noreturn void wrong_choice (Lisp_Object, Lisp_Object); +extern Lisp_Object ash_lsh_impl (Lisp_Object, Lisp_Object, int); /* Defined in emacs.c. */ #ifdef DOUG_LEA_MALLOC -- 2.10.2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 26.0.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.3) of 2016-11-21 Repository revision: 209d85fe5691a9334e14bc63b0c836880831a054