From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.devel Subject: Emacs Lisp JIT Compiler Date: Sun, 12 Aug 2018 22:01:34 -0600 Message-ID: <87va8ej4o1.fsf@tromey.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1534132785 31303 195.159.176.226 (13 Aug 2018 03:59:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 13 Aug 2018 03:59:45 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 13 05:59:41 2018 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 1fp413-000821-VS for ged-emacs-devel@m.gmane.org; Mon, 13 Aug 2018 05:59:38 +0200 Original-Received: from localhost ([::1]:37413 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp43A-0007mB-GN for ged-emacs-devel@m.gmane.org; Mon, 13 Aug 2018 00:01:48 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp433-0007m6-Co for emacs-devel@gnu.org; Mon, 13 Aug 2018 00:01:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp430-0001sU-9q for emacs-devel@gnu.org; Mon, 13 Aug 2018 00:01:41 -0400 Original-Received: from gateway24.websitewelcome.com ([192.185.51.162]:12748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fp430-0001r6-10 for emacs-devel@gnu.org; Mon, 13 Aug 2018 00:01:38 -0400 Original-Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway24.websitewelcome.com (Postfix) with ESMTP id D12E2EE94 for ; Sun, 12 Aug 2018 23:01:36 -0500 (CDT) Original-Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id p42xfszD9BcCXp42xfRc42; Sun, 12 Aug 2018 23:01:36 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:Date:Subject:To:From: Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=S63koBbAumXSUfOV4lq/P+joHcVnimjvvrUF+AoTuQc=; b=LFmKHriKm9N1/TuoJdWD3966zU 5T/cWrGeS2r2o7QKtSkRPkzGqV3/Ra4T3DNFu8Wg1yB7juR/tsVAFzigPja8CQLquJIvz0faeCubg OLkJPB0SCNcR9GXpPHcj1WGt5; Original-Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:60708 helo=bapiya) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fp42x-003AUC-NL; Sun, 12 Aug 2018 23:01:35 -0500 X-Attribution: Tom X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.85.72 X-Source-L: No X-Exim-ID: 1fp42x-003AUC-NL X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-85-72.hlrn.qwest.net (bapiya) [75.166.85.72]:60708 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 192.185.51.162 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:228464 Archived-At: Hi. I've written a JIT compiler for Emacs Lisp, and I'd like to check it in. This JIT is based on GNU libjit, like some other attempts that have come before it. However, this one is somewhat faster than those, primarily because it does all stack manipulations at compile time, not runtime. In some simple benchmarks, it is about 3x faster than the bytecode interpreter. I have only tested this on x86-64. Whether or not the JIT works on a given platform is primarily up to libjit. (I suspect the JIT won't work on x86 with --with-wide-int; but that is something I could fix.) I currently have the JIT set up to always compile all eligible functions (that is, just byte-compiled, lexically-bound functions). It's robust enough that, as far as I can tell, everything works fine in this mode. It would be possible to have it be a bit lazier, say only compile after 100 invocations, or something like that. Aside from the possible --with-wide-int thing, there are two bugs I know of. First, libjit never frees functions. So, if a function is JIT-compiled and then redefined, the old JIT code will linger. It's possible to fix this with a custom allocator and a libjit patch (that I sent but that hasn't been checked in yet). Second, I haven't gotten around to emulating the "quitcounter" behavior in the bytecode interpreter. This seems straightforward. This version of the compiler is pretty basic. It just compiles each bytecode to more or less the obvious thing. I have some plans to make the calling convention a bit less expensive, and to allow for inlining. Note that this change does not involve any semantic changes to Emacs Lisp. Also, if libjit is unavailable, the JIT is simply disabled. Tom