unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Re: [PATCH] Add new lisp function length= with bytecode support
Date: Sun, 12 Mar 2017 23:20:58 -0400	[thread overview]
Message-ID: <jwvpohlub3d.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: STFphb4sMxsPDyCNhhRfPdpYIeUcBDEbs0xGysYQCLLtoLXpiwQH6d0BnJeKZffzxdotBeceB0nxV1YXlF3ea2h_iPg4XiM747A_GVI7ca8=@protonmail.com

> When the bytecode interpreter encounters a length bytecode with a list
> argument followed by a comparison bytecode it defers to the new special
> purpose length comparison functions.
> * src/bytecode.c (exec_byte_code): Change the Blength bytecode case and add
> the new functions.
> * lisp/emacs-lisp/byte-opt.el (byte-optimize-binary-predicate,
> byte-optimize-predicate): Make the byte-compiler put the length and
> comparison bytecodes next to each other when possible.
> * src/lisp.h (length_Beqlsign, length_Bgtr, length_Blss, length_Bleq,
> length_Bgeq, length_Beq): Declare new C functions.

I like that.

> +	      switch (PEEK)
> +		{
> +		case Beqlsign:
> +		  op = FETCH;
> +		  v1 = POP;
> +		  TOP = length_Beqlsign (TOP, v1);
> +		  break;
> +
> +		case Bgtr:
> +		  op = FETCH;
> +		  v1 = POP;
> +		  TOP = length_Bgtr (TOP, v1);
> +		  break;
> +
> +		case Blss:
> +		  op = FETCH;
> +		  v1 = POP;
> +		  TOP = length_Blss (TOP, v1);
> +		  break;
> +
> +		case Bleq:
> +		  op = FETCH;
> +		  v1 = POP;
> +		  TOP = length_Bleq (TOP, v1);
> +		  break;
> +
> +		case Bgeq:
> +		  op = FETCH;
> +		  v1 = POP;
> +		  TOP = length_Bgeq (TOP, v1);
> +		  break;
> +
> +		case Beq:
> +		case Bequal:
> +		  op = FETCH;
> +		  v1 = POP;
> +		  TOP = length_Beq (TOP, v1);
> +		  break;
> +
> +		default:
> +		  TOP = Flength (TOP);
> +		}
> +	    }

Please move most of that to a separate function (which I guess will take
the list, the op and the value to which to compare the list).

> +/* The following are used above in the Blength case. Each assumes s1
> +   is a number or marker and s2 is a list. */
> +
> +Lisp_Object
> +length_Beqlsign (Lisp_Object s1, Lisp_Object s2)
> +{
> +  Lisp_Object val = Qnil;
> +
> +  CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (s1);
> +
> +  if (__builtin_expect (FLOATP (s1), 0))
> +    {
> +      s2 = Flength(s2);
> +      val = arithcompare (s1, s2, ARITH_EQUAL);
> +    }
> +  else
> +    {
> +      intptr_t n = XINT (s1);
> +      intptr_t i = 0;
> +      FOR_EACH_TAIL (s2)
> +	{
> +	  i++;
> +	  if (i > n)
> +	    return val;
> +	}
> +      CHECK_LIST_END (s2, s2);
> +      if (i == n)
> +	val = Qt;
> +    }
> +
> +  return val;
> +}
> +
> +Lisp_Object
> +length_Bgtr (Lisp_Object s1, Lisp_Object s2)
> +{
> +  Lisp_Object val = Qnil;
> +
> +  CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (s1);
> +
> +  if (__builtin_expect (FLOATP (s1), 0))
> +    {
> +      s2 = Flength(s2);
> +      val = arithcompare (s1, s2, ARITH_GRTR);
> +    }
> +  else
> +    {
> +      intptr_t n = XINT (s1);
> +      intptr_t i = 0;
> +      FOR_EACH_TAIL (s2)
> +	{
> +	  i++;
> +	  if (i >= n)
> +	    return val;
> +	}
> +      CHECK_LIST_END (s2, s2);
> +      if (i < n)
> +	val = Qt;
> +    }
> +
> +  return val;
> +}

Similarly, here (and below), I'm wondering if we can't reduce the code
duplication.  Furthermore, you might like to declare them static, so the
compiler is more likely to inline them.

> +Lisp_Object length_Beqlsign (Lisp_Object, Lisp_Object);
> +Lisp_Object length_Bgtr (Lisp_Object, Lisp_Object);
> +Lisp_Object length_Blss (Lisp_Object, Lisp_Object);
> +Lisp_Object length_Bleq (Lisp_Object, Lisp_Object);
> +Lisp_Object length_Bgeq (Lisp_Object, Lisp_Object);
> +Lisp_Object length_Beq (Lisp_Object, Lisp_Object);
 
Don't expose them in lisp.h, since they're only used in bytecode.c.


        Stefan




  reply	other threads:[~2017-03-13  3:20 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-26 22:04 [PATCH] Add new lisp function length= with bytecode support Gdobbins
2017-02-27 16:14 ` Eli Zaretskii
2017-02-27 18:43   ` Gdobbins
2017-02-27 23:06     ` Paul Eggert
2017-02-28  0:35       ` Gdobbins
2017-02-28  9:24 ` Andreas Schwab
2017-03-06  1:59   ` Gdobbins
2017-03-06  6:13     ` Elias Mårtenson
2017-03-06  7:43       ` John Wiegley
2017-03-06 18:00         ` Richard Stallman
2017-03-06 20:36           ` Gdobbins
2017-03-06 20:45             ` Clément Pit-Claudel
2017-03-06 21:03               ` Gdobbins
2017-03-07  0:29                 ` Gdobbins
2017-03-10 10:20                   ` Ken Raeburn
2017-03-10 22:25                     ` Gdobbins
2017-03-13  2:51                       ` Gdobbins
2017-03-13  3:20                         ` Stefan Monnier [this message]
2017-03-14  6:06                           ` Gdobbins
  -- strict thread matches above, loose matches on Subject: below --
2017-03-07 13:52 Constantin Kulikov
2017-03-08  2:00 ` Gdobbins
2017-03-08  2:46   ` Stefan Monnier
2017-03-08  3:31     ` Gdobbins
2017-03-08  4:13       ` Stefan Monnier
2017-03-08  7:01         ` Gdobbins
2017-03-08 16:47           ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvpohlub3d.fsf-monnier+gmane.emacs.devel@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).