From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.devel Subject: Re: Shrinking the C core Date: Mon, 21 Aug 2023 11:26:21 +0000 Message-ID: <87pm3gfxgi.fsf@localhost> References: <20230809094655.793FC18A4654@snark.thyrsus.com> <87y1if8j8t.fsf@linux-m68k.org> <87y1ifi9fv.fsf@dataswamp.org> <87zg2uqdmv.fsf@localhost> <87edk3gbh3.fsf@dataswamp.org> <87jztvnuyb.fsf@localhost> <875y5bdutt.fsf@dataswamp.org> <87y1i6e1uh.fsf@localhost> <874jkub40o.fsf@dataswamp.org> <87jztqdw2l.fsf@localhost> <87msym9i4r.fsf@dataswamp.org> <87a5ula1zt.fsf@dataswamp.org> <87jzto6hct.fsf@localhost> <87bkf06enk.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16540"; mail-complaints-to="usenet@ciao.gmane.io" Cc: incal@dataswamp.org, emacs-devel@gnu.org To: "Alfred M. Szmidt" , Andrea Corallo Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Aug 21 13:26:34 2023 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qY33I-00041G-Bb for ged-emacs-devel@m.gmane-mx.org; Mon, 21 Aug 2023 13:26:32 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qY32m-0003Fd-20; Mon, 21 Aug 2023 07:26:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qY32k-0003FQ-9d for emacs-devel@gnu.org; Mon, 21 Aug 2023 07:25:58 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qY32h-00057O-IY for emacs-devel@gnu.org; Mon, 21 Aug 2023 07:25:58 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 8C3F2240101 for ; Mon, 21 Aug 2023 13:25:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1692617153; bh=z6dXwv1LPuRj9hyAfgfHBWazGegnc5T6fPqnHF8juzc=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=M1BpjcR7DBHVhgzR3tGxsbbZM7/I004QnMcX6PxSeZ7/YLCmn/faBBrA2FTBYPLyN vXGR4msaNpTF5u7VIP+GQASZnmWdTq0fQjg9zTOlOxk2rilQ/ZQ2gITjg1pLDiGPvA M6Ycq46U7AEG7PwGcDX8cmZ+Z0ludidfUtdMaVsBXsU7p/qdEw8ySbAIYQiisUm+r+ eE6JszqgwMIbdNdNwOEqREec6voy27Y4lTCX7tUbGwXokSb2Q6vJPS70CaeUlhf+V5 tba8A92rbce7427xjoAybewyIh8JOHSU6M4i+cp/FATcXstjEivhl8L1loX9th8g/N LXZTaVwQ9rADQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4RTqsq2gzhz6tyq; Mon, 21 Aug 2023 13:25:51 +0200 (CEST) In-Reply-To: Received-SPF: pass client-ip=185.67.36.66; envelope-from=yantar92@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:309059 Archived-At: "Alfred M. Szmidt" 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 : 1100: 48 8b 05 c1 2e 00 00 mov 0x2ec1(%rip),%rax # 3fc8 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 : 1100: 48 8b 05 c9 2e 00 00 mov 0x2ec9(%rip),%rax # 3fd0 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 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 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 . Support Org development at , or support my work at