From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Andrea Corallo Newsgroups: gmane.emacs.bugs Subject: bug#41615: [feature/native-comp] Dump prettier C code. Date: Sun, 31 May 2020 10:45:09 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="58081"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) Cc: 41615@debbugs.gnu.org To: Nicolas =?UTF-8?Q?B=C3=A9rtolo?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun May 31 12:46:12 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1jfLTo-000F3L-2F for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 31 May 2020 12:46:12 +0200 Original-Received: from localhost ([::1]:55448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jfLTn-0005vc-0s for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 31 May 2020 06:46:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jfLTe-0005tY-2n for bug-gnu-emacs@gnu.org; Sun, 31 May 2020 06:46:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48303) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jfLTd-0001Zt-Pj for bug-gnu-emacs@gnu.org; Sun, 31 May 2020 06:46:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jfLTd-0005Ln-OF for bug-gnu-emacs@gnu.org; Sun, 31 May 2020 06:46:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andrea Corallo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 31 May 2020 10:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41615 X-GNU-PR-Package: emacs Original-Received: via spool by 41615-submit@debbugs.gnu.org id=B41615.159092191320510 (code B ref 41615); Sun, 31 May 2020 10:46:01 +0000 Original-Received: (at 41615) by debbugs.gnu.org; 31 May 2020 10:45:13 +0000 Original-Received: from localhost ([127.0.0.1]:59849 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jfLSq-0005Kk-Ik for submit@debbugs.gnu.org; Sun, 31 May 2020 06:45:12 -0400 Original-Received: from mx.sdf.org ([205.166.94.20]:51776) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jfLSo-0005Kb-LP for 41615@debbugs.gnu.org; Sun, 31 May 2020 06:45:11 -0400 Original-Received: from sdf.org (ma.sdf.org [205.166.94.33]) by mx.sdf.org (8.15.2/8.14.5) with ESMTPS id 04VAj980019823 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits) verified NO); Sun, 31 May 2020 10:45:09 GMT Original-Received: (from akrl@localhost) by sdf.org (8.15.2/8.12.8/Submit) id 04VAj9Nw000960; Sun, 31 May 2020 10:45:09 GMT In-Reply-To: ("Nicolas =?UTF-8?Q?B=C3=A9rtolo?="'s message of "Sat, 30 May 2020 19:20:13 -0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181276 Archived-At: Nicolas B=C3=A9rtolo writes: > I have reformatted the patches. > > Sorry for the inconveniences. > > From ef7b9b95cff6824af041a7536588334aeed1ee12 Mon Sep 17 00:00:00 2001 > From: =3D?UTF-8?q?Nicol=3DC3=3DA1s=3D20B=3DC3=3DA9rtolo?=3D > Date: Sat, 30 May 2020 18:33:58 -0300 > Subject: [PATCH 2/2] Define casts using functions. > > This is to dump prettier C files. > This does not affect compilation times in my tests. > > * src/comp.c: Define a 15x15 cast matrix. Use it in emit_coerce(). I like the idea of the patch. I've tested it too and I do not see compile time overhead. > src/comp.c | 279 ++++++++++++++++++++--------------------------------- > 1 file changed, 106 insertions(+), 173 deletions(-) > > diff --git a/src/comp.c b/src/comp.c > index 2f78760764..9d8445de9a 100644 > --- a/src/comp.c > +++ b/src/comp.c > @@ -455,6 +455,8 @@ #define F_RELOC_MAX_SIZE 1500 >=20=20 > static f_reloc_t freloc; >=20=20 > +#define NUM_CAST_TYPES 15 > + > /* C side of the compiler context. */ >=20=20 [...] > +static gcc_jit_function * > +define_cast_from_to (struct cast_type from, int from_index, struct cast_= type to, > + int to_index) > +{ > + Lisp_Object name =3D CALLN (Fformat, > + build_string ("cast_from_%s_to_%s"), > + build_string (from.name), > + build_string (to.name)); Minor, for other code if we know strings are not very long we use format_string not to allocate. Libgccjit copy the string by itself. > + gcc_jit_param *param =3D gcc_jit_context_new_param (comp.ctxt, NULL, > + from.type, "arg"); > + gcc_jit_function *result =3D gcc_jit_context_new_function (comp.ctxt, > NULL, > - comp.lisp_word_tag_type, > - "lisp_word_tag"); > - comp.cast_union_as_lisp_obj_ptr =3D > - gcc_jit_context_new_field (comp.ctxt, > - NULL, > - comp.lisp_obj_ptr_type, > - "lisp_obj_ptr"); > - > - > - gcc_jit_field *cast_union_fields[] =3D > - { comp.cast_union_as_ll, > - comp.cast_union_as_ull, > - comp.cast_union_as_l, > - comp.cast_union_as_ul, > - comp.cast_union_as_u, > - comp.cast_union_as_i, > - comp.cast_union_as_b, > - comp.cast_union_as_uintptr, > - comp.cast_union_as_ptrdiff, > - comp.cast_union_as_c_p, > - comp.cast_union_as_v_p, > - comp.cast_union_as_lisp_cons_ptr, > - comp.cast_union_as_lisp_word, > - comp.cast_union_as_lisp_word_tag, > - comp.cast_union_as_lisp_obj_ptr }; > + GCC_JIT_FUNCTION_ALWAYS_INLINE, We'll have to keep an eye on this always inline. Depending on the GCC version if the inline fail I've seen these ending-up in a unrecoverable compilation error within libgccjit. > + to.type, > + SSDATA (name), > + 1, > + ¶m, > + 0); > + > + DECL_BLOCK (entry_block, result); > + > + gcc_jit_lvalue *tmp_union > + =3D gcc_jit_function_new_local (result, > + NULL, > + comp.cast_union_type, > + "union_cast"); > + > + gcc_jit_block_add_assignment (entry_block, NULL, > + gcc_jit_lvalue_access_field (tmp_union, = NULL, > + comp.cast_union_fields[from_index]), > + gcc_jit_param_as_rvalue (param)); > + > + gcc_jit_block_end_with_return (entry_block, > + NULL, > + gcc_jit_rvalue_access_field ( > + gcc_jit_lvalue_as_rvalue (tmp_union), > + NULL, > + comp.cast_union_fields[to_index])); > + > + return result; > +} > + > +static void > +define_cast_functions (void) > +{ > + struct cast_type cast_types[NUM_CAST_TYPES] > + =3D {{comp.bool_type, "bool"}, Just a nit, in the rest of the file I used spaces after { for array initializers, I think in this patch previously you did it too. > + {comp.char_ptr_type, "char_ptr"}, > + {comp.int_type, "int"}, > + {comp.lisp_cons_ptr_type, "cons_ptr"}, > + {comp.lisp_obj_ptr_type, "lisp_obj_ptr"}, > + {comp.lisp_word_tag_type, "lisp_word_tag"}, > + {comp.lisp_word_type, "lisp_word"}, > + {comp.long_long_type, "long_long"}, > + {comp.long_type, "long"}, > + {comp.ptrdiff_type, "ptrdiff"}, > + {comp.uintptr_type, "uintptr"}, > + {comp.unsigned_long_long_type, "unsigned_long_long"}, > + {comp.unsigned_long_type, "unsigned_long"}, > + {comp.unsigned_type, "unsigned"}, > + {comp.void_ptr_type, "void_ptr"}}; > + On the subject of 'emit_coerce' in case you like to do more work in the area I think would be good to have an additional boolean parameter called like 'safe'. If this is true and we cast from a smaller size to a bigger one we should zero the cast union first. In case false we should raise an ICE. Thanks Andrea --=20 akrl@sdf.org