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: Re: [PATCH] ash, lsh: Avoid code duplication Date: Tue, 22 Nov 2016 01:20:51 +0900 Message-ID: <87d1ho953w.fsf@gmail.com> References: <87inrg99in.fsf@gmail.com> <83k2bw9673.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1479745292 12461 195.159.176.226 (21 Nov 2016 16:21:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 21 Nov 2016 16:21:32 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: Tino Calancha , emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 21 17:21:22 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 1c8rLN-0001Xx-B0 for ged-emacs-devel@m.gmane.org; Mon, 21 Nov 2016 17:21:21 +0100 Original-Received: from localhost ([::1]:50429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8rLQ-0007T9-Qs for ged-emacs-devel@m.gmane.org; Mon, 21 Nov 2016 11:21:24 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41615) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8rLK-0007SW-FW for emacs-devel@gnu.org; Mon, 21 Nov 2016 11:21:19 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c8rLG-0002tj-FM for emacs-devel@gnu.org; Mon, 21 Nov 2016 11:21:18 -0500 Original-Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:35143) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c8rLG-0002tV-96; Mon, 21 Nov 2016 11:21:14 -0500 Original-Received: by mail-pf0-x244.google.com with SMTP id i88so18533965pfk.2; Mon, 21 Nov 2016 08:21:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:in-reply-to:references:user-agent:cc:date :message-id:mime-version; bh=nYHLmZb8087eXBtr3TPGJTQOWf87WZ1CLdfd6MfpVsU=; b=OcP7sUqIRla6DQSy4ewT/JJ2eX4fAfn7U3L3QEpf2eFVl5grRi86SYmEG3liY8kWbU y5O+9N9sBo3txusoV9NGynecw0+K9vrdmwMc82Nveo/pLbKddUum4flzCZJO8NJoQrp2 Lhn/yNTKOv3JKK4E3Uth57orywsIdOhhcdSDIETPPTfCMRYbMB09Zr9CyBEsxaFK69VK gsA1U5pJAWlQMxpttgidlxD8CJT/m8H2tgTyPiUk0cofS+Jq3c0bvs6bv+3xxWO2xOvZ UpRuP8FA0FJ/R7Za/RqUS0RLL2d6tIW11J+pmE8o27GPkKHXXoFUBxqXvAdwgOS9oKW2 45KA== 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:in-reply-to:references :user-agent:cc:date:message-id:mime-version; bh=nYHLmZb8087eXBtr3TPGJTQOWf87WZ1CLdfd6MfpVsU=; b=ibUs6Utjm7RoBnZWKFlK6UFbuHkU/HE87Ez+ALM8zZh4bKi4MhHjCLLuioFfMW2Q6U o9F+Ed+nTZ3MuGpDuDfRnpgnfo5DzNK6r3JfV6kij9Nkudqjcp8dgSQJIJl05pQxuw3t SARIGERyrkQqMkjw4mZDK73qfY07K+heTBohiPYB/VSF3rm7LuCcFoMpP/rCqfxjn0P9 EcP1ubFsY4dTEL0mBOghcni583xxuR65i03SBXtLRb3/T7+b6EIo6HoqwjPjwGjD7Ax+ BeSTzaEHjPDdq61WwzDyH0eagnKp29XFwN27KCF+6EC4X+iXFSSGkKj+AhZHjUvx0r9G ZvNw== X-Gm-Message-State: AKaTC006TEVm5ZFcaw6dQQi0DARDsDDhBZHbj2eMlyf8NMItbVivzAJVSw1SkEkdQQExng== X-Received: by 10.98.78.88 with SMTP id c85mr19271965pfb.138.1479745273096; Mon, 21 Nov 2016 08:21:13 -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 z9sm20703751pge.44.2016.11.21.08.21.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Nov 2016 08:21:12 -0800 (PST) In-Reply-To: <83k2bw9673.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 21 Nov 2016 17:57:20 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::244 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:209525 Archived-At: Eli Zaretskii writes: >> From: Tino Calancha >> Date: Mon, 21 Nov 2016 23:45:36 +0900 >> Cc: tino.calancha@gmail.com >> >> `ash' and `lsh' show some overlap. >> How about following patch? > > With some more work (see below), and if no one objects, why not? > >> +Lisp_Object >> +ash_lsh_impl (register Lisp_Object value, Lisp_Object count, int lsh) > ^^^^^^^ > 'bool', please. > >> --- 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); > > No need to make it extern, as no other C file uses it. Thank you. Following is the new patch after your comments: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From 8ca2e201efcbf93b0e7450cc1a72bb3f6c6f23d4 Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Tue, 22 Nov 2016 01:09:50 +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..a34230f 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, 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, diff --git a/src/lisp.h b/src/lisp.h index e087828..c48c2c8 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); +Lisp_Object ash_lsh_impl (Lisp_Object, Lisp_Object, bool); /* 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