emacs-devel
[Top][All Lists]
Advanced

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

Re: Shrinking the C core


From: Ihor Radchenko
Subject: Re: Shrinking the C core
Date: Mon, 21 Aug 2023 11:26:21 +0000

"Alfred M. Szmidt" <ams@gnu.org> writes:

>    (progn
>      (setq x (list 'a 'b 'c))
>      (listp x))
>
>    `listp' call can definitely be optimized once the compiler knows that
>    `list' returns a list.
>
> A sufficiently smart compiler would optimize that to T sure, the Emacs
> Lisp compiler doesn't.  And that is one of the issues, native
> compilation or not, since right now native compilation gets this to
> work with, and it cannot do magic no matter how much magic dust you
> give it.  
>
> byte code for foo:
>   args: nil
> 0     constant  a
> 1     constant  b
> 2     constant  c
> 3     list3     
> 4     dup       
> 5     varset    x
> 6     listp     
> 7     return    

AFAIK, native compilation should be able to optimize the above byte
code. At least, that's what I thought. But looking at disassembly, it
might actually be not the case.

Oh well. I am clearly missing something about how things work.

(defun test0 ()
  "Return value")

(defun test1 ()
  (let ((x (list 'a 'b 'c)))
    (when (listp x) "Return value")))

(disassemble (byte-compile #'test0))
byte code:
  doc:  Return value
  args: nil
0       constant  "Return value"
1       return    

(native-compile #'test0 "/tmp/test0.eln")
(disassemble #'test0)
0000000000001100 <F7465737430_test0_0>:
    1100:       48 8b 05 c1 2e 00 00    mov    0x2ec1(%rip),%rax        # 3fc8 
<d_reloc@@Base-0x218>
    1107:       48 8b 00                mov    (%rax),%rax
    110a:       c3                      ret
    110b:       0f 1f 44 00 00          nopl   0x0(%rax,%rax,1)

Now, test1

(disassemble (byte-compile #'test1))
byte code:
  args: nil
0       constant  a
1       constant  b
2       constant  c
3       list3     
4       dup       
5       varbind   x
6       listp     
7       goto-if-nil-else-pop 1
10      constant  "Return value"
11:1    unbind    1
12      return    

(native-compile #'test1 "/tmp/test1.eln")
(disassemble #'test1)
0000000000001100 <F7465737431_test1_0>:
    1100:       48 8b 05 c9 2e 00 00    mov    0x2ec9(%rip),%rax        # 3fd0 
<freloc_link_table@@Base-0x268>
    1107:       41 54                   push   %r12
    1109:       31 f6                   xor    %esi,%esi
    110b:       55                      push   %rbp
    110c:       4c 8b 25 b5 2e 00 00    mov    0x2eb5(%rip),%r12        # 3fc8 
<d_reloc@@Base-0x218>
    1113:       53                      push   %rbx
    1114:       48 8b 18                mov    (%rax),%rbx
    1117:       49 8b 7c 24 10          mov    0x10(%r12),%rdi
    111c:       ff 93 d0 20 00 00       call   *0x20d0(%rbx)
    1122:       49 8b 7c 24 08          mov    0x8(%r12),%rdi
    1127:       48 89 c6                mov    %rax,%rsi
    112a:       ff 93 d0 20 00 00       call   *0x20d0(%rbx)
    1130:       49 8b 3c 24             mov    (%r12),%rdi
    1134:       48 89 c6                mov    %rax,%rsi
    1137:       ff 93 d0 20 00 00       call   *0x20d0(%rbx)
    113d:       49 8b 7c 24 20          mov    0x20(%r12),%rdi
    1142:       48 89 c5                mov    %rax,%rbp
    1145:       48 89 c6                mov    %rax,%rsi
    1148:       ff 53 58                call   *0x58(%rbx)
    114b:       48 89 ef                mov    %rbp,%rdi
    114e:       ff 93 30 29 00 00       call   *0x2930(%rbx)
    1154:       48 85 c0                test   %rax,%rax
    1157:       74 17                   je     1170 <F7465737431_test1_0+0x70>
    1159:       49 8b 6c 24 30          mov    0x30(%r12),%rbp
    115e:       bf 06 00 00 00          mov    $0x6,%edi
    1163:       ff 53 28                call   *0x28(%rbx)
    1166:       5b                      pop    %rbx
    1167:       48 89 e8                mov    %rbp,%rax
    116a:       5d                      pop    %rbp
    116b:       41 5c                   pop    %r12
    116d:       c3                      ret
    116e:       66 90                   xchg   %ax,%ax
    1170:       48 89 c5                mov    %rax,%rbp
    1173:       bf 06 00 00 00          mov    $0x6,%edi
    1178:       ff 53 28                call   *0x28(%rbx)
    117b:       48 89 e8                mov    %rbp,%rax
    117e:       5b                      pop    %rbx
    117f:       5d                      pop    %rbp
    1180:       41 5c                   pop    %r12
    1182:       c3                      ret
    1183:       66 66 2e 0f 1f 84 00    data16 cs nopw 0x0(%rax,%rax,1)
    118a:       00 00 00 00 
    118e:       66 90                   xchg   %ax,%ax


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

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