[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Add new lisp function length= with bytecode support
From: |
Stefan Monnier |
Subject: |
Re: [PATCH] Add new lisp function length= with bytecode support |
Date: |
Sun, 12 Mar 2017 23:20:58 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) |
> 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
- Re: [PATCH] Add new lisp function length= with bytecode support, (continued)
- Re: [PATCH] Add new lisp function length= with bytecode support, Elias Mårtenson, 2017/03/06
- Re: [PATCH] Add new lisp function length= with bytecode support, John Wiegley, 2017/03/06
- Re: [PATCH] Add new lisp function length= with bytecode support, Richard Stallman, 2017/03/06
- Re: [PATCH] Add new lisp function length= with bytecode support, Gdobbins, 2017/03/06
- Re: [PATCH] Add new lisp function length= with bytecode support, Clément Pit-Claudel, 2017/03/06
- Re: [PATCH] Add new lisp function length= with bytecode support, Gdobbins, 2017/03/06
- Re: [PATCH] Add new lisp function length= with bytecode support, Gdobbins, 2017/03/06
- Re: [PATCH] Add new lisp function length= with bytecode support, Ken Raeburn, 2017/03/10
- Re: [PATCH] Add new lisp function length= with bytecode support, Gdobbins, 2017/03/10
- Re: [PATCH] Add new lisp function length= with bytecode support, Gdobbins, 2017/03/12
- Re: [PATCH] Add new lisp function length= with bytecode support,
Stefan Monnier <=
- Re: [PATCH] Add new lisp function length= with bytecode support, Gdobbins, 2017/03/14
[PATCH] Add new lisp function length= with bytecode support, Constantin Kulikov, 2017/03/07
- Re: [PATCH] Add new lisp function length= with bytecode support, Gdobbins, 2017/03/07
- Re: [PATCH] Add new lisp function length= with bytecode support, Stefan Monnier, 2017/03/07
- Re: [PATCH] Add new lisp function length= with bytecode support, Gdobbins, 2017/03/07
- Re: [PATCH] Add new lisp function length= with bytecode support, Stefan Monnier, 2017/03/07
- Re: [PATCH] Add new lisp function length= with bytecode support, Gdobbins, 2017/03/08
- Re: [PATCH] Add new lisp function length= with bytecode support, Stefan Monnier, 2017/03/08